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

From: Joe Lawrence

Date: Wed Jul 08 2026 - 15:18:35 EST


On Tue, Jul 07, 2026 at 03:20:26PM +0800, George Guo wrote:
> From: George Guo <guodongtai@xxxxxxxxxx>
>
> Add LoongArch support for KLP_SYSCALL_DEFINEx(), mirroring the generic
> __SYSCALL_DEFINEx() pattern from include/linux/syscalls.h.
>
> Co-developed-by: Kexin Liu <liukexin@xxxxxxxxxx>
> Signed-off-by: Kexin Liu <liukexin@xxxxxxxxxx>
> Signed-off-by: George Guo <guodongtai@xxxxxxxxxx>
> ---
> 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