From 1b1f3b3e1b3945ae6e49081fd3586a6833d4a555 Mon Sep 17 00:00:00 2001 From: Thomas Gleixner Date: Tue, 7 Jul 2026 21:07:01 +0200 Subject: [PATCH] x86/entry: Get rid of the sys_ni_syscall() indirection Invoking sys_ni_syscall() from a code path, which already knows that the syscall number is invalid just to assign -ENOSYS to regs->ax is a pointless exercise. It's even redundant as the low level entry code already has set regs->ax to -ENOSYS on entry. Remove the extra conditionals and the function calls. Signed-off-by: Thomas Gleixner Tested-by: Mukesh Kumar Chaurasiya (IBM) Reviewed-by: Jinjie Ruan Link: https://patch.msgid.link/20260707190254.493733289@kernel.org --- arch/x86/entry/syscall_32.c | 2 -- arch/x86/entry/syscall_64.c | 10 +++------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/arch/x86/entry/syscall_32.c b/arch/x86/entry/syscall_32.c index 6e00929b893c..68e2f1323003 100644 --- a/arch/x86/entry/syscall_32.c +++ b/arch/x86/entry/syscall_32.c @@ -81,8 +81,6 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs, int nr) if (likely(unr < IA32_NR_syscalls)) { unr = array_index_nospec(unr, IA32_NR_syscalls); regs->ax = ia32_sys_call(regs, unr); - } else if (nr != -1) { - regs->ax = __ia32_sys_ni_syscall(regs); } } diff --git a/arch/x86/entry/syscall_64.c b/arch/x86/entry/syscall_64.c index 837aee7db50d..c716e0f546c6 100644 --- a/arch/x86/entry/syscall_64.c +++ b/arch/x86/entry/syscall_64.c @@ -68,7 +68,7 @@ static __always_inline bool do_syscall_x64(struct pt_regs *regs, int nr) return false; } -static __always_inline bool do_syscall_x32(struct pt_regs *regs, int nr) +static __always_inline void do_syscall_x32(struct pt_regs *regs, int nr) { /* * Adjust the starting offset of the table, and convert numbers @@ -80,9 +80,7 @@ static __always_inline bool do_syscall_x32(struct pt_regs *regs, int nr) if (IS_ENABLED(CONFIG_X86_X32_ABI) && likely(xnr < X32_NR_syscalls)) { xnr = array_index_nospec(xnr, X32_NR_syscalls); regs->ax = x32_sys_call(regs, xnr); - return true; } - return false; } /* Returns true to return using SYSRET, or false to use IRET */ @@ -92,10 +90,8 @@ __visible noinstr bool do_syscall_64(struct pt_regs *regs, int nr) instrumentation_begin(); - if (!do_syscall_x64(regs, nr) && !do_syscall_x32(regs, nr) && nr != -1) { - /* Invalid system call, but still a system call. */ - regs->ax = __x64_sys_ni_syscall(regs); - } + if (!do_syscall_x64(regs, nr)) + do_syscall_x32(regs, nr); instrumentation_end(); syscall_exit_to_user_mode(regs);