Skip to content

Commit

Permalink
8253435: Cgroup: 'stomping of _mount_path' crash if manually mounted …
Browse files Browse the repository at this point in the history
…cpusets exist
  • Loading branch information
simonis authored and jerboaa committed Sep 25, 2020
1 parent 2e30ff6 commit 45608cf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/hotspot/os/linux/cgroupSubsystem_linux.cpp
Expand Up @@ -302,8 +302,21 @@ 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) {
log_warning(os, container)("Duplicate cpuset controllers detected. Picking the one at /sys/fs/cgroup");
// 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 (strcmp(cg_infos[CPUSET_IDX]._mount_path, "/sys/fs/cgroup") < 0) {
log_info(os, container)("%s not mounted at /sys/fs/cgroup, skipping!", cg_infos[CPUSET_IDX]._mount_path);
os::free(cg_infos[CPUSET_IDX]._mount_path);
cg_infos[CPUSET_IDX]._mount_path = os::strdup(tmpmount);
} else {
log_info(os, container)("%s not mounted at /sys/fs/cgroup, skipping!", 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
25 changes: 24 additions & 1 deletion test/hotspot/jtreg/containers/cgroup/CgroupSubsystemFactory.java
Expand Up @@ -60,6 +60,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 @@ -102,11 +104,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 @@ -157,6 +162,12 @@ private void setup() {

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

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

cgroupv1MntInfoDoubleCpuset2 = Paths.get(existingDirectory.toString(), "mnt_info_cgroupv1_double_cpuset2");
Files.writeString(cgroupv1MntInfoDoubleCpuset2, mntInfoCgroupv1DoubleCpuset2);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -174,6 +185,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 @@ -246,6 +267,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

0 comments on commit 45608cf

Please sign in to comment.