]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
cgroup: make css_rstat_updated nmi safe
authorShakeel Butt <shakeel.butt@linux.dev>
Tue, 17 Jun 2025 19:57:23 +0000 (12:57 -0700)
committerTejun Heo <tj@kernel.org>
Tue, 17 Jun 2025 20:01:00 +0000 (10:01 -1000)
commit36df6e3dbd7e7b074e55fec080012184e2fa3a46
tree0390e8f547694cc19949b9f96a00a5bc8e8a4bb2
parent1257b8786ac689a2ce5fe3e1741c65038035adc6
cgroup: make css_rstat_updated nmi safe

To make css_rstat_updated() able to safely run in nmi context, let's
move the rstat update tree creation at the flush side and use per-cpu
lockless lists in struct cgroup_subsys to track the css whose stats are
updated on that cpu.

The struct cgroup_subsys_state now has per-cpu lnode which needs to be
inserted into the corresponding per-cpu lhead of struct cgroup_subsys.
Since we want the insertion to be nmi safe, there can be multiple
inserters on the same cpu for the same lnode. Here multiple inserters
are from stacked contexts like softirq, hardirq and nmi.

The current llist does not provide function to protect against the
scenario where multiple inserters can use the same lnode. So, using
llist_node() out of the box is not safe for this scenario.

However we can protect against multiple inserters using the same lnode
by using the fact llist node points to itself when not on the llist and
atomically reset it and select the winner as the single inserter.

Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Tested-by: JP Kobryn <inwardvessel@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup/rstat.c