From: sashiko-bot@kernel.org
To: "Ziyang Men" <ziyang.meme@gmail.com>
Cc: bpf@vger.kernel.org, hannes@cmpxchg.org, tj@kernel.org, mkoutny@suse.com
Subject: Re: [PATCH v3 1/4] cgroup: add BPF kfuncs to read a cpu cgroup's stats
Date: Thu, 20 Aug 2026 21:28:40 +0000 [thread overview]
Message-ID: <20260820212840.AD15E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260820211758.3393984-2-ziyang.meme@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The `bpf_cgroup_base_stat` kfunc is exposed to all BPF program types but unsafely acquires a non-NMI-safe lock and unconditionally enables hardware interrupts, leading to IRQ state corruption, NMI deadlocks, and PREEMPT_RT panics.
--
--- Patch [1]: [PATCH v3 1/4] cgroup: add BPF kfuncs to read a cpu cgroup's stats ---
commit 41558082c4ece37f910c5109f3537477a7ba8820
Author: Ziyang Men <ziyang.meme@gmail.com>
cgroup: add BPF kfuncs to read a cpu cgroup's stats
This commit adds BPF kfuncs for reading CPU cgroup statistics. It registers
css_rstat_flush() and bpf_cgroup_base_stat(), allowing BPF programs to read
CFS bandwidth counters directly.
> diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
> index de816a43db9f0..5db72504a8a5a 100644
> --- a/kernel/cgroup/rstat.c
> +++ b/kernel/cgroup/rstat.c
[ ... ]
> @@ -752,10 +752,49 @@ void cgroup_base_stat_cputime_show(struct seq_file *seq)
> cgroup_force_idle_show(seq, &bstat);
> }
>
> -/* Add bpf kfuncs for css_rstat_updated() and css_rstat_flush() */
> +#ifdef CONFIG_BPF_SYSCALL
> +
> +__bpf_kfunc_start_defs();
> +
> +/**
> + * bpf_cgroup_base_stat - Read a cgroup's base statistics
> + * @cgrp: cgroup to read from
> + * @out: zero-initialized output in nanoseconds
> + *
> + * CPU time is adjusted as for cpu.stat.
> + */
> +__bpf_kfunc void bpf_cgroup_base_stat(struct cgroup *cgrp,
> + struct cgroup_base_stat *out)
> +{
> + if (cgroup_parent(cgrp)) {
> + __css_rstat_lock(&cgrp->self, -1);
> + *out = cgrp->bstat;
> + cputime_adjust(&cgrp->bstat.cputime, &cgrp->prev_cputime,
> + &out->cputime.utime, &out->cputime.stime);
> + __css_rstat_unlock(&cgrp->self, -1);
[Severity: High]
Does this code unconditionally enable hardware interrupts when called from
arbitrary BPF contexts?
Since this kfunc is registered under BPF_PROG_TYPE_UNSPEC without context
checks, it can be called from tracing programs (like kprobes or perf_events)
that may run in NMI context or with interrupts already disabled.
If it executes in an interrupt-disabled context, __css_rstat_unlock() will
unconditionally re-enable hardware interrupts and violate the caller's locking
assumptions:
kernel/cgroup/rstat.c:__css_rstat_unlock() {
...
spin_unlock_irq(lock);
}
Also, could calling this from an atomic tracing context cause a panic on
PREEMPT_RT, since spinlock_t is a sleeping lock there?
> + } else {
> + root_cgroup_cputime(out);
> + }
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260820211758.3393984-1-ziyang.meme@gmail.com?part=1
next prev parent reply other threads:[~2026-08-20 21:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-20 21:17 [PATCH v3 0/4] cgroup: expose cpu.stat and io.stat to BPF Ziyang Men
2026-08-20 21:17 ` [PATCH v3 1/4] cgroup: add BPF kfuncs to read a cpu cgroup's stats Ziyang Men
2026-08-20 21:28 ` sashiko-bot [this message]
2026-08-20 21:17 ` [PATCH v3 2/4] selftests/bpf: add cgroup_iter_cpu test for cpu cgroup kfuncs Ziyang Men
2026-08-20 22:19 ` bot+bpf-ci
2026-08-20 21:17 ` [PATCH v3 3/4] block: add BPF kfuncs to read blkcg io.stat Ziyang Men
2026-08-20 21:40 ` sashiko-bot
2026-08-20 22:19 ` bot+bpf-ci
2026-08-20 21:17 ` [PATCH v3 4/4] selftests/bpf: add test for blkcg io.stat BPF kfuncs Ziyang Men
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=20260820212840.AD15E1F000E9@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 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.