]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cgroup: Add compatibility option for content of /proc/cgroups
authorMichal Koutný <mkoutny@suse.com>
Fri, 18 Jul 2025 09:18:54 +0000 (11:18 +0200)
committerTejun Heo <tj@kernel.org>
Sat, 19 Jul 2025 16:14:44 +0000 (06:14 -1000)
/proc/cgroups lists only v1 controllers by default, however, this is
only enforced since the commit af000ce85293b ("cgroup: Do not report
unavailable v1 controllers in /proc/cgroups") and there is software in
the wild that uses content of /proc/cgroups to decide on availability of
v2 (sic) controllers.

Add a boottime param that can bring back the previous behavior for
setups where the check in the software cannot be changed and it causes
e.g. unintended OOMs.

Also, this patch takes out cgrp_v1_visible from cgroup1_subsys_absent()
guard since it's only important to check which hierarchy (v1 vs v2) the
subsys is attached to. This has no effect on the printed message but
the code is cleaner since cgrp_v1_visible is really about mounted
hierarchies, not the content of /proc/cgroups.

Link: https://lore.kernel.org/r/b26b60b7d0d2a5ecfd2f3c45f95f32922ed24686.camel@decadent.org.uk
Fixes: af000ce85293b ("cgroup: Do not report unavailable v1 controllers in /proc/cgroups")
Fixes: a0ab1453226d8 ("cgroup: Print message when /proc/cgroups is read on v2-only system")
Signed-off-by: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Documentation/admin-guide/kernel-parameters.txt
kernel/cgroup/cgroup-v1.c

index a3ea40b22fb9a1af0603625246bf4691a5f0874a..60fd3f84272b35d9e36a6b2296df51725c2770e7 100644 (file)
                        named mounts. Specifying both "all" and "named" disables
                        all v1 hierarchies.
 
+       cgroup_v1_proc= [KNL] Show also missing controllers in /proc/cgroups
+                       Format: { "true" | "false" }
+                       /proc/cgroups lists only v1 controllers by default.
+                       This compatibility option enables listing also v2
+                       controllers (whose v1 code is not compiled!), so that
+                       semi-legacy software can check this file to decide
+                       about usage of v2 (sic) controllers.
+
        cgroup_favordynmods= [KNL] Enable or Disable favordynmods.
                        Format: { "true" | "false" }
                        Defaults to the value of CONFIG_CGROUP_FAVOR_DYNMODS.
index fa24c032ed6fe054b2f363ff71f48959e83153ab..2a4a387f867abcf8dd534981b7b6e2cb45caa52c 100644 (file)
@@ -32,6 +32,9 @@ static u16 cgroup_no_v1_mask;
 /* disable named v1 mounts */
 static bool cgroup_no_v1_named;
 
+/* Show unavailable controllers in /proc/cgroups */
+static bool proc_show_all;
+
 /*
  * pidlist destructions need to be flushed on cgroup destruction.  Use a
  * separate workqueue as flush domain.
@@ -683,10 +686,11 @@ int proc_cgroupstats_show(struct seq_file *m, void *v)
         */
 
        for_each_subsys(ss, i) {
-               if (cgroup1_subsys_absent(ss))
-                       continue;
                cgrp_v1_visible |= ss->root != &cgrp_dfl_root;
 
+               if (!proc_show_all && cgroup1_subsys_absent(ss))
+                       continue;
+
                seq_printf(m, "%s\t%d\t%d\t%d\n",
                           ss->legacy_name, ss->root->hierarchy_id,
                           atomic_read(&ss->root->nr_cgrps),
@@ -1359,3 +1363,9 @@ static int __init cgroup_no_v1(char *str)
        return 1;
 }
 __setup("cgroup_no_v1=", cgroup_no_v1);
+
+static int __init cgroup_v1_proc(char *str)
+{
+       return (kstrtobool(str, &proc_show_all) == 0);
+}
+__setup("cgroup_v1_proc=", cgroup_v1_proc);