From: sashiko-bot@kernel.org
To: "Ziyang Men" <ziyang.meme@gmail.com>
Cc: hannes@cmpxchg.org, tj@kernel.org, mkoutny@suse.com, bpf@vger.kernel.org
Subject: Re: [PATCH v2 1/2] block: add BPF kfuncs to read blkcg io.stat
Date: Mon, 17 Aug 2026 22:08:29 +0000 [thread overview]
Message-ID: <20260817220830.389671F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260817214205.723267-2-ziyang.meme@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Concurrent execution of `blkcg_fill_root_iostats()` corrupts the `u64_stats_sync` sequence counter, leading to reader deadlocks.
--
--- Patch [1]: [PATCH v2 1/2] block: add BPF kfuncs to read blkcg io.stat ---
commit bdaf96b752ce960b924c3be337708d377f83207c
Author: Ziyang Men <ziyang.meme@gmail.com>
block: add BPF kfuncs to read blkcg io.stat
This commit introduces BPF kfuncs to allow reading per-device block I/O
controller statistics. It exposes blkcg_fill_root_iostats and provides
bpf_blkcg_flush_stats and iterator functions for blkg.
> diff --git a/block/bpf_blkcg.c b/block/bpf_blkcg.c
> new file mode 100644
> index 0000000000000..25c809f5091c2
> --- /dev/null
> +++ b/block/bpf_blkcg.c
[ ... ]
> +__bpf_kfunc void bpf_blkcg_flush_stats(struct cgroup *cgrp)
> +{
> + struct cgroup_subsys_state *css;
> +
> + /* Pin the css for the sleepable flush. */
> + rcu_read_lock();
> + css = cgroup_css(cgrp, &io_cgrp_subsys);
> + if (css && !css_tryget(css))
> + css = NULL;
> + rcu_read_unlock();
> +
> + if (!css)
> + return;
> +
> + if (!css->parent)
> + blkcg_fill_root_iostats();
[Severity: High]
This isn't a bug introduced by this patch, but can concurrent executions
here lead to sequence counter corruption and reader deadlocks on 32-bit
systems?
In block/blk-cgroup.c, blkcg_fill_root_iostats() loops over block devices
and updates statistics without an overarching writer lock:
blkcg_fill_root_iostats() {
...
flags = u64_stats_update_begin_irqsave(&blkg->iostat.sync);
blkg_iostat_set(&blkg->iostat.cur, &tmp);
u64_stats_update_end_irqrestore(&blkg->iostat.sync, flags);
...
}
On 32-bit architectures, u64_stats_update_begin_irqsave() maps to
write_seqcount_begin(), which requires external mutual exclusion to prevent
concurrent writers from corrupting the sequence counter. If the counter
becomes permanently odd, readers using read_seqcount_begin() will spin
infinitely.
While this bug existed previously via concurrent reads of the root cgroup's
io.stat sysfs file, exposing blkcg_fill_root_iostats() via this sleepable
BPF kfunc allows BPF programs to easily and repeatedly trigger this lockless
code path simultaneously across multiple CPUs.
> + else
> + css_rstat_flush(css);
> +
> + css_put(css);
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260817214205.723267-1-ziyang.meme@gmail.com?part=1
next prev parent reply other threads:[~2026-08-17 22:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 21:42 [PATCH v2 0/2] block: expose blkcg io.stat to BPF Ziyang Men
2026-08-17 21:42 ` [PATCH v2 1/2] block: add BPF kfuncs to read blkcg io.stat Ziyang Men
2026-08-17 22:08 ` sashiko-bot [this message]
2026-08-17 22:28 ` bot+bpf-ci
2026-08-18 17:21 ` Tejun Heo
2026-08-18 22:31 ` Ziyang Men
2026-08-18 22:42 ` Tejun Heo
2026-08-18 23:01 ` Ziyang Men
2026-08-17 21:42 ` [PATCH v2 2/2] selftests/bpf: add test for blkcg io.stat BPF kfuncs Ziyang Men
2026-08-17 22:41 ` bot+bpf-ci
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=20260817220830.389671F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=mkoutny@suse.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tj@kernel.org \
--cc=ziyang.meme@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