Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8253435: Cgroup: 'stomping of _mount_path' crash if manually mounted …
…cpusets exist

Reviewed-by: sgehwolf
Backport-of: 0054c15f60cce6470be05d29bfacbdb74cfb7bc9
  • Loading branch information
Jonathan Dowland committed Dec 15, 2022
1 parent d9db01c commit 2bee645
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
22 changes: 20 additions & 2 deletions hotspot/src/os/linux/vm/cgroupSubsystem_linux.cpp
Expand Up @@ -310,8 +310,26 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
cg_infos[MEMORY_IDX]._root_mount_path = os::strdup(tmproot);
cg_infos[MEMORY_IDX]._data_complete = true;
} else if (strcmp(token, "cpuset") == 0) {
assert(cg_infos[CPUSET_IDX]._mount_path == NULL, "stomping of _mount_path");
cg_infos[CPUSET_IDX]._mount_path = os::strdup(tmpmount);
if (cg_infos[CPUSET_IDX]._mount_path != NULL) {
// On some systems duplicate cpuset controllers get mounted in addition to
// the main cgroup controllers most likely under /sys/fs/cgroup. In that
// case pick the one under /sys/fs/cgroup and discard others.
if (strstr(cg_infos[CPUSET_IDX]._mount_path, "/sys/fs/cgroup") != cg_infos[CPUSET_IDX]._mount_path) {
if (PrintContainerInfo) {
tty->print_cr("Duplicate cpuset controllers detected. Picking %s, skipping %s.",
tmpmount, cg_infos[CPUSET_IDX]._mount_path);
}
os::free(cg_infos[CPUSET_IDX]._mount_path);
cg_infos[CPUSET_IDX]._mount_path = os::strdup(tmpmount);
} else {
if (PrintContainerInfo) {
tty->print_cr("Duplicate cpuset controllers detected. Picking %s, skipping %s.",
cg_infos[CPUSET_IDX]._mount_path, tmpmount);
}
}
} else {
cg_infos[CPUSET_IDX]._mount_path = os::strdup(tmpmount);
}
cg_infos[CPUSET_IDX]._root_mount_path = os::strdup(tmproot);
cg_infos[CPUSET_IDX]._data_complete = true;
} else if (strcmp(token, "cpu") == 0) {
Expand Down
Expand Up @@ -63,6 +63,8 @@ public class CgroupSubsystemFactory {
private Path cgroupv1CgInfoNonZeroHierarchy;
private Path cgroupv1MntInfoNonZeroHierarchyOtherOrder;
private Path cgroupv1MntInfoNonZeroHierarchy;
private Path cgroupv1MntInfoDoubleCpuset;
private Path cgroupv1MntInfoDoubleCpuset2;
private String mntInfoEmpty = "";
private Path cgroupV1SelfCgroup;
private Path cgroupV2SelfCgroup;
Expand Down Expand Up @@ -105,11 +107,14 @@ public class CgroupSubsystemFactory {
"41 30 0:37 / /sys/fs/cgroup/devices rw,nosuid,nodev,noexec,relatime shared:13 - cgroup none rw,seclabel,devices\n" +
"42 30 0:38 / /sys/fs/cgroup/cpuset rw,nosuid,nodev,noexec,relatime shared:14 - cgroup none rw,seclabel,cpuset\n" +
"43 30 0:39 / /sys/fs/cgroup/blkio rw,nosuid,nodev,noexec,relatime shared:15 - cgroup none rw,seclabel,blkio\n" +
"44 30 0:40 / /sys/fs/cgroup/freezer rw,nosuid,nodev,noexec,relatime shared:16 - cgroup none rw,seclabel,freezer";
"44 30 0:40 / /sys/fs/cgroup/freezer rw,nosuid,nodev,noexec,relatime shared:16 - cgroup none rw,seclabel,freezer\n";
private String mntInfoHybridRest = cgroupv1MountInfoLineMemory + mntInfoHybridStub;
private String mntInfoHybridMissingMemory = mntInfoHybridStub;
private String mntInfoHybrid = cgroupV2LineHybrid + mntInfoHybridRest;
private String mntInfoHybridFlippedOrder = mntInfoHybridRest + cgroupV2LineHybrid;
private String mntInfoCgroupv1MoreCpusetLine = "121 32 0:37 / /cpusets rw,relatime shared:69 - cgroup none rw,cpuset\n";
private String mntInfoCgroupv1DoubleCpuset = mntInfoCgroupv1MoreCpusetLine + mntInfoHybrid;
private String mntInfoCgroupv1DoubleCpuset2 = mntInfoHybrid + mntInfoCgroupv1MoreCpusetLine;
private String cgroupsNonZeroHierarchy =
"#subsys_name hierarchy num_cgroups enabled\n" +
"cpuset 3 1 1\n" +
Expand Down Expand Up @@ -160,6 +165,12 @@ private void setup() {

cgroupV2MntInfoMissingCgroupv2 = Paths.get(existingDirectory.toString(), "mnt_info_missing_cgroup2");
Files.write(cgroupV2MntInfoMissingCgroupv2, mntInfoHybridStub.getBytes());

cgroupv1MntInfoDoubleCpuset = Paths.get(existingDirectory.toString(), "mnt_info_cgroupv1_double_cpuset");
Files.write(cgroupv1MntInfoDoubleCpuset, mntInfoCgroupv1DoubleCpuset.getBytes());

cgroupv1MntInfoDoubleCpuset2 = Paths.get(existingDirectory.toString(), "mnt_info_cgroupv1_double_cpuset2");
Files.write(cgroupv1MntInfoDoubleCpuset2, mntInfoCgroupv1DoubleCpuset2.getBytes());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -196,6 +207,16 @@ private boolean isValidCgroup(int value) {
return value == CGROUPS_V1 || value == CGROUPS_V2;
}

public void testCgroupv1MultipleCpusetMounts(WhiteBox wb, Path mountInfo) {
String procCgroups = cgroupv1CgInfoNonZeroHierarchy.toString();
String procSelfCgroup = cgroupV1SelfCgroup.toString();
String procSelfMountinfo = mountInfo.toString();
int retval = wb.validateCgroup(procCgroups, procSelfCgroup, procSelfMountinfo);
Asserts.assertEQ(CGROUPS_V1, retval, "Multiple cpuset controllers, but only one in /sys/fs/cgroup");
Asserts.assertTrue(isValidCgroup(retval));
System.out.println("testCgroupv1MultipleCpusetMounts PASSED!");
}

public void testCgroupv1NoMounts(WhiteBox wb) {
String procCgroups = cgroupv1CgInfoZeroHierarchy.toString();
String procSelfCgroup = cgroupV1SelfCgroup.toString();
Expand Down Expand Up @@ -268,6 +289,8 @@ public static void main(String[] args) throws Exception {
test.testCgroupV1HybridMntInfoOrder(wb);
test.testCgroupv1MissingMemoryController(wb);
test.testCgroupv2NoCgroup2Fs(wb);
test.testCgroupv1MultipleCpusetMounts(wb, test.cgroupv1MntInfoDoubleCpuset);
test.testCgroupv1MultipleCpusetMounts(wb, test.cgroupv1MntInfoDoubleCpuset2);
} finally {
test.teardown();
}
Expand Down

1 comment on commit 2bee645

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.