Linux Documentation
 help / color / mirror / Atom feed
From: Reinette Chatre <reinette.chatre@intel.com>
To: Jinjie Ruan <ruanjinjie@huawei.com>, <tony.luck@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>
Subject: Re: [PATCH v7 5/6] fs/resctrl: Recreate the dirty RMIDs when the CDP state changes
Date: Thu, 3 Dec 2026 12:15:55 -0800	[thread overview]
Message-ID: <99edd56e-f8cc-46be-8a34-589c427c5fc2@intel.com> (raw)
In-Reply-To: <20261126095038.2276975-6-ruanjinjie@huawei.com>

Hi Jinjie,

Thank you for this redesign. I find rebuilding the dirty RMIDs
to be the right approach.

On 11/26/26 1:50 AM, Jinjie Ruan wrote:
> 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

"back in limbo" is not quite accurate since the RMIDs may be on free list.
This could perhaps just be "put every RMID that can be allocated in limbo"?

> 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.

Please write with imperative tone. For example,
	Compare the CDP state of every resource, since CDP on any resource
	changes how every CLOSID is monitored. Leave the limbo handling
	unchanged where the RMID does not depend on the CLOSID, as on x86.

...

> ---
>  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;

This is a big change. Previously this was a simple boolean named "limbo_cdp_enabled"
that tracked just the CDP state but now this becomes an int that tracks two different
things, the CDP state as well as the mount state. Having a single variable overloaded
like this is not ideal. The types are also inconsistent with it later being assigned
a boolean. 

Not rebuilding the list on first mount is right, but I think this can be accomplished
without adding a third value here.

setup_rmid_lru_list() already knows which mount is the first, since that is the one that
allocates rmid_ptrs[]. If its call in rdt_get_tree() moved after closid_init(), both things
the rebuild needs would be known when it runs: the CDP state from rdt_enable_ctx() and the
number of CLOSIDs from closid_init(). Nothing between the two calls uses rmid_ptrs[] or
the free list. The first mount could then record the CDP state, later mounts compare against
it and rebuild if it changed, and this could go back to a bool just like it was in v6.

> +
>  /*
>   * @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)

Could this be named more specific, for example "limbo_redirty_all()"?

> +{
> +	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);
> +

After this every RMID other than the default one is on the free list, and the loop below
depends on that. Could it be enforced, for example with WARN_ON_ONCE(rmid_limbo_count)
here? Something left in limbo would otherwise be skipped by the rebuild without any sign.

> +	/* Skip the default RMID, which stays allocated. */
> +	for (u32 idx = 1; idx < idx_limit; idx++) {

Having the loop managed by the index and then removing the list entry for each
creates an implicit dependency here on how the limbo entries were freed. I think
walking the free list that release_limbo_rmids() just created will be more robust:

	list_for_each_entry_safe(entry, tmp, &rmid_free_lru, list) {
		if (entry->closid >= num_closid)
			continue;
		list_del(&entry->list);
		...
	}

> +		struct rmid_entry *entry = __rmid_entry(idx);
> +
> +		if (entry->closid >= closids_supported())

closids_supported() may be zero on a monitor-only system. This will mean that
no RMIDs are placed back?

How about:
	/* Without allocation, only the default CLOSID is in use. */
	num_closid = resctrl_arch_alloc_capable() ? closids_supported() : 1;

> +			continue;
> +
> +		list_del(&entry->list);
> +		add_rmid_to_limbo(entry);

add_rmid_to_limbo() also arms the limbo handler with the default CQM_LIMBOCHECK_INTERVAL,
just for cqm_resume_limbo_handler() to cancel and re-queue it. This is very difficult to
follow.

Could the rebuild only mark the RMIDs dirty, and leave starting the handler to
cqm_resume_limbo_handler()? A new "limbo_add_entry()" that splits out all but 
arming the limbo handler would complements existing  "limbo_release_entry()"  and
keep entry->busy, rmid_limbo_count and closid_num_dirty_rmid[] updated in one place:

	/* Mark an RMID dirty in every domain, without arming the limbo handler. */
	static void limbo_add_entry(struct rmid_entry *entry)
	{
		struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
		struct rdt_l3_mon_domain *d;
		u32 idx;

		lockdep_assert_held(&rdtgroup_mutex);
		lockdep_assert_cpus_held();

		idx = resctrl_arch_rmid_idx_encode(entry->closid, entry->rmid);

		entry->busy = 0;
		list_for_each_entry_rcu(d, &r->mon_domains, hdr.list, lockdep_is_cpus_held()) {
			set_bit(idx, d->rmid_busy_llc);
			entry->busy++;
		}

		rmid_limbo_count++;
		if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID))
			closid_num_dirty_rmid[entry->closid]++;
	}

add_rmid_to_limbo() would then call limbo_add_entry() and only add arming of the limbo handler.

Above changes should ideally be split into a few preparatory patches, which
is now easier to manage with the CDP fixes not headed to stable. I see at least
two preparatory patches:
- moving setup_rmid_lru_list() to later in rdt_get_tree()
- new limbo_add_entry() helper.

> +	}
> +}

> +
>  /**
>   * 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.

This reads as if resctrl in general linked the CDP state of one resource to the
monitoring of another. It does not; checking every resource is there for how MPAM
emulates CDP, which is fine here because only MPAM selects
CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID. Could the comment say so, wherever the check
ends up? For example:

	/*
	 * Only MPAM selects CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID. Its CDP
	 * emulation gives every CLOSID two PARTIDs in every MSC as soon as CDP
	 * is enabled on any resource, so CDP enabled on the L2 alone also
	 * changes how the L3 monitors read an RMID. Check the CDP state of
	 * every resource to accommodate that.
	 */


> +	 */
> +	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;

Based on the examples it seems there may be scenarios where only limited PARTID are
available. If there is thus a system with only two PARTID and one PMG that is mounted
with CDP then only CLOSID 0 is left. A rebuild may then not put any RMID back while a
limbo worker is still queued.

Considering this, should above perhaps be:
	list_for_each_entry_rcu(d, &r->mon_domains, hdr.list, lockdep_is_cpus_held()) {
		/* Drop any worker the unmount left queued. */
		cancel_delayed_work(&d->cqm_limbo);
		if (has_busy_rmid(d))
			cqm_setup_limbo_handler(d, 0, RESCTRL_PICK_ANY_CPU);
	}

This may be 

Reinette

  reply	other threads:[~2026-12-03 20:16 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 ` [PATCH v7 5/6] fs/resctrl: Recreate the dirty RMIDs when the CDP state changes Jinjie Ruan
2026-12-03 20:15   ` Reinette Chatre [this message]
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=99edd56e-f8cc-46be-8a34-589c427c5fc2@intel.com \
    --to=reinette.chatre@intel.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=ruanjinjie@huawei.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