Re: [PATCH v8 02/21] x86/resctrl: Remove the limit on the number of CLOSID
From: James Morse
Date: Thu Apr 24 2025 - 05:13:01 EST
Hello!
On 11/04/2025 17:42, James Morse wrote:
> From: Amit Singh Tomar <amitsinght@xxxxxxxxxxx>
>
> Resctrl allocates and finds free CLOSID values using the bits of a u32.
> This restricts the number of control groups that can be created by
> user-space.
>
> MPAM has an architectural limit of 2^16 CLOSID values, Intel x86 could
> be extended beyond 32 values. There is at least one MPAM platform which
> supports more than 32 CLOSID values.
>
> Replace the fixed size bitmap with calls to the bitmap API to allocate
> an array of a sufficient size.
>
> ffs() returns '1' for bit 0, hence the existing code subtracts 1 from
> the index to get the CLOSID value. find_first_bit() returns the bit
> number which does not need adjusting.
> diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> index 776c8e347654..4e0308040c6e 100644
> --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> @@ -152,20 +152,31 @@ int closids_supported(void)
> return closid_free_map_len;
> }
>
> -static void closid_init(void)
> +static int closid_init(void)
> {
> struct resctrl_schema *s;
> - u32 rdt_min_closid = 32;
> + u32 rdt_min_closid = ~0;
>
> /* Compute rdt_min_closid across all resources */
> list_for_each_entry(s, &resctrl_schema_all, list)
> rdt_min_closid = min(rdt_min_closid, s->num_closid);
Platforms that don't have any controls - only monitors - will still call closid_init().
Previously this initialised the fixed-sized bitmap, which was harmless as helpers like
closid_alloc() are never called.
With this change, rdt_min_closid keeps its dummy initialisation value of ~0, meaning this:
> - closid_free_map = BIT_MASK(rdt_min_closid) - 1;
> + closid_free_map = bitmap_alloc(rdt_min_closid, GFP_KERNEL);
Blows up with a greater than 'max order' error.
I've added a list_empty() check to the top of the function:
| /* Monitor only platforms still call closid_init() */
| if (list_empty(&resctrl_schema_all))
| return 0;
(list-empty as its clearer what goes wrong without the check).
I reckon this is minor, so I'll keep the existing tags.
I'm not aware of anyone building a monitor-only MPAM platform - I configured one by
accident with one of the software models!
Thanks,
James