Re: [PATCH bpf-next v2] cgroup/rstat: disable preemption in css_rstat_updated()

From: Shakeel Butt

Date: Tue Nov 24 2026 - 00:20:15 EST


On Tue, Nov 24, 2026 at 01:03:04PM +0800, Jiayuan Chen wrote:
>
>
> 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@xxxxxxxxx>
> > Closes: https://lore.kernel.org/r/20251119111402.153727-1-jiayuan.chen@xxxxxxxxx/
> > Signed-off-by: Karl Mehltretter <kmehltretter@xxxxxxxxx>
> > ---
> > Assisted by an LLM.
> >
> > v2 places the preemption guard in the kfunc as Alexei requested:
> > https://lore.kernel.org/r/DN26CP5BB6O7.23ALW6CZUBYSD@xxxxxxxxx/
> > 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@xxxxxxxxx/
> > v1: https://lore.kernel.org/r/20261121082843.44614-1-kmehltretter@xxxxxxxxx/
> >
>
> 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.
>

After the commit 8817005efbdfd all the in-kernel usage has moved to
__css_rstat_updated(), so I think this patch is fine.