Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jinjie Ruan <ruanjinjie@huawei.com>
To: <catalin.marinas@arm.com>, <will@kernel.org>,
	<mark.rutland@arm.com>, <oleg@redhat.com>, <shuah@kernel.org>,
	<kees@kernel.org>, <luto@amacapital.net>, <wad@chromium.org>,
	<peterz@infradead.org>, <ada.coupriediaz@arm.com>,
	<linusw@kernel.org>, <kevin.brodsky@arm.com>,
	<yeoreum.yun@arm.com>, <james.morse@arm.com>, <thuth@redhat.com>,
	<tglx@kernel.org>, <vladimir.murzin@arm.com>,
	<broonie@kernel.org>, <ryan.roberts@arm.com>,
	<liqiang01@kylinos.cn>, <linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <linux-kselftest@vger.kernel.org>
Cc: <ruanjinjie@huawei.com>
Subject: [PATCH v20 01/15] arm64: ptrace: Drop redundant pseudo-single-step for SYSEMU_SINGLESTEP
Date: Wed, 30 Sep 2026 18:17:51 +0800	[thread overview]
Message-ID: <20260930101805.1770358-2-ruanjinjie@huawei.com> (raw)
In-Reply-To: <20260930101805.1770358-1-ruanjinjie@huawei.com>

PTRACE_SYSEMU_SINGLESTEP sets both _TIF_SYSCALL_EMU and _TIF_SINGLESTEP.

With _TIF_SINGLESTEP set, the arm64 syscall-exit path synthesises a
pseudo-single-step exception:

	ptrace_report_syscall_exit(regs, 1)
	  -> user_single_step_report()
	     -> info.si_signo = SIGTRAP
	     -> info.si_code = SI_USER
	     -> force_sig_info(&info)

But for PTRACE_SYSEMU_SINGLESTEP it is redundant: the stop before
the instruction following the SVC is already delivered by the hardware
single-step state machine, so the tracer ends up with two stops
at the same PC as below:

	sig=133 si_code=133  SS=0  pc=0x400638   [syscall-enter-stop]
	sig=5   si_code=0    SS=0  pc=0x400638   [pseudo-step, dropped here]
	sig=5   si_code=2    SS=1  pc=0x400638   [hardware single-step]

The pseudo-step was added by commit ac2081cdc4d9 ("arm64: ptrace:
Consistently use pseudo-singlestep exceptions") because a ptrace stop
taken while a system call is in progress may corrupt the stepping state.
For an emulated system call that cannot happen, as the call never runs:

- No syscall-exit-stop, because _TIF_SINGLESTEP is set

- No seccomp trap, because syscall_trace_enter() returns NO_SYSCALL
  when SYSCALL_EMU is set, before the seccomp check

- The syscall body is not executed, so nothing can take a stop while it
  is in progress.

Introduce report_single_step(), which returns false when _TIF_SYSCALL_EMU
is set, so the pseudo-step is skipped for the emulated case. This also
matches the generic entry behaviour.

PTRACE_SINGLESTEP and PTRACE_SYSCALL are unaffected:
- PTRACE_SYSCALL: SYSCALL_TRACE is set and _TIF_SINGLESTEP is not, so
  the syscall-exit-stop is reported as before and no pseudo-step is
  involved;

- PTRACE_SINGLESTEP: _TIF_SINGLESTEP is set but _TIF_SYSCALL_EMU is
  not, so the pseudo-step is still synthesised.  It is still needed
  here, because the system call does execute and the hazard described
  above applies.

Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
 arch/arm64/kernel/ptrace.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
index f743cbec1c3a..96462de75d4b 100644
--- a/arch/arm64/kernel/ptrace.c
+++ b/arch/arm64/kernel/ptrace.c
@@ -2482,16 +2482,26 @@ int syscall_trace_enter(struct pt_regs *regs)
 	return regs->syscallno;
 }
 
+static inline bool report_single_step(unsigned long flags)
+{
+	if (flags & _TIF_SYSCALL_EMU)
+		return false;
+
+	return flags & _TIF_SINGLESTEP;
+}
+
 void syscall_trace_exit(struct pt_regs *regs)
 {
 	unsigned long flags = read_thread_flags();
+	bool step;
 
 	audit_syscall_exit(regs);
 
 	if (flags & _TIF_SYSCALL_TRACEPOINT)
 		trace_sys_exit(regs, syscall_get_return_value(current, regs));
 
-	if (flags & (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP))
+	step = report_single_step(flags);
+	if (step || flags & _TIF_SYSCALL_TRACE)
 		report_syscall_exit(regs);
 
 	rseq_syscall(regs);
-- 
2.34.1



  reply	other threads:[~2026-09-30 10:17 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 10:17 [PATCH v20 00/15] arm64: entry: Convert to Generic Entry Jinjie Ruan
2026-09-30 10:17 ` Jinjie Ruan [this message]
2026-09-30 10:17 ` [PATCH v20 02/15] arm64: ptrace: Rework audit_syscall_entry() Jinjie Ruan
2026-09-30 10:17 ` [PATCH v20 03/15] arm64: ptrace: Open-code seccomp check in syscall_trace_enter() Jinjie Ruan
2026-09-30 10:17 ` [PATCH v20 04/15] arm64: ptrace: Rename and clean up syscall_trace_enter() Jinjie Ruan
2026-09-30 10:17 ` [PATCH v20 05/15] arm64: ptrace: Protect rseq_syscall() from tracer PC modifications Jinjie Ruan
2026-09-30 10:17 ` [PATCH v20 06/15] arm64: syscall: Rework the syscall exit path in el0_svc_common() Jinjie Ruan
2026-09-30 10:17 ` [PATCH v20 07/15] arm64: ptrace: Pass thread flags to trace enter/exit Jinjie Ruan
2026-09-30 10:17 ` [PATCH v20 08/15] arm64: ptrace: Extract arm64_syscall_exit_to_user_mode_work() helper Jinjie Ruan
2026-09-30 10:17 ` [PATCH v20 09/15] arm64: ptrace: Align syscall exit work semantics with generic entry Jinjie Ruan
2026-09-30 10:18 ` [PATCH v20 10/15] arm64: syscall: Use exit-specific flags check in el0_svc_common() Jinjie Ruan
2026-09-30 10:18 ` [PATCH v20 11/15] arm64: syscall: Simplify el0_svc_common() syscall exit path Jinjie Ruan
2026-09-30 10:18 ` [PATCH v20 12/15] arm64: ptrace: Make return type of arm64_syscall_trace_enter() bool Jinjie Ruan
2026-09-30 10:18 ` [PATCH v20 13/15] arm64: entry: Convert to generic entry Jinjie Ruan
2026-09-30 10:18 ` [PATCH v20 14/15] arm64: Inline el0_svc_common() Jinjie Ruan
2026-09-30 10:18 ` [PATCH v20 15/15] selftests/arm64: Add ptrace SYSEMU/single-step tests Jinjie Ruan
2026-10-26  8:52 ` [PATCH v20 00/15] arm64: entry: Convert to Generic Entry 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=20260930101805.1770358-2-ruanjinjie@huawei.com \
    --to=ruanjinjie@huawei.com \
    --cc=ada.coupriediaz@arm.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=james.morse@arm.com \
    --cc=kees@kernel.org \
    --cc=kevin.brodsky@arm.com \
    --cc=linusw@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=liqiang01@kylinos.cn \
    --cc=luto@amacapital.net \
    --cc=mark.rutland@arm.com \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=ryan.roberts@arm.com \
    --cc=shuah@kernel.org \
    --cc=tglx@kernel.org \
    --cc=thuth@redhat.com \
    --cc=vladimir.murzin@arm.com \
    --cc=wad@chromium.org \
    --cc=will@kernel.org \
    --cc=yeoreum.yun@arm.com \
    /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