* [PATCH bpf-next] selftests/bpf: Disable preemption around css_rstat_updated()
@ 2026-11-21 8:28 Karl Mehltretter
2026-11-23 0:47 ` Alexei Starovoitov
0 siblings, 1 reply; 3+ messages in thread
From: Karl Mehltretter @ 2026-11-21 8:28 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, Jiayuan Chen, Puranjay Mohan, cgroups,
linux-kernel, linux-kselftest, linux-rt-devel
cgroup_hierarchical_stats triggers a lockdep warning in
__css_rstat_updated() on PREEMPT_RT. The counter runs at the
cgroup_attach_task tracepoint under spin_lock_irqsave() on
trace_cgroup_path_lock. On PREEMPT_RT this leaves preemption and
interrupts enabled. On non-RT it masks interrupts, satisfying the
assertion.
Disable preemption around css_rstat_updated() so the updater can queue
the update without being preempted.
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/
Link: https://lore.kernel.org/r/fmey2ektwdk7l5aktjz3xb24x3pk3lxy3gfld7reazal6xa6u2@tmryedehqhql/
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
Assisted by an LLM.
Ran test_progs -t cgroup_hierarchical_stats on bpf-next 9867c61abbd4 in
x86-64 KVM guests with lockdep. The test passed on all eight boots.
Boots with an rstat warning Before After
PREEMPT_RT 2/2 0/2
PREEMPT (!RT) 0/2 0/2
tools/testing/selftests/bpf/progs/cgroup_hierarchical_stats.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/cgroup_hierarchical_stats.c b/tools/testing/selftests/bpf/progs/cgroup_hierarchical_stats.c
index 8fc38592a..d4babda81 100644
--- a/tools/testing/selftests/bpf/progs/cgroup_hierarchical_stats.c
+++ b/tools/testing/selftests/bpf/progs/cgroup_hierarchical_stats.c
@@ -6,6 +6,7 @@
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_core_read.h>
+#include "bpf_experimental.h"
char _license[] SEC("license") = "GPL";
@@ -76,7 +77,9 @@ int BPF_PROG(counter, struct cgroup *dst_cgrp, const char *path,
else if (create_percpu_attach_counter(cg_id, 1))
return 0;
+ bpf_preempt_disable();
css_rstat_updated(&dst_cgrp->self, bpf_get_smp_processor_id());
+ bpf_preempt_enable();
return 0;
}
base-commit: 9867c61abbd44f7053a871566b3d982f62c6d8dc
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] selftests/bpf: Disable preemption around css_rstat_updated()
2026-11-21 8:28 [PATCH bpf-next] selftests/bpf: Disable preemption around css_rstat_updated() Karl Mehltretter
@ 2026-11-23 0:47 ` Alexei Starovoitov
2026-11-23 14:32 ` Sebastian Andrzej Siewior
0 siblings, 1 reply; 3+ messages in thread
From: Alexei Starovoitov @ 2026-11-23 0:47 UTC (permalink / raw)
To: Karl Mehltretter, bpf
Cc: 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, Jiayuan Chen, Puranjay Mohan, cgroups,
linux-kernel, linux-kselftest, linux-rt-devel
On Sat, Nov 21, 2026 at 12:28 AM Karl Mehltretter <kmehltretter@gmail.com> wrote:
> trace_cgroup_path_lock. On PREEMPT_RT this leaves preemption and
> interrupts enabled. On non-RT it masks interrupts, satisfying the
> assertion.
let's fix the kfunc instead
diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
index de816a4..d72fe72 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);
}
pw-bot: cr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] selftests/bpf: Disable preemption around css_rstat_updated()
2026-11-23 0:47 ` Alexei Starovoitov
@ 2026-11-23 14:32 ` Sebastian Andrzej Siewior
0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-11-23 14:32 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: Karl Mehltretter, bpf, 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, Jiayuan Chen, Puranjay Mohan, cgroups,
linux-kernel, linux-kselftest, linux-rt-devel
On 2026-11-23 00:47:15 [+0000], Alexei Starovoitov wrote:
> On Sat, Nov 21, 2026 at 12:28 AM Karl Mehltretter <kmehltretter@gmail.com> wrote:
> > trace_cgroup_path_lock. On PREEMPT_RT this leaves preemption and
> > interrupts enabled. On non-RT it masks interrupts, satisfying the
> > assertion.
>
> let's fix the kfunc instead
>
> diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
> index de816a4..d72fe72 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);
This looks like the only call site which did not disable preemption on
its own (the other are either NMI or have get_cpu()).
> }
Sebastian
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-23 14:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-21 8:28 [PATCH bpf-next] selftests/bpf: Disable preemption around css_rstat_updated() Karl Mehltretter
2026-11-23 0:47 ` Alexei Starovoitov
2026-11-23 14:32 ` Sebastian Andrzej Siewior
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®