From: sashiko-bot@kernel.org
To: "Jiayi Zhang" <zhangjiayi1014@gmail.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH] perf/core: mark the lockless accesses to event->state
Date: Wed, 02 Dec 2026 18:29:43 +0000 [thread overview]
Message-ID: <sashiko-outbox-246433@kernel.org> (raw)
In-Reply-To: <20261202181303.4161440-1-zhangjiayi1014@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] perf/core: incomplete marking of lockless accesses to
event->state
--
commit 7ea3a71bbe57ca5b794d6e4edb2f4bb6a7568125
Author: Jiayi Zhang <zhangjiayi1014@gmail.com>
perf/core: mark the lockless accesses to event->state
This commit wraps reads of event->state in perf_poll(), is_event_hup(), and
perf_event_release_kernel() with READ_ONCE(), and wraps stores to
event->state in _perf_event_enable() and perf_event_release_kernel() with
WRITE_ONCE() to address KCSAN data-race reports.
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 602b56b884e71..0e5826ba40601 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
[ ... ]
> @@ -5991,10 +5991,10 @@ int perf_event_release_kernel(struct perf_event *event)
> * Thus this guarantees that we will in fact observe and kill _ALL_
> * child events.
> */
> - if (event->state > PERF_EVENT_STATE_REVOKED) {
> + if (READ_ONCE(event->state) > PERF_EVENT_STATE_REVOKED) {
> perf_remove_from_context(event, DETACH_GROUP|DETACH_DEAD);
> } else {
> - event->state = PERF_EVENT_STATE_DEAD;
> + WRITE_ONCE(event->state, PERF_EVENT_STATE_DEAD);
> }
>
> perf_event_ctx_unlock(event, ctx);
[Severity: Low]
Should the remaining reads and writes of event->state outside ctx->lock
also be marked with READ_ONCE() and WRITE_ONCE()?
This store of PERF_EVENT_STATE_DEAD under ctx->mutex pairs with
is_orphaned_event(), which is called from inherit_event() under
parent_event->child_mutex without parent_event->ctx->lock, yet
is_orphaned_event() still uses a plain load:
kernel/events/core.c:is_orphaned_event() {
return event->state == PERF_EVENT_STATE_DEAD;
}
Similarly, da916e96e2de ("perf: Make perf_pmu_unregister() useable") added
several other event->state <= PERF_EVENT_STATE_REVOKED checks outside
ctx->lock (in _perf_ioctl(), perf_mmap(), perf_fasync(),
__perf_event_set_bpf_prog(), perf_event_set_output(), and inherit_event())
that remain unmarked plain loads and can hit the same KCSAN data-race
reports against event_sched_in() and event_sched_out(). Other unmarked
accesses outside ctx->lock also remain in __perf_read(),
__do_sys_perf_event_open(), and live-event state resets in
perf_event__state_init() (via move_group) and __perf_pmu_install_event().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202181303.4161440-1-zhangjiayi1014@gmail.com?part=1
prev parent reply other threads:[~2026-12-02 18:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 18:13 [PATCH] perf/core: mark the lockless accesses to event->state Jiayi Zhang
2026-12-02 18:29 ` 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=sashiko-outbox-246433@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zhangjiayi1014@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox