From: sashiko-bot@kernel.org
To: "Puranjay Mohan" <puranjay@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v3 1/4] perf/core: Fix NULL pmu_ctx passed to PMU sched_task callback
Date: Mon, 13 Apr 2026 19:31:20 +0000 [thread overview]
Message-ID: <20260413193121.79536C2BCAF@smtp.kernel.org> (raw)
In-Reply-To: <20260413185740.3286146-2-puranjay@kernel.org>
Sashiko AI review found 1 potential issue(s):
- [High] Incomplete Fix / Architectural Regression Masking in __perf_pmu_sched_task()
--
commit f71d68607ec5b88fb13bb33d01fafd22533f428b
Author: Puranjay Mohan <puranjay@kernel.org>
perf/core: Fix NULL pmu_ctx passed to PMU sched_task callback
This commit modifies __perf_pmu_sched_task() to avoid a NULL pointer
dereference when a task has no perf events for a specific PMU. It falls
back to using the CPU context when the task context is NULL, which
prevents crashes when using CPU-wide branch-stack events.
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 1f5699b339ec8..2a8fb78e13471 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -3906,7 +3906,8 @@ static void __perf_pmu_sched_task(struct perf_cpu_pmu_context *cpc,
> perf_ctx_lock(cpuctx, cpuctx->task_ctx);
> perf_pmu_disable(pmu);
>
> - pmu->sched_task(cpc->task_epc, task, sched_in);
> + pmu->sched_task(cpc->task_epc ? cpc->task_epc : &cpc->epc,
> + task, sched_in);
While this prevents the NULL pointer dereference when __perf_pmu_sched_task()
is called, does this fully resolve the issue if the task has an unrelated
perf event?
Looking at the caller perf_pmu_sched_task():
static void perf_pmu_sched_task(struct task_struct *prev,
struct task_struct *next,
bool sched_in)
{
...
if (prev == next || cpuctx->task_ctx)
return;
...
}
If the task has an unrelated event, like a software event, cpuctx->task_ctx
is not NULL, and this returns early.
The fallback path perf_event_context_sched_in/out() calls
perf_ctx_sched_task_cb(), which iterates over ctx->pmu_ctx_list.
Since a PMU with only CPU-wide events is not in ctx->pmu_ctx_list, will this
PMU be silently bypassed?
Could this regression cause branch records to leak across tasks if the
scheduled task has an unrelated perf event?
>
> perf_pmu_enable(pmu);
> perf_ctx_unlock(cpuctx, cpuctx->task_ctx);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260413185740.3286146-1-puranjay@kernel.org?part=1
next prev parent reply other threads:[~2026-04-13 19:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-13 18:57 [PATCH v3 0/4] arm64: Add BRBE support for bpf_get_branch_snapshot() Puranjay Mohan
2026-04-13 18:57 ` [PATCH v3 1/4] perf/core: Fix NULL pmu_ctx passed to PMU sched_task callback Puranjay Mohan
2026-04-13 19:31 ` sashiko-bot [this message]
2026-04-13 18:57 ` [PATCH v3 2/4] perf: Use a union to clear branch entry bitfields Puranjay Mohan
2026-04-13 19:46 ` sashiko-bot
2026-04-13 18:57 ` [PATCH v3 3/4] perf/arm64: Add BRBE support for bpf_get_branch_snapshot() Puranjay Mohan
2026-04-13 20:31 ` sashiko-bot
2026-04-13 18:57 ` [PATCH v3 4/4] selftests/bpf: Adjust wasted entries threshold for ARM64 BRBE Puranjay Mohan
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=20260413193121.79536C2BCAF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=puranjay@kernel.org \
--cc=sashiko@lists.linux.dev \
/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