* [PATCH bpf-next v2] cgroup/rstat: disable preemption in css_rstat_updated()
@ 2026-11-24 3:16 Karl Mehltretter
2026-11-24 5:03 ` Jiayuan Chen
2026-11-24 5:20 ` Shakeel Butt
0 siblings, 2 replies; 4+ messages in thread
From: Karl Mehltretter @ 2026-11-24 3:16 UTC (permalink / raw)
To: bpf
Cc: Karl Mehltretter, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman,
Kumar Kartikeya Dwivedi, Song Liu, Yonghong Song, Jiri Olsa,
Emil Tsalapatis, Ihor Solodrai, Shuah Khan, Tejun Heo,
Johannes Weiner, Michal Koutný,
Shakeel Butt, Waiman Long, Sebastian Andrzej Siewior,
Jiayuan Chen, Puranjay Mohan, cgroups, linux-kernel,
linux-kselftest, linux-rt-devel
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/
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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH bpf-next v2] cgroup/rstat: disable preemption in css_rstat_updated()
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
2026-11-24 5:19 ` Shakeel Butt
2026-11-24 5:20 ` Shakeel Butt
1 sibling, 1 reply; 4+ messages in thread
From: Jiayuan Chen @ 2026-11-24 5:03 UTC (permalink / raw)
To: Karl Mehltretter, bpf, Tejun Heo
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Eduard Zingerman, Kumar Kartikeya Dwivedi,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
Ihor Solodrai, Shuah Khan, Tejun Heo, Johannes Weiner,
Michal Koutný,
Shakeel Butt, Waiman Long, Sebastian Andrzej Siewior,
Puranjay Mohan, cgroups, linux-kernel, linux-kselftest,
linux-rt-devel
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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH bpf-next v2] cgroup/rstat: disable preemption in css_rstat_updated()
2026-11-24 5:03 ` Jiayuan Chen
@ 2026-11-24 5:19 ` Shakeel Butt
0 siblings, 0 replies; 4+ messages in thread
From: Shakeel Butt @ 2026-11-24 5:19 UTC (permalink / raw)
To: Jiayuan Chen
Cc: Karl Mehltretter, bpf, Tejun Heo, Alexei Starovoitov,
Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Song Liu,
Yonghong Song, Jiri Olsa, Emil Tsalapatis, Ihor Solodrai,
Shuah Khan, Johannes Weiner, Michal Koutný,
Waiman Long, Sebastian Andrzej Siewior, Puranjay Mohan, cgroups,
linux-kernel, linux-kselftest, linux-rt-devel
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@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.
>
After the commit 8817005efbdfd all the in-kernel usage has moved to
__css_rstat_updated(), so I think this patch is fine.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next v2] cgroup/rstat: disable preemption in css_rstat_updated()
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
@ 2026-11-24 5:20 ` Shakeel Butt
1 sibling, 0 replies; 4+ messages in thread
From: Shakeel Butt @ 2026-11-24 5:20 UTC (permalink / raw)
To: Karl Mehltretter
Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Eduard Zingerman, Kumar Kartikeya Dwivedi,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
Ihor Solodrai, Shuah Khan, Tejun Heo, Johannes Weiner,
Michal Koutný,
Waiman Long, Sebastian Andrzej Siewior, Jiayuan Chen,
Puranjay Mohan, cgroups, linux-kernel, linux-kselftest,
linux-rt-devel
On Tue, Nov 24, 2026 at 04:16:42AM +0100, 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>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-24 5:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2026-11-24 5:19 ` Shakeel Butt
2026-11-24 5:20 ` Shakeel Butt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®