Re: [patch 09/18] entry: Remove syscall_enter_from_user_mode()

Radu Rendec <[email protected]> Wed, 08 Jul 2026 17:21:19 -0400
Newsgroups org.kernel.vger.linux-hexagon,dev.linux.lists.loongarch,org.infradead.lists.linux-riscv,org.infradead.lists.linux-snps-arc,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-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, 2026-07-07 at 21:06 +0200, Thomas Gleixner wrote:
> All architecture use either:
>=20
> =C2=A0=C2=A0=C2=A0 nr =3D enter_from_user_mode_randomize_stack(regs, nr);

You probably mean syscall_enter_from_user_mode_randomize_stack.

>=20
> or
>=20
> =C2=A0=C2=A0=C2=A0 enter_from_user_mode_randomize_stack(regs);
> =C2=A0=C2=A0=C2=A0 nr =3D syscall_enter_from_user_mode_work(regs, nr);
>=20
> Remove the now unused function.
>=20
> Signed-off-by: Thomas Gleixner <[email protected]>
> ---
> =C2=A0Documentation/core-api/entry.rst |=C2=A0=C2=A0 17 +++++++++-------
> =C2=A0include/linux/entry-common.h=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 =
40 +++------------------------------------
> =C2=A0include/linux/irq-entry-common.h |=C2=A0=C2=A0=C2=A0 6 ++---
> =C2=A03 files changed, 17 insertions(+), 46 deletions(-)
>=20
> --- a/Documentation/core-api/entry.rst
> +++ b/Documentation/core-api/entry.rst
> @@ -68,7 +68,7 @@ low-level C code must not be instrumente
> =C2=A0=C2=A0 noinstr void syscall(struct pt_regs *regs, int nr)
> =C2=A0=C2=A0 {
> =C2=A0	arch_syscall_enter(regs);
> -	nr =3D syscall_enter_from_user_mode(regs, nr);
> +	nr =3D syscall_enter_from_user_mode_randomize_stack(regs, nr);
> =C2=A0
> =C2=A0	instrumentation_begin();
> =C2=A0	if (!invoke_syscall(regs, nr) && nr !=3D -1)
> @@ -78,12 +78,14 @@ low-level C code must not be instrumente
> =C2=A0	syscall_exit_to_user_mode(regs);
> =C2=A0=C2=A0 }
> =C2=A0
> -syscall_enter_from_user_mode() first invokes enter_from_user_mode() whic=
h
> -establishes state in the following order:
> +syscall_enter_from_user_mode_randomize_stack() first invokes
> +enter_from_user_mode_randomize_stack() which establishes state in the
> +following order:
> =C2=A0
> =C2=A0=C2=A0 * Lockdep
> =C2=A0=C2=A0 * RCU / Context tracking
> =C2=A0=C2=A0 * Tracing
> +=C2=A0 * Apply stack randomization
> =C2=A0
> =C2=A0and then invokes the various entry work functions like ptrace, secc=
omp, audit,
> =C2=A0syscall tracing, etc. After all that is done, the instrumentable in=
voke_syscall
> @@ -99,10 +101,11 @@ that it invokes exit_to_user_mode() whic
> =C2=A0=C2=A0 * RCU / Context tracking
> =C2=A0=C2=A0 * Lockdep
> =C2=A0
> -syscall_enter_from_user_mode() and syscall_exit_to_user_mode() are also
> -available as fine grained subfunctions in cases where the architecture c=
ode
> -has to do extra work between the various steps. In such cases it has to
> -ensure that enter_from_user_mode() is called first on entry and
> +syscall_enter_from_user_mode_randomize_stack() and
> +syscall_exit_to_user_mode() are also available as fine grained subfuncti=
ons
> +in cases where the architecture code has to do extra work between the
> +various steps. In such cases it has to ensure that
> +enter_from_user_mode_randomize_stack() is called first on entry and
> =C2=A0exit_to_user_mode() is called last on exit.
> =C2=A0
> =C2=A0Do not nest syscalls. Nested syscalls will cause RCU and/or context=
 tracking
> --- a/include/linux/entry-common.h
> +++ b/include/linux/entry-common.h
> @@ -19,7 +19,7 @@
> =C2=A0#endif
> =C2=A0
> =C2=A0/*
> - * SYSCALL_WORK flags handled in syscall_enter_from_user_mode()
> + * SYSCALL_WORK flags handled in syscall_enter_from_user_mode_work()
> =C2=A0 */
> =C2=A0#define SYSCALL_WORK_ENTER	(SYSCALL_WORK_SECCOMP |			\
> =C2=A0				 SYSCALL_WORK_SYSCALL_TRACEPOINT |	\
> @@ -205,42 +205,10 @@ do {									\
> =C2=A0	_ret;								\
> =C2=A0})
> =C2=A0
> -/**
> - * syscall_enter_from_user_mode - Establish state and check and handle w=
ork
> - *				=C2=A0 before invoking a syscall
> - * @regs:	Pointer to currents pt_regs
> - * @syscall:	The syscall number
> - *
> - * Invoked from architecture specific syscall entry code with interrupts
> - * disabled. The calling code has to be non-instrumentable. When the
> - * function returns all state is correct, interrupts are enabled and the
> - * subsequent functions can be instrumented.
> - *
> - * This is the combination of enter_from_user_mode() and
> - * syscall_enter_from_user_mode_work() to be used when there is no
> - * architecture specific work to be done between the two.
> - *
> - * Returns: The original or a modified syscall number. See
> - * syscall_enter_from_user_mode_work() for further explanation.
> - */
> -static __always_inline long syscall_enter_from_user_mode(struct pt_regs =
*regs, long syscall)
> -{
> -	long ret;
> -
> -	enter_from_user_mode(regs);
> -
> -	instrumentation_begin();
> -	local_irq_enable();
> -	ret =3D syscall_enter_from_user_mode_work(regs, syscall);
> -	instrumentation_end();
> -
> -	return ret;
> -}
> -
> =C2=A0/*
> - * If SYSCALL_EMU is set, then the only reason to report is when
> - * SINGLESTEP is set (i.e. PTRACE_SYSEMU_SINGLESTEP).=C2=A0 This syscall
> - * instruction has been already reported in syscall_enter_from_user_mode=
().
> + * If SYSCALL_EMU is set, then the only reason to report is when SINGLES=
TEP is
> + * set (i.e. PTRACE_SYSEMU_SINGLESTEP).=C2=A0 This syscall instruction h=
as been
> + * already reported in syscall_enter_from_user_mode_work().
> =C2=A0 */
> =C2=A0static __always_inline bool report_single_step(unsigned long work)
> =C2=A0{
> --- a/include/linux/irq-entry-common.h
> +++ b/include/linux/irq-entry-common.h
> @@ -49,9 +49,9 @@
> =C2=A0 * Defaults to an empty implementation. Can be replaced by architec=
ture
> =C2=A0 * specific code.
> =C2=A0 *
> - * Invoked from syscall_enter_from_user_mode() in the non-instrumentable
> - * section. Use __always_inline so the compiler cannot push it out of li=
ne
> - * and make it instrumentable.
> + * Invoked from enter_from_user_mode_syscall_and_randomize_stack() in th=
e
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Probably syscall_enter_from_user_mode_randomize_stack()? But the
reality is it's only ever invoked from enter_from_user_mode(), which is
below in the same file (include/linux/irq-entry-common.h).

Granted, that's an always inline function, and it's used by both macros
you added (since the second one uses the first one).

> + * non-instrumentable section. Use __always_inline so the compiler canno=
t push
> + * it out of line and make it instrumentable.
> =C2=A0 */
> =C2=A0static __always_inline void arch_enter_from_user_mode(struct pt_reg=
s *regs);
> =C2=A0