[PATCH v5 12/16] fs/resctrl: Program kernel mode assignments on CPU hotplug

From: Babu Moger

Date: Wed Aug 26 2026 - 15:37:23 EST


Kernel mode resctrl associations are programmed on a per-CPU basis. When
assign_global_enable_per_cpu is selected, the active kernel mode
association is applied only to CPUs that are online at the time of
configuration. CPUs that come online later are not automatically updated.

As a result, hotplugged CPUs, or CPUs that were offline when the kernel
mode was activated, may run without the intended kernel mode association
even though the mode remains active system-wide.

Add resctrl_kmode_online_cpu() and resctrl_kmode_offline_cpu() and call
them from the existing resctrl_online_cpu() and resctrl_offline_cpu()
paths to maintain kmode_cpu_mask and update kernel mode associations as
CPUs enter or leave the online state.

Signed-off-by: Babu Moger <babu.moger@xxxxxxx>
---
v5: Added resctrl_kmode_offline_cpu() to disable the kernel mode
association and update kmode_cpu_mask when an associated CPU goes
offline.
This addresses sashiko comments:
https://sashiko.dev/#/patchset/cover.1783461016.git.babu.moger%40amd.com?part=11
https://sashiko.dev/#/patchset/cover.1783461016.git.babu.moger%40amd.com?part=10
Also moved the patch earlier than patch 10.
[RESEND PATCH v4 10/15] fs/resctrl: Reset the kernel mode binding when an rdtgroup is removed
That seemed much more clear.

v4: New patch in the series. Patch taken from:
https://lore.kernel.org/lkml/20260611111706.1981788-5-qinyuntan@xxxxxxxxxxxxxxxxx/
Updated the code to enable kernel mode by default whenever a CPU comes
online when one of global-assign mode is enabled.
---
fs/resctrl/rdtgroup.c | 59 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)

diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 06e74b027044..97e4176669e5 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -4951,11 +4951,67 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *hdr
return err;
}

+/*
+ * resctrl_kmode_online_cpu() - Program kernel mode association for @cpu
+ * @cpu: CPU that has just been brought online
+ *
+ * If assign_global_enable_per_cpu is active and the rdtgroup has an active
+ * kernel-mode association, add @cpu to kmode_cpu_mask and program the
+ * corresponding kernel mode association.
+ */
+static void resctrl_kmode_online_cpu(unsigned int cpu)
+{
+ struct rdtgroup *rdtgrp = resctrl_kcfg.active.k_rdtgrp;
+ bool assign_ctrl, assign_mon;
+
+ if (resctrl_kcfg.active.kmode_cur != RESCTRL_ASSIGN_GLOBAL_ENABLE_PER_CPU ||
+ !rdtgrp || !rdtgrp->kmode)
+ return;
+
+ assign_ctrl = (resctrl_kcfg.active.ctrl_mode == KMODE_ASSIGN);
+ assign_mon = (resctrl_kcfg.active.mon_mode == KMODE_ASSIGN);
+
+ cpumask_set_cpu(cpu, &rdtgrp->kmode_cpu_mask);
+
+ resctrl_arch_configure_kmode(cpumask_of(cpu), rdtgrp->closid, assign_ctrl,
+ rdtgrp->mon.rmid, assign_mon, true);
+}
+
+/*
+ * resctrl_kmode_offline_cpu() - Clear kernel mode association for @cpu
+ * @cpu: CPU being taken offline.
+ *
+ * If assign_global_enable_per_cpu is active, disable the kernel mode
+ * association for @cpu and remove it from kmode_cpu_mask.
+ */
+static void resctrl_kmode_offline_cpu(unsigned int cpu)
+{
+ struct rdtgroup *rdtgrp = resctrl_kcfg.active.k_rdtgrp;
+ bool assign_ctrl, assign_mon;
+
+ if (resctrl_kcfg.active.kmode_cur != RESCTRL_ASSIGN_GLOBAL_ENABLE_PER_CPU ||
+ !rdtgrp || !rdtgrp->kmode)
+ return;
+
+ if (!cpumask_test_cpu(cpu, &rdtgrp->kmode_cpu_mask))
+ return;
+
+ assign_ctrl = (resctrl_kcfg.active.ctrl_mode == KMODE_ASSIGN);
+ assign_mon = (resctrl_kcfg.active.mon_mode == KMODE_ASSIGN);
+
+ cpumask_clear_cpu(cpu, &rdtgrp->kmode_cpu_mask);
+
+ resctrl_arch_configure_kmode(cpumask_of(cpu), rdtgrp->closid, assign_ctrl,
+ rdtgrp->mon.rmid, assign_mon, false);
+}
+
void resctrl_online_cpu(unsigned int cpu)
{
mutex_lock(&rdtgroup_mutex);
/* The CPU is set in default rdtgroup after online. */
cpumask_set_cpu(cpu, &rdtgroup_default.cpu_mask);
+ /* Program any active kernel mode association on this CPU. */
+ resctrl_kmode_online_cpu(cpu);
mutex_unlock(&rdtgroup_mutex);
}

@@ -4999,6 +5055,9 @@ void resctrl_offline_cpu(unsigned int cpu)
}
}

+ /* Clear any active kernel mode association on this CPU. */
+ resctrl_kmode_offline_cpu(cpu);
+
if (!l3->mon_capable)
goto out_unlock;

--
2.43.0