The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
	linux-rt-devel@lists.linux.dev, linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5] ARM, ARM64, LONGARCH, XTENSA: Delay HW BP notification to task_work()
Date: Fri, 20 Nov 2026 15:15:44 +0000	[thread overview]
Message-ID: <sashiko-outbox-225444@kernel.org> (raw)
In-Reply-To: <20261120144553.TjgAd_G6@linutronix.de>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] loongarch: ptrace: do_watch() forces SIGTRAP before
  perf_arch_hwbp_send_sig()
--

commit e42e3194215f3def1d0ba2e055fc294e66e5d8ac
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

ARM, ARM64, LONGARCH, XTENSA: Delay HW BP notification to task_work()

This commit defers ptrace hardware breakpoint signal notifications on ARM,
ARM64, LoongArch, and Xtensa to task_work via perf_hwbp_notify() so that
sighand->siglock is not acquired with interrupts disabled on PREEMPT_RT.

> diff --git a/arch/loongarch/kernel/ptrace.c b/arch/loongarch/kernel/ptrace.c
> index be38430f7e280..27e7e64591592 100644
> --- a/arch/loongarch/kernel/ptrace.c
> +++ b/arch/loongarch/kernel/ptrace.c
> @@ -384,9 +384,7 @@ static int lbt_set(struct task_struct *target,
>  /*
>   * Handle hitting a HW-breakpoint.
>   */
> -static void ptrace_hbptriggered(struct perf_event *bp,
> -				struct perf_sample_data *data,
> -				struct pt_regs *regs)
> +void perf_arch_hwbp_send_sig(struct perf_event *bp)
>  {
>  	int i;
>  	struct arch_hw_breakpoint *bkpt = counter_arch_bp(bp);
> @@ -479,7 +477,7 @@ static struct perf_event *ptrace_hbp_create(unsigned int note_type,
>  	attr.bp_type	= type;
>  	attr.disabled	= 1;
>  
> -	bp = register_user_hw_breakpoint(&attr, ptrace_hbptriggered, NULL, tsk);
> +	bp = register_user_hw_breakpoint(&attr, perf_hwbp_notify, NULL, tsk);
>  	if (IS_ERR(bp))
>  		return bp;

[Severity: High]
Does deferring force_sig_ptrace_errno_trap() to task_work cause do_watch()
to queue a generic SI_KERNEL SIGTRAP first and drop the TRAP_HWBKPT
siginfo?

On LoongArch, do_watch() runs with interrupts disabled and forces SIGTRAP
before returning through irqentry_exit():

arch/loongarch/kernel/traps.c:do_watch() {
	...
	bool need_sigtrap = !!current->ptrace;
	...
	if (test_tsk_thread_flag(current, TIF_SINGLESTEP)) {
		...
	} else {
		need_sigtrap |= breakpoint_handler(regs);
		need_sigtrap |= watchpoint_handler(regs);
	}

	if (need_sigtrap)
		force_sig(SIGTRAP);
out:
#endif
	irqentry_exit(regs, state);
}

Previously, breakpoint_handler() and watchpoint_handler() ran
ptrace_hbptriggered() synchronously, queueing SIGTRAP with TRAP_HWBKPT, the
slot index in si_errno, and the breakpoint address in si_addr before
do_watch() reached force_sig(SIGTRAP), which __send_signal_locked() then
ignored via legacy_queue().

With perf_arch_hwbp_send_sig() deferred to TWA_RESUME, force_sig(SIGTRAP)
in do_watch() now runs first while interrupts are still disabled.  That
queues a generic SI_KERNEL SIGTRAP, causing __send_signal_locked() to drop
the subsequent TRAP_HWBKPT siginfo from perf_arch_hwbp_send_sig(), and
still acquires sighand->siglock in atomic context on PREEMPT_RT.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120144553.TjgAd_G6@linutronix.de?part=1

      parent reply	other threads:[~2026-11-20 15:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 14:45 [PATCH v5] ARM, ARM64, LONGARCH, XTENSA: Delay HW BP notification to task_work() Sebastian Andrzej Siewior
2026-11-20 15:03 ` Peter Zijlstra
2026-11-20 15:15 ` sashiko-bot [this message]

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=sashiko-outbox-225444@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /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