Skip to content

Commit 3c41382

Browse files
Werkovhtejun
authored andcommitted
cgroup: Disallow mounting v1 hierarchies without controller implementation
The configs that disable some v1 controllers would still allow mounting them but with no controller-specific files. (Making such hierarchies equivalent to named v1 hierarchies.) To achieve behavior consistent with actual out-compilation of a whole controller, the mounts should treat respective controllers as non-existent. Wrap implementation into a helper function, leverage legacy_files to detect compiled out controllers. The effect is that mounts on v1 would fail and produce a message like: [ 1543.999081] cgroup: Unknown subsys name 'memory' Signed-off-by: Michal Koutný <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 659f90f commit 3c41382

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

kernel/cgroup/cgroup-v1.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ bool cgroup1_ssid_disabled(int ssid)
4646
return cgroup_no_v1_mask & (1 << ssid);
4747
}
4848

49+
static bool cgroup1_subsys_absent(struct cgroup_subsys *ss)
50+
{
51+
/* Check also dfl_cftypes for file-less controllers, i.e. perf_event */
52+
return ss->legacy_cftypes == NULL && ss->dfl_cftypes;
53+
}
54+
4955
/**
5056
* cgroup_attach_task_all - attach task 'tsk' to all cgroups of task 'from'
5157
* @from: attach to all cgroups of a given task
@@ -932,7 +938,8 @@ int cgroup1_parse_param(struct fs_context *fc, struct fs_parameter *param)
932938
if (ret != -ENOPARAM)
933939
return ret;
934940
for_each_subsys(ss, i) {
935-
if (strcmp(param->key, ss->legacy_name))
941+
if (strcmp(param->key, ss->legacy_name) ||
942+
cgroup1_subsys_absent(ss))
936943
continue;
937944
if (!cgroup_ssid_enabled(i) || cgroup1_ssid_disabled(i))
938945
return invalfc(fc, "Disabled controller '%s'",
@@ -1024,7 +1031,8 @@ static int check_cgroupfs_options(struct fs_context *fc)
10241031
mask = ~((u16)1 << cpuset_cgrp_id);
10251032
#endif
10261033
for_each_subsys(ss, i)
1027-
if (cgroup_ssid_enabled(i) && !cgroup1_ssid_disabled(i))
1034+
if (cgroup_ssid_enabled(i) && !cgroup1_ssid_disabled(i) &&
1035+
!cgroup1_subsys_absent(ss))
10281036
enabled |= 1 << i;
10291037

10301038
ctx->subsys_mask &= enabled;

0 commit comments

Comments
 (0)