Skip to content

Commit 8c992e2

Browse files
James Morsebp3tk0v
authored andcommitted
x86/resctrl: Resctrl_exit() teardown resctrl but leave the mount point
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. In this scenario the MPAM driver will reset the hardware, but it needs a way to tell resctrl that no further configuration should be attempted. In particular, moving tasks between control or monitor groups does not interact with the architecture code, so there is no opportunity for the arch code to indicate that the hardware is no-longer functioning. 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> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Tony Luck <tony.luck@intel.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Reviewed-by: Fenghua Yu <fenghuay@nvidia.com> Tested-by: Fenghua Yu <fenghuay@nvidia.com> Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64 Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Amit Singh Tomar <amitsinght@marvell.com> # arm64 Tested-by: Shanker Donthineni <sdonthineni@nvidia.com> # arm64 Tested-by: Babu Moger <babu.moger@amd.com> Tested-by: Tony Luck <tony.luck@intel.com> Link: https://lore.kernel.org/20250515165855.31452-9-james.morse@arm.com
1 parent 8eb7ad6 commit 8c992e2

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

arch/x86/kernel/cpu/resctrl/rdtgroup.c

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,6 +3078,22 @@ static void rmdir_all_sub(void)
30783078
kernfs_remove(kn_mondata);
30793079
}
30803080

3081+
static void resctrl_fs_teardown(void)
3082+
{
3083+
lockdep_assert_held(&rdtgroup_mutex);
3084+
3085+
/* Cleared by rdtgroup_destroy_root() */
3086+
if (!rdtgroup_default.kn)
3087+
return;
3088+
3089+
rmdir_all_sub();
3090+
rdt_pseudo_lock_release();
3091+
rdtgroup_default.mode = RDT_MODE_SHAREABLE;
3092+
closid_exit();
3093+
schemata_list_destroy();
3094+
rdtgroup_destroy_root();
3095+
}
3096+
30813097
static void rdt_kill_sb(struct super_block *sb)
30823098
{
30833099
struct rdt_resource *r;
@@ -3091,12 +3107,7 @@ static void rdt_kill_sb(struct super_block *sb)
30913107
for_each_alloc_capable_rdt_resource(r)
30923108
resctrl_arch_reset_all_ctrls(r);
30933109

3094-
rmdir_all_sub();
3095-
rdt_pseudo_lock_release();
3096-
rdtgroup_default.mode = RDT_MODE_SHAREABLE;
3097-
closid_exit();
3098-
schemata_list_destroy();
3099-
rdtgroup_destroy_root();
3110+
resctrl_fs_teardown();
31003111
if (resctrl_arch_alloc_capable())
31013112
resctrl_arch_disable_alloc();
31023113
if (resctrl_arch_mon_capable())
@@ -4127,6 +4138,8 @@ static int rdtgroup_setup_root(struct rdt_fs_context *ctx)
41274138

41284139
static void rdtgroup_destroy_root(void)
41294140
{
4141+
lockdep_assert_held(&rdtgroup_mutex);
4142+
41304143
kernfs_destroy_root(rdt_root);
41314144
rdtgroup_default.kn = NULL;
41324145
}
@@ -4441,23 +4454,42 @@ static bool __exit resctrl_online_domains_exist(void)
44414454
return false;
44424455
}
44434456

4444-
/*
4457+
/**
44454458
* resctrl_exit() - Remove the resctrl filesystem and free resources.
44464459
*
4460+
* Called by the architecture code in response to a fatal error.
4461+
* Removes resctrl files and structures from kernfs to prevent further
4462+
* configuration.
4463+
*
44474464
* When called by the architecture code, all CPUs and resctrl domains must be
44484465
* offline. This ensures the limbo and overflow handlers are not scheduled to
44494466
* run, meaning the data structures they access can be freed by
44504467
* resctrl_mon_resource_exit().
4468+
*
4469+
* After resctrl_exit() returns, the architecture code should return an
4470+
* error from all resctrl_arch_ functions that can do this.
4471+
* resctrl_arch_get_resource() must continue to return struct rdt_resources
4472+
* with the correct rid field to ensure the filesystem can be unmounted.
44514473
*/
44524474
void __exit resctrl_exit(void)
44534475
{
44544476
cpus_read_lock();
44554477
WARN_ON_ONCE(resctrl_online_domains_exist());
4478+
4479+
mutex_lock(&rdtgroup_mutex);
4480+
resctrl_fs_teardown();
4481+
mutex_unlock(&rdtgroup_mutex);
4482+
44564483
cpus_read_unlock();
44574484

44584485
debugfs_remove_recursive(debugfs_resctrl);
4486+
debugfs_resctrl = NULL;
44594487
unregister_filesystem(&rdt_fs_type);
4460-
sysfs_remove_mount_point(fs_kobj, "resctrl");
4488+
4489+
/*
4490+
* Do not remove the sysfs mount point added by resctrl_init() so that
4491+
* it can be used to umount resctrl.
4492+
*/
44614493

44624494
resctrl_mon_resource_exit();
44634495
}

0 commit comments

Comments
 (0)