Re: [patch 18/18] entry, treewide: Make syscall_enter_from_user_mode[_work]() indicate syscall execution

Mukesh Kumar Chaurasiya <[email protected]> Fri, 10 Jul 2026 01:19:28 +0530
Newsgroups org.infradead.lists.linux-snps-arc,dev.linux.lists.loongarch,org.infradead.lists.linux-riscv,org.infradead.lists.linux-um,org.kernel.vger.linux-alpha,org.kernel.vger.linux-arch,org.kernel.vger.linux-csky,org.kernel.vger.linux-doc,org.kernel.vger.linux-hexagon,org.kernel.vger.linux-kernel,org.kernel.vger.linux-m68k,org.kernel.vger.linux-mips,org.kernel.vger.linux-openrisc,org.kernel.vger.linux-parisc,org.kernel.vger.linux-s390,org.kernel.vger.linux-sh,org.kernel.vger.sparclinux,org.ozlabs.lists.linuxppc-dev
Message-ID <[email protected]>
On Tue, Jul 07, 2026 at 09:07:09PM +0200, Thomas Gleixner wrote:
> From: Michal Such=E1nek <[email protected]>
> =

> 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 modifyi=
ng
> entity requests to abort the syscall and set the return value already. Th=
at
> 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 =3D syscall_enter_from_user_mode(regs, nr);
>     if ((unsigned)nr < SYSCALLNR_MAX)
>     	handle_syscall(regs, nr);
>     else if (nr !=3D -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 her=
e,
> 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=E1nek <[email protected]>
> Signed-off-by: Thomas Gleixner <[email protected]>
> Cc: Jonathan Corbet <[email protected]>
> Cc: Arnd Bergmann <[email protected]>
> Cc: Mark Rutland <[email protected]>
> Cc: Huacai Chen <[email protected]>
> Cc: Michael Ellerman <[email protected]>
> Cc: Shrikanth Hegde <[email protected]>
> Cc: Paul Walmsley <[email protected]>
> Cc: Palmer Dabbelt <[email protected]>
> Cc: Sven Schnelle <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> ---
>  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 =3D 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 >=3D NR_syscalls)) {
>  		if (unlikely(trap_is_unsupported_scv(regs))) {

Apart from this.


Reviewed-by: Mukesh Kumar Chaurasiya (IBM) <[email protected]>

_______________________________________________
linux-snps-arc mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-snps-arc