[PATCH v3 2/8] arm_mpam: resctrl: Use find_component() when allocating a domain

From: Reinette Chatre

Date: Mon Nov 09 2026 - 23:25:30 EST


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. However, the SRCU
read lock is only needed while walking the component list, and
find_component() holds it for that walk.

Replace the open-coded walk with find_component().

Signed-off-by: Reinette Chatre <reinette.chatre@xxxxxxxxx>
Tested-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
Reviewed-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
---
Changes since RFC v2:
- Add Jinjie's Reviewed-by tag.
- Add Jinjie's Tested-by tag.
- Shorten changelog. (Ben)
---
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 1b1e724ae040..a75f653031fd 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -1648,21 +1648,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);
--
2.56.0