Re: [PATCH v6 05/30] x86,fs/resctrl: Improve domain type checking

From: Reinette Chatre
Date: Tue Jul 08 2025 - 17:02:59 EST


Hi Tony,

On 6/26/25 9:49 AM, Tony Luck wrote:
> The rdt_domain_hdr structure is used in both control and monitor
> domain structures to provide common methods for operations such as
> adding a CPU to a domain, removing a CPU from a domain, accessing
> the mask of all CPUs in a domain.
>
> The "type" field provides a simple check whether a domain is a
> control or monitor domain so that programming errors operating
> on domains will be quickly caught.
>
> To prepare for additional domain types that depend on the rdt_resource
> to which they are connected add the resource id into the header
> and check that in addition to the type.
>
> At this point all monitoring events are tied to the RDT_RESOURCE_L3
> resource. So hard code the check in rdtgroup_mondata_show() to
> that resource id.

Comment about this hardcoding below ...

>
> Signed-off-by: Tony Luck <tony.luck@xxxxxxxxx>
> ---
> include/linux/resctrl.h | 9 +++++++++
> arch/x86/kernel/cpu/resctrl/core.c | 10 ++++++----
> fs/resctrl/ctrlmondata.c | 2 +-
> 3 files changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
> index 478d7a935ca3..dc7ccd60e8c2 100644
> --- a/include/linux/resctrl.h
> +++ b/include/linux/resctrl.h
> @@ -131,15 +131,24 @@ enum resctrl_domain_type {
> * @list: all instances of this resource
> * @id: unique id for this instance
> * @type: type of this instance
> + * @rid: index of resource for this domain

Similar comment as in patch #1 about use of "index" in resctrl fs.

> * @cpu_mask: which CPUs share this resource
> */
> struct rdt_domain_hdr {
> struct list_head list;
> int id;
> enum resctrl_domain_type type;
> + enum resctrl_res_level rid;
> struct cpumask cpu_mask;
> };
>

...

> diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c
> index ad7ffc6acf13..cdb4bc8baa99 100644
> --- a/fs/resctrl/ctrlmondata.c
> +++ b/fs/resctrl/ctrlmondata.c
> @@ -643,7 +643,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
> * the resource to find the domain with "domid".
> */
> hdr = resctrl_find_domain(&r->mon_domains, domid, NULL);
> - if (!hdr || WARN_ON_ONCE(hdr->type != RESCTRL_MON_DOMAIN)) {
> + if (!hdr || !domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3)) {
> ret = -ENOENT;
> goto out;
> }

I do not see why this hardcoding is required since the resource ID is available via the
struct mon_data associated with the file. Looks like this is undone in patch #9 anyway
so the explicit handling by this patch is unclear.

Reinette