All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dapeng Mi <dapeng1.mi@linux.intel.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Andi Kleen <ak@linux.intel.com>,
	Eranian Stephane <eranian@google.com>
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Dapeng Mi <dapeng1.mi@intel.com>, Zide Chen <zide.chen@intel.com>,
	Falcon Thomas <thomas.falcon@intel.com>,
	Xudong Hao <xudong.hao@intel.com>,
	Dapeng Mi <dapeng1.mi@linux.intel.com>,
	Hanxiang Xu <xuhx@hust.edu.cn>
Subject: [PATCH 2/2] perf/core: Cancel PMU mux hrtimer before freeing per-CPU context
Date: Mon,  2 Nov 2026 08:59:05 +0800	[thread overview]
Message-ID: <20261102005905.2017784-2-dapeng1.mi@linux.intel.com> (raw)
In-Reply-To: <20261102005905.2017784-1-dapeng1.mi@linux.intel.com>

perf_pmu_free() can free the PMU's per-CPU perf_cpu_pmu_context while
the multiplexing hrtimer is still armed. Once the timer expires, it
dereferences the freed cpc and can crash the kernel.

Cancel the multiplexing hrtimer before freeing the PMU context by adding
a perf_mux_cancel_hrtimer() helper and invoking it from the PMU free
path.

Reported-by: Hanxiang Xu <xuhx@hust.edu.cn>
Closes: https://lore.kernel.org/all/ca4f133.14714.1a162b8654c.Coremail.xuhx@hust.edu.cn/
Fixes: 8f4c4963d283 ("perf/core: Simplify the perf_pmu_register() error path")
Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
---
 kernel/events/core.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index e088c31534bc..54eb962ab6ff 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -1316,6 +1316,12 @@ static void __perf_mux_hrtimer_init(struct perf_cpu_pmu_context *cpc, int cpu)
 		      HRTIMER_MODE_ABS_PINNED_HARD);
 }
 
+static void perf_mux_cancel_hrtimer(struct perf_cpu_pmu_context *cpc)
+{
+	cpc->hrtimer_active = 0;
+	hrtimer_cancel(&cpc->hrtimer);
+}
+
 static int perf_mux_hrtimer_restart(struct perf_cpu_pmu_context *cpc)
 {
 	struct hrtimer *timer = &cpc->hrtimer;
@@ -13024,6 +13030,7 @@ static void perf_pmu_free(struct pmu *pmu)
 			cpc = *per_cpu_ptr(pmu->cpu_pmu_context, cpu);
 			if (!cpc)
 				continue;
+			perf_mux_cancel_hrtimer(cpc);
 			if (cpc->epc.embedded) {
 				/* refcount managed */
 				put_pmu_ctx(&cpc->epc);
-- 
2.34.1


  reply	other threads:[~2026-11-02  1:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02  0:59 [PATCH 1/2] perf/core: Avoid NULL dereference in mux interval store Dapeng Mi
2026-11-02  0:59 ` Dapeng Mi [this message]
2026-11-02  1:14   ` [PATCH 2/2] perf/core: Cancel PMU mux hrtimer before freeing per-CPU context sashiko-bot
2026-11-02  1:22 ` [PATCH 1/2] perf/core: Avoid NULL dereference in mux interval store sashiko-bot

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=20261102005905.2017784-2-dapeng1.mi@linux.intel.com \
    --to=dapeng1.mi@linux.intel.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=dapeng1.mi@intel.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=thomas.falcon@intel.com \
    --cc=xudong.hao@intel.com \
    --cc=xuhx@hust.edu.cn \
    --cc=zide.chen@intel.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.