From: sashiko-bot@kernel.org
To: "Li Pengfei" <ljdlns1987@gmail.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v5 1/3] trace: add lock-free stackmap for stack trace deduplication
Date: Wed, 02 Sep 2026 06:57:44 +0000 [thread overview]
Message-ID: <20260902065744.DFA1E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260902064242.28606-2-lipengfei28@xiaomi.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] ftrace_stackmap_reset() omits ring buffer clearing and tracing state verification, violating the design claimed in the commit message.
--
commit 5edd2c96008787e0c0b7c542cb960e049ed8c84f
Author: Pengfei Li <lipengfei28@xiaomi.com>
trace: add lock-free stackmap for stack trace deduplication
This commit adds a lock-free hash map (ftrace_stackmap) to deduplicate kernel
stack traces for the ftrace ring buffer. By storing a 4-byte stack_id instead
of full traces, it reduces buffer usage while providing NMI-safe, lock-free
inserts and lookups.
> diff --git a/kernel/trace/trace_stackmap.c b/kernel/trace/trace_stackmap.c
> new file mode 100644
> index 0000000000000..6d938aa414dca
> --- /dev/null
> +++ b/kernel/trace/trace_stackmap.c
[ ... ]
> +int ftrace_stackmap_reset(struct ftrace_stackmap *smap)
> +{
> + int cpu;
> +
> + if (!smap)
> + return 0;
> +
> + if (atomic_cmpxchg(&smap->resetting, 0, 1) != 0)
> + return -EBUSY;
> +
> + /*
> + * synchronize_rcu() itself is a full barrier; no extra smp_mb()
> + * is needed before it. It drains in-flight ftrace callbacks that
> + * may have already passed the resetting check with the old value.
> + */
> + synchronize_rcu();
[Severity: Medium]
The commit message states: "Reset uses atomic_cmpxchg() to claim the resetting
flag, then verifies tracer_tracing_is_on() returns false."
Is there a missing check here? It looks like ftrace_stackmap_reset() omits
the tracing state verification entirely, meaning a reset could proceed while
tracing is active despite the design claims.
[ ... ]
> + /*
> + * Take the reader_sem in exclusive mode. This serializes the
> + * memset against any tracefs reader (seq_file iteration or
> + * stack_map_bin snapshot) that may currently hold the rwsem
> + * for read. synchronize_rcu() already drained the hot path;
> + * this rwsem covers process-context readers that aren't
> + * preempt-disabled.
> + */
> + down_write(&smap->reader_sem);
> +
> + memset(smap->entries, 0, sizeof(*smap->entries) * smap->map_size);
[Severity: Medium]
The commit message explicitly states: "Reset is destructive: under the
reader_sem write lock it clears the owning trace_array's ring buffer (and
snapshot buffer) BEFORE the map, so an external observer never sees 'trace
still has <stack_id N> but the map is already empty'. The buffers are cleared
with tracing_reset_all_cpus()".
Should tracing_reset_all_cpus() be called before this memset? As it is
implemented, the map is cleared without the ring buffer being cleared first.
Could this lead to misleading or corrupted trace data resolution from the
user's perspective, violating the design outlined in the commit message?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260902064242.28606-1-lipengfei28@xiaomi.com?part=1
next prev parent reply other threads:[~2026-09-02 6:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 6:42 [RFC PATCH v5 0/3] trace: stack trace deduplication for ftrace ring buffer Li Pengfei
2026-09-02 6:42 ` [RFC PATCH v5 1/3] trace: add lock-free stackmap for stack trace deduplication Li Pengfei
2026-09-02 6:57 ` sashiko-bot [this message]
2026-09-03 13:19 ` Pengfei Li
2026-09-02 6:42 ` [RFC PATCH v5 2/3] trace: integrate stackmap into ftrace stack recording path Li Pengfei
2026-09-02 6:54 ` sashiko-bot
2026-09-03 13:21 ` Pengfei Li
2026-09-02 6:42 ` [RFC PATCH v5 3/3] trace: add documentation, selftest and tooling for stackmap Li Pengfei
2026-09-02 6:51 ` sashiko-bot
2026-09-03 13:22 ` Pengfei Li
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=20260902065744.DFA1E1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=ljdlns1987@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox