mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jinjie Ruan <ruanjinjie@huawei.com>
To: <tony.luck@intel.com>, <reinette.chatre@intel.com>,
	<Dave.Martin@arm.com>, <james.morse@arm.com>,
	<babu.moger@amd.com>, <corbet@lwn.net>,
	<skhan@linuxfoundation.org>, <rdunlap@infradead.org>,
	<bp@alien8.de>, <tan.shaopeng@fujitsu.com>, <fenghuay@nvidia.com>,
	<will@kernel.org>, <gshan@redhat.com>, <jic23@kernel.org>,
	<ben.horgan@arm.com>, <zengheng4@huawei.com>, <x86@kernel.org>,
	<linux-kernel@vger.kernel.org>, <linux-doc@vger.kernel.org>
Cc: <ruanjinjie@huawei.com>
Subject: [PATCH v7 5/6] fs/resctrl: Recreate the dirty RMIDs when the CDP state changes
Date: Thu, 26 Nov 2026 17:50:37 +0800	[thread overview]
Message-ID: <20261126095038.2276975-6-ruanjinjie@huawei.com> (raw)
In-Reply-To: <20261126095038.2276975-1-ruanjinjie@huawei.com>

On MPAM an RMID is read through the PARTIDs of its CLOSID: CLOSID c is
PARTID c without CDP, and PARTIDs 2c and 2c+1 with CDP. A mount that
changes the CDP state changes how every RMID is read, but the RMIDs keep
the dirty state they had under the previous CDP state.

With 5 PARTIDs:

  mount                  CDP off, CLOSID c -> PARTID c
  mkdir g1..g4           CLOSIDs 1..4
  umount                 RMIDs enter limbo with CLOSIDs 1..4
  mount -o cdp           CDP on, CLOSID c -> PARTIDs 2c, 2c+1
  limbo handler          reads CLOSID 2 as PARTID 5 > PARTID_MAX 4

  mpam:__mpam_irq_handler: error irq from msc:1 'MSMONCFG_ID_RANGE', partid:5, pmg: 0, ris: 0
  mpam:mpam_disable: MPAM disabled due to hardware error interrupt

The other direction fails silently, and the free RMIDs are affected too.
With CDP the default group's code accesses tag cache lines with PARTID 1.
Mounted again without CDP, a new group given CLOSID 1 and RMID 0 starts
out counting those lines, although that RMID was never in limbo.

When a mount changes the CDP state, put every RMID that can be allocated
back in limbo, so that each one is checked as it is now read before it
is reused. Until then, creating a group may fail with -EBUSY. The RMIDs
of a CLOSID that is out of range under the new CDP state can neither be
read nor allocated, and stay free. CDP on any resource changes how every
CLOSID is monitored, so the CDP state of every resource is compared.
Where the RMID does not depend on the CLOSID, as on x86, nothing changes.

Fixes: 6789fb99282c ("arm_mpam: resctrl: Add CDP emulation")
Suggested-by: Ben Horgan <ben.horgan@arm.com>
Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Cc: <stable@vger.kernel.org>
---
v7:
- Recreate the dirty RMIDs instead of releasing the ones in limbo: the
  cache lines of every RMID may now be accounted to a different RMID,
  including the RMIDs that were free, so all of them are checked with
  the new mapping before they can be reused (Ben, Reinette).
- Trigger the recreation on the CDP change alone, without testing
  whether a domain has RMIDs in limbo (Reinette).
- Leave the RMIDs of a CLOSID that is out of range under the new CDP
  state on the free list instead of reading them.
- Do not recreate the dirty RMIDs on the first mount, before which only
  the default RMID is used, so that a group can be created right after
  the first mount with CDP.
- Link to v6: https://lore.kernel.org/all/6dd79d09-576b-4086-ba5c-7f8663292a6e@arm.com/
---
 fs/resctrl/monitor.c | 57 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 56 insertions(+), 1 deletion(-)

diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 5f3d39f0d3ed..8d78360efda8 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -70,6 +70,13 @@ static u32 *closid_num_dirty_rmid;
  */
 static unsigned int rmid_limbo_count;
 
+/*
+ * @limbo_cdp_state - 1 if the RMIDs were last checked with CDP enabled, 0 if
+ *     not, -1 before the first mount, when only the default RMID has been
+ *     used. Only used when CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID is defined.
+ */
+static int limbo_cdp_state = -1;
+
 /*
  * @rmid_entry - The entry in the limbo and free lists.
  */
@@ -1040,11 +1047,42 @@ int setup_rmid_lru_list(void)
 	return 0;
 }
 
+/*
+ * A change of the CDP state changes how every RMID is read, so any RMID, free
+ * or in limbo, may now count cache lines left by another. Put every RMID that
+ * can be allocated back in limbo. The others can neither be read nor
+ * allocated until the CDP state changes back.
+ */
+static void recreate_dirty_rmids(struct rdt_resource *r)
+{
+	u32 idx_limit = resctrl_arch_system_num_rmid_idx();
+	struct rdt_l3_mon_domain *d;
+
+	lockdep_assert_cpus_held();
+	lockdep_assert_held(&rdtgroup_mutex);
+
+	/* Only the default group exists, so this frees every other RMID. */
+	list_for_each_entry_rcu(d, &r->mon_domains, hdr.list, lockdep_is_cpus_held())
+		release_limbo_rmids(d);
+
+	/* Skip the default RMID, which stays allocated. */
+	for (u32 idx = 1; idx < idx_limit; idx++) {
+		struct rmid_entry *entry = __rmid_entry(idx);
+
+		if (entry->closid >= closids_supported())
+			continue;
+
+		list_del(&entry->list);
+		add_rmid_to_limbo(entry);
+	}
+}
+
 /**
  * cqm_resume_limbo_handler() - 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.
+ * domain that still has RMIDs in limbo, after checking every RMID again if
+ * the mount changed how they are read.
  */
 void cqm_resume_limbo_handler(void)
 {
@@ -1057,6 +1095,23 @@ void cqm_resume_limbo_handler(void)
 	if (!r->mon_capable || !resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID))
 		return;
 
+	/*
+	 * Where the RMID depends on the CLOSID, the CDP state decides how an
+	 * RMID is read. CDP on any resource changes how every CLOSID is
+	 * monitored, including by the L3.
+	 */
+	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
+		struct rdt_resource *res;
+		bool cdp_enabled = false;
+
+		for_each_rdt_resource(res)
+			cdp_enabled |= resctrl_arch_get_cdp_enabled(res->rid);
+
+		if (limbo_cdp_state >= 0 && cdp_enabled != limbo_cdp_state)
+			recreate_dirty_rmids(r);
+		limbo_cdp_state = cdp_enabled;
+	}
+
 	list_for_each_entry_rcu(d, &r->mon_domains, hdr.list, lockdep_is_cpus_held()) {
 		if (!has_busy_rmid(d))
 			continue;
-- 
2.34.1


  parent reply	other threads:[~2026-11-26  9:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  9:50 [PATCH v7 0/6] fs/resctrl: Fix some resctl bugs related to mpam Jinjie Ruan
2026-11-26  9:50 ` [PATCH v7 1/6] fs/resctrl: Report a temporary RMID shortage per CLOSID Jinjie Ruan
2026-11-26  9:50 ` [PATCH v7 2/6] fs/resctrl: Do not allocate a monitor context when releasing limbo RMIDs Jinjie Ruan
2026-11-26  9:50 ` [PATCH v7 3/6] fs/resctrl: Clear the CDP state after the cleanup Jinjie Ruan
2026-11-26  9:50 ` [PATCH v7 4/6] fs/resctrl: Stop the limbo handler while resctrl is unmounted Jinjie Ruan
2026-11-26  9:50 ` Jinjie Ruan [this message]
2026-12-03 20:15   ` [PATCH v7 5/6] fs/resctrl: Recreate the dirty RMIDs when the CDP state changes Reinette Chatre
2026-11-26  9:50 ` [PATCH v7 6/6] fs/resctrl: Disallow monitor group move when the RMID index changes Jinjie Ruan
2026-12-03 20:05 ` [PATCH v7 0/6] fs/resctrl: Fix some resctl bugs related to mpam Reinette Chatre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126095038.2276975-6-ruanjinjie@huawei.com \
    --to=ruanjinjie@huawei.com \
    --cc=Dave.Martin@arm.com \
    --cc=babu.moger@amd.com \
    --cc=ben.horgan@arm.com \
    --cc=bp@alien8.de \
    --cc=corbet@lwn.net \
    --cc=fenghuay@nvidia.com \
    --cc=gshan@redhat.com \
    --cc=james.morse@arm.com \
    --cc=jic23@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=reinette.chatre@intel.com \
    --cc=skhan@linuxfoundation.org \
    --cc=tan.shaopeng@fujitsu.com \
    --cc=tony.luck@intel.com \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    --cc=zengheng4@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®