Re: [PATCH v5 1/2] perf/core: Prevent duplicate sigtrap task work enqueue

From: Peter Zijlstra

Date: Fri Nov 20 2026 - 10:08:15 EST


On Fri, Nov 20, 2026 at 03:16:06PM +0100, Sebastian Andrzej Siewior wrote:
> On 2026-11-20 13:14:36 [+0100], Peter Zijlstra wrote:
> > > Also use smp_load_acquire() when checking pending_work in
> > > the exclude_kernel warning path to ensure the read is properly
> > > ordered.
> >
> > I am confused by the use of smp_*() and cmpxchg() here. Where is the
> > multi-cpu scenario?
>
> The same event is used in process context and NMI
> | perf-tc1-7647 [001] d..6. 114.513688: __perf_event_overflow: ffff888100d68540
> | perf-tc1-7647 [001] d.Z2. 114.513703: __perf_event_overflow: ffff888100d68540
>
> I don't see how to deal with this without cmpxchg. And the same event is
> also used by other task

You can do CMPXCHG (without the LOCK) prefix; the helper is called
cmpxchg_local().

> | perf-tc1-7657 [001] d.Z2. 114.598356: __perf_event_overflow: ffff888100d68540
>
> which makes me thing that it could be pinned to another CPU (unless
> there is something that impossible and it is strictly per-CPU).
>
> The smp load/store macros is my fault as it looked better to do this
> than plain stores (given that we have the cmpxchg already).

It is confusing as all heck. This is all task-local, and a task can only
ever run on one CPU at the time.