Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Kevin Brodsky <kevin.brodsky@arm.com>
To: Jinjie Ruan <ruanjinjie@huawei.com>,
	catalin.marinas@arm.com, will@kernel.org, oleg@redhat.com,
	tglx@linutronix.de, peterz@infradead.org, luto@kernel.org,
	shuah@kernel.org, kees@kernel.org, wad@chromium.org,
	akpm@linux-foundation.org, ldv@strace.io, macro@orcam.me.uk,
	deller@gmx.de, mark.rutland@arm.com, song@kernel.org,
	mbenes@suse.cz, ryan.roberts@arm.com, ada.coupriediaz@arm.com,
	anshuman.khandual@arm.com, broonie@kernel.org,
	pengcan@kylinos.cn, dvyukov@google.com, kmal@cock.li,
	lihongbo22@huawei.com, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v7 03/11] arm64/ptrace: Refator el0_svc_common()
Date: Tue, 18 Nov 2025 18:10:44 +0100	[thread overview]
Message-ID: <57c2c83c-9eea-40e0-9f95-47f21b1c75be@arm.com> (raw)
In-Reply-To: <20251117133048.53182-4-ruanjinjie@huawei.com>

In subject: s/refator/refactor/

Also nit: this is less about ptrace than about syscall entry, so maybe
"arm64/syscall:"?

On 17/11/2025 14:30, Jinjie Ruan wrote:
> Compared to the generic entry code, arm64 terminate the process

s/terminate/terminates/ (similar observation for other commit messages)

> after report_syscall_exit() if the syscall is issued within
> a restartable sequence.

Presumably this implies that forcing SIGSEGV before or after calling the
tracing handlers makes no difference, if so it should be clarified.

> In preparation for moving arm64 over to the generic entry code,
> refactor el0_svc_common() as below:
>
> - Extract syscall_exit_to_user_mode_prepare() to replace the
>   the combination of read_thread_flags() and syscall_trace_exit(),
>   also move the syscall exit check logic into it.
>
> - Move rseq_syscall() ahead, so the CONFIG_DEBUG_RSEQ check is
>   not needed.
>
> - Move has_syscall_work() helper into asm/syscall.h, which will be
>   reused by ptrace.c.
>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> ---
>  arch/arm64/include/asm/syscall.h |  7 ++++++-
>  arch/arm64/kernel/ptrace.c       | 10 +++++++++-
>  arch/arm64/kernel/syscall.c      | 26 +++++---------------------
>  3 files changed, 20 insertions(+), 23 deletions(-)
>
> diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h
> index d69f590a989b..6225981fbbdb 100644
> --- a/arch/arm64/include/asm/syscall.h
> +++ b/arch/arm64/include/asm/syscall.h
> @@ -114,7 +114,12 @@ static inline int syscall_get_arch(struct task_struct *task)
>  	return AUDIT_ARCH_AARCH64;
>  }
>  
> +static inline bool has_syscall_work(unsigned long flags)
> +{
> +	return unlikely(flags & _TIF_SYSCALL_WORK);
> +}
> +
>  int syscall_trace_enter(struct pt_regs *regs, long syscall, unsigned long flags);
> -void syscall_trace_exit(struct pt_regs *regs, unsigned long flags);
> +void syscall_exit_to_user_mode_prepare(struct pt_regs *regs);
>  
>  #endif	/* __ASM_SYSCALL_H */
> diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
> index bbb868f6b292..95984bbf53db 100644
> --- a/arch/arm64/kernel/ptrace.c
> +++ b/arch/arm64/kernel/ptrace.c
> @@ -2403,7 +2403,7 @@ int syscall_trace_enter(struct pt_regs *regs, long syscall, unsigned long flags)
>  	return regs->syscallno;
>  }
>  
> -void syscall_trace_exit(struct pt_regs *regs, unsigned long flags)
> +static void syscall_trace_exit(struct pt_regs *regs, unsigned long flags)
>  {
>  	audit_syscall_exit(regs);
>  
> @@ -2412,8 +2412,16 @@ void syscall_trace_exit(struct pt_regs *regs, unsigned long flags)
>  
>  	if (flags & (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP))
>  		report_syscall_exit(regs);
> +}
> +
> +void syscall_exit_to_user_mode_prepare(struct pt_regs *regs)
> +{
> +	unsigned long flags = read_thread_flags();
>  
>  	rseq_syscall(regs);
> +
> +	if (has_syscall_work(flags) || flags & _TIF_SINGLESTEP)
> +		syscall_trace_exit(regs, flags);

Since we're trying to align as much with the generic code as possible,
we might as well rename this function to syscall_exit_work() as well.

>  }
>  
>  /*
> diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c
> index 6e3fe760e0bb..9713b038d750 100644
> --- a/arch/arm64/kernel/syscall.c
> +++ b/arch/arm64/kernel/syscall.c
> @@ -65,11 +65,6 @@ static void invoke_syscall(struct pt_regs *regs, unsigned int scno,
>  	choose_random_kstack_offset(get_random_u16());
>  }
>  
> -static inline bool has_syscall_work(unsigned long flags)
> -{
> -	return unlikely(flags & _TIF_SYSCALL_WORK);
> -}
> -
>  static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr,
>  			   const syscall_fn_t syscall_table[])
>  {
> @@ -125,26 +120,15 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr,
>  		if (scno == NO_SYSCALL)
>  			syscall_set_return_value(current, regs, -ENOSYS, 0);
>  		scno = syscall_trace_enter(regs, regs->syscallno, flags);
> -		if (scno == NO_SYSCALL)
> -			goto trace_exit;

Why not keep the goto instead of duplicating the call? It could be
renamed if necessary.

- Kevin

> +		if (scno == NO_SYSCALL) {
> +			syscall_exit_to_user_mode_prepare(regs);
> +			return;
> +		}
>  	}
>  
>  	invoke_syscall(regs, scno, sc_nr, syscall_table);
>  
> -	/*
> -	 * The tracing status may have changed under our feet, so we have to
> -	 * check again. However, if we were tracing entry, then we always trace
> -	 * exit regardless, as the old entry assembly did.
> -	 */
> -	if (!has_syscall_work(flags) && !IS_ENABLED(CONFIG_DEBUG_RSEQ)) {
> -		flags = read_thread_flags();
> -		if (!has_syscall_work(flags) && !(flags & _TIF_SINGLESTEP))
> -			return;
> -	}
> -
> -trace_exit:
> -	flags = read_thread_flags();
> -	syscall_trace_exit(regs, flags);
> +	syscall_exit_to_user_mode_prepare(regs);
>  }
>  
>  void do_el0_svc(struct pt_regs *regs)

  reply	other threads:[~2025-11-18 17:10 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-17 13:30 [PATCH v7 00/11] arm64: entry: Convert to Generic Entry Jinjie Ruan
2025-11-17 13:30 ` [PATCH v7 01/11] arm64/ptrace: Split report_syscall() Jinjie Ruan
2025-11-18 17:09   ` Kevin Brodsky
2025-11-19  9:49     ` Jinjie Ruan
2025-11-25 13:06       ` Kevin Brodsky
2025-11-17 13:30 ` [PATCH v7 02/11] arm64/ptrace: Refactor syscall_trace_enter/exit() Jinjie Ruan
2025-11-18 17:09   ` Kevin Brodsky
2025-11-20 11:05     ` Jinjie Ruan
2025-11-17 13:30 ` [PATCH v7 03/11] arm64/ptrace: Refator el0_svc_common() Jinjie Ruan
2025-11-18 17:10   ` Kevin Brodsky [this message]
2025-11-20 12:03     ` Jinjie Ruan
2025-11-17 13:30 ` [PATCH v7 04/11] entry: Add syscall_exit_to_user_mode_prepare() helper Jinjie Ruan
2025-11-17 13:43   ` Thomas Gleixner
2025-11-18 17:11   ` Kevin Brodsky
2025-11-17 13:30 ` [PATCH v7 05/11] arm64/ptrace: Handle ptrace_report_syscall_entry() error Jinjie Ruan
2025-11-18 17:12   ` Kevin Brodsky
2025-11-21  4:15     ` Jinjie Ruan
2025-11-24  9:16       ` Kevin Brodsky
2025-11-17 13:30 ` [PATCH v7 06/11] arm64/ptrace: Expand secure_computing() in place Jinjie Ruan
2025-11-18 17:12   ` Kevin Brodsky
2025-11-21  7:29     ` Jinjie Ruan
2025-11-17 13:30 ` [PATCH v7 07/11] arm64/ptrace: Use syscall_get_arguments() heleper Jinjie Ruan
2025-11-18 17:12   ` Kevin Brodsky
2025-11-17 13:30 ` [PATCH v7 08/11] entry: Add arch_ptrace_report_syscall_entry/exit() Jinjie Ruan
2025-11-18 17:13   ` Kevin Brodsky
2025-11-24  9:34     ` Jinjie Ruan
2025-11-24 15:23       ` Kevin Brodsky
2025-11-25  2:43         ` Jinjie Ruan
2025-11-25 13:10           ` Kevin Brodsky
2025-11-17 13:30 ` [PATCH v7 09/11] entry: Add has_syscall_work() helper Jinjie Ruan
2025-11-18 17:13   ` Kevin Brodsky
2025-11-25  3:23     ` Jinjie Ruan
2025-11-17 13:30 ` [PATCH v7 10/11] arm64: entry: Convert to generic entry Jinjie Ruan
2025-11-18 17:14   ` Kevin Brodsky
2025-11-25  4:00     ` Jinjie Ruan
2025-11-17 13:30 ` [PATCH v7 11/11] selftests: sud_test: Support aarch64 Jinjie Ruan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57c2c83c-9eea-40e0-9f95-47f21b1c75be@arm.com \
    --to=kevin.brodsky@arm.com \
    --cc=ada.coupriediaz@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=deller@gmx.de \
    --cc=dvyukov@google.com \
    --cc=kees@kernel.org \
    --cc=kmal@cock.li \
    --cc=ldv@strace.io \
    --cc=lihongbo22@huawei.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=macro@orcam.me.uk \
    --cc=mark.rutland@arm.com \
    --cc=mbenes@suse.cz \
    --cc=oleg@redhat.com \
    --cc=pengcan@kylinos.cn \
    --cc=peterz@infradead.org \
    --cc=ruanjinjie@huawei.com \
    --cc=ryan.roberts@arm.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=wad@chromium.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox