[patch 18/18] entry, treewide: Make syscall_enter_from_user_mode[_work]() indicate syscall execution
Mukesh Kumar Chaurasiya
mkchauras at gmail.com
Thu Jul 9 12:49:28 PDT 2026
On Tue, Jul 07, 2026 at 09:07:09PM +0200, Thomas Gleixner wrote:
> From: Michal Suchánek <msuchanek at suse.de>
>
> The return values of syscall_enter_from_user_mode[_work]() are
> non-intuitive. Both functions return the syscall number which should be
> invoked by the architecture specific syscall entry code. The returned
> number can be:
>
> - the unmodified syscall number which was handed in by the caller
>
> - a modified syscall number (ptrace, seccomp, trace/probe/bpf)
>
> That has an additional twist. If the return value is -1L then the caller is
> not allowed to modify the return value as that indicates that the modifying
> entity requests to abort the syscall and set the return value already. That
> can obviously not be differentiated from a syscall which handed in -1 as
> syscall number.
>
> The established way to deal with that is:
>
> set_return_value(regs, -ENOSYS);
> nr = syscall_enter_from_user_mode(regs, nr);
> if ((unsigned)nr < SYSCALLNR_MAX)
> handle_syscall(regs, nr);
> else if (nr != -1)
> set_return_value(regs, -ENOSYS);
>
> The latter is obviously redundant, but that's just a leftover of the
> historical evolution of this code. S390 has some special requirements here,
> which can be avoided when the return value is not ambiguous.
>
> Now that the functions which modify the syscall number and want to abort
> are converted to indicate that with a boolean return value, it's obvious to
> hand this through to the callers.
>
> Rework syscall_enter_from_user_mode[_work]) so they take a pointer to the
> syscall number and return a boolean, which indicates whether the syscall
> should be handled or not.
>
> That's not only more intuitive, it also results in slightly denser
> executable code on x86 at least, but perf results are neutral and within
> the noise.
>
> [ tglx: Adopted it to the changes in the generic entry code, fixed up the
> 32-bit fallout and rewrote change log ]
>
> Signed-off-by: Michal Suchánek <msuchanek at suse.de>
> Signed-off-by: Thomas Gleixner <tglx at kernel.org>
> Cc: Jonathan Corbet <corbet at lwn.net>
> Cc: Arnd Bergmann <arnd at arndb.de>
> Cc: Mark Rutland <mark.rutland at arm.com>
> Cc: Huacai Chen <chenhuacai at kernel.org>
> Cc: Michael Ellerman <mpe at ellerman.id.au>
> Cc: Shrikanth Hegde <sshegde at linux.ibm.com>
> Cc: Paul Walmsley <pjw at kernel.org>
> Cc: Palmer Dabbelt <palmer at dabbelt.com>
> Cc: Sven Schnelle <svens at linux.ibm.com>
> Cc: linux-doc at vger.kernel.org
> Cc: loongarch at lists.linux.dev
> Cc: linuxppc-dev at lists.ozlabs.org
> Cc: linux-riscv at lists.infradead.org
> Cc: linux-s390 at vger.kernel.org
> ---
> Documentation/core-api/entry.rst | 18 +++++++++++-------
> arch/loongarch/kernel/syscall.c | 14 +++++++-------
> arch/powerpc/kernel/syscall.c | 3 ++-
> arch/riscv/kernel/traps.c | 11 +++++------
> arch/s390/kernel/syscall.c | 7 +++++--
> arch/x86/entry/syscall_32.c | 25 ++++++++++++-------------
> arch/x86/entry/syscall_64.c | 12 ++++++------
> include/linux/entry-common.h | 12 +++++-------
> 8 files changed, 53 insertions(+), 49 deletions(-)
>
>
[...]
> syscall_exit_to_user_mode(regs);
> --- a/arch/powerpc/kernel/syscall.c
> +++ b/arch/powerpc/kernel/syscall.c
> @@ -18,7 +18,8 @@ notrace long system_call_exception(struc
> long ret;
> syscall_fn f;
>
> - r0 = syscall_enter_from_user_mode_randomize_stack(regs, r0);
> + if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0))
Missing one closing ')'.
> + return syscall_get_error(current, regs);
>
> if (unlikely(r0 >= NR_syscalls)) {
> if (unlikely(trap_is_unsupported_scv(regs))) {
Apart from this.
Reviewed-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras at gmail.com>
More information about the linux-riscv
mailing list