The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Tengda Wu <wutengda@huaweicloud.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: 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,
	Tengda Wu <wutengda@huaweicloud.com>
Subject: [PATCH v5 0/2] perf/core: Fix sigtrap task_work races
Date: Thu, 19 Nov 2026 09:50:59 +0000	[thread overview]
Message-ID: <cover.1795053619.git.wutengda@huaweicloud.com> (raw)

Two fixes for sigtrap task_work handling since the switch to always
enqueue SIGTRAP via task_work.

The warning splats and PoCs for both patches are too long to inline
in the commit messages, so they are provided as separate replies at
the following links:

Patch 1: https://lore.kernel.org/all/29aa123c-36a2-460f-b76b-a8dfe1eb542f@huaweicloud.com/
Patch 2: https://lore.kernel.org/all/d1b24bbf-9111-4766-87c8-ff97adcac727@huaweicloud.com/

Patch 1 fixes a re-entrancy race in __perf_event_overflow(): pending_work
was set only after task_work_add(), so an NMI could re-enter and enqueue
the same pending_task twice, creating a cycle in the task work list and
unbalancing the event refcount. Claim pending_work before enqueuing, and
clear it if the enqueue fails.

Patch 2 fixes a WARN_ON_ONCE() in perf_sigtrap() triggered by the context
fast-swap path swapping ctx->task while a sigtrap event has pending task
work. SIGTRAP is targeted at ctx->task, so exclude sigtrap events from
fast-swap alongside inherit+sample-read events.

Changelog
=========
v4 -> v5:
  - v4: https://lore.kernel.org/all/cover.1794914794.git.wutengda@huaweicloud.com/
  - Roll back patch 2 to v3 to avoid the fast swap isolation omission in
    the nr_no_switch_fast 1->0 scenario. (Shashiko)
v3 -> v4:
  - v3: https://lore.kernel.org/all/cover.1793870900.git.wutengda@huaweicloud.com/
  - Patch 1: Use acquire/release pairs for pending_work updates (Sebastian)
  - Patch 2: Remove redundant nr_no_switch_fast updates (Sebastian)
v2 -> v3:
  - v2: https://lore.kernel.org/all/20261102021355.650671-1-wutengda@huaweicloud.com/
  - Added Patch 2 to fix WARN_ON_ONCE() in perf_sigtrap()
v1 -> v2:
  - v1: https://lore.kernel.org/all/20261031114520.642476-1-wutengda@huaweicloud.com/
  - Drop the redundant event->pending_work assignment. (Sashiko)

Tengda Wu (2):
  perf/core: Prevent duplicate sigtrap task work enqueue
  perf/core: Disable context fast-swap for sigtrap events

 include/linux/perf_event.h |  6 ++---
 kernel/events/core.c       | 48 ++++++++++++++++++++++++++------------
 2 files changed, 35 insertions(+), 19 deletions(-)

-- 
2.34.1


             reply	other threads:[~2026-11-19  9:51 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  9:50 Tengda Wu [this message]
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-25 10:55                   ` Sebastian Andrzej Siewior
2026-11-25 16:17                     ` Peter Zijlstra
2026-11-25 16:45                       ` Sebastian Andrzej Siewior
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
2026-11-25 10:03                 ` Tengda Wu
2026-11-25 10:09                   ` Tengda Wu
2026-11-25 13:36                     ` Peter Zijlstra
2026-11-25 16:13                       ` Peter Zijlstra
2026-11-26  1:59                         ` Tengda Wu
2026-11-26 11:01                           ` Peter Zijlstra
2026-11-26 12:44                         ` [tip: perf/urgent] perf: Fix sigtrap vs fast-switch tip-bot2 for Peter Zijlstra
2026-11-26 12:44                         ` [tip: perf/urgent] perf: Fix sigtrap for software events tip-bot2 for Peter Zijlstra
2026-11-25  9:30             ` [PATCH v5 2/2] perf/core: Disable context fast-swap for sigtrap events 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=cover.1795053619.git.wutengda@huaweicloud.com \
    --to=wutengda@huaweicloud.com \
    --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=peterz@infradead.org \
    /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