Re: [PATCH v5 2/2] perf/core: Disable context fast-swap for sigtrap events
From: Peter Zijlstra
Date: Wed Nov 25 2026 - 04:30:49 EST
On Wed, Nov 25, 2026 at 10:08:09AM +0100, Peter Zijlstra wrote:
> On Tue, Nov 24, 2026 at 04:42:34PM +0800, Tengda Wu wrote:
>
> > From the stack, we can see:
> >
> > perf_event_context_sched_out
> > // fast path
> > perf_ctx_enable(ctx, 0);
> > perf_pmu_enable
> > if (!--(*count)) // equals 0
> > pmu->pmu_enable(pmu);
> > __intel_pmu_enable_all.constprop
> > do_trace_write_msr
> > perf_tp_event
> >
> > In perf_tp_event():
> > if (perf_tp_event_match(event, &raw, regs)) {
> > if (!perf_pmu_enabled(event->pmu)) return 0; // not satisfied, continue downward
> > perf_swevent_event
> > __perf_event_overflow
> > task_work_add // event->ctx->task mismatches 'current'
> > }
> >
> > Because pmu_disable_count is already 0, the subsequent perf_tp_event_match()
> > cannot block it via perf_pmu_enabled(), so the problem can be reproduced.
>
> Right, but at this point there isn't really a problem, all the pointers
> have been swapped already and state should be consistent again.
>
> I *think* the problem is that task_work_add() is using current while it
> should be using ctx->task. In that case the above will enqueue on the
> next task, which is correct.
>
> But also, we could probably write this to do:
>
> if (*count == 1) {
> pmu->pmu_enable(pmu);
> barrier();
> (*count)--;
> }
Note that this on its own isn't going to help. All the event that happen
between perf_event_task_sched_out() and switch_to() will trip the same
problem.
> > Maybe my original nr_no_switch_fast approach is still worth considering.
> > -- it would account for sigtrap events at attach time and keep them off
> > the fast path entirely, rather than trying to filter the overflow after
> > the swap has already happened.
>
> Disabling switch_fast really hurts performance; doing that should be a
> last resort. I think I can fix this. Let me try and see if the
> reproducer works for me so I can more easily poke at this.
>
>