From: Yipeng Zou <zouyipeng@huawei.com> hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/release-management/issues/ID5CMS -------------------------------- Add a debug mode that forces the entire system (all tasks, all CPUs) to use the "fast syscall" path for every system-call invocation. The switch is activated at boot with "xcall=debug" on the kernel cmdline. WARNING: This option deliberately bypasses several safety checks and can expose latent bugs in architecture-specific assembly stubs, ptrace, audit, compat or instrumentation code. It is explicitly unsupported for production systems and may render the machine unstable or insecure. Use only in controlled test environments! Signed-off-by: Yipeng Zou <zouyipeng@huawei.com> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> --- arch/arm64/include/asm/xcall.h | 8 ++++++++ arch/arm64/kernel/cpufeature.c | 5 +++++ arch/arm64/kernel/xcall/xcall.c | 12 ++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/xcall.h b/arch/arm64/include/asm/xcall.h index 735a14870e4e..0f70f03cc3a2 100644 --- a/arch/arm64/include/asm/xcall.h +++ b/arch/arm64/include/asm/xcall.h @@ -13,6 +13,14 @@ #define SVC_0000 0xd4000001 #define SVC_FFFF 0xd41fffe1 +/* + * Only can switch by cmdline 'xcall=debug', + * By default xcall init with XCALL_MODE_TASK. + */ +#define XCALL_MODE_TASK 0 +#define XCALL_MODE_SYSTEM 1 +extern int sw_xcall_mode; + struct xcall_comm { char *name; char *binary; diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 625a77760126..7a04e97bd3dc 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -2447,6 +2447,11 @@ static int __init xcall_setup(char *str) { static_branch_enable(&xcall_enable); + if (str && !strcmp(str, "=debug")) { + sw_xcall_mode = XCALL_MODE_SYSTEM; + pr_warn("Enable xcall across the entire system, for debugging only!\n"); + } + return 1; } __setup("xcall", xcall_setup); diff --git a/arch/arm64/kernel/xcall/xcall.c b/arch/arm64/kernel/xcall/xcall.c index 96e6274571d3..35bc959a0a51 100644 --- a/arch/arm64/kernel/xcall/xcall.c +++ b/arch/arm64/kernel/xcall/xcall.c @@ -10,17 +10,25 @@ #include <linux/slab.h> #include <asm/xcall.h> +// Only can switch by cmdline 'xcall=debug' +int sw_xcall_mode = XCALL_MODE_TASK; + static inline int sw_xcall_init_task(struct task_struct *p, struct task_struct *orig) { p->xinfo = kzalloc(sizeof(struct xcall_info), GFP_KERNEL); if (!p->xinfo) return -ENOMEM; - if (orig->xinfo) { + if (!orig->xinfo) + return 0; + + /* In xcall debug mode, all syscalls are enabled by default! */ + if (sw_xcall_mode == XCALL_MODE_SYSTEM) + memset(TASK_XINFO(p)->xcall_enable, 1, (__NR_syscalls + 1) * sizeof(u8)); + else memcpy(TASK_XINFO(p)->xcall_enable, TASK_XINFO(orig)->xcall_enable, (__NR_syscalls + 1) * sizeof(u8)); - } return 0; } -- 2.34.1