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: Fri, 20 Nov 2026 17:30:07 +0100 [thread overview]
Message-ID: <20261120163007.GB2668564@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <55b1a2845b0ad34a874a7653644e34af9eb068d3.1795053619.git.wutengda@huaweicloud.com>
On Thu, Nov 19, 2026 at 09:51:01AM +0000, Tengda Wu wrote:
> perf_sigtrap() contains:
>
> WARN_ON_ONCE(event->ctx->task != current)
>
> The warning assumes that an event's ctx->task always matches the task
> that ends up running the pending task_work. That assumption can be
> broken by the context fast-swap path.
>
> The failure sequence is:
>
> 1. A -> B switch, perf_event_context_sched_out() takes the fast path
> and does WRITE_ONCE(ctx->task, next) / WRITE_ONCE(next_ctx->task, task).
> An NMI then hits while the context is swapped, and
> __perf_event_overflow() queues pending task_work on the *current*
> task (A), even though the event now belongs to B's swapped-in
> context view.
>
> 2. B -> A switch. Because A now has pending task_work,
> nr_no_switch_fast is non-zero, so the slow path is taken and
> ctx->task is *not* swapped back.
>
> 3. A returns to user mode, task_work runs perf_pending_task() ->
> perf_sigtrap(), and event->ctx->task no longer equals current,
> tripping the WARN_ON_ONCE().
>
> The context fast-swap path was already excluded for events that need
> stable task association (inherit + sample read). sigtrap events have
> the same requirement: the SIGTRAP is targeted at ctx->task and must not
> be delivered after ctx->task has been swapped to another task.
>
> Fix this by also excluding events with attr->sigtrap from the fast-swap
> path, i.e. bump nr_no_switch_fast for sigtrap events in
> list_add_event()/list_del_event(), and update the comment describing
> the invariant accordingly.
This patch cannot be right, because it leaves in place the existing
sigtrap / nr_no_switch_fast bits.
Also, this is very sad; it might be better to try and fix up the special
case where the NMI hits the middle of context switch.
next prev parent reply other threads:[~2026-11-20 16:30 UTC|newest]
Thread overview: 28+ 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 9:59 ` sashiko-bot
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-19 9:51 ` [PATCH v5 2/2] perf/core: Disable context fast-swap for sigtrap events Tengda Wu
2026-11-19 10:03 ` sashiko-bot
2026-11-19 11:39 ` 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 [this message]
2026-11-20 17:06 ` Sebastian Andrzej Siewior
2026-11-20 17:37 ` Peter Zijlstra
2026-11-20 17:46 ` 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=20261120163007.GB2668564@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.