Re: [PATCH v8 08/32] x86/resctrl: Clean up domain_remove_cpu_ctrl()

From: Reinette Chatre
Date: Thu Aug 14 2025 - 00:00:05 EST


Hi Tony,

On 8/11/25 11:16 AM, Tony Luck wrote:
> For symmetry with domain_remove_cpu_mon() refactor to take an
> early return when removing a CPU does not empty the domain.

"refactor" -> "refactor domain_remove_cpu_ctrl()"
so that changelog stands on its own and is not continuation of subject.

>
> Signed-off-by: Tony Luck <tony.luck@xxxxxxxxx>
> ---
> arch/x86/kernel/cpu/resctrl/core.c | 29 ++++++++++++++---------------
> 1 file changed, 14 insertions(+), 15 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
> index 448c2bf9837d..911100994fcd 100644
> --- a/arch/x86/kernel/cpu/resctrl/core.c
> +++ b/arch/x86/kernel/cpu/resctrl/core.c
> @@ -603,25 +603,24 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_resource *r)
> if (!domain_header_is_valid(hdr, RESCTRL_CTRL_DOMAIN, r->rid))
> return;
>
> + cpumask_clear_cpu(cpu, &hdr->cpu_mask);
> + if (!cpumask_empty(&hdr->cpu_mask))
> + return;
> +

Here is another instance where the domain_header_is_valid() checking is
moved away from the subsequent container_of() that it is intended to protect.

> d = container_of(hdr, struct rdt_ctrl_domain, hdr);
> hw_dom = resctrl_to_arch_ctrl_dom(d);
>
> - cpumask_clear_cpu(cpu, &d->hdr.cpu_mask);
> - if (cpumask_empty(&d->hdr.cpu_mask)) {
> - resctrl_offline_ctrl_domain(r, d);
> - list_del_rcu(&d->hdr.list);
> - synchronize_rcu();
> -
> - /*
> - * rdt_ctrl_domain "d" is going to be freed below, so clear
> - * its pointer from pseudo_lock_region struct.
> - */
> - if (d->plr)
> - d->plr->d = NULL;
> - ctrl_domain_free(hw_dom);
> + resctrl_offline_ctrl_domain(r, d);
> + list_del_rcu(&d->hdr.list);

Missing the change mentioned in cover letter.

> + synchronize_rcu();
>
> - return;
> - }
> + /*
> + * rdt_ctrl_domain "d" is going to be freed below, so clear
> + * its pointer from pseudo_lock_region struct.
> + */
> + if (d->plr)
> + d->plr->d = NULL;
> + ctrl_domain_free(hw_dom);
> }
>
> static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r)

Reinette