]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/resctrl: Check all domains are offline in resctrl_exit()
authorJames Morse <james.morse@arm.com>
Thu, 15 May 2025 16:58:37 +0000 (16:58 +0000)
committerBorislav Petkov (AMD) <bp@alien8.de>
Thu, 15 May 2025 19:02:21 +0000 (21:02 +0200)
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 offline all monitor and control
domains before calling resctrl_exit().

Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Fenghua Yu <fenghuay@nvidia.com>
Tested-by: Fenghua Yu <fenghuay@nvidia.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Tested-by: Tony Luck <tony.luck@intel.com>
Link: https://lore.kernel.org/20250515165855.31452-8-james.morse@arm.com
arch/x86/kernel/cpu/resctrl/rdtgroup.c

index 88197afbbb8ac8c6082c3eeed6c11c5763f27adb..29f76ad21f1c162d7686639a750338934ccabb1e 100644 (file)
@@ -4420,8 +4420,41 @@ cleanup_mountpoint:
        return ret;
 }
 
+static bool __exit resctrl_online_domains_exist(void)
+{
+       struct rdt_resource *r;
+
+       /*
+        * Only walk capable resources to allow resctrl_arch_get_resource()
+        * to return dummy 'not capable' resources.
+        */
+       for_each_alloc_capable_rdt_resource(r) {
+               if (!list_empty(&r->ctrl_domains))
+                       return true;
+       }
+
+       for_each_mon_capable_rdt_resource(r) {
+               if (!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");