All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Tengda Wu <wutengda@huaweicloud.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	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 1/2] perf/core: Prevent duplicate sigtrap task work enqueue
Date: Thu, 19 Nov 2026 13:09:25 +0100	[thread overview]
Message-ID: <20261119120925.Ecvw25kh@linutronix.de> (raw)
In-Reply-To: <45bd71c976aea1a0e8bf5762dd6b6552e6009439.1795053619.git.wutengda@huaweicloud.com>

On 2026-11-19 09:51:00 [+0000], Tengda Wu wrote:
> The sigtrap handling in __perf_event_overflow() checks
> event->pending_work before calling task_work_add(), but only sets
> pending_work after the task work has been queued.
> 
> This leaves a window where an NMI can interrupt task_work_add()
> and re-enter __perf_event_overflow() for the same event. Since
> pending_work is still zero, the nested invocation can enqueue
> the same pending_task again.
> 
> The re-entrant call path looks like this:
> 
>   __perf_event_overflow()
>     task_work_add()
>       kasan_record_aux_stack()
>         <NMI>
>           __perf_event_overflow()
>             task_work_add()
> 
> The nested invocation may enqueue pending_task before the
> outer invocation does. When the outer invocation resumes, it
> inserts the same task work entry again, potentially creating
> a cycle in the task work list.
> 
> As a result, perf_pending_task() may be executed repeatedly,
> leading to unbalanced event reference counting.

The repeated task_work_add() will corrupt the list.

> Fix this by atomically claiming pending_work with
> cmpxchg_acquire() before calling task_work_add(). This ensures
> that only one invocation can enqueue the task work, even when
> another overflow occurs re-entrantly from an NMI.
> 
> If task_work_add() fails, clear the claim with
> smp_store_release() to allow a subsequent overflow to retry.

"to revert to previous state".

> In perf_pending_task(), defer clearing pending_work until
> after perf_sigtrap() has completed. Use smp_store_release()
> to ensure that a subsequent overflow cannot re-queue the task
> work before the previous invocation has finished handling it.
> 
> Also use smp_load_acquire() when checking pending_work in
> the exclude_kernel warning path to ensure the read is properly
> ordered.
> 
> Fixes: c5d93d23a260 ("perf: Enqueue SIGTRAP always via task_work.")
> Signed-off-by: Tengda Wu <wutengda@huaweicloud.com>

Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Sebastian

  parent reply	other threads:[~2026-11-19 12:09 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 [this message]
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
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=20261119120925.Ecvw25kh@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 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.