Re: [PATCH v5 2/2] perf/core: Disable context fast-swap for sigtrap events

From: Peter Zijlstra

Date: Wed Nov 25 2026 - 11:14:06 EST


On Wed, Nov 25, 2026 at 02:36:01PM +0100, Peter Zijlstra wrote:
> On Wed, Nov 25, 2026 at 06:09:04PM +0800, Tengda Wu wrote:
>
> > >> Ah, I'm currently running it on an SPR Xeon; do I need to use
> > >> non-default arguments or just run the thing in a loop and drink tea
> > >> until it goes pop?
> > >
> > > No need to pass any other arguments; running it as follows should be enough:
> > >
> > > for i {1..100}; do ./fast_swap ; done
> > >
> >
> > Correction: for i in {1..100}
>
> I used: while :; do ./perf-sigtrap-switch-poc; done
>
> > One more detail: I also specified a boot parameter (which might make it
> > easier to reproduce?):
> >
> > preempt=none
>
> That option is no longer available.
>
> Anyway, I've had it running for a few hours now; but no joy :-( -- this
> is an unmodified tip/master kernel since I wanted to make sure I could
> reproduce before trying to fix.
>
> I'll just leave it running ...

7 hours and nothing :-(

I'm going to have to ask you to try and reproduce I'm afraid.

--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1236,6 +1236,7 @@ extern const struct perf_event_attr *per
extern void perf_event_print_debug(void);
extern void perf_pmu_disable(struct pmu *pmu);
extern void perf_pmu_enable(struct pmu *pmu);
+extern bool perf_pmu_enabled(struct pmu *pmu);
extern void perf_sched_cb_dec(struct pmu *pmu);
extern void perf_sched_cb_inc(struct pmu *pmu);
extern int perf_event_task_disable(void);
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -1366,6 +1366,12 @@ void perf_pmu_enable(struct pmu *pmu)
pmu->pmu_enable(pmu);
}

+bool perf_pmu_enabled(struct pmu *pmu)
+{
+ int *count = &this_cpc(pmu)->pmu_disable_count;
+ return *count == 0;
+}
+
static void perf_assert_pmu_disabled(struct pmu *pmu)
{
int *count = &this_cpc(pmu)->pmu_disable_count;
@@ -10955,7 +10961,7 @@ static int __perf_event_overflow(struct
* claim the pending_work before task_work_add() recurses.
*/
if (cmpxchg_local(&event->pending_work, 0, 1) == 0) {
- if (!task_work_add(current, &event->pending_task, notify_mode)) {
+ if (!task_work_add(event->ctx->task, &event->pending_task, notify_mode)) {
event->pending_work = pending_id;
local_inc(&event->ctx->nr_no_switch_fast);
WARN_ON_ONCE(!atomic_long_inc_not_zero(&event->refcount));
@@ -11151,6 +11157,9 @@ static int perf_swevent_match(struct per
struct perf_sample_data *data,
struct pt_regs *regs)
{
+ if (!perf_pmu_enabled(event->pmu))
+ return 0;
+
if (event->attr.type != type)
return 0;

@@ -11531,6 +11540,9 @@ static int perf_tp_event_match(struct pe
struct perf_raw_record *raw,
struct pt_regs *regs)
{
+ if (!perf_pmu_enabled(event->pmu))
+ return 0;
+
if (event->hw.state & PERF_HES_STOPPED)
return 0;
/*