Re: [PATCH v2] cgroup: Add preemption protection to css_rstat_updated()
From: Waiman Long
Date: Fri Nov 21 2025 - 10:47:51 EST
On 11/21/25 1:21 AM, Jiayuan Chen wrote:
November 21, 2025 at 13:07, "Waiman Long" <llong@xxxxxxxxxx mailto:llong@xxxxxxxxxx?to=%22Waiman%20Long%22%20%3Cllong%40redhat.com%3E > wrote:
On 11/20/25 11:06 PM, Jiayuan Chen wrote:If that's really the case, then I'd rather add a new wrapper kfunc for BPF
BPF programs do not disable preemption, they only disable migration.My understand of Tejun's comment is to add bpf_preempt_disable() and bpf_preempt_enable() calls around the css_rstat_updated() call in the bpf program defined in tools/testing/selftests/bpf/prog_tests/cgroup_hierarchical_stats.c instead of adding that in the css_rstat_updated() function itself. But I may be wrong.
Therefore, when running the cgroup_hierarchical_stats selftest, a
warning [1] is generated.
The css_rstat_updated() function is lockless and reentrant. However,
as Tejun pointed out [2], preemption-related considerations need to
be considered. Since css_rstat_updated() can be called from BPF where
preemption is not disabled by its framework and it has already been
exposed as a kfunc to BPF programs, introducing a new kfunc like bpf_xx
will break existing uses. Thus, we directly make css_rstat_updated()
preempt-safe here.
Cheers, Longman
to replace css_rstat_updated(). Otherwise, whether it gets triggered would
depend entirely on users behavior.
Right now, this WARNING is showing up in all BPF selftests. Although it's not
treated as an error that fails the tests,it's visible in the action runs:
https://github.com/kernel-patches/bpf/actions
All the existing callers of css_rstat_updated() except the bpf selftest has preemption disabled. So it doesn't make sense to impose a cost (though small) on kernel code that are in production kernel in order to make a selftest pass with no change.
Cheers,
Longman