[RFC PATCH v2 01/10] arm_mpam: resctrl: Use find_component() when allocating a domain
Ben Horgan
ben.horgan at arm.com
Tue Nov 3 07:01:30 PST 2026
Hi Reinette,
The change seems good but I think the commit message can be cut down at bit.
On 19/10/2026 23:07, Reinette Chatre wrote:
> mpam_resctrl_alloc_domain() starts by checking that the resource's
> class has a component whose CPU affinity includes the CPU, and fails the
> domain allocation otherwise. When the resource supports allocation, that
> component also backs the control domain. The check uses an open-coded
> walk of the class's component list, while the same function uses
> find_component() to find the component backing each monitoring event.
>
> The open-coded walk duplicates find_component(). It also holds the SRCU
> read lock until mpam_resctrl_alloc_domain() returns,
, -> .
which suggests that
> the component needs this protection while the domain is set up.
>
> The component does not need it. Components are freed only when an MSC
> fails to probe, in which case MPAM is never enabled and no resctrl
> domain is created, or by mpam_disable(), which first removes the CPU
> hotplug callbacks and thereby tears down all resctrl domains. A component> therefore outlives every domain that refers to it.
You can drop the above section. The SRCU read lock, as you say, is just
intended for walking the list and modulo any bugs we can just take that
as read.
However, ...> The SRCU read lock is
> only needed while walking the component list, and find_component() holds
> it for that walk.
In addition, mpam_resctrl_alloc_domain() only runs
> from MPAM's CPU hotplug startup callback, which already holds the SRCU
> read lock throughout.
I think this can go from the commit message too. It is interesting that
you point it out though as that is unexpected. I should have used
scoped_guard() in the case you are removing and in mpam_cpu_online()
rather than guard() so that the lock can be dropped as early as possible
and make the intent of the lock clearer.
Thanks,
Ben
>
> Replace the open-coded walk with find_component().
>
> Signed-off-by: Reinette Chatre <reinette.chatre at intel.com>
> ---
> drivers/resctrl/mpam_resctrl.c | 13 ++-----------
> 1 file changed, 2 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
> index 9cec5843e8fa..3d5f90f9f1f3 100644
> --- a/drivers/resctrl/mpam_resctrl.c
> +++ b/drivers/resctrl/mpam_resctrl.c
> @@ -1623,21 +1623,12 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
> struct rdt_l3_mon_domain *mon_d;
> struct rdt_ctrl_domain *ctrl_d;
> struct mpam_class *class = res->class;
> - struct mpam_component *comp_iter, *ctrl_comp;
> + struct mpam_component *ctrl_comp;
> struct rdt_resource *r = &res->resctrl_res;
>
> lockdep_assert_held(&domain_list_lock);
>
> - ctrl_comp = NULL;
> - guard(srcu)(&mpam_srcu);
> - list_for_each_entry_srcu(comp_iter, &class->components, class_list,
> - srcu_read_lock_held(&mpam_srcu)) {
> - if (cpumask_test_cpu(cpu, &comp_iter->affinity)) {
> - ctrl_comp = comp_iter;
> - break;
> - }
> - }
> -
> + ctrl_comp = find_component(class, cpu);
> /* class has no component for this CPU */
> if (WARN_ON_ONCE(!ctrl_comp))
> return ERR_PTR(-EINVAL);
More information about the linux-arm-kernel
mailing list