Re: [PATCH v5] ARM, ARM64, LONGARCH, XTENSA: Delay HW BP notification to task_work()
From: sashiko-bot
Date: Fri Nov 20 2026 - 10:16:26 EST
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@xxxxxxxxxxxxx>
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@xxxxxxxxxxxxx?part=1