[PATCH v7 16/19] fs/resctrl: Reject mode changes for groups backing kernel mode

From: Babu Moger

Date: Wed Nov 11 2026 - 18:09:30 EST


The RESCTRL_GLOBAL_ENABLE_PER_CPU kernel mode uses the CLOSID and/or
RMID of a backing group when transitioning from user mode to kernel
mode. Since the CLOSID and RMID are shared with the group's tasks, the
backing group must remain shareable while kernel mode is active.

Reject mode changes for a group backing the active kernel mode and for
the parent of a backing monitor group.

Also reject reparenting a backing monitor group, as it would change the
monitor group's parent and implicitly modify the active kernel mode
configuration.

Signed-off-by: Babu Moger <babu.moger@xxxxxxx>
---
v7: Changelog update.
Moved the patch after the kernel_mode modify interface.
Added code comments to justify reparenting.

v6: New patch to fix sashiko feedback.
https://sashiko.dev/#/patchset/cover.1787772750.git.babu.moger%40amd.com
---
fs/resctrl/rdtgroup.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)

diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 872755532fb4..1ad169e714a4 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -1994,6 +1994,27 @@ static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp)
return true;
}

+/* True when @rdtgrp or one of its monitor groups backs the kernel mode. */
+static bool rdtgroup_has_kmode_global(struct rdtgroup *rdtgrp)
+{
+ struct rdtgroup *child;
+
+ if (!resctrl_kmode.rdtgrp)
+ return false;
+
+ if (resctrl_kmode.rdtgrp == rdtgrp)
+ return true;
+
+ if (rdtgrp->type != RDTCTRL_GROUP)
+ return false;
+
+ list_for_each_entry(child, &rdtgrp->mon.crdtgrp_list, mon.crdtgrp_list)
+ if (child == resctrl_kmode.rdtgrp)
+ return true;
+
+ return false;
+}
+
/*
* rdtgroup_mode_write - Modify the resource group's mode
*/
@@ -2034,6 +2055,12 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
goto out;
}

+ if (rdtgroup_has_kmode_global(rdtgrp)) {
+ rdt_last_cmd_puts("Cannot change mode for kernel mode backing group\n");
+ ret = -EINVAL;
+ goto out;
+ }
+
if (!strcmp(buf, "shareable")) {
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
ret = rdtgroup_locksetup_exit(rdtgrp);
@@ -4922,6 +4949,19 @@ static int rdtgroup_rename(struct kernfs_node *kn,
goto out;
}

+ /*
+ * Changing the parent of a group backing the active kernel mode changes
+ * the effective CLOSID and/or RMID configuration applied to kernel work.
+ * Reject such moves and require kernel mode to be reconfigured explicitly
+ * instead.
+ */
+ if (rdtgrp == resctrl_kmode.rdtgrp &&
+ rdtgrp->mon.parent != new_prdtgrp) {
+ rdt_last_cmd_puts("Cannot move a group that backs kernel mode\n");
+ ret = -EPERM;
+ goto out;
+ }
+
/*
* Allocate the cpumask for use in mongrp_reparent() to avoid the
* possibility of failing to allocate it after kernfs_rename() has
--
2.43.0