From: sashiko-bot@kernel.org
To: "Minwoo Ahn" <mwahn402@gmail.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2] perf/core: Fix sampling period inconsistency across CPU migration
Date: Wed, 29 Apr 2026 09:13:34 +0000 [thread overview]
Message-ID: <20260429091335.87487C2BCC6@smtp.kernel.org> (raw)
In-Reply-To: <20260429055924.10594-1-mwahn402@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Memory leak of struct perf_event_context in perf_get_task_ctxp()
- [High] Cross-session interference due to flawed inheritance matching in perf_get_task_ctxp()
--
commit 1659d24a7199e1068822505af2a6e5f2de5e9e1a
Author: Minwoo Ahn <mwahn402@gmail.com>
perf/core: Fix sampling period inconsistency across CPU migration
This commit introduces struct perf_task_context to preserve the sampling
state of per-task software events when task migration occurs. It allocates
a shared context across per-CPU perf_event instances to transport the
period_left value between CPUs.
[ ... ]
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
[ ... ]
> @@ -13259,6 +13291,41 @@ static void account_event(struct perf_event *event)
> account_pmu_sb_event(event);
> }
>
> +static struct perf_task_context *
> +perf_get_task_ctxp(struct perf_event *event, struct task_struct *task,
> + bool inherit)
> +{
> + struct perf_task_context *ctxp = NULL;
> + struct perf_event_context *ctx;
> + struct perf_event *iter;
> + unsigned long flags;
> +
> + ctx = perf_lock_task_context(task, &flags);
> + if (ctx) {
> + list_for_each_entry(iter, &ctx->event_list, event_entry) {
> + if (iter->perf_task_ctxp &&
> + (iter->owner == current ||
> + (inherit && !iter->owner)) &&
Could this cause independent tracing sessions to interfere with each other?
If two separate sessions monitor the same process with identical
configurations, their inherited child events will both have an owner of NULL.
Since perf_event_equal_task_ctx() only compares the config and sample_period,
the second session's child event might incorrectly match the first session's
event.
Would this lead to independent sessions sharing the same perf_task_ctxp and
clobbering each other's period_left state during task migrations?
> + perf_event_equal_task_ctx(&iter->attr,
> + &event->attr)) {
> + ctxp = iter->perf_task_ctxp;
> + refcount_inc(&ctxp->refcount);
> + break;
> + }
> + }
> + raw_spin_unlock_irqrestore(&ctx->lock, flags);
Does this leak the perf_event_context?
perf_lock_task_context() returns the context with its reference count
incremented, so the caller is typically responsible for dropping the reference
by calling put_ctx() after unlocking it.
Because put_ctx() is missing here, it seems this could leak the context and
the task_struct it pins each time a per-task software sampling event is
successfully created.
> + }
> +
> + if (!ctxp) {
> + ctxp = kzalloc_obj(struct perf_task_context);
> + if (!ctxp)
> + return NULL;
> + refcount_set(&ctxp->refcount, 1);
> + }
> +
> + return ctxp;
> +}
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260429055924.10594-1-mwahn402@gmail.com?part=1
prev parent reply other threads:[~2026-04-29 9:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-29 5:59 [PATCH v2] perf/core: Fix sampling period inconsistency across CPU migration Minwoo Ahn
2026-04-29 9:13 ` sashiko-bot [this message]
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=20260429091335.87487C2BCC6@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mwahn402@gmail.com \
--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