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

From: Tengda Wu

Date: Wed Nov 25 2026 - 21:00:12 EST




On 2026/11/26 0:13, Peter Zijlstra wrote:
> 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.
>>

Uh, I tested on linux-next, base commit: 84abb955b101 (tag: next-20261113).
That option is still present at that commit.

>> 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.
>

Strange. Maybe the SPR Xeon is too fast, or the PMU tracepoint just isn't
hitting? It's also possible that the old Intel machine I'm using locally
(a 2014-era old CPU) is so slow that the probability of taking the fastpath
is higher.

> --- 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;
> /*


Hmm, I applied that patch to my local environment and tested it, and
I no longer see the warning. The issue should be resolved.

Tested-by: Tengda Wu <wutengda@xxxxxxxxxxxxxxx>

Thanks,
Tengda