From: sashiko-bot@kernel.org
To: "Jaewon Jung" <jaewon8868@gmail.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] tracing: Make event_enable_count_probe() count atomic
Date: Thu, 03 Dec 2026 05:16:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-247181@kernel.org> (raw)
In-Reply-To: <20261203045851.2243395-1-jaewon8868@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] tracing: unchecked cmpxchg loses decrements in
event_enable_count_probe()
- [Low] tracing: redundant smp_wmb() before atomic_long_cmpxchg() in
probe callback
- [Low] tracing: commit message omits barrier and reordering rationale
--
commit 41e0885247841d0dfe5e2b4d512d00bff70bfd6e
Author: Jaewon Jung <jaewon8868@gmail.com>
> tracing: Make event_enable_count_probe() count atomic
>
> Concurrent callbacks race on the plain count read and decrement. This can
> lose updates or turn 0 into -1 (unlimited). Use atomic_long_t and cmpxchg
> for the decrement.
>
> Fixes: 3cd715de2611 ("tracing: Add function probe triggers to enable/disable events")
> Signed-off-by: Jaewon Jung <jaewon8868@gmail.com>
[Severity: Low]
Could the commit message also explain why update_event_probe() is moved
ahead of the count decrement, why the memory barriers are added, and why
atomic_long_cmpxchg() ignores failure? Right now it only mentions making
count atomic and using cmpxchg, leaving the ordering changes and their
rationale undocumented.
> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index 0d4195b43208e..72db3921665b1 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
[ ... ]
> @@ -4447,18 +4447,27 @@ event_enable_count_probe(unsigned long ip, unsigned long parent_ip,
>
> edata = *pdata;
>
> - if (!edata->count)
> + long count = atomic_long_read(&edata->count);
> +
> + if (!count)
> return;
>
> + /* Make sure we see count before checking event state */
> + smp_rmb();
> +
> /* Skip if the event is in a state we want to switch to */
> if (edata->enable == !test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT,
> &edata->file->flags))
> return;
>
> - if (edata->count != -1)
> - (edata->count)--;
> -
> update_event_probe(edata);
> +
> + if (count != -1) {
> + /* Make sure event state is visible before updating count */
> + smp_wmb();
[Severity: Low]
Is this smp_wmb() redundant before atomic_long_cmpxchg()?
Value-returning atomic RMW operations already imply full memory ordering
on success, and a failed atomic_long_cmpxchg() performs no write before
returning. On weakly ordered architectures such as arm64, this emits
back-to-back barriers (dmb ishst before casal). Dropping smp_wmb(), or
pairing atomic_long_read_acquire() with atomic_long_cmpxchg_release(),
avoids the duplicate barrier.
> +
> + atomic_long_cmpxchg(&edata->count, count, count - 1);
> + }
[Severity: Medium]
Can discarding the return value of atomic_long_cmpxchg() lose count
decrements or let the probe fire after count reaches zero?
Suppose edata->enable is true, edata->count is 2, and a paired
disable_event probe or tracefs write toggles the event back off between
two concurrent callbacks:
CPU0 CPU1 CPU2
event_enable_count_probe()
read count // 2
test_bit() // disabled
update_event_probe()
disable event
event_enable_count_probe()
read count // 2
test_bit() // disabled
update_event_probe()
cmpxchg(2 -> 1) // ok
cmpxchg(2 -> 1) // fails, ignored <-- decrement lost
Both CPUs performed an enable transition, but edata->count remains 1
instead of 0, allowing a third enable. With an initial count of 1, the
same interleaving lets CPU0 call update_event_probe() and re-enable the
event after edata->count has already reached 0.
Since EVENT_FILE_FL_SOFT_DISABLED_BIT is a single bit, using
test_and_clear_bit() / test_and_set_bit() to claim the state transition
and retrying the count decrement on cmpxchg failure would keep the count
accurate.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203045851.2243395-1-jaewon8868@gmail.com?part=1
next prev parent reply other threads:[~2026-12-03 5:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 2:51 [PATCH] tracing: Make event_enable_count_probe() count atomic Jaewon Jung
2026-12-03 3:02 ` sashiko-bot
2026-12-03 4:58 ` Jaewon Jung
2026-12-03 5:16 ` sashiko-bot [this message]
2026-12-03 13:33 ` Steven Rostedt
2026-12-04 0:11 ` Jaewon Jung
2026-12-03 13:14 ` Jaewon Jung
2026-12-03 13:30 ` 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=sashiko-outbox-247181@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=jaewon8868@gmail.com \
--cc=linux-trace-kernel@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.