]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cgroup: pair max limit READ_ONCE() with WRITE_ONCE()
authorRen Tamura <ren.tamura.oss@gmail.com>
Thu, 28 May 2026 04:28:39 +0000 (13:28 +0900)
committerTejun Heo <tj@kernel.org>
Thu, 28 May 2026 15:40:06 +0000 (05:40 -1000)
cgroup.max.descendants and cgroup.max.depth are shown through seq_file.
Their show callbacks read cgrp->max_descendants and cgrp->max_depth with
READ_ONCE(), respectively.

The corresponding write callbacks update the same scalar fields while
holding the cgroup lock, but the seq_file show path does not serialize
against those stores. This leaves the lockless show-side loads annotated
with READ_ONCE(), while the corresponding stores remain plain stores.

Use WRITE_ONCE() for the updates so the intended lockless access is marked
consistently on both sides. This does not change locking, ordering, or
user-visible semantics.

Assisted-by: OpenAI-Codex:gpt-5.5
Signed-off-by: Ren Tamura <ren.tamura.oss@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup/cgroup.c

index bdc8deedb4f792a0d1c7fabf45e211888591a644..6e92791d279edec740df1dd938731bb928e124cd 100644 (file)
@@ -3734,7 +3734,7 @@ static ssize_t cgroup_max_descendants_write(struct kernfs_open_file *of,
        if (!cgrp)
                return -ENOENT;
 
-       cgrp->max_descendants = descendants;
+       WRITE_ONCE(cgrp->max_descendants, descendants);
 
        cgroup_kn_unlock(of->kn);
 
@@ -3777,7 +3777,7 @@ static ssize_t cgroup_max_depth_write(struct kernfs_open_file *of,
        if (!cgrp)
                return -ENOENT;
 
-       cgrp->max_depth = depth;
+       WRITE_ONCE(cgrp->max_depth, depth);
 
        cgroup_kn_unlock(of->kn);