[PATCH v3 02/47] arm_mpam: Use non-atomic bitops when modifying feature bitmap

Ben Horgan posted 47 patches 4 weeks ago
There is a newer version of this series
[PATCH v3 02/47] arm_mpam: Use non-atomic bitops when modifying feature bitmap
Posted by Ben Horgan 4 weeks ago
In the test__props_mismatch() kunit test we rely on the struct mpam_props
being packed to ensure memcmp doesn't consider packing. Making it packed
reduces the alignment of the features bitmap and so breaks a requirement
for the use of atomics. As we don't rely on the set/clear of these bits
being atomic, just make them non-atomic.

Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Signed-off-by: Ben Horgan <ben.horgan@arm.com>
---
Changes since v2:
Add comment (Jonathan)
---
 drivers/resctrl/mpam_internal.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_internal.h
index 17cdc3080d58..e8971842b124 100644
--- a/drivers/resctrl/mpam_internal.h
+++ b/drivers/resctrl/mpam_internal.h
@@ -200,8 +200,12 @@ struct mpam_props {
 } PACKED_FOR_KUNIT;
 
 #define mpam_has_feature(_feat, x)	test_bit(_feat, (x)->features)
-#define mpam_set_feature(_feat, x)	set_bit(_feat, (x)->features)
-#define mpam_clear_feature(_feat, x)	clear_bit(_feat, (x)->features)
+/*
+ * The non-atomic get/set operations are used because if struct mpam_props is
+ * packed, the alignment requirements for atomics aren't met.
+ */
+#define mpam_set_feature(_feat, x)	__set_bit(_feat, (x)->features)
+#define mpam_clear_feature(_feat, x)	__clear_bit(_feat, (x)->features)
 
 /* The values for MSMON_CFG_MBWU_FLT.RWBW */
 enum mon_filter_options {
-- 
2.43.0
Re: [PATCH v3 02/47] arm_mpam: Use non-atomic bitops when modifying feature bitmap
Posted by Catalin Marinas 3 weeks, 3 days ago
On Mon, Jan 12, 2026 at 04:58:29PM +0000, Ben Horgan wrote:
> In the test__props_mismatch() kunit test we rely on the struct mpam_props
> being packed to ensure memcmp doesn't consider packing. Making it packed
> reduces the alignment of the features bitmap and so breaks a requirement
> for the use of atomics. As we don't rely on the set/clear of these bits
> being atomic, just make them non-atomic.
> 
> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
> Signed-off-by: Ben Horgan <ben.horgan@arm.com>
> ---
> Changes since v2:
> Add comment (Jonathan)
> ---
>  drivers/resctrl/mpam_internal.h | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_internal.h
> index 17cdc3080d58..e8971842b124 100644
> --- a/drivers/resctrl/mpam_internal.h
> +++ b/drivers/resctrl/mpam_internal.h
> @@ -200,8 +200,12 @@ struct mpam_props {
>  } PACKED_FOR_KUNIT;
>  
>  #define mpam_has_feature(_feat, x)	test_bit(_feat, (x)->features)
> -#define mpam_set_feature(_feat, x)	set_bit(_feat, (x)->features)
> -#define mpam_clear_feature(_feat, x)	clear_bit(_feat, (x)->features)
> +/*
> + * The non-atomic get/set operations are used because if struct mpam_props is
> + * packed, the alignment requirements for atomics aren't met.
> + */
> +#define mpam_set_feature(_feat, x)	__set_bit(_feat, (x)->features)
> +#define mpam_clear_feature(_feat, x)	__clear_bit(_feat, (x)->features)

After discussing privately, I can see how test__props_mismatch() can
end up with unaligned atomics on the mmap_props::features array. Happy to
pick it up for 6.19 (probably the first patch as well, though that's
harmless).

Is there a Fixes tag here for future reference?

-- 
Catalin
Re: [PATCH v3 02/47] arm_mpam: Use non-atomic bitops when modifying feature bitmap
Posted by Ben Horgan 3 weeks, 3 days ago
Hi Catalin,

On 1/16/26 11:57, Catalin Marinas wrote:
> On Mon, Jan 12, 2026 at 04:58:29PM +0000, Ben Horgan wrote:
>> In the test__props_mismatch() kunit test we rely on the struct mpam_props
>> being packed to ensure memcmp doesn't consider packing. Making it packed
>> reduces the alignment of the features bitmap and so breaks a requirement
>> for the use of atomics. As we don't rely on the set/clear of these bits
>> being atomic, just make them non-atomic.
>>
>> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
>> Signed-off-by: Ben Horgan <ben.horgan@arm.com>
>> ---
>> Changes since v2:
>> Add comment (Jonathan)
>> ---
>>  drivers/resctrl/mpam_internal.h | 8 ++++++--
>>  1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_internal.h
>> index 17cdc3080d58..e8971842b124 100644
>> --- a/drivers/resctrl/mpam_internal.h
>> +++ b/drivers/resctrl/mpam_internal.h
>> @@ -200,8 +200,12 @@ struct mpam_props {
>>  } PACKED_FOR_KUNIT;
>>  
>>  #define mpam_has_feature(_feat, x)	test_bit(_feat, (x)->features)
>> -#define mpam_set_feature(_feat, x)	set_bit(_feat, (x)->features)
>> -#define mpam_clear_feature(_feat, x)	clear_bit(_feat, (x)->features)
>> +/*
>> + * The non-atomic get/set operations are used because if struct mpam_props is
>> + * packed, the alignment requirements for atomics aren't met.
>> + */
>> +#define mpam_set_feature(_feat, x)	__set_bit(_feat, (x)->features)
>> +#define mpam_clear_feature(_feat, x)	__clear_bit(_feat, (x)->features)
> 
> After discussing privately, I can see how test__props_mismatch() can
> end up with unaligned atomics on the mmap_props::features array. Happy to
> pick it up for 6.19 (probably the first patch as well, though that's
> harmless).

Yes please.

> 
> Is there a Fixes tag here for future reference?
> 

Yes, the mpam_set/clear macros were introduced in

Fixes: 8c90dc68a5de ("arm_mpam: Probe the hardware features resctrl supports")

Thanks,

Ben
Re: [PATCH v3 02/47] arm_mpam: Use non-atomic bitops when modifying feature bitmap
Posted by Ben Horgan 3 weeks, 3 days ago

On 1/16/26 12:02, Ben Horgan wrote:
> Hi Catalin,
> 
> On 1/16/26 11:57, Catalin Marinas wrote:
>> On Mon, Jan 12, 2026 at 04:58:29PM +0000, Ben Horgan wrote:
>>> In the test__props_mismatch() kunit test we rely on the struct mpam_props
>>> being packed to ensure memcmp doesn't consider packing. Making it packed
>>> reduces the alignment of the features bitmap and so breaks a requirement
>>> for the use of atomics. As we don't rely on the set/clear of these bits
>>> being atomic, just make them non-atomic.
>>>
>>> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
>>> Signed-off-by: Ben Horgan <ben.horgan@arm.com>
>>> ---
>>> Changes since v2:
>>> Add comment (Jonathan)
>>> ---
>>>  drivers/resctrl/mpam_internal.h | 8 ++++++--
>>>  1 file changed, 6 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_internal.h
>>> index 17cdc3080d58..e8971842b124 100644
>>> --- a/drivers/resctrl/mpam_internal.h
>>> +++ b/drivers/resctrl/mpam_internal.h
>>> @@ -200,8 +200,12 @@ struct mpam_props {
>>>  } PACKED_FOR_KUNIT;
>>>  
>>>  #define mpam_has_feature(_feat, x)	test_bit(_feat, (x)->features)
>>> -#define mpam_set_feature(_feat, x)	set_bit(_feat, (x)->features)
>>> -#define mpam_clear_feature(_feat, x)	clear_bit(_feat, (x)->features)
>>> +/*
>>> + * The non-atomic get/set operations are used because if struct mpam_props is
>>> + * packed, the alignment requirements for atomics aren't met.
>>> + */
>>> +#define mpam_set_feature(_feat, x)	__set_bit(_feat, (x)->features)
>>> +#define mpam_clear_feature(_feat, x)	__clear_bit(_feat, (x)->features)
>>
>> After discussing privately, I can see how test__props_mismatch() can
>> end up with unaligned atomics on the mmap_props::features array. Happy to
>> pick it up for 6.19 (probably the first patch as well, though that's
>> harmless).
> 
> Yes please.
> 
>>
>> Is there a Fixes tag here for future reference?
>>
> 
> Yes, the mpam_set/clear macros were introduced in

The mpam_set_clear() actually comes after in:
c10ca83a7783 arm_mpam: Merge supported features during mpam_enable() into mpam_class
but I think the fixes below is still the correct one as it is where we could 
first start seeing the problem.
> 
> Fixes: 8c90dc68a5de ("arm_mpam: Probe the hardware features resctrl supports")
> 
> Thanks,
> 
> Ben
> 
> 
 
Thanks,

Ben
Re: [PATCH v3 02/47] arm_mpam: Use non-atomic bitops when modifying feature bitmap
Posted by Catalin Marinas 3 weeks, 3 days ago
On Fri, Jan 16, 2026 at 12:12:53PM +0000, Ben Horgan wrote:
> On 1/16/26 12:02, Ben Horgan wrote:
> > On 1/16/26 11:57, Catalin Marinas wrote:
> >> On Mon, Jan 12, 2026 at 04:58:29PM +0000, Ben Horgan wrote:
> >>> In the test__props_mismatch() kunit test we rely on the struct mpam_props
> >>> being packed to ensure memcmp doesn't consider packing. Making it packed
> >>> reduces the alignment of the features bitmap and so breaks a requirement
> >>> for the use of atomics. As we don't rely on the set/clear of these bits
> >>> being atomic, just make them non-atomic.
> >>>
> >>> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
> >>> Signed-off-by: Ben Horgan <ben.horgan@arm.com>
> >>> ---
> >>> Changes since v2:
> >>> Add comment (Jonathan)
> >>> ---
> >>>  drivers/resctrl/mpam_internal.h | 8 ++++++--
> >>>  1 file changed, 6 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_internal.h
> >>> index 17cdc3080d58..e8971842b124 100644
> >>> --- a/drivers/resctrl/mpam_internal.h
> >>> +++ b/drivers/resctrl/mpam_internal.h
> >>> @@ -200,8 +200,12 @@ struct mpam_props {
> >>>  } PACKED_FOR_KUNIT;
> >>>  
> >>>  #define mpam_has_feature(_feat, x)	test_bit(_feat, (x)->features)
> >>> -#define mpam_set_feature(_feat, x)	set_bit(_feat, (x)->features)
> >>> -#define mpam_clear_feature(_feat, x)	clear_bit(_feat, (x)->features)
> >>> +/*
> >>> + * The non-atomic get/set operations are used because if struct mpam_props is
> >>> + * packed, the alignment requirements for atomics aren't met.
> >>> + */
> >>> +#define mpam_set_feature(_feat, x)	__set_bit(_feat, (x)->features)
> >>> +#define mpam_clear_feature(_feat, x)	__clear_bit(_feat, (x)->features)
> >>
> >> After discussing privately, I can see how test__props_mismatch() can
> >> end up with unaligned atomics on the mmap_props::features array. Happy to
> >> pick it up for 6.19 (probably the first patch as well, though that's
> >> harmless).
> > 
> > Yes please.
> > 
> >>
> >> Is there a Fixes tag here for future reference?
> >>
> > 
> > Yes, the mpam_set/clear macros were introduced in
> 
> The mpam_set_clear() actually comes after in:
> c10ca83a7783 arm_mpam: Merge supported features during mpam_enable() into mpam_class
> but I think the fixes below is still the correct one as it is where we could 
> first start seeing the problem.
> > 
> > Fixes: 8c90dc68a5de ("arm_mpam: Probe the hardware features resctrl supports")

Yes, I left the original as that's the one first introducing the atomic
bitops on this structure.

-- 
Catalin
Re: [PATCH v3 02/47] arm_mpam: Use non-atomic bitops when modifying feature bitmap
Posted by Gavin Shan 3 weeks, 4 days ago
On 1/13/26 12:58 AM, Ben Horgan wrote:
> In the test__props_mismatch() kunit test we rely on the struct mpam_props
> being packed to ensure memcmp doesn't consider packing. Making it packed
> reduces the alignment of the features bitmap and so breaks a requirement
> for the use of atomics. As we don't rely on the set/clear of these bits
> being atomic, just make them non-atomic.
> 
> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
> Signed-off-by: Ben Horgan <ben.horgan@arm.com>
> ---
> Changes since v2:
> Add comment (Jonathan)
> ---
>   drivers/resctrl/mpam_internal.h | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
> 

Reviewed-by: Gavin Shan <gshan@redhat.com>