mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Tengda Wu <wutengda@huaweicloud.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	James Clark <james.clark@linaro.org>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 2/2] perf/core: Disable context fast-swap for sigtrap events
Date: Wed, 25 Nov 2026 10:38:36 +0100	[thread overview]
Message-ID: <20261125093836.GX2668804@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <4d17dd3b-df73-45c0-8113-f4ca259d549b@huaweicloud.com>

On Wed, Nov 25, 2026 at 05:29:38PM +0800, Tengda Wu wrote:
> 
> 
> On 2026/11/25 17:08, 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.
> > 
> 
> I considered this before, but it involves the issue of whether the count
> overflow in the sched_out stage should be attributed to the current or next
> task, and I wasn't very confident about it, so I didn't adopt it.

All of switch_fast suffers that problem. Mostly we've ignored it since
kernel events around a context switch are hard to attribute to any one
particular task, so a little fuzz left or right of the switch doesn't
matter too much, as long as its consistent.

> > 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.
> > 
> 
> OK. Just a reminder that the PoC I provided needs to be run in an Intel
> environment, so that the tracepoint can be hit when pmu_enable is executed.

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?

  reply	other threads:[~2026-11-25  9:38 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  9:50 [PATCH v5 0/2] perf/core: Fix sigtrap task_work races Tengda Wu
2026-11-19  9:51 ` [PATCH v5 1/2] perf/core: Prevent duplicate sigtrap task work enqueue Tengda Wu
2026-11-19 12:09   ` Sebastian Andrzej Siewior
2026-11-20 12:14   ` Peter Zijlstra
2026-11-20 14:16     ` Sebastian Andrzej Siewior
2026-11-20 15:04       ` Peter Zijlstra
2026-11-20 15:10         ` Sebastian Andrzej Siewior
2026-11-20 15:24           ` Peter Zijlstra
2026-11-20 15:44   ` Peter Zijlstra
2026-11-20 15:49     ` Sebastian Andrzej Siewior
2026-11-20 16:01       ` Peter Zijlstra
2026-11-20 16:26         ` Peter Zijlstra
2026-11-20 17:28           ` Sebastian Andrzej Siewior
2026-11-20 17:49             ` Peter Zijlstra
2026-11-23  2:10               ` Tengda Wu
2026-11-23  8:00               ` Sebastian Andrzej Siewior
2026-11-25  8:27                 ` Peter Zijlstra
2026-11-23  1:17             ` Tengda Wu
2026-11-23  7:54               ` Sebastian Andrzej Siewior
2026-11-19  9:51 ` [PATCH v5 2/2] perf/core: Disable context fast-swap for sigtrap events Tengda Wu
2026-11-19 12:11   ` Sebastian Andrzej Siewior
2026-11-19 12:17     ` Tengda Wu
2026-11-19 13:07       ` Sebastian Andrzej Siewior
2026-11-19 13:19         ` Tengda Wu
2026-11-19 13:48           ` Sebastian Andrzej Siewior
2026-11-20  0:55             ` Tengda Wu
2026-11-20 16:30   ` Peter Zijlstra
2026-11-20 17:06     ` Sebastian Andrzej Siewior
2026-11-20 17:37   ` Peter Zijlstra
2026-11-20 17:46     ` Peter Zijlstra
2026-11-23  3:11       ` Tengda Wu
2026-11-24  8:42         ` Tengda Wu
2026-11-25  9:08           ` Peter Zijlstra
2026-11-25  9:29             ` Tengda Wu
2026-11-25  9:38               ` Peter Zijlstra [this message]
2026-11-25  9:30             ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125093836.GX2668804@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=bigeasy@linutronix.de \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=wutengda@huaweicloud.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®