[RFC PATCH 34/38] arm_mpam: Add quirk framework

James Morse posted 38 patches 2 months ago
There is a newer version of this series
[RFC PATCH 34/38] arm_mpam: Add quirk framework
Posted by James Morse 2 months ago
From: Shanker Donthineni <sdonthineni@nvidia.com>

The MPAM specification includes the MPAMF_IIDR, which serves to
uniquely identify the MSC implementation through a combination of
implementer details, product ID, variant, and revision. Certain
hardware issues/errata can be resolved using software workarounds.

Introduce a quirk framework to allow workarounds to be enabled based
on the MPAMF_IIDR value.

Signed-off-by: Shanker Donthineni <sdonthineni@nvidia.com>
[ morse: Stash the IIDR so this doesn't need an IPI, enable quirks only
  once, move the description to the callback so it can be pr_once()d, add
  an enum of workarounds for popular errata. Add macros for making lists
  of product/revision/vendor half readable ]
Signed-off-by: James Morse <james.morse@arm.com>
---
 drivers/resctrl/mpam_devices.c  | 27 +++++++++++++++++++++++++++
 drivers/resctrl/mpam_internal.h | 26 ++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index 741e14e1e6cf..f0f6f9b55ad4 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -630,6 +630,25 @@ static struct mpam_msc_ris *mpam_get_or_create_ris(struct mpam_msc *msc,
 	return ERR_PTR(-ENOENT);
 }
 
+static const struct mpam_quirk mpam_quirks[] = {
+	{ NULL }, /* Sentinel */
+};
+
+static void mpam_enable_quirks(struct mpam_msc *msc)
+{
+	const struct mpam_quirk *quirk;
+
+	for (quirk = &mpam_quirks[0]; quirk->iidr_mask; quirk++) {
+		if (quirk->iidr != (msc->iidr & quirk->iidr_mask))
+			continue;
+
+		if (quirk->init)
+			quirk->init(msc, quirk);
+		else
+			mpam_set_quirk(quirk->workaround, msc);
+	}
+}
+
 /*
  * IHI009A.a has this nugget: "If a monitor does not support automatic behaviour
  * of NRDY, software can use this bit for any purpose" - so hardware might not
@@ -864,8 +883,11 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc)
 	/* Grab an IDR value to find out how many RIS there are */
 	mutex_lock(&msc->part_sel_lock);
 	idr = mpam_msc_read_idr(msc);
+	msc->iidr = mpam_read_partsel_reg(msc, IIDR);
 	mutex_unlock(&msc->part_sel_lock);
 
+	mpam_enable_quirks(msc);
+
 	msc->ris_max = FIELD_GET(MPAMF_IDR_RIS_MAX, idr);
 
 	/* Use these values so partid/pmg always starts with a valid value */
@@ -1987,6 +2009,7 @@ static bool mpam_has_cmax_wd_feature(struct mpam_props *props)
  * resulting safe value must be compatible with both. When merging values in
  * the tree, all the aliasing resources must be handled first.
  * On mismatch, parent is modified.
+ * Quirks on an MSC will apply to all MSC in that class.
  */
 static void __props_mismatch(struct mpam_props *parent,
 			     struct mpam_props *child, bool alias)
@@ -2106,6 +2129,7 @@ static void __props_mismatch(struct mpam_props *parent,
  * nobble the class feature, as we can't configure all the resources.
  * e.g. The L3 cache is composed of two resources with 13 and 17 portion
  * bitmaps respectively.
+ * Quirks on an MSC will apply to all MSC in that class.
  */
 static void
 __class_props_mismatch(struct mpam_class *class, struct mpam_vmsc *vmsc)
@@ -2119,6 +2143,9 @@ __class_props_mismatch(struct mpam_class *class, struct mpam_vmsc *vmsc)
 	dev_dbg(dev, "Merging features for class:0x%lx &= vmsc:0x%lx\n",
 		(long)cprops->features, (long)vprops->features);
 
+	/* Merge quirks */
+	class->quirks |= vmsc->msc->quirks;
+
 	/* Take the safe value for any common features */
 	__props_mismatch(cprops, vprops, false);
 }
diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_internal.h
index d381906545ed..de3e5faa12b2 100644
--- a/drivers/resctrl/mpam_internal.h
+++ b/drivers/resctrl/mpam_internal.h
@@ -88,6 +88,8 @@ struct mpam_msc {
 	u8			pmg_max;
 	unsigned long		ris_idxs;
 	u32			ris_max;
+	u32			iidr;
+	u16			quirks;
 
 	/*
 	 * error_irq_lock is taken when registering/unregistering the error
@@ -215,6 +217,29 @@ struct mpam_props {
 #define mpam_set_feature(_feat, x)	set_bit(_feat, (x)->features)
 #define mpam_clear_feature(_feat, x)	clear_bit(_feat, (x)->features)
 
+/* Workaround bits for msc->quirks */
+enum mpam_device_quirks {
+	MPAM_QUIRK_LAST,
+};
+
+#define mpam_has_quirk(_quirk, x)	((1 << (_quirk) & (x)->quirks))
+#define mpam_set_quirk(_quirk, x)	((x)->quirks |= (1 << (_quirk)))
+
+struct mpam_quirk {
+	void (*init)(struct mpam_msc *msc, const struct mpam_quirk *quirk);
+
+	u32 iidr;
+	u32 iidr_mask;
+
+	enum mpam_device_quirks workaround;
+};
+
+#define MPAM_IIDR_MATCH_ONE	FIELD_PREP_CONST(MPAMF_IIDR_PRODUCTID,   0xfff) | \
+				FIELD_PREP_CONST(MPAMF_IIDR_VARIANT,     0xf  ) | \
+				FIELD_PREP_CONST(MPAMF_IIDR_REVISION,    0xf  ) | \
+				FIELD_PREP_CONST(MPAMF_IIDR_IMPLEMENTER, 0xfff)
+
+
 /* The values for MSMON_CFG_MBWU_FLT.RWBW */
 enum mon_filter_options {
 	COUNT_BOTH	= 0,
@@ -258,6 +283,7 @@ struct mpam_class {
 
 	struct mpam_props	props;
 	u32			nrdy_usec;
+	u16			quirks;
 	u8			level;
 	enum mpam_class_types	type;
 
-- 
2.39.5
Re: [RFC PATCH 34/38] arm_mpam: Add quirk framework
Posted by Jonathan Cameron 1 month, 2 weeks ago
On Fri, 5 Dec 2025 21:58:57 +0000
James Morse <james.morse@arm.com> wrote:

> From: Shanker Donthineni <sdonthineni@nvidia.com>
> 
> The MPAM specification includes the MPAMF_IIDR, which serves to
> uniquely identify the MSC implementation through a combination of
> implementer details, product ID, variant, and revision. Certain
> hardware issues/errata can be resolved using software workarounds.
> 
> Introduce a quirk framework to allow workarounds to be enabled based
> on the MPAMF_IIDR value.
> 
> Signed-off-by: Shanker Donthineni <sdonthineni@nvidia.com>
> [ morse: Stash the IIDR so this doesn't need an IPI, enable quirks only
>   once, move the description to the callback so it can be pr_once()d, add
>   an enum of workarounds for popular errata. Add macros for making lists
>   of product/revision/vendor half readable ]
> Signed-off-by: James Morse <james.morse@arm.com>
> ---
>  drivers/resctrl/mpam_devices.c  | 27 +++++++++++++++++++++++++++
>  drivers/resctrl/mpam_internal.h | 26 ++++++++++++++++++++++++++
>  2 files changed, 53 insertions(+)
> 
> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
> index 741e14e1e6cf..f0f6f9b55ad4 100644
> --- a/drivers/resctrl/mpam_devices.c
> +++ b/drivers/resctrl/mpam_devices.c
> @@ -630,6 +630,25 @@ static struct mpam_msc_ris *mpam_get_or_create_ris(struct mpam_msc *msc,
>  	return ERR_PTR(-ENOENT);
>  }
>  
> +static const struct mpam_quirk mpam_quirks[] = {
> +	{ NULL }, /* Sentinel */

Drop the trailing , given I assume whole point is nothing after this?

> +};
> +
> +static void mpam_enable_quirks(struct mpam_msc *msc)
> +{
> +	const struct mpam_quirk *quirk;
> +
> +	for (quirk = &mpam_quirks[0]; quirk->iidr_mask; quirk++) {
> +		if (quirk->iidr != (msc->iidr & quirk->iidr_mask))
> +			continue;
> +
> +		if (quirk->init)
> +			quirk->init(msc, quirk);

I'm curious why you don't return a bool from this and call
mpam_set_quirk() if that's not indicating it should not be set.
Seems a bit odd to push the tracking that is relevant to the generic
framework (mpam_set_quirk) down into the particular quirk inits.

> +		else
> +			mpam_set_quirk(quirk->workaround, msc);
> +	}
> +}

> diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_internal.h
> index d381906545ed..de3e5faa12b2 100644
> --- a/drivers/resctrl/mpam_internal.h
> +++ b/drivers/resctrl/mpam_internal.h
> @@ -88,6 +88,8 @@ struct mpam_msc {
>  	u8			pmg_max;
>  	unsigned long		ris_idxs;
>  	u32			ris_max;
> +	u32			iidr;
> +	u16			quirks;
>  
>  	/*
>  	 * error_irq_lock is taken when registering/unregistering the error
> @@ -215,6 +217,29 @@ struct mpam_props {
>  #define mpam_set_feature(_feat, x)	set_bit(_feat, (x)->features)
>  #define mpam_clear_feature(_feat, x)	clear_bit(_feat, (x)->features)
>  
> +/* Workaround bits for msc->quirks */
> +enum mpam_device_quirks {
> +	MPAM_QUIRK_LAST,

Dropping this comma should make it harder for anyone to stick an entry
after this.
Re: [RFC PATCH 34/38] arm_mpam: Add quirk framework
Posted by Ben Horgan 1 month, 2 weeks ago
Hi Jonathan,

Thanks for your review. I haven't replied to every point but unless
commented I have acted on them.

On 12/18/25 14:04, Jonathan Cameron wrote:
> On Fri, 5 Dec 2025 21:58:57 +0000
> James Morse <james.morse@arm.com> wrote:
> 
>> From: Shanker Donthineni <sdonthineni@nvidia.com>
>>
>> The MPAM specification includes the MPAMF_IIDR, which serves to
>> uniquely identify the MSC implementation through a combination of
>> implementer details, product ID, variant, and revision. Certain
>> hardware issues/errata can be resolved using software workarounds.
>>
>> Introduce a quirk framework to allow workarounds to be enabled based
>> on the MPAMF_IIDR value.
>>
>> Signed-off-by: Shanker Donthineni <sdonthineni@nvidia.com>
>> [ morse: Stash the IIDR so this doesn't need an IPI, enable quirks only
>>   once, move the description to the callback so it can be pr_once()d, add
>>   an enum of workarounds for popular errata. Add macros for making lists
>>   of product/revision/vendor half readable ]
>> Signed-off-by: James Morse <james.morse@arm.com>
>> ---
>>  drivers/resctrl/mpam_devices.c  | 27 +++++++++++++++++++++++++++
>>  drivers/resctrl/mpam_internal.h | 26 ++++++++++++++++++++++++++
>>  2 files changed, 53 insertions(+)
>>
>> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
>> index 741e14e1e6cf..f0f6f9b55ad4 100644
>> --- a/drivers/resctrl/mpam_devices.c
>> +++ b/drivers/resctrl/mpam_devices.c
>> @@ -630,6 +630,25 @@ static struct mpam_msc_ris *mpam_get_or_create_ris(struct mpam_msc *msc,
>>  	return ERR_PTR(-ENOENT);
>>  }
>>  
>> +static const struct mpam_quirk mpam_quirks[] = {
>> +	{ NULL }, /* Sentinel */
> 
> Drop the trailing , given I assume whole point is nothing after this?
> 
>> +};
>> +
>> +static void mpam_enable_quirks(struct mpam_msc *msc)
>> +{
>> +	const struct mpam_quirk *quirk;
>> +
>> +	for (quirk = &mpam_quirks[0]; quirk->iidr_mask; quirk++) {
>> +		if (quirk->iidr != (msc->iidr & quirk->iidr_mask))
>> +			continue;
>> +
>> +		if (quirk->init)
>> +			quirk->init(msc, quirk);
> 
> I'm curious why you don't return a bool from this and call
> mpam_set_quirk() if that's not indicating it should not be set.
> Seems a bit odd to push the tracking that is relevant to the generic
> framework (mpam_set_quirk) down into the particular quirk inits.

Good point. I've changed the init to return 0 or an error.

> 
>> +		else
>> +			mpam_set_quirk(quirk->workaround, msc);
>> +	}
>> +}
> 
>> diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_internal.h
>> index d381906545ed..de3e5faa12b2 100644
>> --- a/drivers/resctrl/mpam_internal.h
>> +++ b/drivers/resctrl/mpam_internal.h
>> @@ -88,6 +88,8 @@ struct mpam_msc {
>>  	u8			pmg_max;
>>  	unsigned long		ris_idxs;
>>  	u32			ris_max;
>> +	u32			iidr;
>> +	u16			quirks;
>>  
>>  	/*
>>  	 * error_irq_lock is taken when registering/unregistering the error
>> @@ -215,6 +217,29 @@ struct mpam_props {
>>  #define mpam_set_feature(_feat, x)	set_bit(_feat, (x)->features)
>>  #define mpam_clear_feature(_feat, x)	clear_bit(_feat, (x)->features)
>>  
>> +/* Workaround bits for msc->quirks */
>> +enum mpam_device_quirks {
>> +	MPAM_QUIRK_LAST,
> 
> Dropping this comma should make it harder for anyone to stick an entry
> after this.

Commas removed.

Thanks,

Ben