From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Tengda Wu <wutengda@huaweicloud.com>,
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 18:06:26 +0100 [thread overview]
Message-ID: <20261120170626.1UyR31Sg@linutronix.de> (raw)
In-Reply-To: <20261120163007.GB2668564@noisy.programming.kicks-ass.net>
On 2026-11-20 17:30:07 [+0100], Peter Zijlstra wrote:
> This patch cannot be right, because it leaves in place the existing
> sigtrap / nr_no_switch_fast bits.
I said the same thing and then sashiko came with
https://lore.kernel.org/all/sashiko-outbox-218736@kernel.org/
| [Severity: Medium]
| Can ctx->nr_no_switch_fast drop to zero while event->pending_task is still
| queued if the sigtrap event is detached before perf_pending_task() runs?
|
| Detaching an event does not cancel or flush event->pending_task; instead,
| pending_task holds a reference to the event until the task returns to user
| space. When a parent event with attr.inherit and attr.sigtrap is closed while
| a child event has pending_task queued, perf_event_release_kernel() detaches the
| child events from their cloned contexts without uncloning them:
|
| CPU0 (task A) CPU1
| __perf_event_overflow(child_A)
| task_work_add(A, &child_A->pending_task)
| perf_event_release_kernel(parent)
| perf_remove_from_context(child_A, ...)
| list_del_event(child_A, ctx_A)
| local_dec(&ctx_A->nr_no_switch_fast)
| perf_remove_from_context(child_B, ...)
| list_del_event(child_B, ctx_B)
| local_dec(&ctx_B->nr_no_switch_fast)
| schedule() (A -> B)
| perf_event_context_sched_out(A, B)
| /* context_equiv(ctx_A, ctx_B) && nr_no_switch_fast == 0 */
| WRITE_ONCE(ctx_A->task, B)
| ...
| perf_pending_task(&child_A->pending_task)
| perf_sigtrap(child_A)
| WARN_ON_ONCE(event->ctx->task != current) <-- trips WARN, drops SIGTRAP
|
| Keeping the increment in __perf_event_overflow() and decrement in
| perf_pending_task() alongside list_add_event() and list_del_event() would keep
| nr_no_switch_fast elevated until pending_task completes. Note that because
| list_add_event() and list_del_event() can run on a remote CPU under ctx->lock
| while __perf_event_overflow() or perf_pending_task() runs on ctx->task's CPU
| without ctx->lock, nr_no_switch_fast would also need to be atomic_t rather than
| CPU-local local_t.
Sebastian
next prev parent reply other threads:[~2026-11-20 17:06 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
2026-11-20 17:06 ` Sebastian Andrzej Siewior [this message]
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=20261120170626.1UyR31Sg@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--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=peterz@infradead.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