Re: [PATCH v5 1/2] perf/core: Prevent duplicate sigtrap task work enqueue
From: Peter Zijlstra
Date: Fri Nov 20 2026 - 10:25:12 EST
On Fri, Nov 20, 2026 at 04:10:17PM +0100, Sebastian Andrzej Siewior wrote:
> On 2026-11-20 16:04:52 [+0100], Peter Zijlstra wrote:
> > 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.
>
> Given the two pids I was assuming (!knowing) that two CPUs could be
> involved.
>
> So you are saying cmpxchg_local() and a plain assign/WRITE_ONCE rather
> than the smp.* given that this is all task local.
Well, from what I can remember, only task bound self-monitoring events
can signal, and the whole task_work is per necessity task local. Which
makes it all local.
It is indeed {READ,WRITE}_ONCE() combined with barrier() if you really
need to beat the compiler into submission.
But let me go try and read this Changelog in more detail.