[PATCH] fs/resctrl: Fix deadlock for errors during mount

From: Tony Luck

Date: Fri May 01 2026 - 14:56:28 EST


Sashiko noticed[1] a deadlock in the resctrl mount code.

rdt_get_tree() acquires rdtgroup_mutex before calling kernfs_get_tree(). If
superblock setup fails inside kernfs_get_tree(), the VFS calls kill_sb on
the same thread before the call returns. rdt_kill_sb() unconditionally
attempts to acquire rdtgroup_mutex and deadlock occurs.

Add a boolean rdt_kill_sb_locked flag. Set it for the duration of
kernfs_get_tree() and check in rdt_kill_sb() to determine if locks
are already held.

Fixes: 5ff193fbde20 ("x86/intel_rdt: Add basic resctrl filesystem support")
Assisted-by: GitHub-Copilot:claude-sonnet-4.6
Signed-off-by: Tony Luck <tony.luck@xxxxxxxxx>
Link: https://sashiko.dev/#/patchset/20260429184858.36423-1-tony.luck%40intel.com [1]
---
fs/resctrl/rdtgroup.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 5dfdaa6f9d8f..8544020ef420 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -2782,6 +2782,9 @@ static void schemata_list_destroy(void)
}
}

+/* Protected by the serialized mount path (rdtgroup_mutex + resctrl_mounted). */
+static bool rdt_kill_sb_locked;
+
static int rdt_get_tree(struct fs_context *fc)
{
struct rdt_fs_context *ctx = rdt_fc2context(fc);
@@ -2855,7 +2858,9 @@ static int rdt_get_tree(struct fs_context *fc)
if (ret)
goto out_mondata;

+ rdt_kill_sb_locked = true;
ret = kernfs_get_tree(fc);
+ rdt_kill_sb_locked = false;
if (ret < 0)
goto out_psl;

@@ -3173,8 +3178,10 @@ static void rdt_kill_sb(struct super_block *sb)
{
struct rdt_resource *r;

- cpus_read_lock();
- mutex_lock(&rdtgroup_mutex);
+ if (!rdt_kill_sb_locked) {
+ cpus_read_lock();
+ mutex_lock(&rdtgroup_mutex);
+ }

rdt_disable_ctx();

@@ -3189,8 +3196,10 @@ static void rdt_kill_sb(struct super_block *sb)
resctrl_arch_disable_mon();
resctrl_mounted = false;
kernfs_kill_sb(sb);
- mutex_unlock(&rdtgroup_mutex);
- cpus_read_unlock();
+ if (!rdt_kill_sb_locked) {
+ mutex_unlock(&rdtgroup_mutex);
+ cpus_read_unlock();
+ }
}

static struct file_system_type rdt_fs_type = {
--
2.54.0