[PATCH v7 33/49] x86/resctrl: resctrl_exit() teardown resctrl but leave the mount point

James Morse
2025-02-28T20:01:58Z

resctrl_exit() was intended for use when the 'resctrl' module was unloaded.
resctrl can't be built as a module, and the kernfs helpers are not exported
so this is unlikely to change. MPAM has an error interrupt which indicates
the MPAM driver has gone haywire. Should this occur tasks could run with
the wrong control values, leading to bad performance for important tasks.
The MPAM driver needs a way to tell resctrl that no further configuration
should be attempted.

Using resctrl_exit() for this leaves the system in a funny state as
resctrl is still mounted, but cannot be un-mounted because the sysfs
directory that is typically used has been removed. Dave Martin suggests
this may cause systemd trouble in the future as not all filesystems
can be unmounted.

Add calls to remove all the files and directories in resctrl, and
remove the sysfs_remove_mount_point() call that leaves the system
in a funny state. When triggered, this causes all the resctrl files
to disappear. resctrl can be unmounted, but not mounted again.

Signed-off-by: James Morse <james.morse@arm.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
---
Changes since v6:
* Added kdoc and comment to resctrl_exit().

Changes since v5:
* Serialise rdtgroup_destroy_root() against umount().
* Check rdtgroup_default.kn to protect against duplicate calls.
---
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 2f34b7215679..0d74a6d98dba 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -4094,8 +4094,12 @@ static int rdtgroup_setup_root(struct rdt_fs_context *ctx)

static void rdtgroup_destroy_root(void)
{
- kernfs_destroy_root(rdt_root);
- rdtgroup_default.kn = NULL;
+ lockdep_assert_held(&rdtgroup_mutex);
+
+ if (rdtgroup_default.kn) {
+ kernfs_destroy_root(rdt_root);
+ rdtgroup_default.kn = NULL;
+ }
}

static void __init rdtgroup_setup_default(void)
@@ -4387,11 +4391,26 @@ int __init resctrl_init(void)
return ret;
}

+/**
+ * resctrl_exit() - Remove the resctrl filesystem and free resources.
+ *
+ * Called by the architecture code in response to a fatal error.
+ * Resctrl files and structures are removed from kernfs to prevent further
+ * configuration.
+ */
void __exit resctrl_exit(void)
{
+ mutex_lock(&rdtgroup_mutex);
+ rdtgroup_destroy_root();
+ mutex_unlock(&rdtgroup_mutex);
+
debugfs_remove_recursive(debugfs_resctrl);
unregister_filesystem(&rdt_fs_type);
- sysfs_remove_mount_point(fs_kobj, "resctrl");
+
+ /*
+ * The sysfs mount point added by resctrl_init() is not removed so that
+ * it can be used to umount resctrl.
+ */

resctrl_mon_resource_exit();
}
--
2.39.5