Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.175 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794316911; b=FjXw1O0dIa23Tpeo4POd/ZeyyfPlazS92gSHw6oW3MWPaNHQ8pbJKcuUHrvVHBt3aASh 0mBo93EozqnMZZLfztLOJfq4Z8XP6JzX7djZ/fxJ/KWAkLYYbg1XHZCfQcdnPe8m37jp8 RsePM3UU7weQK4YUiUaZ4XiF4xT45CG4Mniruj+UOpGVgSR7jyiFMKNduHPRuFbH4oBbt 2Hy9R8B69T7ODIJ8XbWAqsqMs7ooDse6MXL6kywClfKMmEBRsmA6uUJ+AdWa5qkfT1kLc tPoLpquttuMeRx0dWx0+hdJ/+xBEejqMCHqQRc7L1/bZIHMqEHKhVoLtKrWAx8EPwBg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794316911; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=OTx52hVUF9lB6fufKA+RTnJSg0CR3TeUfaD+GwbgFjg=; b=cBxEHnQwC5Oo0K4ljeMBUa9jasEI7JRBOi1FXqVIemXzbKPVosgs51Y/pBZcQ55dq0Bl FfrPKi37BYKOgvAwYuotGsDFNsHzMEUsiEMDpRjyAKao44699eQAwqwBcsMHHa6JvX71J WhgRuvBebIDZxv/DLe8cUk3riA71f9huqL4QEr7QtXbnexVW+gt5znCtfUQ0cSnIdlkBW cx67KvHU/wqHsUvJnR6pnSt17oJZkxUORFOq8I4eGcigSEq32ZBxQDMxGF4Bgq2RWcqwl LQ7tFuMyF7DCA+Ss9z5EDMB77Gvc7n2cWaZxzOycHAUjUVI/jtkjd3IaiUM63oxwpjw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=bwwQv6k4; arc=none smtp.remote-ip=209.85.214.175 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACB8D606A7E4 for ; Tue, 10 Nov 2026 13:21:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ACB8D606A7E4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=bwwQv6k4 Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2e95bd1c14cso17877065ad.2 for ; Tue, 10 Nov 2026 05:21:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794316910; x=1794921710; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=OTx52hVUF9lB6fufKA+RTnJSg0CR3TeUfaD+GwbgFjg=; b=bwwQv6k4ch7Zi69wVw03rlERsLKhtmjzvFifgz/1itFmaxm0W6//Aqxxyv5C1LZOG5 D+JshKqDrmreIiJNzEQpcjSri5eShQY1Ko8kOuEX9doR52jV1+89+dlDhKaFtQqGr681 nUZ2g6/cD5J64v36BzEzudi+DXODbJbSdM6d7nqthX76r+gbd4Il7M+EUrCE39nwpTRm gBW3px2ulwLU9A5g1Ibs2e8G8wIkC5n3pi7INRFTgHeer1Wm7sWeJDN++tt21iP7V5D1 5DDY/tKbX8BzXVn9MLSDfXTsCYm2pycfPM/+F11N7AXJFEYSSzMeNI6lEia+h6lLsjPy iYfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794316910; x=1794921710; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=OTx52hVUF9lB6fufKA+RTnJSg0CR3TeUfaD+GwbgFjg=; b=yI4NUSxs+vXGHiYuVdSsaxUgQ/MpzsjSvLNJeb1jiB4fvPgZYGtu4wzDH+lZ8T3Oae nz/iIFWpC0p4vL3gSnaCw6DTrKEMimUk0UzU6M8IP8YsAloCLw/lud0ROU99GFbd51ry syjWp93DGPnethzFORjE+ma5S620p/qRJT+qphtHLdAyI03tHqlvkumoYAfcT9E6MHrh D0NJHtbq579oAELwavSnGgsTzO3kjtTq1bEhZjLBCU7D05uq72xfzJtwT1e8N5Sl5N/x vi6WQdL3PnrI8bhYBDnh2tVShabZHEwMeuxTmcfOWJnmhxGTcOYSt9vESL9JON7iGcH+ YUiQ== X-Forwarded-Encrypted: i=1; AL+hErHHnDM9Hqb484aaF0Wjhu6FXx1ZEKXfsWpximFoSGitw+NfPRg5l+SKdXl5Ish1GsUjLt6R+cd+jss=@vger.kernel.org X-Gm-Message-State: APuU4Z8+XT49lH1Nfess7FbAdG0Yjm9WuzQ2RyN/jDLgEqhwHGUZgAIJ ZBLbo7X13MhqCX94HB87I0bHA4UBPbV8tTmvn9FEd0Uuc1ef7nB5cArn X-Gm-Gg: AYBFou1LluF/ow6fJYsYb40TVa3TMXu1TMjo145rmklcoePJBdyxKaM8amEmesiZkw0 wccib8CPp7ciS/usyPlOuRDj5918EmTmx5sxdtw2q7T4rN5JVqN7EHvwmeNXNA5jFbjNrIiu1mq dmVqzjDrejT5Zi5z8J05dgwpqEXmHagVmlN96+2qxnbBgPc8EA8jHxwEMF4o+aZrh8Uft61q2BU hSSdmO/JvHAygA/DjW0rXW5cTfDkIGEY++45NpdrKFVnGPwucfGqzqywsgTyAmqoR4HzBF05O8F aHqGeWpO4Mzx8NAoFx2rg4gBsuaRBJqYb80v8EXqfGBYABcRcpJdoT89vnSxfXde3fsmY6qG+Sj QfD2H0+ZLjC3xWLtBSKxR1hL4Z9B9kg8ngzFffrAfVF4CR9mv/2ZfVmomfslq+cmWw4RXFilhmO Bwkn28eBU4w2G0jTUrMEIgjUoM6atebpF5zGMhjvaPtyxAspmaHXjU5e5ZVSI9i4cnyXdI3BFgX gay+5e7AsSWxD3oT6JG0Cy8vZNNhu2jVUeDub/oA3nrfESDCjk8gi95MF0ESeG01Z8Km5h+kXeK YKAPADeA2eSnODXzUC0XvXzg7pQC362MoNRpIQtrGePoPUwEXCHt3JjV8U5a1tA= X-Received: by 2002:a17:903:1a0c:b0:2ed:ebc:460f with SMTP id d9443c01a7336-2edb91fc398mr24141765ad.33.1794316909936; Tue, 10 Nov 2026 05:21:49 -0800 (PST) Received: from r00799764-ThinkCentre-M920t-N000.. ([139.159.170.67]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2edb6d4a31esm8861065ad.22.2026.11.10.05.21.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2026 05:21:49 -0800 (PST) From: Jinjie Ruan To: babu.moger@amd.com, ben.horgan@arm.com, bp@alien8.de, corbet@lwn.net, dave.hansen@linux.intel.com, Dave.Martin@arm.com, fenghuay@nvidia.com, gshan@redhat.com, hpa@zytor.com, james.morse@arm.com, jic23@kernel.org, mingo@redhat.com, rdunlap@infradead.org, reinette.chatre@intel.com, skhan@linuxfoundation.org, tan.shaopeng@fujitsu.com, tglx@kernel.org, tony.luck@intel.com, zengheng4@huawei.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: ruanjinjie@huawei.com Subject: [PATCH v5 4/7] fs/resctrl: Stop the limbo handler while resctrl is unmounted Date: Tue, 10 Nov 2026 21:20:51 +0800 Message-ID: <20261110132054.3702-5-ruanjinjie01@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261110132054.3702-1-ruanjinjie01@gmail.com> References: <20261110132054.3702-1-ruanjinjie01@gmail.com> X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jinjie Ruan A group's RMID is not returned to the free list when the group is removed. It stays in limbo until the cache lines tagged with it are evicted, and the limbo handler reads its occupancy counter in the meantime. The limbo handler keeps running after resctrl is unmounted, while the MBM overflow handler stops once resctrl_mounted is cleared. Reading the RMIDs in limbo while resctrl is unmounted is not safe on every architecture. On MPAM the counter of an RMID is selected by the PARTIDs of the CLOSID that owned it, and the CLOSID to PARTID mapping depends on the CDP state. The unmount clears the CDP state, so the handler that keeps running reads the RMIDs freed under CDP through the PARTIDs of the cleared state. Stop the limbo handler while resctrl is unmounted, as the overflow handler does, and restart it after a mount on every domain that still has RMIDs in limbo. The worker can stay queued across the unmount, so cancel it before queuing it again. This keeps the limbo handler lifetime the same on every architecture. On x86 the RMIDs in limbo are no longer drained while resctrl is unmounted. Nothing needs them until the mount that follows the unmount, after which the handler frees them as before. Fixes: 6789fb99282c ("arm_mpam: resctrl: Add CDP emulation") Suggested-by: Reinette Chatre Signed-off-by: Jinjie Ruan Cc: # 7.1+ --- fs/resctrl/internal.h | 1 + fs/resctrl/monitor.c | 43 +++++++++++++++++++++++++++++++++++++++++-- fs/resctrl/rdtgroup.c | 2 ++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 1c85e06f09bf..c95fa6ce62e6 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -373,6 +373,7 @@ void closid_free(int closid); int setup_rmid_lru_list(void); void free_rmid_lru_list(void); +void resctrl_limbo_resume(void); int alloc_rmid(u32 closid); diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index ae9ddd380515..f56d0e32fd06 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -852,6 +852,13 @@ void cqm_handle_limbo(struct work_struct *work) */ mutex_lock(&rdtgroup_mutex); + /* + * If the filesystem has been unmounted this work no longer needs to + * run. resctrl_limbo_resume() restarts it on the next mount. + */ + if (!resctrl_mounted) + goto out_unlock; + /* * Ensure the worker is dedicated to a CPU as intended and not * relocated by workqueue subsystem as part of CPU going offline. @@ -1001,8 +1008,8 @@ int setup_rmid_lru_list(void) /* * Called on every mount, but the number of RMIDs cannot change * after the first mount, so keep using the same set of rmid_ptrs[] - * until resctrl_exit(). Note that the limbo handler continues to - * access rmid_ptrs[] after resctrl is unmounted. + * until resctrl_exit(). Note that the RMIDs in limbo stay in limbo + * across an unmount and are checked again after the next mount. */ if (rmid_ptrs) return 0; @@ -1033,6 +1040,38 @@ int setup_rmid_lru_list(void) return 0; } +/** + * resctrl_limbo_resume() - Restart the limbo handler after a mount. + * + * The limbo handler stops while resctrl is unmounted. Restart it on every + * domain that still has RMIDs in limbo. + */ +void resctrl_limbo_resume(void) +{ + struct rdt_l3_mon_domain *d; + struct rdt_resource *r; + + lockdep_assert_cpus_held(); + lockdep_assert_held(&rdtgroup_mutex); + + if (!resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) + return; + + r = resctrl_arch_get_resource(RDT_RESOURCE_L3); + list_for_each_entry_rcu(d, &r->mon_domains, hdr.list, + lockdep_is_cpus_held()) { + if (!has_busy_rmid(d)) + continue; + + /* + * The unmount may have left the worker queued. Cancel it so + * it is queued again on a CPU picked now. + */ + cancel_delayed_work(&d->cqm_limbo); + cqm_setup_limbo_handler(d, 0, RESCTRL_PICK_ANY_CPU); + } +} + void free_rmid_lru_list(void) { if (!resctrl_arch_mon_capable()) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 3312637fb514..b702fe6dbbec 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -3267,6 +3267,8 @@ static int rdt_get_tree(struct fs_context *fc) RESCTRL_PICK_ANY_CPU); } + resctrl_limbo_resume(); + /* * Ensure root remains accessible after mutex is unlocked so that * kernfs_kill_sb() can run safely if called by kernfs_get_tree()'s -- 2.43.0