From: sashiko-bot@kernel.org
To: l1za0.sec@gmail.com
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH] perf: avoid lockdep warning in self-monitoring perf_event_open
Date: Sun, 07 Jun 2026 16:36:27 +0000 [thread overview]
Message-ID: <20260607163627.F22CD1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260607162622.15534-1-l1za0.sec@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Hard deadlock and unsafe `this_cpu_ptr()` usage due to bypass of IPI context in `perf_install_in_context()`.
--
commit edfe32c20b9adaadf4bb22117c091b1b0e31a92d
Author: Haocheng Yu <l1za0.sec@gmail.com>
perf: avoid lockdep warning in self-monitoring perf_event_open
This commit attempts to fix a lockdep warning by adding a fast path for
self-monitoring in perf_install_in_context(). It directly calls
__perf_install_in_context() instead of using task_function_call() when the
target task is current.
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 7935d5663944e..6e689f2dafbd9 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
[ ... ]
> @@ -3199,6 +3199,10 @@ perf_install_in_context(struct perf_event_context *ctx,
> */
> smp_mb();
> again:
> + if (task == current) {
> + __perf_install_in_context(event);
> + return;
> + }
[Severity: High]
Does this direct call to __perf_install_in_context() introduce a regression
by running with preemption and interrupts enabled?
Since perf_install_in_context() only holds ctx->mutex here, preemption and
interrupts are still active. When __perf_install_in_context() is called
directly instead of via IPI, it executes:
kernel/events/core.c:__perf_install_in_context() {
...
struct perf_cpu_context *cpuctx = this_cpu_ptr(&perf_cpu_context);
...
}
Will this trigger a warning for using this_cpu_ptr() in preemptible context,
and potentially allow the task to migrate and corrupt per-CPU data?
Additionally, __perf_install_in_context() acquires locks without disabling
interrupts:
kernel/events/core.c:__perf_install_in_context() {
...
raw_spin_lock(&cpuctx->ctx.lock);
if (ctx->task) {
raw_spin_lock(&ctx->lock);
...
}
If a hardware PMU interrupt or a timer tick (like perf_event_task_tick())
fires on the same CPU while these locks are held, could this regression
result in a hard deadlock when the interrupt handler attempts to acquire
them again?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260607162622.15534-1-l1za0.sec@gmail.com?part=1
prev parent reply other threads:[~2026-06-07 16:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-07 16:26 [PATCH] perf: avoid lockdep warning in self-monitoring perf_event_open l1za0.sec
2026-06-07 16:36 ` 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=20260607163627.F22CD1F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=l1za0.sec@gmail.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@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 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.