Re: [PATCH v3 07/12] klp-build: Add LoongArch syscall patching macro

Joe Lawrence <[email protected]>
Newsgroups dev.linux.lists.llvm,dev.linux.lists.loongarch,org.kernel.vger.linux-kernel,org.kernel.vger.live-patching
Message-ID <[email protected]>
On Tue, Jul 07, 2026 at 03:20:26PM +0800, George Guo wrote:
> From: George Guo <[email protected]>
> 
> Add LoongArch support for KLP_SYSCALL_DEFINEx(), mirroring the generic
> __SYSCALL_DEFINEx() pattern from include/linux/syscalls.h.
> 
> Co-developed-by: Kexin Liu <[email protected]>
> Signed-off-by: Kexin Liu <[email protected]>
> Signed-off-by: George Guo <[email protected]>
> ---
>  include/linux/livepatch_helpers.h | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/include/linux/livepatch_helpers.h b/include/linux/livepatch_helpers.h
> index 4b647b83865f..a8aad067177b 100644
> --- a/include/linux/livepatch_helpers.h
> +++ b/include/linux/livepatch_helpers.h
> @@ -91,6 +91,28 @@
>  	}								\
>  	static inline long __klp_do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))
>  
> +#elif defined(CONFIG_LOONGARCH)
> +
> +#define __KLP_SYSCALL_DEFINEx(x, name, ...)                             \
> +	__diag_push();                                                  \
> +	__diag_ignore(GCC, 8, "-Wattribute-alias",                      \
> +		      "Type aliasing is used to sanitize syscall arguments");\
> +	asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))       \
> +		__attribute__((alias(__stringify(__se_sys##name))));    \
> +	ALLOW_ERROR_INJECTION(sys##name, ERRNO);                        \
> +	static inline long __klp_do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
> +	asmlinkage long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \
> +	asmlinkage long __attribute__((optimize("-fno-optimize-sibling-calls")))\
> +			__se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__))  \
> +	{                                                               \
> +		long ret = __klp_do_sys##name(__MAP(x,__SC_CAST,__VA_ARGS__));\
> +		__MAP(x,__SC_TEST,__VA_ARGS__);                         \
> +		__PROTECT(x, ret,__MAP(x,__SC_ARGS,__VA_ARGS__));       \
> +		return ret;                                             \
> +	}                                                               \
> +	__diag_pop();                                                   \
> +	static inline long __klp_do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))
> +
>  #endif

Nit: The other macros in livepatch_helpers use tabs to pad out to the
line continuation '\'.

--
Joe
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.