mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Luo Gengkun <luogengkun2@huawei.com>
Cc: mingo@redhat.com, acme@kernel.org, namhyung@kernel.org,
	mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
	jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com,
	james.clark@linaro.org, elver@google.com, dvyukov@google.com,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf/core: Fix race between perf_event_exit_task and perf_pending_task
Date: Fri, 18 Sep 2026 11:50:49 +0200	[thread overview]
Message-ID: <20260918095049.GL1837346@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20260416033443.1492483-1-luogengkun2@huawei.com>

On Thu, Apr 16, 2026 at 03:34:43AM +0000, Luo Gengkun wrote:
> A race condition exists between perf_event_exit_task() and perf_pending_task().
> 
> During begin_new_exec(), perf_event_exit_task() may be called, and the
> PF_EXITING flag is not set on task. so perf_sigtrap() continues to execute
> and triggers WARN_ON_ONCE(event->ctx->task != current).
> 
> To fix this problem, also check if the event->ctx->task is TASK_TOMBSTONE.
> 
> Fixes: 97ba62b27867 ("perf: Add support for SIGTRAP on perf events")
> Signed-off-by: Luo Gengkun <luogengkun2@huawei.com>
> ---
>  kernel/events/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 1f5699b339ec..3422900263fa 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -7543,7 +7543,7 @@ static void perf_sigtrap(struct perf_event *event)
>  	 * Both perf_pending_task() and perf_pending_irq() can race with the
>  	 * task exiting.
>  	 */
> -	if (current->flags & PF_EXITING)
> +	if (current->flags & PF_EXITING || event->ctx->task == TASK_TOMBSTONE)
>  		return;

Since do_exit() also calls perf_event_exit_task() (albeit a little later
than exit_signals()), and task_can_queue_signal() will return false when
PF_EXITING, and we ignore the return value of
send_sig_perf()/send_sig_info(). I don't think we need to check both.

That is, I think:

	if (event->ctx->task == TASK_TOMBSTONE)

is sufficient. Also, the comment needs updating.

  parent reply	other threads:[~2026-09-18  9:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-16  3:34 Luo Gengkun
2026-09-15 21:34 ` Ian Rogers
2026-09-18  9:02   ` Dmitry Vyukov
2026-09-18  9:50 ` Peter Zijlstra [this message]
2026-09-20  7:50   ` [PATCH v2] perf/core: Fix race between perf_event_exit_task() and perf_pending_task() Luo Gengkun

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=20260918095049.GL1837346@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=dvyukov@google.com \
    --cc=elver@google.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=luogengkun2@huawei.com \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.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

all inboxes | Powered by JetHome®