From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: Karl Mehltretter <kmehltretter@gmail.com>,
bpf@vger.kernel.org, Tejun Heo <tj@kernel.org>
Cc: "Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"Jiri Olsa" <jolsa@kernel.org>,
"Emil Tsalapatis" <emil@etsalapatis.com>,
"Ihor Solodrai" <ihor.solodrai@linux.dev>,
"Shuah Khan" <shuah@kernel.org>, "Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Waiman Long" <longman@redhat.com>,
"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
"Puranjay Mohan" <puranjay@kernel.org>,
cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-rt-devel@lists.linux.dev
Subject: Re: [PATCH bpf-next v2] cgroup/rstat: disable preemption in css_rstat_updated()
Date: Tue, 24 Nov 2026 13:03:04 +0800 [thread overview]
Message-ID: <c665ace5-dfd5-4fb7-abcc-7454f732fb36@linux.dev> (raw)
In-Reply-To: <20261124031642.40616-1-kmehltretter@gmail.com>
On 11/24/26 11:16 AM, Karl Mehltretter wrote:
> BPF programs can call css_rstat_updated() with preemption enabled.
> The kfunc calls __css_rstat_updated(), which requires preemption to
> be disabled while it queues an rstat update. A cgroup iterator can
> hit the lockdep assertion on both RT and non-RT kernels. The
> cgroup_hierarchical_stats selftest can also hit it on PREEMPT_RT:
> spin_lock_irqsave() on trace_cgroup_path_lock leaves preemption and
> interrupts enabled there.
>
> Disable preemption in the BPF wrapper after validating the CPU and
> before calling __css_rstat_updated().
>
> Fixes: 36df6e3dbd7e ("cgroup: make css_rstat_updated nmi safe")
> Reported-by: Jiayuan Chen <jiayuan.chen@linux.dev>
> Closes: https://lore.kernel.org/r/20251119111402.153727-1-jiayuan.chen@linux.dev/
> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
> ---
> Assisted by an LLM.
>
> v2 places the preemption guard in the kfunc as Alexei requested:
> https://lore.kernel.org/r/DN26CP5BB6O7.23ALW6CZUBYSD@gmail.com/
> Since 8817005efbdf split out the BPF-only wrapper, v2 does not add
> preemption operations to the in-kernel callers discussed when Jiayuan
> proposed the earlier kernel-side version in November 2025:
> https://lore.kernel.org/r/20251121040655.89584-1-jiayuan.chen@linux.dev/
> v1: https://lore.kernel.org/r/20261121082843.44614-1-kmehltretter@gmail.com/
>
I suggest you target cgroup-tree instread of bpf-tree if you need revise, because
you only modified pure cgroup file.
Since your v2 does the same operation as my previous v1 which was denied
by cgroup maintainer, I also suggest you wait their replies (
As time goes by, situation can change).
I still insist on kernel-side modification just like this patch because we should
prevent 'wrong' bpf code from triggering WARNING.
> Tested in x86-64 KVM guests with lockdep on bpf-next 9867c61abbd4
> (base and v2) and 2bf3351c5f89 (v2). Both tests passed on all 24 boots.
>
> Boots with an rstat warning base v2 rebased v2
> PREEMPT_RT, cgroup_hierarchical_stats 2/2 0/2 0/2
> PREEMPT_RT, iter/cgroup 2/2 0/2 0/2
> PREEMPT (!RT), cgroup_hierarchical_stats 0/2 0/2 0/2
> PREEMPT (!RT), iter/cgroup 2/2 0/2 0/2
>
> kernel/cgroup/rstat.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
> index de816a43db9f..d72fe721cea0 100644
> --- a/kernel/cgroup/rstat.c
> +++ b/kernel/cgroup/rstat.c
> @@ -131,6 +131,7 @@ __bpf_kfunc void css_rstat_updated(struct cgroup_subsys_state *css, int cpu)
> if (unlikely(cpu < 0 || cpu >= nr_cpu_ids || !cpu_possible(cpu)))
> return;
>
> + guard(preempt)();
> __css_rstat_updated(css, cpu);
> }
>
>
> base-commit: 2bf3351c5f894697e8443eeef5333d4c4ce90cab
prev parent reply other threads:[~2026-11-24 5:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 3:16 [PATCH bpf-next v2] cgroup/rstat: disable preemption in css_rstat_updated() Karl Mehltretter
2026-11-24 5:03 ` Jiayuan Chen [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=c665ace5-dfd5-4fb7-abcc-7454f732fb36@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=bpf@vger.kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=hannes@cmpxchg.org \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=kmehltretter@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=longman@redhat.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=mkoutny@suse.com \
--cc=puranjay@kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=tj@kernel.org \
--cc=yonghong.song@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