[PATCH v9 03/27] x86/resctrl: Check all domains are offline in resctrl_exit()
From: James Morse
Date: Fri Apr 25 2025 - 13:39:29 EST
resctrl_exit() removes things like the resctrl mount point directory
and unregisters the filesystem prior to freeing data structures that
were allocated during resctrl_init().
This assumes that there are no online domains when resctrl_exit() is
called. If any domain were online, the limbo or overflow handler could
be scheduled to run.
Add a check for any online control or monitor domains, and document that
the architecture code is required to do this.
Suggested-by: Reinette Chatre <reinette.chatre@xxxxxxxxx>
Signed-off-by: James Morse <james.morse@xxxxxxx>
---
Changes since v8:
* This patch is new.
---
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 88197afbbb8a..f617ac97758b 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -4420,8 +4420,32 @@ int __init resctrl_init(void)
return ret;
}
+static bool __exit resctrl_online_domains_exist(void)
+{
+ struct rdt_resource *r;
+
+ for_each_rdt_resource(r) {
+ if (!list_empty(&r->ctrl_domains) || !list_empty(&r->mon_domains))
+ return true;
+ }
+
+ return false;
+}
+
+/*
+ * resctrl_exit() - Remove the resctrl filesystem and free resources.
+ *
+ * When called by the architecture code, all CPUs and resctrl domains must be
+ * offline. This ensures the limbo and overflow handlers are not scheduled to
+ * run, meaning the data structures they access can be freed by
+ * resctrl_mon_resource_exit().
+ */
void __exit resctrl_exit(void)
{
+ cpus_read_lock();
+ WARN_ON_ONCE(resctrl_online_domains_exist());
+ cpus_read_unlock();
+
debugfs_remove_recursive(debugfs_resctrl);
unregister_filesystem(&rdt_fs_type);
sysfs_remove_mount_point(fs_kobj, "resctrl");
--
2.39.5