Skip to contentSkip to conversation

arm_mpam: resctrl: Separate MPAM domains

RFC PATCH Superseded Reinette Chatre 4 participants 40 messages Oct 19 – Nov 4 MPAM driver

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Reinette Chatre

author reviewer
#0 lore raw

v2 cover arm_mpam: resctrl: Separate MPAM domains

RFC v1: https://lore.kernel.org/lkml/85ca29e89eacf12cfa7071249419e7cadb8f0691.1788220029.git.reinette.chatre@intel.com/

The MPAM driver represents a resctrl domain with a single structure, struct mpam_resctrl_dom, that holds both a control domain and a monitoring domain. On a system that supports both allocation and monitoring, one instance is created for each domain and its two domains are added to the resource's control and monitoring domain lists.

Holding both domains in one structure requires control and monitoring to be done at the same scope, and ties each control domain to a monitoring domain. This does not fit the proposed support for multiple controls per resource [1]. There, each control of a resource, for example a "min" and a "max" memory bandwidth control, has its own list of control domains while the resource keeps a single list of monitoring domains. With one structure for both, every control domain would come with a monitoring domain of its own, which does not reflect the resource.

This series gives control and monitoring domains their own structures, set up and torn down independently as CPUs come online and go offline, in preparation for supporting multiple controls per resource. Along the way it stops failing CPU online when a domain cannot be set up, and adds checks when setting up a monitoring domain.

  1-2   Preparatory cleanups of domain allocation
  3     Do not fail CPU online when domain setup fails
  4-6   Separate the control and monitoring domain structures
  7-9   Checks when setting up a monitoring domain
  10    Comment update, kept separate for review

An earlier version of the domain split was posted on its own [2]. This version incorporates the feedback from that discussion. It gives each type of domain its own structure instead of duplicating the shared one, sets up each domain independently instead of undoing one domain when setting up the other fails, and adds the checks in patches 8 and 9.

Patch 7 turns a WARN_ON_ONCE(0) into a warning that fires. It is a separate patch because it is not clear whether the silent failure was intended. If it was, the patch can instead drop the dead WARN_ON_ONCE().

This is an RFC because I am only able to compile test MPAM changes, which is also why the patches are small and each change is justified on its own. Patches can be squashed if preferred, for example patch 10 into patches 5 and 9. Testing on MPAM hardware would be greatly appreciated, as is any other feedback.

The series is based on the for-next/mpam branch of the arm64 tree:
git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/85ca29e89eacf12cfa7071249419e7cadb8f0691.1788220029.git.reinette.chatre@intel.com/

Reinette Chatre (10):
arm_mpam: resctrl: Use find_component() when allocating a domain
arm_mpam: resctrl: Rename ctrl_comp in mpam_resctrl_alloc_domain()
arm_mpam: resctrl: Do not fail CPU online when domain setup fails
arm_mpam: resctrl: Split control and monitoring domain setup into
helpers
arm_mpam: resctrl: Give the monitoring domain its own structure
arm_mpam: resctrl: Rename struct mpam_resctrl_dom to
mpam_resctrl_ctrl_dom
arm_mpam: resctrl: Warn when no monitoring component is found for a
CPU
arm_mpam: resctrl: Require a component for each monitoring event
arm_mpam: resctrl: Require monitoring components to cover the same
CPUs
arm_mpam: resctrl: Update the comment on monitoring domain setup

 drivers/resctrl/mpam_devices.c  |   2 +-
 drivers/resctrl/mpam_internal.h |  11 +-
 drivers/resctrl/mpam_resctrl.c  | 325 +++++++++++++++++---------------
 3 files changed, 181 insertions(+), 157 deletions(-)

base-commit: 8ea457f746d915d55f78b43d33b1cd618f3d93ad

Signature · 1 line
2.55.0
author reviewer
#1 lore raw

RFC PATCH v2 1/10 arm_mpam: resctrl: Use find_component() when allocating a domain

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. 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.

Replace the open-coded walk with find_component().

---
 drivers/resctrl/mpam_resctrl.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/resctrl/mpam_resctrl.c +2 -11
index 9cec5843e8fa..3d5f90f9f1f3 100644
@@ -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);
Signature · 1 line
2.55.0
Reviewed-by on v2 1/10
#2 lore raw

Re: [RFC PATCH v2 01/10] arm_mpam: resctrl: Use find_component() when allocating a domain

Quoted 41 lines · Reinette Chatre

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. 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.

Replace the open-coded walk with find_component().

---
 drivers/resctrl/mpam_resctrl.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/resctrl/mpam_resctrl.c +1 -1
index 9cec5843e8fa..3d5f90f9f1f3 100644
@@ -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);

drivers/resctrl/mpam_resctrl.c mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res) · line 1639

Quoted 10 lines
drivers/resctrl/mpam_resctrl.c +0 -9
 
-	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;
-		}
-	}

LGTM

Quoted 5 lines
drivers/resctrl/mpam_resctrl.c +1 -1
-
+	ctrl_comp = find_component(class, cpu);
 	/* class has no component for this CPU */
 	if (WARN_ON_ONCE(!ctrl_comp))
 		return ERR_PTR(-EINVAL);
Signature · 2 lines
Best regards,
Jinjie
Reviewed-by on v2 1/10
#3 lore raw

Re: [RFC PATCH v2 01/10] arm_mpam: resctrl: Use find_component() when allocating a domain

In reply to Reinette Chatre
Quoted 41 lines · Reinette Chatre

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. 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.

Replace the open-coded walk with find_component().

---
 drivers/resctrl/mpam_resctrl.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/resctrl/mpam_resctrl.c +1 -1
index 9cec5843e8fa..3d5f90f9f1f3 100644
@@ -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);

drivers/resctrl/mpam_resctrl.c mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res) · line 1639

Quoted 10 lines
drivers/resctrl/mpam_resctrl.c +0 -9
 
-	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;
-		}
-	}

LGTM

Quoted 5 lines
drivers/resctrl/mpam_resctrl.c +1 -1
-
+	ctrl_comp = find_component(class, cpu);
 	/* class has no component for this CPU */
 	if (WARN_ON_ONCE(!ctrl_comp))
 		return ERR_PTR(-EINVAL);
Signature · 2 lines
Best regards,
Jinjie
author reviewer
#4 lore raw

Re: [RFC PATCH v2 01/10] arm_mpam: resctrl: Use find_component() when allocating a domain

Quoted 56 lines · Jinjie Ruan
Quoted 41 lines · Reinette Chatre

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. 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.

Replace the open-coded walk with find_component().

---
 drivers/resctrl/mpam_resctrl.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/resctrl/mpam_resctrl.c +1 -1
index 9cec5843e8fa..3d5f90f9f1f3 100644
@@ -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);

drivers/resctrl/mpam_resctrl.c mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res) · line 1639

Quoted 10 lines
drivers/resctrl/mpam_resctrl.c +0 -9
 
-	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;
-		}
-	}

LGTM

Quoted 2 lines

Thank you very much for taking a look at this series.

Reinette

maintainer
#5 lore raw

Re: [RFC PATCH v2 01/10] arm_mpam: resctrl: Use find_component() when allocating a domain

In reply to Reinette Chatre

Hi Reinette,

The change seems good but I think the commit message can be cut down at bit.

Quoted 9 lines · Reinette Chatre

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

Quoted 6 lines

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

Quoted 2 lines

only needed while walking the component list, and find_component() holds it for that walk.

In addition, mpam_resctrl_alloc_domain() only runs

Quoted 2 lines

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

Quoted 36 lines

Replace the open-coded walk with find_component().

---
 drivers/resctrl/mpam_resctrl.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/resctrl/mpam_resctrl.c +2 -11
index 9cec5843e8fa..3d5f90f9f1f3 100644
@@ -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);
author reviewer
#7 lore raw

Re: [RFC PATCH v2 01/10] arm_mpam: resctrl: Use find_component() when allocating a domain

Hi Ben,

Quoted 4 lines · Ben Horgan
Quoted 3 lines · Ben Horgan

Hi Reinette,

The change seems good but I think the commit message can be cut down at bit.

Thank you very much for taking a look and providing the needed changes. Since I am unable to test and especially since this involved a locking change I ended up with changelogs containing more than the usual reasoning about correctness.

Quoted 3 lines

It looks like this patch also has the plus of addressing this sashiko report:
https://sashiko.dev/#/bug/linux-9a564d61-b4d8-400d-b4b9-cd5f20729468

oh. Would you like this commit to capture this? To do so I can add the following tags:

Fixes 09e61daf8e96 ("arm_mpam: resctrl: Add boilerplate cpuhp and domain allocation")

Reinette

maintainer
#8 lore raw

Re: [RFC PATCH v2 01/10] arm_mpam: resctrl: Use find_component() when allocating a domain

Hi Reinette,

Quoted 6 lines · Reinette Chatre

Hi Ben,

Quoted 3 lines · Ben Horgan
Quoted 2 lines · Ben Horgan

Hi Reinette,

Quoted 8 lines
Quoted 1 line
Quoted 1 line

The change seems good but I think the commit message can be cut down at bit.

Thank you very much for taking a look and providing the needed changes. Since I
am unable to test and especially since this involved a locking change I ended up
with changelogs containing more than the usual reasoning about correctness.> >> It looks like this patch also has the plus of addressing this sashiko

Quoted 2 lines

report:
https://sashiko.dev/#/bug/linux-9a564d61-b4d8-400d-b4b9-cd5f20729468

oh. Would you like this commit to capture this? To do so I can add the following tags:

I don't think it counts as a real bug as its only going against the cleanup.h guidance and making the code fragile rather than actually breaking anything. Good to fix though.

Thanks,

Ben

Quoted 8 lines
Fixes 09e61daf8e96 ("arm_mpam: resctrl: Add boilerplate cpuhp and domain allocation")
Quoted 1 line

Reinette

author reviewer
#9 lore raw

RFC PATCH v2 2/10 arm_mpam: resctrl: Rename ctrl_comp in mpam_resctrl_alloc_domain()

In reply to Reinette Chatre

mpam_resctrl_alloc_domain() looks up the component of the resource's class that contains the CPU and fails the domain allocation if there is none. The component is held in a local variable named ctrl_comp and, when the resource supports allocation, it also backs the control domain.

The lookup and its check apply to every resource, including one that supports only monitoring. For such a resource the component does not back a control domain, so the name ctrl_comp is misleading. The name also makes a comment in the same function ambiguous. The comment notes that there may be no ctrl_comp for the L3, which is true of the control domain's component but contradicts the local variable, which always refers to a component once the lookup succeeds.

Rename the local variable to comp. Keep the ctrl_comp name for the control domain's reference to its component because it only ever refers to the component that backs the control domain. Leave the comment unchanged since it now unambiguously refers to that component.

No functional change.

---
 drivers/resctrl/mpam_resctrl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/resctrl/mpam_resctrl.c +5 -5
index 3d5f90f9f1f3..b07e5dd895dd 100644
@@ -1623,14 +1623,14 @@ 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 *ctrl_comp;
+	struct mpam_component *comp;
 	struct rdt_resource *r = &res->resctrl_res;
 
 	lockdep_assert_held(&domain_list_lock);
 
-	ctrl_comp = find_component(class, cpu);
+	comp = find_component(class, cpu);
 	/* class has no component for this CPU */
-	if (WARN_ON_ONCE(!ctrl_comp))
+	if (WARN_ON_ONCE(!comp))
 		return ERR_PTR(-EINVAL);
 
 	dom = kzalloc_node(sizeof(*dom), GFP_KERNEL, cpu_to_node(cpu));
@@ -1638,10 +1638,10 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 		return ERR_PTR(-ENOMEM);
 
 	if (r->alloc_capable) {
-		dom->ctrl_comp = ctrl_comp;
+		dom->ctrl_comp = comp;
 
 		ctrl_d = &dom->resctrl_ctrl_dom;
-		mpam_resctrl_domain_hdr_init(cpu, ctrl_comp, r->rid, &ctrl_d->hdr);
+		mpam_resctrl_domain_hdr_init(cpu, comp, r->rid, &ctrl_d->hdr);
 		ctrl_d->hdr.type = RESCTRL_CTRL_DOMAIN;
 		err = resctrl_online_ctrl_domain(r, ctrl_d);
 		if (err)
Signature · 1 line
2.55.0
Reviewed-by on v2 2/10
#10 lore raw

Re: [RFC PATCH v2 02/10] arm_mpam: resctrl: Rename ctrl_comp in mpam_resctrl_alloc_domain()

Quoted 30 lines · Reinette Chatre

mpam_resctrl_alloc_domain() looks up the component of the resource's class that contains the CPU and fails the domain allocation if there is none. The component is held in a local variable named ctrl_comp and, when the resource supports allocation, it also backs the control domain.

The lookup and its check apply to every resource, including one that supports only monitoring. For such a resource the component does not back a control domain, so the name ctrl_comp is misleading. The name also makes a comment in the same function ambiguous. The comment notes that there may be no ctrl_comp for the L3, which is true of the control domain's component but contradicts the local variable, which always refers to a component once the lookup succeeds.

Rename the local variable to comp. Keep the ctrl_comp name for the control domain's reference to its component because it only ever refers to the component that backs the control domain. Leave the comment unchanged since it now unambiguously refers to that component.

No functional change.

---
 drivers/resctrl/mpam_resctrl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/resctrl/mpam_resctrl.c +0 -0
index 3d5f90f9f1f3..b07e5dd895dd 100644

drivers/resctrl/mpam_resctrl.c mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res) · line 1627

Quoted 6 lines
drivers/resctrl/mpam_resctrl.c +1 -1
@@ -1623,14 +1623,14 @@ 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 *ctrl_comp;
+	struct mpam_component *comp;
 	struct rdt_resource *r = &res->resctrl_res;
Quoted 24 lines
drivers/resctrl/mpam_resctrl.c +4 -4
 	lockdep_assert_held(&domain_list_lock);
 
-	ctrl_comp = find_component(class, cpu);
+	comp = find_component(class, cpu);
 	/* class has no component for this CPU */
-	if (WARN_ON_ONCE(!ctrl_comp))
+	if (WARN_ON_ONCE(!comp))
 		return ERR_PTR(-EINVAL);
 
 	dom = kzalloc_node(sizeof(*dom), GFP_KERNEL, cpu_to_node(cpu));
@@ -1638,10 +1638,10 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 		return ERR_PTR(-ENOMEM);
 
 	if (r->alloc_capable) {
-		dom->ctrl_comp = ctrl_comp;
+		dom->ctrl_comp = comp;
 
 		ctrl_d = &dom->resctrl_ctrl_dom;
-		mpam_resctrl_domain_hdr_init(cpu, ctrl_comp, r->rid, &ctrl_d->hdr);
+		mpam_resctrl_domain_hdr_init(cpu, comp, r->rid, &ctrl_d->hdr);
 		ctrl_d->hdr.type = RESCTRL_CTRL_DOMAIN;
 		err = resctrl_online_ctrl_domain(r, ctrl_d);
 		if (err)
Signature · 2 lines
Best regards,
Jinjie
author reviewer
#11 lore raw

Re: [RFC PATCH v2 02/10] arm_mpam: resctrl: Rename ctrl_comp in mpam_resctrl_alloc_domain()

Quoted 28 lines · Jinjie Ruan
Quoted 25 lines · Reinette Chatre

mpam_resctrl_alloc_domain() looks up the component of the resource's class that contains the CPU and fails the domain allocation if there is none. The component is held in a local variable named ctrl_comp and, when the resource supports allocation, it also backs the control domain.

The lookup and its check apply to every resource, including one that supports only monitoring. For such a resource the component does not back a control domain, so the name ctrl_comp is misleading. The name also makes a comment in the same function ambiguous. The comment notes that there may be no ctrl_comp for the L3, which is true of the control domain's component but contradicts the local variable, which always refers to a component once the lookup succeeds.

Rename the local variable to comp. Keep the ctrl_comp name for the control domain's reference to its component because it only ever refers to the component that backs the control domain. Leave the comment unchanged since it now unambiguously refers to that component.

No functional change.

---
 drivers/resctrl/mpam_resctrl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 14 lines

drivers/resctrl/mpam_resctrl.c mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res) · line 1627

Quoted 11 lines
drivers/resctrl/mpam_resctrl.c +1 -1
index 3d5f90f9f1f3..b07e5dd895dd 100644
@@ -1623,14 +1623,14 @@ 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 *ctrl_comp;
+	struct mpam_component *comp;
 	struct rdt_resource *r = &res->resctrl_res;

Thank you very much.

Reinette

maintainer Reviewed-by on v2 2/10
#12 lore raw

Re: [RFC PATCH v2 02/10] arm_mpam: resctrl: Rename ctrl_comp in mpam_resctrl_alloc_domain()

In reply to Reinette Chatre

Hi Reinette,

Quoted 13 lines · Reinette Chatre

mpam_resctrl_alloc_domain() looks up the component of the resource's class that contains the CPU and fails the domain allocation if there is none. The component is held in a local variable named ctrl_comp and, when the resource supports allocation, it also backs the control domain.

The lookup and its check apply to every resource, including one that supports only monitoring. For such a resource the component does not back a control domain, so the name ctrl_comp is misleading. The name also makes a comment in the same function ambiguous. The comment notes that there may be no ctrl_comp for the L3, which is true of the control domain's component but contradicts the local variable, which always refers to a component once the lookup succeeds.

Quoted 8 lines

Rename the local variable to comp. Keep the ctrl_comp name for the control domain's reference to its component because it only ever refers to the component that backs the control domain. Leave the comment unchanged since it now unambiguously refers to that component.

No functional change.

Makes sense.

Quoted 39 lines
---
 drivers/resctrl/mpam_resctrl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/resctrl/mpam_resctrl.c +5 -5
index 3d5f90f9f1f3..b07e5dd895dd 100644
@@ -1623,14 +1623,14 @@ 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 *ctrl_comp;
+	struct mpam_component *comp;
 	struct rdt_resource *r = &res->resctrl_res;
 
 	lockdep_assert_held(&domain_list_lock);
 
-	ctrl_comp = find_component(class, cpu);
+	comp = find_component(class, cpu);
 	/* class has no component for this CPU */
-	if (WARN_ON_ONCE(!ctrl_comp))
+	if (WARN_ON_ONCE(!comp))
 		return ERR_PTR(-EINVAL);
 
 	dom = kzalloc_node(sizeof(*dom), GFP_KERNEL, cpu_to_node(cpu));
@@ -1638,10 +1638,10 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 		return ERR_PTR(-ENOMEM);
 
 	if (r->alloc_capable) {
-		dom->ctrl_comp = ctrl_comp;
+		dom->ctrl_comp = comp;
 
 		ctrl_d = &dom->resctrl_ctrl_dom;
-		mpam_resctrl_domain_hdr_init(cpu, ctrl_comp, r->rid, &ctrl_d->hdr);
+		mpam_resctrl_domain_hdr_init(cpu, comp, r->rid, &ctrl_d->hdr);
 		ctrl_d->hdr.type = RESCTRL_CTRL_DOMAIN;
 		err = resctrl_online_ctrl_domain(r, ctrl_d);
 		if (err)
author reviewer
#13 lore raw

RFC PATCH v2 3/10 arm_mpam: resctrl: Do not fail CPU online when domain setup fails

In reply to Reinette Chatre

When a CPU comes online, mpam_resctrl_online_cpu() adds it to the resctrl domains of each resource in use, and sets up a new domain when the CPU is the first of its domain to come online. A failure to set up a domain is returned as the failure of MPAM's CPU hotplug startup callback.

The CPU hotplug core does not run the teardown callback for a CPU whose startup callback failed, so everything done for the CPU before the failure stays in place: the CPU remains in the domains of the resources that were handled before the failing one, and MPAM's per-MSC state for the CPU is not undone. If the failure happens when MPAM installs its CPU hotplug callbacks during enabling, the hotplug core discards the callbacks, leaving MPAM enabled and resctrl initialized but MPAM no longer notified of CPU hotplug. If it happens when a CPU comes online later, the CPU fails to come online.

Setting up a domain only fails if a memory allocation fails or if a class unexpectedly has no component for the CPU. For such rare failures losing a resctrl domain is a smaller cost than failing CPU online or leaving MPAM in an inconsistent state.

Do not report domain setup failures from mpam_resctrl_online_cpu() and leave the CPU without a domain for that resource. Make mpam_resctrl_alloc_domain() return nothing since its failures are no longer reported. Keep adding the CPU to resctrl's default group even when a domain could not be set up, since the CPU is online and runs tasks regardless, and resctrl expects every online CPU to belong to a resource group. Drop the warning when a CPU going offline has no domain, since a missing domain is now expected.

Only domains that were set up are exposed through resctrl and torn down when their CPUs go offline. When another CPU of the same domain comes online, it sets up the domain again, and if that succeeds the domain does not include the CPU for which setup failed.

---
 drivers/resctrl/mpam_devices.c  |  2 +-
 drivers/resctrl/mpam_internal.h |  4 ++--
 drivers/resctrl/mpam_resctrl.c  | 31 +++++++++++++++----------------
 3 files changed, 18 insertions(+), 19 deletions(-)
drivers/resctrl/mpam_devices.c +1 -1
index 48adc49b833c..d17d7a72dba1 100644
@@ -2249,7 +2249,7 @@ static int mpam_cpu_online(unsigned int cpu)
 	}
 
 	if (mpam_resctrl_enabled)
-		return mpam_resctrl_online_cpu(cpu);
+		mpam_resctrl_online_cpu(cpu);
 
 	return 0;
 }
drivers/resctrl/mpam_internal.h +2 -2
index 1f86cc158100..84c7adbb1a40 100644
@@ -525,13 +525,13 @@ int mpam_get_cpumask_from_cache_id(unsigned long cache_id, u32 cache_level,
 #ifdef CONFIG_RESCTRL_FS
 int mpam_resctrl_setup(void);
 void mpam_resctrl_exit(void);
-int mpam_resctrl_online_cpu(unsigned int cpu);
+void mpam_resctrl_online_cpu(unsigned int cpu);
 void mpam_resctrl_offline_cpu(unsigned int cpu);
 void mpam_resctrl_teardown_class(struct mpam_class *class);
 #else
 static inline int mpam_resctrl_setup(void) { return 0; }
 static inline void mpam_resctrl_exit(void) { }
-static inline int mpam_resctrl_online_cpu(unsigned int cpu) { return 0; }
+static inline void mpam_resctrl_online_cpu(unsigned int cpu) { }
 static inline void mpam_resctrl_offline_cpu(unsigned int cpu) { }
 static inline void mpam_resctrl_teardown_class(struct mpam_class *class) { }
 #endif /* CONFIG_RESCTRL_FS */
drivers/resctrl/mpam_resctrl.c +15 -16
index b07e5dd895dd..dc442851fd7e 100644
@@ -1615,8 +1615,8 @@ static struct mpam_component *find_component(struct mpam_class *class, int cpu)
 	return NULL;
 }
 
-static struct mpam_resctrl_dom *
-mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
+static void mpam_resctrl_alloc_domain(unsigned int cpu,
+				      struct mpam_resctrl_res *res)
 {
 	int err;
 	struct mpam_resctrl_dom *dom;
@@ -1631,11 +1631,11 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 	comp = find_component(class, cpu);
 	/* class has no component for this CPU */
 	if (WARN_ON_ONCE(!comp))
-		return ERR_PTR(-EINVAL);
+		return;
 
 	dom = kzalloc_node(sizeof(*dom), GFP_KERNEL, cpu_to_node(cpu));
 	if (!dom)
-		return ERR_PTR(-ENOMEM);
+		return;
 
 	if (r->alloc_capable) {
 		dom->ctrl_comp = comp;
@@ -1678,7 +1678,6 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 		}
 		if (!any_mon_comp) {
 			WARN_ON_ONCE(0);
-			err = -EFAULT;
 			goto offline_ctrl_domain;
 		}
 
@@ -1694,7 +1693,7 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 		pr_debug("Skipped monitor domain online - no monitors\n");
 	}
 
-	return dom;
+	return;
 
 offline_ctrl_domain:
 	if (r->alloc_capable) {
@@ -1703,9 +1702,6 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 	}
 free_domain:
 	kfree(dom);
-	dom = ERR_PTR(err);
-
-	return dom;
 }
 
 /*
@@ -1757,7 +1753,7 @@ mpam_resctrl_get_domain_from_cpu(int cpu, struct mpam_resctrl_res *res)
 	return mpam_resctrl_get_mon_domain_from_cpu(cpu);
 }
 
-int mpam_resctrl_online_cpu(unsigned int cpu)
+void mpam_resctrl_online_cpu(unsigned int cpu)
 {
 	struct mpam_resctrl_res *res;
 	enum resctrl_res_level rid;
@@ -1772,9 +1768,13 @@ int mpam_resctrl_online_cpu(unsigned int cpu)
 
 		dom = mpam_resctrl_get_domain_from_cpu(cpu, res);
 		if (!dom) {
-			dom = mpam_resctrl_alloc_domain(cpu, res);
-			if (IS_ERR(dom))
-				return PTR_ERR(dom);
+			/*
+			 * On failure the CPU is left without a domain for this
+			 * resource, which mpam_resctrl_offline_cpu() tolerates.
+			 * resctrl_online_cpu() still adds the CPU to the default
+			 * group because the CPU is online and runs tasks.
+			 */
+			mpam_resctrl_alloc_domain(cpu, res);
 		} else {
 			if (r->alloc_capable) {
 				struct rdt_ctrl_domain *ctrl_d = &dom->resctrl_ctrl_dom;
@@ -1790,8 +1790,6 @@ int mpam_resctrl_online_cpu(unsigned int cpu)
 	}
 
 	resctrl_online_cpu(cpu);
-
-	return 0;
 }
 
 void mpam_resctrl_offline_cpu(unsigned int cpu)
@@ -1812,8 +1810,9 @@ void mpam_resctrl_offline_cpu(unsigned int cpu)
 		if (!res->class)
 			continue;	// dummy resource
 
+		/* The domain may be missing if its setup failed. */
 		dom = mpam_resctrl_get_domain_from_cpu(cpu, res);
-		if (WARN_ON_ONCE(!dom))
+		if (!dom)
 			continue;
 
 		if (r->alloc_capable) {
Signature · 1 line
2.55.0
Reviewed-by on v2 3/10
#14 lore raw

Re: [RFC PATCH v2 03/10] arm_mpam: resctrl: Do not fail CPU online when domain setup fails

Quoted 4 lines · Reinette Chatre

When a CPU comes online, mpam_resctrl_online_cpu() adds it to the resctrl domains of each resource in use, and sets up a new domain when the CPU is the first of its domain to come online. A failure to set up a domain is returned as the failure of MPAM's CPU hotplug startup callback.

Indeed the code works this way.

Quoted 8 lines

The CPU hotplug core does not run the teardown callback for a CPU whose startup callback failed, so everything done for the CPU before the failure stays in place: the CPU remains in the domains of the resources that were handled before the failing one, and MPAM's per-MSC state for the CPU is not undone. If the failure happens when MPAM installs its CPU hotplug callbacks during enabling, the hotplug core discards the callbacks, leaving MPAM enabled and resctrl initialized but MPAM no

By the way, I previously ran into a case during testing where adding the "maxcpu" boot parameter caused MPAM enabling to fail.

Link:
https://lore.kernel.org/all/[email protected]/

Quoted 8 lines

longer notified of CPU hotplug. If it happens when a CPU comes online later, the CPU fails to come online.

Setting up a domain only fails if a memory allocation fails or if a class unexpectedly has no component for the CPU. For such rare failures losing a resctrl domain is a smaller cost than failing CPU online or leaving MPAM in an inconsistent state.

Quoted 4 lines

Do not report domain setup failures from mpam_resctrl_online_cpu() and leave the CPU without a domain for that resource. Make mpam_resctrl_alloc_domain() return nothing since its failures are no longer reported. Keep adding the CPU to resctrl's default group even

Yes, We now always call resctrl_online_cpu() to add them to the default group.

Quoted 4 lines

when a domain could not be set up, since the CPU is online and runs tasks regardless, and resctrl expects every online CPU to belong to a resource group. Drop the warning when a CPU going offline has no domain, since a missing domain is now expected.

It is now valid for the domain to be empty when a CPU goes offline.

Quoted 138 lines

Only domains that were set up are exposed through resctrl and torn down when their CPUs go offline. When another CPU of the same domain comes online, it sets up the domain again, and if that succeeds the domain does not include the CPU for which setup failed.

---
 drivers/resctrl/mpam_devices.c  |  2 +-
 drivers/resctrl/mpam_internal.h |  4 ++--
 drivers/resctrl/mpam_resctrl.c  | 31 +++++++++++++++----------------
 3 files changed, 18 insertions(+), 19 deletions(-)
drivers/resctrl/mpam_devices.c +1 -1
index 48adc49b833c..d17d7a72dba1 100644
@@ -2249,7 +2249,7 @@ static int mpam_cpu_online(unsigned int cpu)
 	}
 
 	if (mpam_resctrl_enabled)
-		return mpam_resctrl_online_cpu(cpu);
+		mpam_resctrl_online_cpu(cpu);
 
 	return 0;
 }
drivers/resctrl/mpam_internal.h +2 -2
index 1f86cc158100..84c7adbb1a40 100644
@@ -525,13 +525,13 @@ int mpam_get_cpumask_from_cache_id(unsigned long cache_id, u32 cache_level,
 #ifdef CONFIG_RESCTRL_FS
 int mpam_resctrl_setup(void);
 void mpam_resctrl_exit(void);
-int mpam_resctrl_online_cpu(unsigned int cpu);
+void mpam_resctrl_online_cpu(unsigned int cpu);
 void mpam_resctrl_offline_cpu(unsigned int cpu);
 void mpam_resctrl_teardown_class(struct mpam_class *class);
 #else
 static inline int mpam_resctrl_setup(void) { return 0; }
 static inline void mpam_resctrl_exit(void) { }
-static inline int mpam_resctrl_online_cpu(unsigned int cpu) { return 0; }
+static inline void mpam_resctrl_online_cpu(unsigned int cpu) { }
 static inline void mpam_resctrl_offline_cpu(unsigned int cpu) { }
 static inline void mpam_resctrl_teardown_class(struct mpam_class *class) { }
 #endif /* CONFIG_RESCTRL_FS */
drivers/resctrl/mpam_resctrl.c +13 -15
index b07e5dd895dd..dc442851fd7e 100644
@@ -1615,8 +1615,8 @@ static struct mpam_component *find_component(struct mpam_class *class, int cpu)
 	return NULL;
 }
 
-static struct mpam_resctrl_dom *
-mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
+static void mpam_resctrl_alloc_domain(unsigned int cpu,
+				      struct mpam_resctrl_res *res)
 {
 	int err;
 	struct mpam_resctrl_dom *dom;
@@ -1631,11 +1631,11 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 	comp = find_component(class, cpu);
 	/* class has no component for this CPU */
 	if (WARN_ON_ONCE(!comp))
-		return ERR_PTR(-EINVAL);
+		return;
 
 	dom = kzalloc_node(sizeof(*dom), GFP_KERNEL, cpu_to_node(cpu));
 	if (!dom)
-		return ERR_PTR(-ENOMEM);
+		return;
 
 	if (r->alloc_capable) {
 		dom->ctrl_comp = comp;
@@ -1678,7 +1678,6 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 		}
 		if (!any_mon_comp) {
 			WARN_ON_ONCE(0);
-			err = -EFAULT;
 			goto offline_ctrl_domain;
 		}
 
@@ -1694,7 +1693,7 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 		pr_debug("Skipped monitor domain online - no monitors\n");
 	}
 
-	return dom;
+	return;
 
 offline_ctrl_domain:
 	if (r->alloc_capable) {
@@ -1703,9 +1702,6 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 	}
 free_domain:
 	kfree(dom);
-	dom = ERR_PTR(err);
-
-	return dom;
 }
 
 /*
@@ -1757,7 +1753,7 @@ mpam_resctrl_get_domain_from_cpu(int cpu, struct mpam_resctrl_res *res)
 	return mpam_resctrl_get_mon_domain_from_cpu(cpu);
 }
 
-int mpam_resctrl_online_cpu(unsigned int cpu)
+void mpam_resctrl_online_cpu(unsigned int cpu)
 {
 	struct mpam_resctrl_res *res;
 	enum resctrl_res_level rid;
@@ -1772,9 +1768,13 @@ int mpam_resctrl_online_cpu(unsigned int cpu)
 
 		dom = mpam_resctrl_get_domain_from_cpu(cpu, res);
 		if (!dom) {
-			dom = mpam_resctrl_alloc_domain(cpu, res);
-			if (IS_ERR(dom))
-				return PTR_ERR(dom);
+			/*
+			 * On failure the CPU is left without a domain for this
+			 * resource, which mpam_resctrl_offline_cpu() tolerates.
+			 * resctrl_online_cpu() still adds the CPU to the default
+			 * group because the CPU is online and runs tasks.
+			 */
+			mpam_resctrl_alloc_domain(cpu, res);
 		} else {
 			if (r->alloc_capable) {
 				struct rdt_ctrl_domain *ctrl_d = &dom->resctrl_ctrl_dom;
@@ -1790,8 +1790,6 @@ int mpam_resctrl_online_cpu(unsigned int cpu)
 	}
 
 	resctrl_online_cpu(cpu);
-
-	return 0;
 }
 
 void mpam_resctrl_offline_cpu(unsigned int cpu)

drivers/resctrl/mpam_resctrl.c void mpam_resctrl_offline_cpu(unsigned int cpu) · line 1816

Quoted 8 lines
drivers/resctrl/mpam_resctrl.c +2 -1
@@ -1812,8 +1810,9 @@ void mpam_resctrl_offline_cpu(unsigned int cpu)
 		if (!res->class)
 			continue;	// dummy resource
 
+		/* The domain may be missing if its setup failed. */
 		dom = mpam_resctrl_get_domain_from_cpu(cpu, res);
-		if (WARN_ON_ONCE(!dom))
+		if (!dom)
 			continue;
Quoted 2 lines
drivers/resctrl/mpam_resctrl.c +0 -0
 		if (r->alloc_capable) {
Signature · 2 lines
Best regards,
Jinjie
maintainer
#15 lore raw

Re: [RFC PATCH v2 03/10] arm_mpam: resctrl: Do not fail CPU online when domain setup fails

In reply to Reinette Chatre

Hi Reinette,

Thanks for addressing this.

Quoted 90 lines · Reinette Chatre

When a CPU comes online, mpam_resctrl_online_cpu() adds it to the resctrl domains of each resource in use, and sets up a new domain when the CPU is the first of its domain to come online. A failure to set up a domain is returned as the failure of MPAM's CPU hotplug startup callback.

The CPU hotplug core does not run the teardown callback for a CPU whose startup callback failed, so everything done for the CPU before the failure stays in place: the CPU remains in the domains of the resources that were handled before the failing one, and MPAM's per-MSC state for the CPU is not undone. If the failure happens when MPAM installs its CPU hotplug callbacks during enabling, the hotplug core discards the callbacks, leaving MPAM enabled and resctrl initialized but MPAM no longer notified of CPU hotplug. If it happens when a CPU comes online later, the CPU fails to come online.

Setting up a domain only fails if a memory allocation fails or if a class unexpectedly has no component for the CPU. For such rare failures losing a resctrl domain is a smaller cost than failing CPU online or leaving MPAM in an inconsistent state.

Do not report domain setup failures from mpam_resctrl_online_cpu() and leave the CPU without a domain for that resource. Make mpam_resctrl_alloc_domain() return nothing since its failures are no longer reported. Keep adding the CPU to resctrl's default group even when a domain could not be set up, since the CPU is online and runs tasks regardless, and resctrl expects every online CPU to belong to a resource group. Drop the warning when a CPU going offline has no domain, since a missing domain is now expected.

Only domains that were set up are exposed through resctrl and torn down when their CPUs go offline. When another CPU of the same domain comes online, it sets up the domain again, and if that succeeds the domain does not include the CPU for which setup failed.

---
 drivers/resctrl/mpam_devices.c  |  2 +-
 drivers/resctrl/mpam_internal.h |  4 ++--
 drivers/resctrl/mpam_resctrl.c  | 31 +++++++++++++++----------------
 3 files changed, 18 insertions(+), 19 deletions(-)
drivers/resctrl/mpam_devices.c +1 -1
index 48adc49b833c..d17d7a72dba1 100644
@@ -2249,7 +2249,7 @@ static int mpam_cpu_online(unsigned int cpu)
 	}
 
 	if (mpam_resctrl_enabled)
-		return mpam_resctrl_online_cpu(cpu);
+		mpam_resctrl_online_cpu(cpu);
 
 	return 0;
 }
drivers/resctrl/mpam_internal.h +2 -2
index 1f86cc158100..84c7adbb1a40 100644
@@ -525,13 +525,13 @@ int mpam_get_cpumask_from_cache_id(unsigned long cache_id, u32 cache_level,
 #ifdef CONFIG_RESCTRL_FS
 int mpam_resctrl_setup(void);
 void mpam_resctrl_exit(void);
-int mpam_resctrl_online_cpu(unsigned int cpu);
+void mpam_resctrl_online_cpu(unsigned int cpu);
 void mpam_resctrl_offline_cpu(unsigned int cpu);
 void mpam_resctrl_teardown_class(struct mpam_class *class);
 #else
 static inline int mpam_resctrl_setup(void) { return 0; }
 static inline void mpam_resctrl_exit(void) { }
-static inline int mpam_resctrl_online_cpu(unsigned int cpu) { return 0; }
+static inline void mpam_resctrl_online_cpu(unsigned int cpu) { }
 static inline void mpam_resctrl_offline_cpu(unsigned int cpu) { }
 static inline void mpam_resctrl_teardown_class(struct mpam_class *class) { }
 #endif /* CONFIG_RESCTRL_FS */
drivers/resctrl/mpam_resctrl.c +2 -2
index b07e5dd895dd..dc442851fd7e 100644
@@ -1615,8 +1615,8 @@ static struct mpam_component *find_component(struct mpam_class *class, int cpu)
 	return NULL;
 }
 
-static struct mpam_resctrl_dom *
-mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
+static void mpam_resctrl_alloc_domain(unsigned int cpu,
+				      struct mpam_resctrl_res *res)
 {
 	int err;
 	struct mpam_resctrl_dom *dom;

drivers/resctrl/mpam_resctrl.c mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res) · line 1638

Quoted 10 lines
drivers/resctrl/mpam_resctrl.c +2 -2
@@ -1631,11 +1631,11 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 	comp = find_component(class, cpu);
 	/* class has no component for this CPU */
 	if (WARN_ON_ONCE(!comp))
-		return ERR_PTR(-EINVAL);
+		return;
 
 	dom = kzalloc_node(sizeof(*dom), GFP_KERNEL, cpu_to_node(cpu));
 	if (!dom)
-		return ERR_PTR(-ENOMEM);
+		return;

Do you think a warning is warranted here?

drivers/resctrl/mpam_resctrl.c mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res) · line 1680

Quoted 7 lines
drivers/resctrl/mpam_resctrl.c +0 -0
 	if (r->alloc_capable) {
 		dom->ctrl_comp = comp;
@@ -1678,7 +1678,6 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 		}
 		if (!any_mon_comp) {
 			WARN_ON_ONCE(0);

I think you could fold in your patch 7 here.
arm_mpam: resctrl: Warn when no monitoring component is found for a CPU

Thanks,

Ben

Quoted 69 lines
drivers/resctrl/mpam_resctrl.c +11 -12
-			err = -EFAULT;
 			goto offline_ctrl_domain;
 		}
 
@@ -1694,7 +1693,7 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 		pr_debug("Skipped monitor domain online - no monitors\n");
 	}
 
-	return dom;
+	return;
 
 offline_ctrl_domain:
 	if (r->alloc_capable) {
@@ -1703,9 +1702,6 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 	}
 free_domain:
 	kfree(dom);
-	dom = ERR_PTR(err);
-
-	return dom;
 }
 
 /*
@@ -1757,7 +1753,7 @@ mpam_resctrl_get_domain_from_cpu(int cpu, struct mpam_resctrl_res *res)
 	return mpam_resctrl_get_mon_domain_from_cpu(cpu);
 }
 
-int mpam_resctrl_online_cpu(unsigned int cpu)
+void mpam_resctrl_online_cpu(unsigned int cpu)
 {
 	struct mpam_resctrl_res *res;
 	enum resctrl_res_level rid;
@@ -1772,9 +1768,13 @@ int mpam_resctrl_online_cpu(unsigned int cpu)
 
 		dom = mpam_resctrl_get_domain_from_cpu(cpu, res);
 		if (!dom) {
-			dom = mpam_resctrl_alloc_domain(cpu, res);
-			if (IS_ERR(dom))
-				return PTR_ERR(dom);
+			/*
+			 * On failure the CPU is left without a domain for this
+			 * resource, which mpam_resctrl_offline_cpu() tolerates.
+			 * resctrl_online_cpu() still adds the CPU to the default
+			 * group because the CPU is online and runs tasks.
+			 */
+			mpam_resctrl_alloc_domain(cpu, res);
 		} else {
 			if (r->alloc_capable) {
 				struct rdt_ctrl_domain *ctrl_d = &dom->resctrl_ctrl_dom;
@@ -1790,8 +1790,6 @@ int mpam_resctrl_online_cpu(unsigned int cpu)
 	}
 
 	resctrl_online_cpu(cpu);
-
-	return 0;
 }
 
 void mpam_resctrl_offline_cpu(unsigned int cpu)
@@ -1812,8 +1810,9 @@ void mpam_resctrl_offline_cpu(unsigned int cpu)
 		if (!res->class)
 			continue;	// dummy resource
 
+		/* The domain may be missing if its setup failed. */
 		dom = mpam_resctrl_get_domain_from_cpu(cpu, res);
-		if (WARN_ON_ONCE(!dom))
+		if (!dom)
 			continue;
 
 		if (r->alloc_capable) {
author reviewer
#16 lore raw

Re: [RFC PATCH v2 03/10] arm_mpam: resctrl: Do not fail CPU online when domain setup fails

Hi Ben,

Quoted 1 line · Ben Horgan

On 19/10/2026 23:07, Reinette Chatre wrote:

...

Quoted 22 lines
Quoted 22 lines
drivers/resctrl/mpam_resctrl.c +3 -3
index b07e5dd895dd..dc442851fd7e 100644
@@ -1615,8 +1615,8 @@ static struct mpam_component *find_component(struct mpam_class *class, int cpu)
 	return NULL;
 }
 
-static struct mpam_resctrl_dom *
-mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
+static void mpam_resctrl_alloc_domain(unsigned int cpu,
+				      struct mpam_resctrl_res *res)
 {
 	int err;
 	struct mpam_resctrl_dom *dom;
@@ -1631,11 +1631,11 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 	comp = find_component(class, cpu);
 	/* class has no component for this CPU */
 	if (WARN_ON_ONCE(!comp))
-		return ERR_PTR(-EINVAL);
+		return;
 
Quoted 6 lines

drivers/resctrl/mpam_resctrl.c mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res) · line 1638

Quoted 4 lines
drivers/resctrl/mpam_resctrl.c +1 -1
 	dom = kzalloc_node(sizeof(*dom), GFP_KERNEL, cpu_to_node(cpu));
 	if (!dom)
-		return ERR_PTR(-ENOMEM);
+		return;

Do you think a warning is warranted here?

Sure. I'll add a warning here in the next version, propagated in later patches to mpam_resctrl_add_cpu_ctrl_domain() and mpam_resctrl_add_cpu_mon_domain().

Quoted 11 lines

drivers/resctrl/mpam_resctrl.c mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res) · line 1680

Quoted 8 lines
drivers/resctrl/mpam_resctrl.c +0 -0
 	if (r->alloc_capable) {
 		dom->ctrl_comp = comp;
@@ -1678,7 +1678,6 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 		}
 		if (!any_mon_comp) {
 			WARN_ON_ONCE(0);

I think you could fold in your patch 7 here.
arm_mpam: resctrl: Warn when no monitoring component is found for a CPU

Will do.

Reinette

author reviewer
#17 lore raw

RFC PATCH v2 4/10 arm_mpam: resctrl: Split control and monitoring domain setup into helpers

In reply to Reinette Chatre

mpam_resctrl_alloc_domain() allocates one structure that holds both the control domain and the monitoring domain of a resource. It sets up whichever of the two domains the resource supports, with the setup of both open coded in the function, and undoes the control domain if setting up the monitoring domain fails.

Apart from the code that manages domains, every user of the structure accesses only one of its two domains, so the monitoring domain can be given a structure of its own. Doing so starts with separating its setup from that of the control domain.

Move the setup of each domain into its own helper in preparation for giving the monitoring domain its own structure as part of supporting multiple controls per resource. Keep the allocation and the error handling in mpam_resctrl_alloc_domain() so that a failure to set up the monitoring domain still undoes the control domain.

No functional change intended.

---
 drivers/resctrl/mpam_resctrl.c | 116 ++++++++++++++++++++-------------
 1 file changed, 70 insertions(+), 46 deletions(-)
drivers/resctrl/mpam_resctrl.c +70 -46
index dc442851fd7e..246560247a28 100644
@@ -1615,13 +1615,77 @@ static struct mpam_component *find_component(struct mpam_class *class, int cpu)
 	return NULL;
 }
 
+static int mpam_resctrl_setup_ctrl_domain(unsigned int cpu,
+					  struct rdt_resource *r,
+					  struct mpam_component *comp,
+					  struct mpam_resctrl_dom *dom)
+{
+	struct rdt_ctrl_domain *ctrl_d = &dom->resctrl_ctrl_dom;
+	int err;
+
+	dom->ctrl_comp = comp;
+
+	mpam_resctrl_domain_hdr_init(cpu, comp, r->rid, &ctrl_d->hdr);
+	ctrl_d->hdr.type = RESCTRL_CTRL_DOMAIN;
+	err = resctrl_online_ctrl_domain(r, ctrl_d);
+	if (err)
+		return err;
+
+	mpam_resctrl_domain_insert(&r->ctrl_domains, &ctrl_d->hdr);
+
+	return 0;
+}
+
+static int mpam_resctrl_setup_mon_domain(unsigned int cpu,
+					 struct rdt_resource *r,
+					 struct mpam_resctrl_dom *dom)
+{
+	struct rdt_l3_mon_domain *mon_d = &dom->resctrl_mon_dom;
+	struct mpam_component *any_mon_comp = NULL;
+	enum resctrl_event_id eventid;
+	struct mpam_resctrl_mon *mon;
+	int err;
+
+	/*
+	 * Even if the monitor domain is backed by a different
+	 * component, the L3 component IDs need to be used... only
+	 * there may be no ctrl_comp for the L3.
+	 * Search each event's class list for a component with
+	 * overlapping CPUs and set up the dom->mon_comp array.
+	 */
+
+	for_each_mpam_resctrl_mon(mon, eventid) {
+		struct mpam_component *mon_comp;
+
+		if (!mon->class)
+			continue;       // dummy resource
+
+		mon_comp = find_component(mon->class, cpu);
+		dom->mon_comp[eventid] = mon_comp;
+		if (mon_comp)
+			any_mon_comp = mon_comp;
+	}
+	if (!any_mon_comp) {
+		WARN_ON_ONCE(0);
+		return -EFAULT;
+	}
+
+	mpam_resctrl_domain_hdr_init(cpu, any_mon_comp, r->rid, &mon_d->hdr);
+	mon_d->hdr.type = RESCTRL_MON_DOMAIN;
+	err = resctrl_online_mon_domain(r, &mon_d->hdr);
+	if (err)
+		return err;
+
+	mpam_resctrl_domain_insert(&r->mon_domains, &mon_d->hdr);
+
+	return 0;
+}
+
 static void mpam_resctrl_alloc_domain(unsigned int cpu,
 				      struct mpam_resctrl_res *res)
 {
 	int err;
 	struct mpam_resctrl_dom *dom;
-	struct rdt_l3_mon_domain *mon_d;
-	struct rdt_ctrl_domain *ctrl_d;
 	struct mpam_class *class = res->class;
 	struct mpam_component *comp;
 	struct rdt_resource *r = &res->resctrl_res;
@@ -1638,57 +1702,17 @@ static void mpam_resctrl_alloc_domain(unsigned int cpu,
 		return;
 
 	if (r->alloc_capable) {
-		dom->ctrl_comp = comp;
-
-		ctrl_d = &dom->resctrl_ctrl_dom;
-		mpam_resctrl_domain_hdr_init(cpu, comp, r->rid, &ctrl_d->hdr);
-		ctrl_d->hdr.type = RESCTRL_CTRL_DOMAIN;
-		err = resctrl_online_ctrl_domain(r, ctrl_d);
+		err = mpam_resctrl_setup_ctrl_domain(cpu, r, comp, dom);
 		if (err)
 			goto free_domain;
-
-		mpam_resctrl_domain_insert(&r->ctrl_domains, &ctrl_d->hdr);
 	} else {
 		pr_debug("Skipped control domain online - no controls\n");
 	}
 
 	if (r->mon_capable) {
-		struct mpam_component *any_mon_comp = NULL;
-		struct mpam_resctrl_mon *mon;
-		enum resctrl_event_id eventid;
-
-		/*
-		 * Even if the monitor domain is backed by a different
-		 * component, the L3 component IDs need to be used... only
-		 * there may be no ctrl_comp for the L3.
-		 * Search each event's class list for a component with
-		 * overlapping CPUs and set up the dom->mon_comp array.
-		 */
-
-		for_each_mpam_resctrl_mon(mon, eventid) {
-			struct mpam_component *mon_comp;
-
-			if (!mon->class)
-				continue;       // dummy resource
-
-			mon_comp = find_component(mon->class, cpu);
-			dom->mon_comp[eventid] = mon_comp;
-			if (mon_comp)
-				any_mon_comp = mon_comp;
-		}
-		if (!any_mon_comp) {
-			WARN_ON_ONCE(0);
-			goto offline_ctrl_domain;
-		}
-
-		mon_d = &dom->resctrl_mon_dom;
-		mpam_resctrl_domain_hdr_init(cpu, any_mon_comp, r->rid, &mon_d->hdr);
-		mon_d->hdr.type = RESCTRL_MON_DOMAIN;
-		err = resctrl_online_mon_domain(r, &mon_d->hdr);
+		err = mpam_resctrl_setup_mon_domain(cpu, r, dom);
 		if (err)
 			goto offline_ctrl_domain;
-
-		mpam_resctrl_domain_insert(&r->mon_domains, &mon_d->hdr);
 	} else {
 		pr_debug("Skipped monitor domain online - no monitors\n");
 	}
@@ -1697,8 +1721,8 @@ static void mpam_resctrl_alloc_domain(unsigned int cpu,
 
 offline_ctrl_domain:
 	if (r->alloc_capable) {
-		mpam_resctrl_offline_domain_hdr(cpu, &ctrl_d->hdr);
-		resctrl_offline_ctrl_domain(r, ctrl_d);
+		mpam_resctrl_offline_domain_hdr(cpu, &dom->resctrl_ctrl_dom.hdr);
+		resctrl_offline_ctrl_domain(r, &dom->resctrl_ctrl_dom);
 	}
 free_domain:
 	kfree(dom);
Signature · 1 line
2.55.0
Reviewed-by on v2 4/10
#18 lore raw

Re: [RFC PATCH v2 04/10] arm_mpam: resctrl: Split control and monitoring domain setup into helpers

Quoted 111 lines · Reinette Chatre

mpam_resctrl_alloc_domain() allocates one structure that holds both the control domain and the monitoring domain of a resource. It sets up whichever of the two domains the resource supports, with the setup of both open coded in the function, and undoes the control domain if setting up the monitoring domain fails.

Apart from the code that manages domains, every user of the structure accesses only one of its two domains, so the monitoring domain can be given a structure of its own. Doing so starts with separating its setup from that of the control domain.

Move the setup of each domain into its own helper in preparation for giving the monitoring domain its own structure as part of supporting multiple controls per resource. Keep the allocation and the error handling in mpam_resctrl_alloc_domain() so that a failure to set up the monitoring domain still undoes the control domain.

No functional change intended.

---
 drivers/resctrl/mpam_resctrl.c | 116 ++++++++++++++++++++-------------
 1 file changed, 70 insertions(+), 46 deletions(-)
drivers/resctrl/mpam_resctrl.c +66 -2
index dc442851fd7e..246560247a28 100644
@@ -1615,13 +1615,77 @@ static struct mpam_component *find_component(struct mpam_class *class, int cpu)
 	return NULL;
 }
 
+static int mpam_resctrl_setup_ctrl_domain(unsigned int cpu,
+					  struct rdt_resource *r,
+					  struct mpam_component *comp,
+					  struct mpam_resctrl_dom *dom)
+{
+	struct rdt_ctrl_domain *ctrl_d = &dom->resctrl_ctrl_dom;
+	int err;
+
+	dom->ctrl_comp = comp;
+
+	mpam_resctrl_domain_hdr_init(cpu, comp, r->rid, &ctrl_d->hdr);
+	ctrl_d->hdr.type = RESCTRL_CTRL_DOMAIN;
+	err = resctrl_online_ctrl_domain(r, ctrl_d);
+	if (err)
+		return err;
+
+	mpam_resctrl_domain_insert(&r->ctrl_domains, &ctrl_d->hdr);
+
+	return 0;
+}
+
+static int mpam_resctrl_setup_mon_domain(unsigned int cpu,
+					 struct rdt_resource *r,
+					 struct mpam_resctrl_dom *dom)
+{
+	struct rdt_l3_mon_domain *mon_d = &dom->resctrl_mon_dom;
+	struct mpam_component *any_mon_comp = NULL;
+	enum resctrl_event_id eventid;
+	struct mpam_resctrl_mon *mon;
+	int err;
+
+	/*
+	 * Even if the monitor domain is backed by a different
+	 * component, the L3 component IDs need to be used... only
+	 * there may be no ctrl_comp for the L3.
+	 * Search each event's class list for a component with
+	 * overlapping CPUs and set up the dom->mon_comp array.
+	 */
+
+	for_each_mpam_resctrl_mon(mon, eventid) {
+		struct mpam_component *mon_comp;
+
+		if (!mon->class)
+			continue;       // dummy resource
+
+		mon_comp = find_component(mon->class, cpu);
+		dom->mon_comp[eventid] = mon_comp;
+		if (mon_comp)
+			any_mon_comp = mon_comp;
+	}
+	if (!any_mon_comp) {
+		WARN_ON_ONCE(0);
+		return -EFAULT;
+	}
+
+	mpam_resctrl_domain_hdr_init(cpu, any_mon_comp, r->rid, &mon_d->hdr);
+	mon_d->hdr.type = RESCTRL_MON_DOMAIN;
+	err = resctrl_online_mon_domain(r, &mon_d->hdr);
+	if (err)
+		return err;
+
+	mpam_resctrl_domain_insert(&r->mon_domains, &mon_d->hdr);
+
+	return 0;
+}
+
 static void mpam_resctrl_alloc_domain(unsigned int cpu,
 				      struct mpam_resctrl_res *res)
 {
 	int err;
 	struct mpam_resctrl_dom *dom;
-	struct rdt_l3_mon_domain *mon_d;
-	struct rdt_ctrl_domain *ctrl_d;
 	struct mpam_class *class = res->class;
 	struct mpam_component *comp;
 	struct rdt_resource *r = &res->resctrl_res;
@@ -1638,57 +1702,17 @@ static void mpam_resctrl_alloc_domain(unsigned int cpu,
 		return;
 

drivers/resctrl/mpam_resctrl.c static void mpam_resctrl_alloc_domain(unsigned int cpu, · line 1707

Quoted 10 lines
drivers/resctrl/mpam_resctrl.c +1 -6
 	if (r->alloc_capable) {
-		dom->ctrl_comp = comp;
-
-		ctrl_d = &dom->resctrl_ctrl_dom;
-		mpam_resctrl_domain_hdr_init(cpu, comp, r->rid, &ctrl_d->hdr);
-		ctrl_d->hdr.type = RESCTRL_CTRL_DOMAIN;
-		err = resctrl_online_ctrl_domain(r, ctrl_d);
+		err = mpam_resctrl_setup_ctrl_domain(cpu, r, comp, dom);
 		if (err)
 			goto free_domain;

LGTM

Quoted 58 lines
drivers/resctrl/mpam_resctrl.c +3 -38
-
-		mpam_resctrl_domain_insert(&r->ctrl_domains, &ctrl_d->hdr);
 	} else {
 		pr_debug("Skipped control domain online - no controls\n");
 	}
 
 	if (r->mon_capable) {
-		struct mpam_component *any_mon_comp = NULL;
-		struct mpam_resctrl_mon *mon;
-		enum resctrl_event_id eventid;
-
-		/*
-		 * Even if the monitor domain is backed by a different
-		 * component, the L3 component IDs need to be used... only
-		 * there may be no ctrl_comp for the L3.
-		 * Search each event's class list for a component with
-		 * overlapping CPUs and set up the dom->mon_comp array.
-		 */
-
-		for_each_mpam_resctrl_mon(mon, eventid) {
-			struct mpam_component *mon_comp;
-
-			if (!mon->class)
-				continue;       // dummy resource
-
-			mon_comp = find_component(mon->class, cpu);
-			dom->mon_comp[eventid] = mon_comp;
-			if (mon_comp)
-				any_mon_comp = mon_comp;
-		}
-		if (!any_mon_comp) {
-			WARN_ON_ONCE(0);
-			goto offline_ctrl_domain;
-		}
-
-		mon_d = &dom->resctrl_mon_dom;
-		mpam_resctrl_domain_hdr_init(cpu, any_mon_comp, r->rid, &mon_d->hdr);
-		mon_d->hdr.type = RESCTRL_MON_DOMAIN;
-		err = resctrl_online_mon_domain(r, &mon_d->hdr);
+		err = mpam_resctrl_setup_mon_domain(cpu, r, dom);
 		if (err)
 			goto offline_ctrl_domain;
-
-		mpam_resctrl_domain_insert(&r->mon_domains, &mon_d->hdr);
 	} else {
 		pr_debug("Skipped monitor domain online - no monitors\n");
 	}
@@ -1697,8 +1721,8 @@ static void mpam_resctrl_alloc_domain(unsigned int cpu,
 
 offline_ctrl_domain:
 	if (r->alloc_capable) {
-		mpam_resctrl_offline_domain_hdr(cpu, &ctrl_d->hdr);
-		resctrl_offline_ctrl_domain(r, ctrl_d);
+		mpam_resctrl_offline_domain_hdr(cpu, &dom->resctrl_ctrl_dom.hdr);
+		resctrl_offline_ctrl_domain(r, &dom->resctrl_ctrl_dom);
 	}
 free_domain:
 	kfree(dom);
Signature · 2 lines
Best regards,
Jinjie
#19 lore raw

Re: [RFC PATCH v2 04/10] arm_mpam: resctrl: Split control and monitoring domain setup into helpers

In reply to Reinette Chatre

Hello Ben, Reinette

Quoted 88 lines

mpam_resctrl_alloc_domain() allocates one structure that holds both the control domain and the monitoring domain of a resource. It sets up whichever of the two domains the resource supports, with the setup of both open coded in the function, and undoes the control domain if setting up the monitoring domain fails.

Apart from the code that manages domains, every user of the structure accesses only one of its two domains, so the monitoring domain can be given a structure of its own. Doing so starts with separating its setup from that of the control domain.

Move the setup of each domain into its own helper in preparation for giving the monitoring domain its own structure as part of supporting multiple controls per resource. Keep the allocation and the error handling in mpam_resctrl_alloc_domain() so that a failure to set up the monitoring domain still undoes the control domain.

No functional change intended.

---
 drivers/resctrl/mpam_resctrl.c | 116 ++++++++++++++++++++-------------
 1 file changed, 70 insertions(+), 46 deletions(-)
drivers/resctrl/mpam_resctrl.c +56 -0
index dc442851fd7e..246560247a28 100644
@@ -1615,13 +1615,77 @@ static struct mpam_component *find_component(struct mpam_class *class, int cpu)
         return NULL;
 }
 
+static int mpam_resctrl_setup_ctrl_domain(unsigned int cpu,
+                                         struct rdt_resource *r,
+                                         struct mpam_component *comp,
+                                         struct mpam_resctrl_dom *dom)
+{
+       struct rdt_ctrl_domain *ctrl_d = &dom->resctrl_ctrl_dom;
+       int err;
+
+       dom->ctrl_comp = comp;
+
+       mpam_resctrl_domain_hdr_init(cpu, comp, r->rid, &ctrl_d->hdr);
+       ctrl_d->hdr.type = RESCTRL_CTRL_DOMAIN;
+       err = resctrl_online_ctrl_domain(r, ctrl_d);
+       if (err)
+               return err;
+
+       mpam_resctrl_domain_insert(&r->ctrl_domains, &ctrl_d->hdr);
+
+       return 0;
+}
+
+static int mpam_resctrl_setup_mon_domain(unsigned int cpu,
+                                        struct rdt_resource *r,
+                                        struct mpam_resctrl_dom *dom)
+{
+       struct rdt_l3_mon_domain *mon_d = &dom->resctrl_mon_dom;
+       struct mpam_component *any_mon_comp = NULL;
+       enum resctrl_event_id eventid;
+       struct mpam_resctrl_mon *mon;
+       int err;
+
+       /*
+        * Even if the monitor domain is backed by a different
+        * component, the L3 component IDs need to be used... only
+        * there may be no ctrl_comp for the L3.
+        * Search each event's class list for a component with
+        * overlapping CPUs and set up the dom->mon_comp array.
+        */
+
+       for_each_mpam_resctrl_mon(mon, eventid) {
+               struct mpam_component *mon_comp;
+
+               if (!mon->class)
+                       continue;       // dummy resource
+
+               mon_comp = find_component(mon->class, cpu);
+               dom->mon_comp[eventid] = mon_comp;
+               if (mon_comp)
+                       any_mon_comp = mon_comp;
+       }
+       if (!any_mon_comp) {
+               WARN_ON_ONCE(0);
+               return -EFAULT;
+       }
+
+       mpam_resctrl_domain_hdr_init(cpu, any_mon_comp, r->rid, &mon_d->hdr);

drivers/resctrl/mpam_resctrl.c static struct mpam_component *find_component(struct mpam_class *class, int cpu) · line 1683

Quoted 10 lines
drivers/resctrl/mpam_resctrl.c +10 -0
+       mon_d->hdr.type = RESCTRL_MON_DOMAIN;
+       err = resctrl_online_mon_domain(r, &mon_d->hdr);
+       if (err)
+               return err;
+
+       mpam_resctrl_domain_insert(&r->mon_domains, &mon_d->hdr);
+
+       return 0;
+}
+

Currently, it returns success even when the domain fails to be inserted. Is there a specific reason for this design? I believe it would be safer if mpam_resctrl_domain_insert() returned an int to indicate success or failure.

For example:

	static int mpam_resctrl_domain_insert(struct list_head *list,
					       struct rdt_domain_hdr *new)
	{
		struct rdt_domain_hdr *err;
		struct list_head *pos = NULL;

		lockdep_assert_held(&domain_list_lock);

		err = resctrl_find_domain(list, new->id, &pos);
		if (WARN_ON_ONCE(err))
			return -EEXIST;

		list_add_tail_rcu(&new->list, pos);
		
		return 0;
	}

Wouldn't this be a more robust approach for error handling?

Best regards,
Shaopeng TAN

Quoted 83 lines
drivers/resctrl/mpam_resctrl.c +4 -47
 static void mpam_resctrl_alloc_domain(unsigned int cpu,
                                       struct mpam_resctrl_res *res)
 {
         int err;
         struct mpam_resctrl_dom *dom;
-       struct rdt_l3_mon_domain *mon_d;
-       struct rdt_ctrl_domain *ctrl_d;
         struct mpam_class *class = res->class;
         struct mpam_component *comp;
         struct rdt_resource *r = &res->resctrl_res;
@@ -1638,57 +1702,17 @@ static void mpam_resctrl_alloc_domain(unsigned int cpu,
                 return;
 
         if (r->alloc_capable) {
-               dom->ctrl_comp = comp;
-
-               ctrl_d = &dom->resctrl_ctrl_dom;
-               mpam_resctrl_domain_hdr_init(cpu, comp, r->rid, &ctrl_d->hdr);
-               ctrl_d->hdr.type = RESCTRL_CTRL_DOMAIN;
-               err = resctrl_online_ctrl_domain(r, ctrl_d);
+               err = mpam_resctrl_setup_ctrl_domain(cpu, r, comp, dom);
                 if (err)
                         goto free_domain;
-
-               mpam_resctrl_domain_insert(&r->ctrl_domains, &ctrl_d->hdr);
         } else {
                 pr_debug("Skipped control domain online - no controls\n");
         }
 
         if (r->mon_capable) {
-               struct mpam_component *any_mon_comp = NULL;
-               struct mpam_resctrl_mon *mon;
-               enum resctrl_event_id eventid;
-
-               /*
-                * Even if the monitor domain is backed by a different
-                * component, the L3 component IDs need to be used... only
-                * there may be no ctrl_comp for the L3.
-                * Search each event's class list for a component with
-                * overlapping CPUs and set up the dom->mon_comp array.
-                */
-
-               for_each_mpam_resctrl_mon(mon, eventid) {
-                       struct mpam_component *mon_comp;
-
-                       if (!mon->class)
-                               continue;       // dummy resource
-
-                       mon_comp = find_component(mon->class, cpu);
-                       dom->mon_comp[eventid] = mon_comp;
-                       if (mon_comp)
-                               any_mon_comp = mon_comp;
-               }
-               if (!any_mon_comp) {
-                       WARN_ON_ONCE(0);
-                       goto offline_ctrl_domain;
-               }
-
-               mon_d = &dom->resctrl_mon_dom;
-               mpam_resctrl_domain_hdr_init(cpu, any_mon_comp, r->rid, &mon_d->hdr);
-               mon_d->hdr.type = RESCTRL_MON_DOMAIN;
-               err = resctrl_online_mon_domain(r, &mon_d->hdr);
+               err = mpam_resctrl_setup_mon_domain(cpu, r, dom);
                 if (err)
                         goto offline_ctrl_domain;
-
-               mpam_resctrl_domain_insert(&r->mon_domains, &mon_d->hdr);
         } else {
                 pr_debug("Skipped monitor domain online - no monitors\n");
         }
@@ -1697,8 +1721,8 @@ static void mpam_resctrl_alloc_domain(unsigned int cpu,
 
 offline_ctrl_domain:
         if (r->alloc_capable) {
-               mpam_resctrl_offline_domain_hdr(cpu, &ctrl_d->hdr);
-               resctrl_offline_ctrl_domain(r, ctrl_d);
+               mpam_resctrl_offline_domain_hdr(cpu, &dom->resctrl_ctrl_dom.hdr);
+               resctrl_offline_ctrl_domain(r, &dom->resctrl_ctrl_dom);
         }
 free_domain:
         kfree(dom);
--

2.55.0

author reviewer
#20 lore raw

Re: [RFC PATCH v2 04/10] arm_mpam: resctrl: Split control and monitoring domain setup into helpers

Hi Shaopeng,

Thank you very much for taking a look.

On 11/1/26 9:41 PM, Shaopeng Tan (Fujitsu) wrote:

...

Quoted 78 lines
Quoted 64 lines
drivers/resctrl/mpam_resctrl.c +56 -0
index dc442851fd7e..246560247a28 100644
@@ -1615,13 +1615,77 @@ static struct mpam_component *find_component(struct mpam_class *class, int cpu)
         return NULL;
 }
 
+static int mpam_resctrl_setup_ctrl_domain(unsigned int cpu,
+                                         struct rdt_resource *r,
+                                         struct mpam_component *comp,
+                                         struct mpam_resctrl_dom *dom)
+{
+       struct rdt_ctrl_domain *ctrl_d = &dom->resctrl_ctrl_dom;
+       int err;
+
+       dom->ctrl_comp = comp;
+
+       mpam_resctrl_domain_hdr_init(cpu, comp, r->rid, &ctrl_d->hdr);
+       ctrl_d->hdr.type = RESCTRL_CTRL_DOMAIN;
+       err = resctrl_online_ctrl_domain(r, ctrl_d);
+       if (err)
+               return err;
+
+       mpam_resctrl_domain_insert(&r->ctrl_domains, &ctrl_d->hdr);
+
+       return 0;
+}
+
+static int mpam_resctrl_setup_mon_domain(unsigned int cpu,
+                                        struct rdt_resource *r,
+                                        struct mpam_resctrl_dom *dom)
+{
+       struct rdt_l3_mon_domain *mon_d = &dom->resctrl_mon_dom;
+       struct mpam_component *any_mon_comp = NULL;
+       enum resctrl_event_id eventid;
+       struct mpam_resctrl_mon *mon;
+       int err;
+
+       /*
+        * Even if the monitor domain is backed by a different
+        * component, the L3 component IDs need to be used... only
+        * there may be no ctrl_comp for the L3.
+        * Search each event's class list for a component with
+        * overlapping CPUs and set up the dom->mon_comp array.
+        */
+
+       for_each_mpam_resctrl_mon(mon, eventid) {
+               struct mpam_component *mon_comp;
+
+               if (!mon->class)
+                       continue;       // dummy resource
+
+               mon_comp = find_component(mon->class, cpu);
+               dom->mon_comp[eventid] = mon_comp;
+               if (mon_comp)
+                       any_mon_comp = mon_comp;
+       }
+       if (!any_mon_comp) {
+               WARN_ON_ONCE(0);
+               return -EFAULT;
+       }
+
+       mpam_resctrl_domain_hdr_init(cpu, any_mon_comp, r->rid, &mon_d->hdr);

drivers/resctrl/mpam_resctrl.c static struct mpam_component *find_component(struct mpam_class *class, int cpu) · line 1683

Quoted 10 lines
drivers/resctrl/mpam_resctrl.c +10 -0
+       mon_d->hdr.type = RESCTRL_MON_DOMAIN;
+       err = resctrl_online_mon_domain(r, &mon_d->hdr);
+       if (err)
+               return err;
+
+       mpam_resctrl_domain_insert(&r->mon_domains, &mon_d->hdr);
+
+       return 0;
+}
+

Currently, it returns success even when the domain fails to be inserted. Is there a specific reason for this design? I believe it would be safer if mpam_resctrl_domain_insert() returned an int to indicate success or failure.

Quoted 3 lines

For example:
static int mpam_resctrl_domain_insert(struct list_head *list,
struct rdt_domain_hdr *new)

Could mpam_resctrl_domain_insert() ever fail? A domain is only created after the lookup found none for this CPU. For a control domain the lookup is by the component's CPU affinity while the insert checks the domain id, but the id is the component's id and component affinities within a class do not overlap, so absence of one implies absence of the other. For a monitoring domain both are the L3 cache id.

For mpam_resctrl_domain_insert() to return a failure an insert would have found an existing domain which means a domain appeared _after_ it was found to be absent. That would be a driver bug rather than a runtime error. The WARN_ON_ONCE() reports it. Handling it would add unwind code for a state that cannot occur.

This is how I understand the flow and believe this is why the existing code does not report it.

Reinette

maintainer
#21 lore raw

Re: [RFC PATCH v2 04/10] arm_mpam: resctrl: Split control and monitoring domain setup into helpers

In reply to Reinette Chatre

Hi Reinette,

Generally makes sense.

Quoted 76 lines · Reinette Chatre

mpam_resctrl_alloc_domain() allocates one structure that holds both the control domain and the monitoring domain of a resource. It sets up whichever of the two domains the resource supports, with the setup of both open coded in the function, and undoes the control domain if setting up the monitoring domain fails.

Apart from the code that manages domains, every user of the structure accesses only one of its two domains, so the monitoring domain can be given a structure of its own. Doing so starts with separating its setup from that of the control domain.

Move the setup of each domain into its own helper in preparation for giving the monitoring domain its own structure as part of supporting multiple controls per resource. Keep the allocation and the error handling in mpam_resctrl_alloc_domain() so that a failure to set up the monitoring domain still undoes the control domain.

No functional change intended.

---
 drivers/resctrl/mpam_resctrl.c | 116 ++++++++++++++++++++-------------
 1 file changed, 70 insertions(+), 46 deletions(-)
drivers/resctrl/mpam_resctrl.c +44 -0
index dc442851fd7e..246560247a28 100644
@@ -1615,13 +1615,77 @@ static struct mpam_component *find_component(struct mpam_class *class, int cpu)
 	return NULL;
 }
 
+static int mpam_resctrl_setup_ctrl_domain(unsigned int cpu,
+					  struct rdt_resource *r,
+					  struct mpam_component *comp,
+					  struct mpam_resctrl_dom *dom)
+{
+	struct rdt_ctrl_domain *ctrl_d = &dom->resctrl_ctrl_dom;
+	int err;
+
+	dom->ctrl_comp = comp;
+
+	mpam_resctrl_domain_hdr_init(cpu, comp, r->rid, &ctrl_d->hdr);
+	ctrl_d->hdr.type = RESCTRL_CTRL_DOMAIN;
+	err = resctrl_online_ctrl_domain(r, ctrl_d);
+	if (err)
+		return err;
+
+	mpam_resctrl_domain_insert(&r->ctrl_domains, &ctrl_d->hdr);
+
+	return 0;
+}
+
+static int mpam_resctrl_setup_mon_domain(unsigned int cpu,
+					 struct rdt_resource *r,
+					 struct mpam_resctrl_dom *dom)
+{
+	struct rdt_l3_mon_domain *mon_d = &dom->resctrl_mon_dom;
+	struct mpam_component *any_mon_comp = NULL;
+	enum resctrl_event_id eventid;
+	struct mpam_resctrl_mon *mon;
+	int err;
+
+	/*
+	 * Even if the monitor domain is backed by a different
+	 * component, the L3 component IDs need to be used... only
+	 * there may be no ctrl_comp for the L3.
+	 * Search each event's class list for a component with
+	 * overlapping CPUs and set up the dom->mon_comp array.
+	 */
+
+	for_each_mpam_resctrl_mon(mon, eventid) {
+		struct mpam_component *mon_comp;
+
+		if (!mon->class)
+			continue;       // dummy resource

drivers/resctrl/mpam_resctrl.c static struct mpam_component *find_component(struct mpam_class *class, int cpu) · line 1671

Quoted 10 lines
drivers/resctrl/mpam_resctrl.c +10 -0
+
+		mon_comp = find_component(mon->class, cpu);
+		dom->mon_comp[eventid] = mon_comp;
+		if (mon_comp)
+			any_mon_comp = mon_comp;
+	}
+	if (!any_mon_comp) {
+		WARN_ON_ONCE(0);
+		return -EFAULT;
+	}

If you squash the the warning patch into patch 3 as I suggest there then this copy needs to change too (of course).

Thanks,

Ben

Quoted 93 lines
drivers/resctrl/mpam_resctrl.c +16 -46
+
+	mpam_resctrl_domain_hdr_init(cpu, any_mon_comp, r->rid, &mon_d->hdr);
+	mon_d->hdr.type = RESCTRL_MON_DOMAIN;
+	err = resctrl_online_mon_domain(r, &mon_d->hdr);
+	if (err)
+		return err;
+
+	mpam_resctrl_domain_insert(&r->mon_domains, &mon_d->hdr);
+
+	return 0;
+}
+
 static void mpam_resctrl_alloc_domain(unsigned int cpu,
 				      struct mpam_resctrl_res *res)
 {
 	int err;
 	struct mpam_resctrl_dom *dom;
-	struct rdt_l3_mon_domain *mon_d;
-	struct rdt_ctrl_domain *ctrl_d;
 	struct mpam_class *class = res->class;
 	struct mpam_component *comp;
 	struct rdt_resource *r = &res->resctrl_res;
@@ -1638,57 +1702,17 @@ static void mpam_resctrl_alloc_domain(unsigned int cpu,
 		return;
 
 	if (r->alloc_capable) {
-		dom->ctrl_comp = comp;
-
-		ctrl_d = &dom->resctrl_ctrl_dom;
-		mpam_resctrl_domain_hdr_init(cpu, comp, r->rid, &ctrl_d->hdr);
-		ctrl_d->hdr.type = RESCTRL_CTRL_DOMAIN;
-		err = resctrl_online_ctrl_domain(r, ctrl_d);
+		err = mpam_resctrl_setup_ctrl_domain(cpu, r, comp, dom);
 		if (err)
 			goto free_domain;
-
-		mpam_resctrl_domain_insert(&r->ctrl_domains, &ctrl_d->hdr);
 	} else {
 		pr_debug("Skipped control domain online - no controls\n");
 	}
 
 	if (r->mon_capable) {
-		struct mpam_component *any_mon_comp = NULL;
-		struct mpam_resctrl_mon *mon;
-		enum resctrl_event_id eventid;
-
-		/*
-		 * Even if the monitor domain is backed by a different
-		 * component, the L3 component IDs need to be used... only
-		 * there may be no ctrl_comp for the L3.
-		 * Search each event's class list for a component with
-		 * overlapping CPUs and set up the dom->mon_comp array.
-		 */
-
-		for_each_mpam_resctrl_mon(mon, eventid) {
-			struct mpam_component *mon_comp;
-
-			if (!mon->class)
-				continue;       // dummy resource
-
-			mon_comp = find_component(mon->class, cpu);
-			dom->mon_comp[eventid] = mon_comp;
-			if (mon_comp)
-				any_mon_comp = mon_comp;
-		}
-		if (!any_mon_comp) {
-			WARN_ON_ONCE(0);
-			goto offline_ctrl_domain;
-		}
-
-		mon_d = &dom->resctrl_mon_dom;
-		mpam_resctrl_domain_hdr_init(cpu, any_mon_comp, r->rid, &mon_d->hdr);
-		mon_d->hdr.type = RESCTRL_MON_DOMAIN;
-		err = resctrl_online_mon_domain(r, &mon_d->hdr);
+		err = mpam_resctrl_setup_mon_domain(cpu, r, dom);
 		if (err)
 			goto offline_ctrl_domain;
-
-		mpam_resctrl_domain_insert(&r->mon_domains, &mon_d->hdr);
 	} else {
 		pr_debug("Skipped monitor domain online - no monitors\n");
 	}
@@ -1697,8 +1721,8 @@ static void mpam_resctrl_alloc_domain(unsigned int cpu,
 
 offline_ctrl_domain:
 	if (r->alloc_capable) {
-		mpam_resctrl_offline_domain_hdr(cpu, &ctrl_d->hdr);
-		resctrl_offline_ctrl_domain(r, ctrl_d);
+		mpam_resctrl_offline_domain_hdr(cpu, &dom->resctrl_ctrl_dom.hdr);
+		resctrl_offline_ctrl_domain(r, &dom->resctrl_ctrl_dom);
 	}
 free_domain:
 	kfree(dom);
author reviewer
#22 lore raw

RFC PATCH v2 5/10 arm_mpam: resctrl: Give the monitoring domain its own structure

In reply to Reinette Chatre

One structure holds both the control domain and the monitoring domain of a resource. The two domains are allocated together when the first CPU of the domain comes online and freed together once both have lost their last CPU. A failure to set up the monitoring domain undoes the control domain.

Apart from the code that manages domains, nothing uses both domains of the structure. Keeping them in one structure nevertheless ties each control domain to a monitoring domain, which does not fit supporting multiple controls per resource.

Move the monitoring domain and its components into a new structure, struct mpam_resctrl_mon_dom. Manage control and monitoring domains separately when CPUs come online and go offline: look up, set up, and tear down each domain on its own and free it once it has lost its last CPU.

Do not let a failure to set up one type of domain affect the other. Keep a control domain that was set up when setting up the monitoring domain for the same CPU fails, and set up the monitoring domain even when setting up the control domain fails. This is consistent with domain setup failures not failing CPU online: only domains that were set up are exposed through resctrl.

Look for a component of the resource's class that contains the CPU only when setting up a control domain, since that component backs the control domain. Setting up a monitoring domain already fails if no monitoring class has a component for the CPU.

Look up monitoring domains by L3 cache ID on all systems, as was already done on systems without controls. Monitoring domain IDs are always those of the L3, so this finds the same domain as looking it up through its control domain did.

Drop the debug messages about resources without controls or monitors. They reported which of the two domains in the shared structure was left unused, which no longer applies now that each domain type has its own structure.

---
 drivers/resctrl/mpam_internal.h |   5 +-
 drivers/resctrl/mpam_resctrl.c  | 226 ++++++++++++++++----------------
 2 files changed, 117 insertions(+), 114 deletions(-)
drivers/resctrl/mpam_internal.h +3 -2
index 84c7adbb1a40..1df439ecb055 100644
@@ -434,15 +434,16 @@ struct mpam_msc_ris {
 
 struct mpam_resctrl_dom {
 	struct mpam_component		*ctrl_comp;
+	struct rdt_ctrl_domain		resctrl_ctrl_dom;
+};
 
+struct mpam_resctrl_mon_dom {
 	/*
 	 * There is no single mon_comp because different events may be backed
 	 * by different class/components. mon_comp is indexed by the event
 	 * number.
 	 */
 	struct mpam_component		*mon_comp[QOS_NUM_EVENTS];
-
-	struct rdt_ctrl_domain		resctrl_ctrl_dom;
 	struct rdt_l3_mon_domain	resctrl_mon_dom;
 };
 
drivers/resctrl/mpam_resctrl.c +114 -112

317 lines not on this page · raw message

Signature · 1 line
2.55.0
Reviewed-by on v2 5/10
#23 lore raw

Re: [RFC PATCH v2 05/10] arm_mpam: resctrl: Give the monitoring domain its own structure

Quoted 100 lines · Reinette Chatre

One structure holds both the control domain and the monitoring domain of a resource. The two domains are allocated together when the first CPU of the domain comes online and freed together once both have lost their last CPU. A failure to set up the monitoring domain undoes the control domain.

Apart from the code that manages domains, nothing uses both domains of the structure. Keeping them in one structure nevertheless ties each control domain to a monitoring domain, which does not fit supporting multiple controls per resource.

Move the monitoring domain and its components into a new structure, struct mpam_resctrl_mon_dom. Manage control and monitoring domains separately when CPUs come online and go offline: look up, set up, and tear down each domain on its own and free it once it has lost its last CPU.

Do not let a failure to set up one type of domain affect the other. Keep a control domain that was set up when setting up the monitoring domain for the same CPU fails, and set up the monitoring domain even when setting up the control domain fails. This is consistent with domain setup failures not failing CPU online: only domains that were set up are exposed through resctrl.

Look for a component of the resource's class that contains the CPU only when setting up a control domain, since that component backs the control domain. Setting up a monitoring domain already fails if no monitoring class has a component for the CPU.

Look up monitoring domains by L3 cache ID on all systems, as was already done on systems without controls. Monitoring domain IDs are always those of the L3, so this finds the same domain as looking it up through its control domain did.

Drop the debug messages about resources without controls or monitors. They reported which of the two domains in the shared structure was left unused, which no longer applies now that each domain type has its own structure.

---
 drivers/resctrl/mpam_internal.h |   5 +-
 drivers/resctrl/mpam_resctrl.c  | 226 ++++++++++++++++----------------
 2 files changed, 117 insertions(+), 114 deletions(-)
drivers/resctrl/mpam_internal.h +3 -2
index 84c7adbb1a40..1df439ecb055 100644
@@ -434,15 +434,16 @@ struct mpam_msc_ris {
 
 struct mpam_resctrl_dom {
 	struct mpam_component		*ctrl_comp;
+	struct rdt_ctrl_domain		resctrl_ctrl_dom;
+};
 
+struct mpam_resctrl_mon_dom {
 	/*
 	 * There is no single mon_comp because different events may be backed
 	 * by different class/components. mon_comp is indexed by the event
 	 * number.
 	 */
 	struct mpam_component		*mon_comp[QOS_NUM_EVENTS];
-
-	struct rdt_ctrl_domain		resctrl_ctrl_dom;
 	struct rdt_l3_mon_domain	resctrl_mon_dom;
 };
 
drivers/resctrl/mpam_resctrl.c +3 -3
index 246560247a28..ce5519635c51 100644
@@ -510,7 +510,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,
 			   u32 closid, u32 rmid, enum resctrl_event_id eventid,
 			   void *arch_priv, u64 *val, void *arch_mon_ctx)
 {
-	struct mpam_resctrl_dom *l3_dom;
+	struct mpam_resctrl_mon_dom *l3_dom;
 	struct mpam_component *mon_comp;
 	u32 mon_idx = *(u32 *)arch_mon_ctx;
 	enum mpam_device_features mon_type;
@@ -524,7 +524,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,
 	if (eventid >= QOS_NUM_EVENTS || !mon->class)
 		return -EINVAL;
 
-	l3_dom = container_of(hdr, struct mpam_resctrl_dom, resctrl_mon_dom.hdr);
+	l3_dom = container_of(hdr, struct mpam_resctrl_mon_dom, resctrl_mon_dom.hdr);
 	mon_comp = l3_dom->mon_comp[eventid];
 
 	if (eventid != QOS_L3_OCCUP_EVENT_ID)
@@ -542,7 +542,7 @@ int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
 			   enum resctrl_event_id eventid, u64 *val)
 {
 	struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
-	struct mpam_resctrl_dom *l3_dom;
+	struct mpam_resctrl_mon_dom *l3_dom;
 	struct mpam_component *mon_comp;
 
 	if (!mpam_is_enabled())

drivers/resctrl/mpam_resctrl.c int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d, · line 555

Quoted 6 lines
drivers/resctrl/mpam_resctrl.c +1 -1
@@ -551,7 +551,7 @@ int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
 	if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class)
 		return -EINVAL;
 
-	l3_dom = container_of(d, struct mpam_resctrl_dom, resctrl_mon_dom);
+	l3_dom = container_of(d, struct mpam_resctrl_mon_dom, resctrl_mon_dom);
 	mon_comp = l3_dom->mon_comp[eventid];

Maybe following code could be extracted into a helper

553 >-------if (!mpam_is_enabled())
554 >------->-------return -EINVAL;
555
556 >-------if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class) 557 >------->-------return -EINVAL;
558
559 >-------l3_dom = container_of(d, struct mpam_resctrl_dom,
resctrl_mon_dom);
560 >-------mon_comp = l3_dom->mon_comp[eventid];

Quoted 106 lines
drivers/resctrl/mpam_resctrl.c +6 -53
 	return read_mon_cdp_safe(mon, mon_comp, mpam_feat_msmon_mbwu,
@@ -599,7 +599,7 @@ void resctrl_arch_reset_cntr(struct rdt_resource *r, struct rdt_l3_mon_domain *d
 			     enum resctrl_event_id eventid)
 {
 	struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
-	struct mpam_resctrl_dom *l3_dom;
+	struct mpam_resctrl_mon_dom *l3_dom;
 	struct mpam_component *mon_comp;
 
 	if (!mpam_is_enabled())
@@ -608,7 +608,7 @@ void resctrl_arch_reset_cntr(struct rdt_resource *r, struct rdt_l3_mon_domain *d
 	if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class)
 		return;
 
-	l3_dom = container_of(d, struct mpam_resctrl_dom, resctrl_mon_dom);
+	l3_dom = container_of(d, struct mpam_resctrl_mon_dom, resctrl_mon_dom);
 	mon_comp = l3_dom->mon_comp[eventid];
 
 	reset_mon_cdp_safe(mon, mon_comp, USE_PRE_ALLOCATED, closid, rmid);
@@ -1638,7 +1638,7 @@ static int mpam_resctrl_setup_ctrl_domain(unsigned int cpu,
 
 static int mpam_resctrl_setup_mon_domain(unsigned int cpu,
 					 struct rdt_resource *r,
-					 struct mpam_resctrl_dom *dom)
+					 struct mpam_resctrl_mon_dom *dom)
 {
 	struct rdt_l3_mon_domain *mon_d = &dom->resctrl_mon_dom;
 	struct mpam_component *any_mon_comp = NULL;
@@ -1681,53 +1681,6 @@ static int mpam_resctrl_setup_mon_domain(unsigned int cpu,
 	return 0;
 }
 
-static void mpam_resctrl_alloc_domain(unsigned int cpu,
-				      struct mpam_resctrl_res *res)
-{
-	int err;
-	struct mpam_resctrl_dom *dom;
-	struct mpam_class *class = res->class;
-	struct mpam_component *comp;
-	struct rdt_resource *r = &res->resctrl_res;
-
-	lockdep_assert_held(&domain_list_lock);
-
-	comp = find_component(class, cpu);
-	/* class has no component for this CPU */
-	if (WARN_ON_ONCE(!comp))
-		return;
-
-	dom = kzalloc_node(sizeof(*dom), GFP_KERNEL, cpu_to_node(cpu));
-	if (!dom)
-		return;
-
-	if (r->alloc_capable) {
-		err = mpam_resctrl_setup_ctrl_domain(cpu, r, comp, dom);
-		if (err)
-			goto free_domain;
-	} else {
-		pr_debug("Skipped control domain online - no controls\n");
-	}
-
-	if (r->mon_capable) {
-		err = mpam_resctrl_setup_mon_domain(cpu, r, dom);
-		if (err)
-			goto offline_ctrl_domain;
-	} else {
-		pr_debug("Skipped monitor domain online - no monitors\n");
-	}
-
-	return;
-
-offline_ctrl_domain:
-	if (r->alloc_capable) {
-		mpam_resctrl_offline_domain_hdr(cpu, &dom->resctrl_ctrl_dom.hdr);
-		resctrl_offline_ctrl_domain(r, &dom->resctrl_ctrl_dom);
-	}
-free_domain:
-	kfree(dom);
-}
-
 /*
  * We know all the monitors are associated with the L3, even if there are no
  * controls and therefore no control component. Find the cache-id for the CPU
@@ -1735,10 +1688,10 @@ static void mpam_resctrl_alloc_domain(unsigned int cpu,
  * This relies on mpam_resctrl_pick_domain_id() using the L3 cache-id
  * for anything that is not a cache.
  */
-static struct mpam_resctrl_dom *mpam_resctrl_get_mon_domain_from_cpu(int cpu)
+static struct mpam_resctrl_mon_dom *mpam_resctrl_get_mon_domain_from_cpu(int cpu)
 {
 	int cache_id;
-	struct mpam_resctrl_dom *dom;
+	struct mpam_resctrl_mon_dom *dom;
 	struct mpam_resctrl_res *l3 = &mpam_resctrl_controls[RDT_RESOURCE_L3];
 
 	lockdep_assert_cpus_held();
@@ -1758,7 +1711,7 @@ static struct mpam_resctrl_dom *mpam_resctrl_get_mon_domain_from_cpu(int cpu)
 }
 
 static struct mpam_resctrl_dom *
-mpam_resctrl_get_domain_from_cpu(int cpu, struct mpam_resctrl_res *res)
+mpam_resctrl_get_ctrl_domain_from_cpu(int cpu, struct mpam_resctrl_res *res)
 {
 	struct mpam_resctrl_dom *dom;
 	struct rdt_resource *r = &res->resctrl_res;

drivers/resctrl/mpam_resctrl.c mpam_resctrl_get_domain_from_cpu(int cpu, struct mpam_resctrl_res *res) · line 1726

Quoted 6 lines
drivers/resctrl/mpam_resctrl.c +1 -2
@@ -1770,11 +1723,97 @@ mpam_resctrl_get_domain_from_cpu(int cpu, struct mpam_resctrl_res *res)
 			return dom;
 	}
 
-	if (r->rid != RDT_RESOURCE_L3)
-		return NULL;
+	return NULL;

LGTM

Quoted 184 lines
drivers/resctrl/mpam_resctrl.c +103 -53
+}
+
+static void mpam_resctrl_add_cpu_ctrl_domain(unsigned int cpu,
+					     struct mpam_resctrl_res *res)
+{
+	struct rdt_resource *r = &res->resctrl_res;
+	struct mpam_resctrl_dom *dom;
+	struct mpam_component *comp;
+
+	lockdep_assert_held(&domain_list_lock);
+
+	dom = mpam_resctrl_get_ctrl_domain_from_cpu(cpu, res);
+	if (dom) {
+		mpam_resctrl_online_domain_hdr(cpu, &dom->resctrl_ctrl_dom.hdr);
+		return;
+	}
+
+	comp = find_component(res->class, cpu);
+	/* class has no component for this CPU */
+	if (WARN_ON_ONCE(!comp))
+		return;
+
+	dom = kzalloc_node(sizeof(*dom), GFP_KERNEL, cpu_to_node(cpu));
+	if (!dom)
+		return;
 
-	/* Search the mon domain list too - needed on monitor only platforms. */
-	return mpam_resctrl_get_mon_domain_from_cpu(cpu);
+	if (mpam_resctrl_setup_ctrl_domain(cpu, r, comp, dom))
+		kfree(dom);
+}
+
+static void mpam_resctrl_add_cpu_mon_domain(unsigned int cpu,
+					    struct mpam_resctrl_res *res)
+{
+	struct rdt_resource *r = &res->resctrl_res;
+	struct mpam_resctrl_mon_dom *dom;
+
+	lockdep_assert_held(&domain_list_lock);
+
+	dom = mpam_resctrl_get_mon_domain_from_cpu(cpu);
+	if (dom) {
+		mpam_resctrl_online_domain_hdr(cpu, &dom->resctrl_mon_dom.hdr);
+		return;
+	}
+
+	dom = kzalloc_node(sizeof(*dom), GFP_KERNEL, cpu_to_node(cpu));
+	if (!dom)
+		return;
+
+	if (mpam_resctrl_setup_mon_domain(cpu, r, dom))
+		kfree(dom);
+}
+
+static void mpam_resctrl_remove_cpu_ctrl_domain(unsigned int cpu,
+						struct mpam_resctrl_res *res)
+{
+	struct rdt_resource *r = &res->resctrl_res;
+	struct mpam_resctrl_dom *dom;
+
+	lockdep_assert_held(&domain_list_lock);
+
+	/* The domain may be missing if its setup failed. */
+	dom = mpam_resctrl_get_ctrl_domain_from_cpu(cpu, res);
+	if (!dom)
+		return;
+
+	if (!mpam_resctrl_offline_domain_hdr(cpu, &dom->resctrl_ctrl_dom.hdr))
+		return;
+
+	resctrl_offline_ctrl_domain(r, &dom->resctrl_ctrl_dom);
+	kfree(dom);
+}
+
+static void mpam_resctrl_remove_cpu_mon_domain(unsigned int cpu,
+					       struct mpam_resctrl_res *res)
+{
+	struct rdt_resource *r = &res->resctrl_res;
+	struct mpam_resctrl_mon_dom *dom;
+
+	lockdep_assert_held(&domain_list_lock);
+
+	/* The domain may be missing if its setup failed. */
+	dom = mpam_resctrl_get_mon_domain_from_cpu(cpu);
+	if (!dom)
+		return;
+
+	if (!mpam_resctrl_offline_domain_hdr(cpu, &dom->resctrl_mon_dom.hdr))
+		return;
+
+	resctrl_offline_mon_domain(r, &dom->resctrl_mon_dom.hdr);
+	kfree(dom);
 }
 
 void mpam_resctrl_online_cpu(unsigned int cpu)
@@ -1784,33 +1823,21 @@ void mpam_resctrl_online_cpu(unsigned int cpu)
 
 	guard(mutex)(&domain_list_lock);
 	for_each_mpam_resctrl_control(res, rid) {
-		struct mpam_resctrl_dom *dom;
 		struct rdt_resource *r = &res->resctrl_res;
 
 		if (!res->class)
 			continue;	// dummy_resource;
 
-		dom = mpam_resctrl_get_domain_from_cpu(cpu, res);
-		if (!dom) {
-			/*
-			 * On failure the CPU is left without a domain for this
-			 * resource, which mpam_resctrl_offline_cpu() tolerates.
-			 * resctrl_online_cpu() still adds the CPU to the default
-			 * group because the CPU is online and runs tasks.
-			 */
-			mpam_resctrl_alloc_domain(cpu, res);
-		} else {
-			if (r->alloc_capable) {
-				struct rdt_ctrl_domain *ctrl_d = &dom->resctrl_ctrl_dom;
-
-				mpam_resctrl_online_domain_hdr(cpu, &ctrl_d->hdr);
-			}
-			if (r->mon_capable) {
-				struct rdt_l3_mon_domain *mon_d = &dom->resctrl_mon_dom;
-
-				mpam_resctrl_online_domain_hdr(cpu, &mon_d->hdr);
-			}
-		}
+		/*
+		 * A domain that fails to be set up leaves the CPU without that
+		 * domain, which mpam_resctrl_offline_cpu() tolerates.
+		 * resctrl_online_cpu() still adds the CPU to the default group
+		 * because the CPU is online and runs tasks.
+		 */
+		if (r->alloc_capable)
+			mpam_resctrl_add_cpu_ctrl_domain(cpu, res);
+		if (r->mon_capable)
+			mpam_resctrl_add_cpu_mon_domain(cpu, res);
 	}
 
 	resctrl_online_cpu(cpu);
@@ -1825,40 +1852,15 @@ void mpam_resctrl_offline_cpu(unsigned int cpu)
 
 	guard(mutex)(&domain_list_lock);
 	for_each_mpam_resctrl_control(res, rid) {
-		struct mpam_resctrl_dom *dom;
-		struct rdt_l3_mon_domain *mon_d;
-		struct rdt_ctrl_domain *ctrl_d;
-		bool ctrl_dom_empty, mon_dom_empty;
 		struct rdt_resource *r = &res->resctrl_res;
 
 		if (!res->class)
 			continue;	// dummy resource
 
-		/* The domain may be missing if its setup failed. */
-		dom = mpam_resctrl_get_domain_from_cpu(cpu, res);
-		if (!dom)
-			continue;
-
-		if (r->alloc_capable) {
-			ctrl_d = &dom->resctrl_ctrl_dom;
-			ctrl_dom_empty = mpam_resctrl_offline_domain_hdr(cpu, &ctrl_d->hdr);
-			if (ctrl_dom_empty)
-				resctrl_offline_ctrl_domain(&res->resctrl_res, ctrl_d);
-		} else {
-			ctrl_dom_empty = true;
-		}
-
-		if (r->mon_capable) {
-			mon_d = &dom->resctrl_mon_dom;
-			mon_dom_empty = mpam_resctrl_offline_domain_hdr(cpu, &mon_d->hdr);
-			if (mon_dom_empty)
-				resctrl_offline_mon_domain(&res->resctrl_res, &mon_d->hdr);
-		} else {
-			mon_dom_empty = true;
-		}
-
-		if (ctrl_dom_empty && mon_dom_empty)
-			kfree(dom);
+		if (r->alloc_capable)
+			mpam_resctrl_remove_cpu_ctrl_domain(cpu, res);
+		if (r->mon_capable)
+			mpam_resctrl_remove_cpu_mon_domain(cpu, res);
 	}
 }
 
Signature · 2 lines
Best regards,
Jinjie
author reviewer
#24 lore raw

Re: [RFC PATCH v2 05/10] arm_mpam: resctrl: Give the monitoring domain its own structure

Hi Jinjie,

Quoted 1 line · Jinjie Ruan

在 2026/10/20 6:07, Reinette Chatre 写道:

...

Quoted 4 lines
Quoted 4 lines
drivers/resctrl/mpam_resctrl.c +0 -0
index 246560247a28..ce5519635c51 100644

...

Quoted 19 lines
Quoted 10 lines
drivers/resctrl/mpam_resctrl.c +1 -1
@@ -542,7 +542,7 @@ int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
 			   enum resctrl_event_id eventid, u64 *val)
 {
 	struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
-	struct mpam_resctrl_dom *l3_dom;
+	struct mpam_resctrl_mon_dom *l3_dom;
 	struct mpam_component *mon_comp;
 
 	if (!mpam_is_enabled())

drivers/resctrl/mpam_resctrl.c int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d, · line 555

Quoted 6 lines
drivers/resctrl/mpam_resctrl.c +1 -1
@@ -551,7 +551,7 @@ int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
 	if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class)
 		return -EINVAL;
 
-	l3_dom = container_of(d, struct mpam_resctrl_dom, resctrl_mon_dom);
+	l3_dom = container_of(d, struct mpam_resctrl_mon_dom, resctrl_mon_dom);
 	mon_comp = l3_dom->mon_comp[eventid];

Maybe following code could be extracted into a helper

Quoted 10 lines

553 >-------if (!mpam_is_enabled())
554 >------->-------return -EINVAL;
555
556 >-------if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class) 557 >------->-------return -EINVAL;
558
559 >-------l3_dom = container_of(d, struct mpam_resctrl_dom,
resctrl_mon_dom);
560 >-------mon_comp = l3_dom->mon_comp[eventid];

Below shows an example of such helper created (for convenience) on top of this series. Only compile tested. Is this what you had in mind? If it looks ok I will rebase to the beginning of this series as a new preparatory patch since it refactors code adjacent to this series.

---8<---

 drivers/resctrl/mpam_resctrl.c | 62 ++++++++++++++++++++++------------
 1 file changed, 41 insertions(+), 21 deletions(-)
drivers/resctrl/mpam_resctrl.c +41 -21
index 61fbde9c0960..d75954f8a0ad 100644
@@ -7,6 +7,7 @@
 #include <linux/cacheinfo.h>
 #include <linux/cpu.h>
 #include <linux/cpumask.h>
+#include <linux/err.h>
 #include <linux/errno.h>
 #include <linux/limits.h>
 #include <linux/list.h>
@@ -536,26 +537,51 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,
 				 closid, rmid, val);
 }
 
-/* MBWU counters when in ABMC mode */
-int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
-			   u32 closid, u32 rmid, int mon_idx,
-			   enum resctrl_event_id eventid, u64 *val)
+/**
+ * find_mbwu_mon_comp() - Find the component counting @eventid in a domain
+ * @d:		The monitoring domain to search.
+ * @eventid:	The event to find the counting component for.
+ *
+ * The counters reached through this component are the monitors MPAM
+ * pre-allocated for bandwidth counting. Cache occupancy is not counted by
+ * those monitors, it is read on demand via resctrl_arch_rmid_read().
+ *
+ * Return: the component counting @eventid in @d, or an error pointer when
+ * MPAM is disabled, when @eventid is cache occupancy, or when no class was
+ * picked to count @eventid.
+ */
+static struct mpam_component *find_mbwu_mon_comp(struct rdt_l3_mon_domain *d,
+						 enum resctrl_event_id eventid)
 {
-	struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
 	struct mpam_resctrl_mon_dom *l3_dom;
-	struct mpam_component *mon_comp;
+	struct mpam_resctrl_mon *mon;
 
 	if (!mpam_is_enabled())
-		return -EINVAL;
+		return ERR_PTR(-EINVAL);
 
+	mon = &mpam_resctrl_counters[eventid];
 	if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class)
-		return -EINVAL;
+		return ERR_PTR(-EINVAL);
 
 	l3_dom = container_of(d, struct mpam_resctrl_mon_dom, resctrl_mon_dom);
-	mon_comp = l3_dom->mon_comp[eventid];
 
-	return read_mon_cdp_safe(mon, mon_comp, mpam_feat_msmon_mbwu,
-				 USE_PRE_ALLOCATED, closid, rmid, val);
+	return l3_dom->mon_comp[eventid];
+}
+
+/* MBWU counters when in ABMC mode */
+int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
+			   u32 closid, u32 rmid, int mon_idx,
+			   enum resctrl_event_id eventid, u64 *val)
+{
+	struct mpam_component *mon_comp;
+
+	mon_comp = find_mbwu_mon_comp(d, eventid);
+	if (IS_ERR(mon_comp))
+		return PTR_ERR(mon_comp);
+
+	return read_mon_cdp_safe(&mpam_resctrl_counters[eventid], mon_comp,
+				 mpam_feat_msmon_mbwu, USE_PRE_ALLOCATED,
+				 closid, rmid, val);
 }
 
 static void __reset_mon(struct mpam_resctrl_mon *mon, struct mpam_component *mon_comp,
@@ -598,20 +624,14 @@ void resctrl_arch_reset_cntr(struct rdt_resource *r, struct rdt_l3_mon_domain *d
 			     u32 closid, u32 rmid, int cntr_id,
 			     enum resctrl_event_id eventid)
 {
-	struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
-	struct mpam_resctrl_mon_dom *l3_dom;
 	struct mpam_component *mon_comp;
 
-	if (!mpam_is_enabled())
-		return;
-
-	if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class)
+	mon_comp = find_mbwu_mon_comp(d, eventid);
+	if (IS_ERR(mon_comp))
 		return;
 
-	l3_dom = container_of(d, struct mpam_resctrl_mon_dom, resctrl_mon_dom);
-	mon_comp = l3_dom->mon_comp[eventid];
-
-	reset_mon_cdp_safe(mon, mon_comp, USE_PRE_ALLOCATED, closid, rmid);
+	reset_mon_cdp_safe(&mpam_resctrl_counters[eventid], mon_comp,
+			   USE_PRE_ALLOCATED, closid, rmid);
 }
 
 /*

---8<---

Quoted 11 lines

drivers/resctrl/mpam_resctrl.c mpam_resctrl_get_domain_from_cpu(int cpu, struct mpam_resctrl_res *res) · line 1726

Quoted 7 lines
drivers/resctrl/mpam_resctrl.c +1 -2
@@ -1770,11 +1723,97 @@ mpam_resctrl_get_domain_from_cpu(int cpu, struct mpam_resctrl_res *res)
 			return dom;
 	}
 
-	if (r->rid != RDT_RESOURCE_L3)
-		return NULL;
+	return NULL;

LGTM

Thank you very much.

Reinette

#25 lore raw

Re: [RFC PATCH v2 05/10] arm_mpam: resctrl: Give the monitoring domain its own structure

Quoted 44 lines · Reinette Chatre

Hi Jinjie,

Quoted 1 line · Jinjie Ruan

在 2026/10/20 6:07, Reinette Chatre 写道:

...

Quoted 4 lines
Quoted 4 lines
drivers/resctrl/mpam_resctrl.c +0 -0
index 246560247a28..ce5519635c51 100644

...

Quoted 19 lines
Quoted 10 lines
drivers/resctrl/mpam_resctrl.c +1 -1
@@ -542,7 +542,7 @@ int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
 			   enum resctrl_event_id eventid, u64 *val)
 {
 	struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
-	struct mpam_resctrl_dom *l3_dom;
+	struct mpam_resctrl_mon_dom *l3_dom;
 	struct mpam_component *mon_comp;
 
 	if (!mpam_is_enabled())

drivers/resctrl/mpam_resctrl.c int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d, · line 555

Quoted 6 lines
drivers/resctrl/mpam_resctrl.c +1 -1
@@ -551,7 +551,7 @@ int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
 	if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class)
 		return -EINVAL;
 
-	l3_dom = container_of(d, struct mpam_resctrl_dom, resctrl_mon_dom);
+	l3_dom = container_of(d, struct mpam_resctrl_mon_dom, resctrl_mon_dom);
 	mon_comp = l3_dom->mon_comp[eventid];

Maybe following code could be extracted into a helper

Quoted 10 lines

553 >-------if (!mpam_is_enabled())
554 >------->-------return -EINVAL;
555
556 >-------if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class) 557 >------->-------return -EINVAL;
558
559 >-------l3_dom = container_of(d, struct mpam_resctrl_dom,
resctrl_mon_dom);
560 >-------mon_comp = l3_dom->mon_comp[eventid];

Quoted 4 lines

Below shows an example of such helper created (for convenience) on top of this series. Only compile tested. Is this what you had in mind? If it looks ok I will rebase to the beginning of this series as a new preparatory patch since it refactors code adjacent to this series.

Right. It looks fine to me. resctrl_arch_rmid_read() seems a little different.

Quoted 121 lines

---8<---

 drivers/resctrl/mpam_resctrl.c | 62 ++++++++++++++++++++++------------
 1 file changed, 41 insertions(+), 21 deletions(-)
drivers/resctrl/mpam_resctrl.c +41 -22
index 61fbde9c0960..d75954f8a0ad 100644
@@ -7,6 +7,7 @@
 #include <linux/cacheinfo.h>
 #include <linux/cpu.h>
 #include <linux/cpumask.h>
+#include <linux/err.h>
 #include <linux/errno.h>
 #include <linux/limits.h>
 #include <linux/list.h>
@@ -536,26 +537,51 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,
 				 closid, rmid, val);
 }
 
-/* MBWU counters when in ABMC mode */
-int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
-			   u32 closid, u32 rmid, int mon_idx,
-			   enum resctrl_event_id eventid, u64 *val)
+/**
+ * find_mbwu_mon_comp() - Find the component counting @eventid in a domain
+ * @d:		The monitoring domain to search.
+ * @eventid:	The event to find the counting component for.
+ *
+ * The counters reached through this component are the monitors MPAM
+ * pre-allocated for bandwidth counting. Cache occupancy is not counted by
+ * those monitors, it is read on demand via resctrl_arch_rmid_read().
+ *
+ * Return: the component counting @eventid in @d, or an error pointer when
+ * MPAM is disabled, when @eventid is cache occupancy, or when no class was
+ * picked to count @eventid.
+ */
+static struct mpam_component *find_mbwu_mon_comp(struct rdt_l3_mon_domain *d,
+						 enum resctrl_event_id eventid)
 {
-	struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
 	struct mpam_resctrl_mon_dom *l3_dom;
-	struct mpam_component *mon_comp;
+	struct mpam_resctrl_mon *mon;
 
 	if (!mpam_is_enabled())
-		return -EINVAL;
+		return ERR_PTR(-EINVAL);
 
+	mon = &mpam_resctrl_counters[eventid];
 	if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class)
-		return -EINVAL;
+		return ERR_PTR(-EINVAL);
 
 	l3_dom = container_of(d, struct mpam_resctrl_mon_dom, resctrl_mon_dom);
-	mon_comp = l3_dom->mon_comp[eventid];
 
-	return read_mon_cdp_safe(mon, mon_comp, mpam_feat_msmon_mbwu,
-				 USE_PRE_ALLOCATED, closid, rmid, val);
+	return l3_dom->mon_comp[eventid];
+}
+
+/* MBWU counters when in ABMC mode */
+int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
+			   u32 closid, u32 rmid, int mon_idx,
+			   enum resctrl_event_id eventid, u64 *val)
+{
+	struct mpam_component *mon_comp;
+
+	mon_comp = find_mbwu_mon_comp(d, eventid);
+	if (IS_ERR(mon_comp))
+		return PTR_ERR(mon_comp);
+
+	return read_mon_cdp_safe(&mpam_resctrl_counters[eventid], mon_comp,
+				 mpam_feat_msmon_mbwu, USE_PRE_ALLOCATED,
+				 closid, rmid, val);
 }
 
 static void __reset_mon(struct mpam_resctrl_mon *mon, struct mpam_component *mon_comp,
@@ -598,20 +624,14 @@ void resctrl_arch_reset_cntr(struct rdt_resource *r, struct rdt_l3_mon_domain *d
 			     u32 closid, u32 rmid, int cntr_id,
 			     enum resctrl_event_id eventid)
 {
-	struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
-	struct mpam_resctrl_mon_dom *l3_dom;
 	struct mpam_component *mon_comp;
 
-	if (!mpam_is_enabled())
-		return;
-
-	if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class)
+	mon_comp = find_mbwu_mon_comp(d, eventid);
+	if (IS_ERR(mon_comp))
 		return;
 
-	l3_dom = container_of(d, struct mpam_resctrl_mon_dom, resctrl_mon_dom);
-	mon_comp = l3_dom->mon_comp[eventid];
-
-	reset_mon_cdp_safe(mon, mon_comp, USE_PRE_ALLOCATED, closid, rmid);
+	reset_mon_cdp_safe(&mpam_resctrl_counters[eventid], mon_comp,
+			   USE_PRE_ALLOCATED, closid, rmid);
 }
 
 /*
---8<--- 
Quoted 5 lines
Quoted 5 lines
drivers/resctrl/mpam_resctrl.c +0 -0
@@ -1770,11 +1723,97 @@ mpam_resctrl_get_domain_from_cpu(int cpu, struct mpam_resctrl_res *res)
 			return dom;
 	}
 
Quoted 7 lines

drivers/resctrl/mpam_resctrl.c mpam_resctrl_get_domain_from_cpu(int cpu, struct mpam_resctrl_res *res) · line 1726

Quoted 3 lines
drivers/resctrl/mpam_resctrl.c +1 -2
-	if (r->rid != RDT_RESOURCE_L3)
-		return NULL;
+	return NULL;

LGTM

Thank you very much.

Reinette

Signature · 2 lines
Best regards,
Jinjie
author reviewer
#26 lore raw

RFC PATCH v2 6/10 arm_mpam: resctrl: Rename struct mpam_resctrl_dom to mpam_resctrl_ctrl_dom

In reply to Reinette Chatre

struct mpam_resctrl_dom holds the control domain of a resource, while its monitoring domain is held by struct mpam_resctrl_mon_dom. Unlike the name of the monitoring structure, the name struct mpam_resctrl_dom does not say which kind of domain the structure holds.

Rename it to struct mpam_resctrl_ctrl_dom to match its monitoring counterpart.

No functional change.

---
 drivers/resctrl/mpam_internal.h |  2 +-
 drivers/resctrl/mpam_resctrl.c  | 18 +++++++++---------
 2 files changed, 10 insertions(+), 10 deletions(-)
drivers/resctrl/mpam_internal.h +1 -1
index 1df439ecb055..dc304e4e0dc0 100644
@@ -432,7 +432,7 @@ struct mpam_msc_ris {
 	struct mpam_garbage	garbage;
 };
 
-struct mpam_resctrl_dom {
+struct mpam_resctrl_ctrl_dom {
 	struct mpam_component		*ctrl_comp;
 	struct rdt_ctrl_domain		resctrl_ctrl_dom;
 };
drivers/resctrl/mpam_resctrl.c +9 -9
index ce5519635c51..022920be1862 100644
@@ -1375,7 +1375,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d,
 	struct mpam_config *cfg;
 	struct mpam_props *cprops;
 	struct mpam_resctrl_res *res;
-	struct mpam_resctrl_dom *dom;
+	struct mpam_resctrl_ctrl_dom *dom;
 	enum mpam_device_features configured_by;
 
 	lockdep_assert_cpus_held();
@@ -1384,7 +1384,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d,
 		return resctrl_get_default_ctrl(r);
 
 	res = container_of(r, struct mpam_resctrl_res, resctrl_res);
-	dom = container_of(d, struct mpam_resctrl_dom, resctrl_ctrl_dom);
+	dom = container_of(d, struct mpam_resctrl_ctrl_dom, resctrl_ctrl_dom);
 	cprops = &res->class->props;
 
 	/*
@@ -1435,7 +1435,7 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d,
 	struct mpam_config cfg;
 	struct mpam_props *cprops;
 	struct mpam_resctrl_res *res;
-	struct mpam_resctrl_dom *dom;
+	struct mpam_resctrl_ctrl_dom *dom;
 
 	lockdep_assert_cpus_held();
 	lockdep_assert_irqs_enabled();
@@ -1448,7 +1448,7 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d,
 	 * resctrl_arch_update_domains() relies on this.
 	 */
 	res = container_of(r, struct mpam_resctrl_res, resctrl_res);
-	dom = container_of(d, struct mpam_resctrl_dom, resctrl_ctrl_dom);
+	dom = container_of(d, struct mpam_resctrl_ctrl_dom, resctrl_ctrl_dom);
 	cprops = &res->class->props;
 
 	if (mpam_resctrl_hide_cdp(r->rid))
@@ -1618,7 +1618,7 @@ static struct mpam_component *find_component(struct mpam_class *class, int cpu)
 static int mpam_resctrl_setup_ctrl_domain(unsigned int cpu,
 					  struct rdt_resource *r,
 					  struct mpam_component *comp,
-					  struct mpam_resctrl_dom *dom)
+					  struct mpam_resctrl_ctrl_dom *dom)
 {
 	struct rdt_ctrl_domain *ctrl_d = &dom->resctrl_ctrl_dom;
 	int err;
@@ -1710,10 +1710,10 @@ static struct mpam_resctrl_mon_dom *mpam_resctrl_get_mon_domain_from_cpu(int cpu
 	return NULL;
 }
 
-static struct mpam_resctrl_dom *
+static struct mpam_resctrl_ctrl_dom *
 mpam_resctrl_get_ctrl_domain_from_cpu(int cpu, struct mpam_resctrl_res *res)
 {
-	struct mpam_resctrl_dom *dom;
+	struct mpam_resctrl_ctrl_dom *dom;
 	struct rdt_resource *r = &res->resctrl_res;
 
 	lockdep_assert_cpus_held();
@@ -1730,7 +1730,7 @@ static void mpam_resctrl_add_cpu_ctrl_domain(unsigned int cpu,
 					     struct mpam_resctrl_res *res)
 {
 	struct rdt_resource *r = &res->resctrl_res;
-	struct mpam_resctrl_dom *dom;
+	struct mpam_resctrl_ctrl_dom *dom;
 	struct mpam_component *comp;
 
 	lockdep_assert_held(&domain_list_lock);
@@ -1780,7 +1780,7 @@ static void mpam_resctrl_remove_cpu_ctrl_domain(unsigned int cpu,
 						struct mpam_resctrl_res *res)
 {
 	struct rdt_resource *r = &res->resctrl_res;
-	struct mpam_resctrl_dom *dom;
+	struct mpam_resctrl_ctrl_dom *dom;
 
 	lockdep_assert_held(&domain_list_lock);
 
Signature · 1 line
2.55.0
Reviewed-by on v2 6/10
#27 lore raw

Re: [RFC PATCH v2 06/10] arm_mpam: resctrl: Rename struct mpam_resctrl_dom to mpam_resctrl_ctrl_dom

Quoted 9 lines · Reinette Chatre

struct mpam_resctrl_dom holds the control domain of a resource, while its monitoring domain is held by struct mpam_resctrl_mon_dom. Unlike the name of the monitoring structure, the name struct mpam_resctrl_dom does not say which kind of domain the structure holds.

Rename it to struct mpam_resctrl_ctrl_dom to match its monitoring counterpart.

No functional change.

LGTM

Quoted 100 lines
---
 drivers/resctrl/mpam_internal.h |  2 +-
 drivers/resctrl/mpam_resctrl.c  | 18 +++++++++---------
 2 files changed, 10 insertions(+), 10 deletions(-)
drivers/resctrl/mpam_internal.h +1 -1
index 1df439ecb055..dc304e4e0dc0 100644
@@ -432,7 +432,7 @@ struct mpam_msc_ris {
 	struct mpam_garbage	garbage;
 };
 
-struct mpam_resctrl_dom {
+struct mpam_resctrl_ctrl_dom {
 	struct mpam_component		*ctrl_comp;
 	struct rdt_ctrl_domain		resctrl_ctrl_dom;
 };
drivers/resctrl/mpam_resctrl.c +9 -9
index ce5519635c51..022920be1862 100644
@@ -1375,7 +1375,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d,
 	struct mpam_config *cfg;
 	struct mpam_props *cprops;
 	struct mpam_resctrl_res *res;
-	struct mpam_resctrl_dom *dom;
+	struct mpam_resctrl_ctrl_dom *dom;
 	enum mpam_device_features configured_by;
 
 	lockdep_assert_cpus_held();
@@ -1384,7 +1384,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d,
 		return resctrl_get_default_ctrl(r);
 
 	res = container_of(r, struct mpam_resctrl_res, resctrl_res);
-	dom = container_of(d, struct mpam_resctrl_dom, resctrl_ctrl_dom);
+	dom = container_of(d, struct mpam_resctrl_ctrl_dom, resctrl_ctrl_dom);
 	cprops = &res->class->props;
 
 	/*
@@ -1435,7 +1435,7 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d,
 	struct mpam_config cfg;
 	struct mpam_props *cprops;
 	struct mpam_resctrl_res *res;
-	struct mpam_resctrl_dom *dom;
+	struct mpam_resctrl_ctrl_dom *dom;
 
 	lockdep_assert_cpus_held();
 	lockdep_assert_irqs_enabled();
@@ -1448,7 +1448,7 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d,
 	 * resctrl_arch_update_domains() relies on this.
 	 */
 	res = container_of(r, struct mpam_resctrl_res, resctrl_res);
-	dom = container_of(d, struct mpam_resctrl_dom, resctrl_ctrl_dom);
+	dom = container_of(d, struct mpam_resctrl_ctrl_dom, resctrl_ctrl_dom);
 	cprops = &res->class->props;
 
 	if (mpam_resctrl_hide_cdp(r->rid))
@@ -1618,7 +1618,7 @@ static struct mpam_component *find_component(struct mpam_class *class, int cpu)
 static int mpam_resctrl_setup_ctrl_domain(unsigned int cpu,
 					  struct rdt_resource *r,
 					  struct mpam_component *comp,
-					  struct mpam_resctrl_dom *dom)
+					  struct mpam_resctrl_ctrl_dom *dom)
 {
 	struct rdt_ctrl_domain *ctrl_d = &dom->resctrl_ctrl_dom;
 	int err;
@@ -1710,10 +1710,10 @@ static struct mpam_resctrl_mon_dom *mpam_resctrl_get_mon_domain_from_cpu(int cpu
 	return NULL;
 }
 
-static struct mpam_resctrl_dom *
+static struct mpam_resctrl_ctrl_dom *
 mpam_resctrl_get_ctrl_domain_from_cpu(int cpu, struct mpam_resctrl_res *res)
 {
-	struct mpam_resctrl_dom *dom;
+	struct mpam_resctrl_ctrl_dom *dom;
 	struct rdt_resource *r = &res->resctrl_res;
 
 	lockdep_assert_cpus_held();
@@ -1730,7 +1730,7 @@ static void mpam_resctrl_add_cpu_ctrl_domain(unsigned int cpu,
 					     struct mpam_resctrl_res *res)
 {
 	struct rdt_resource *r = &res->resctrl_res;
-	struct mpam_resctrl_dom *dom;
+	struct mpam_resctrl_ctrl_dom *dom;
 	struct mpam_component *comp;
 
 	lockdep_assert_held(&domain_list_lock);
@@ -1780,7 +1780,7 @@ static void mpam_resctrl_remove_cpu_ctrl_domain(unsigned int cpu,
 						struct mpam_resctrl_res *res)
 {
 	struct rdt_resource *r = &res->resctrl_res;
-	struct mpam_resctrl_dom *dom;
+	struct mpam_resctrl_ctrl_dom *dom;
 
 	lockdep_assert_held(&domain_list_lock);
 
Signature · 2 lines
Best regards,
Jinjie
author reviewer
#28 lore raw

RFC PATCH v2 7/10 arm_mpam: resctrl: Warn when no monitoring component is found for a CPU

In reply to Reinette Chatre

Setting up a monitoring domain fails if no monitoring class has a component that contains the CPU. This is not expected to happen: a resource only supports monitoring when at least one monitoring class was picked, and only classes that cover all possible CPUs are picked for monitoring.

The failure path calls WARN_ON_ONCE(0), which never warns. The unexpected failure is thus silent and the CPU is left without a monitoring domain with nothing reporting why.

Warn when no monitoring component is found for the CPU, as is already done when setting up a control domain finds no component in the resource's class.

---
 drivers/resctrl/mpam_resctrl.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/resctrl/mpam_resctrl.c +1 -3
index 022920be1862..63c5bf45856d 100644
@@ -1665,10 +1665,8 @@ static int mpam_resctrl_setup_mon_domain(unsigned int cpu,
 		if (mon_comp)
 			any_mon_comp = mon_comp;
 	}
-	if (!any_mon_comp) {
-		WARN_ON_ONCE(0);
+	if (WARN_ON_ONCE(!any_mon_comp))
 		return -EFAULT;
-	}
 
 	mpam_resctrl_domain_hdr_init(cpu, any_mon_comp, r->rid, &mon_d->hdr);
 	mon_d->hdr.type = RESCTRL_MON_DOMAIN;
Signature · 1 line
2.55.0
Reviewed-by on v2 7/10
#29 lore raw

Re: [RFC PATCH v2 07/10] arm_mpam: resctrl: Warn when no monitoring component is found for a CPU

Quoted 24 lines · Reinette Chatre

Setting up a monitoring domain fails if no monitoring class has a component that contains the CPU. This is not expected to happen: a resource only supports monitoring when at least one monitoring class was picked, and only classes that cover all possible CPUs are picked for monitoring.

The failure path calls WARN_ON_ONCE(0), which never warns. The unexpected failure is thus silent and the CPU is left without a monitoring domain with nothing reporting why.

Warn when no monitoring component is found for the CPU, as is already done when setting up a control domain finds no component in the resource's class.

---
 drivers/resctrl/mpam_resctrl.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/resctrl/mpam_resctrl.c +0 -0
index 022920be1862..63c5bf45856d 100644

drivers/resctrl/mpam_resctrl.c static int mpam_resctrl_setup_mon_domain(unsigned int cpu, · line 1671

Quoted 8 lines
drivers/resctrl/mpam_resctrl.c +1 -3
@@ -1665,10 +1665,8 @@ static int mpam_resctrl_setup_mon_domain(unsigned int cpu,
 		if (mon_comp)
 			any_mon_comp = mon_comp;
 	}
-	if (!any_mon_comp) {
-		WARN_ON_ONCE(0);
+	if (WARN_ON_ONCE(!any_mon_comp))
 		return -EFAULT;
-	}
Quoted 3 lines
drivers/resctrl/mpam_resctrl.c +0 -0
 	mpam_resctrl_domain_hdr_init(cpu, any_mon_comp, r->rid, &mon_d->hdr);
 	mon_d->hdr.type = RESCTRL_MON_DOMAIN;
Signature · 2 lines
Best regards,
Jinjie
author reviewer
#30 lore raw

RFC PATCH v2 8/10 arm_mpam: resctrl: Require a component for each monitoring event

In reply to Reinette Chatre

Setting up a monitoring domain looks up, for each monitoring event, the component of the event's class that contains the CPU and records it in the domain. Reading and resetting the event's counters in the domain then use the recorded component.

If an event's class has no component for the CPU, the domain is still set up as long as another event's class has one, and the event is left without a component. Reading or resetting the event's counters in that domain then dereferences a NULL component. This is not expected to happen since only classes that cover all possible CPUs are picked for monitoring.

Fail setting up the monitoring domain, with a warning, if an event's class has no component for the CPU, so that every event of a monitoring domain has a component.

Keep the check that at least one component was found. It now only fails if no event has a class, and so captures that a resource that supports monitoring has at least one monitoring event with a class.

---
 drivers/resctrl/mpam_resctrl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/resctrl/mpam_resctrl.c +4 -2
index 63c5bf45856d..36a924734484 100644
@@ -1661,9 +1661,11 @@ static int mpam_resctrl_setup_mon_domain(unsigned int cpu,
 			continue;       // dummy resource
 
 		mon_comp = find_component(mon->class, cpu);
+		if (WARN_ON_ONCE(!mon_comp))
+			return -EFAULT;
+
 		dom->mon_comp[eventid] = mon_comp;
-		if (mon_comp)
-			any_mon_comp = mon_comp;
+		any_mon_comp = mon_comp;
 	}
 	if (WARN_ON_ONCE(!any_mon_comp))
 		return -EFAULT;
Signature · 1 line
2.55.0
maintainer Reviewed-by on v2 8/10
#31 lore raw

Re: [RFC PATCH v2 08/10] arm_mpam: resctrl: Require a component for each monitoring event

Hi Reinette,

Seems good to me.

Quoted 43 lines · Reinette Chatre

Setting up a monitoring domain looks up, for each monitoring event, the component of the event's class that contains the CPU and records it in the domain. Reading and resetting the event's counters in the domain then use the recorded component.

If an event's class has no component for the CPU, the domain is still set up as long as another event's class has one, and the event is left without a component. Reading or resetting the event's counters in that domain then dereferences a NULL component. This is not expected to happen since only classes that cover all possible CPUs are picked for monitoring.

Fail setting up the monitoring domain, with a warning, if an event's class has no component for the CPU, so that every event of a monitoring domain has a component.

Keep the check that at least one component was found. It now only fails if no event has a class, and so captures that a resource that supports monitoring has at least one monitoring event with a class.

---
 drivers/resctrl/mpam_resctrl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/resctrl/mpam_resctrl.c +4 -2
index 63c5bf45856d..36a924734484 100644
@@ -1661,9 +1661,11 @@ static int mpam_resctrl_setup_mon_domain(unsigned int cpu,
 			continue;       // dummy resource
 
 		mon_comp = find_component(mon->class, cpu);
+		if (WARN_ON_ONCE(!mon_comp))
+			return -EFAULT;
+
 		dom->mon_comp[eventid] = mon_comp;
-		if (mon_comp)
-			any_mon_comp = mon_comp;
+		any_mon_comp = mon_comp;
 	}
 	if (WARN_ON_ONCE(!any_mon_comp))
 		return -EFAULT;
author reviewer
#32 lore raw

RFC PATCH v2 9/10 arm_mpam: resctrl: Require monitoring components to cover the same CPUs

In reply to Reinette Chatre

A monitoring domain records the component that backs each of its monitoring events and takes its ID from one of these components. The domain represents the CPUs of one L3 cache, while each event's counters are read from the event's own component.

If the components of a monitoring domain covered different CPUs, the counts of an event would not belong to the CPUs that the domain represents. This is not expected to happen: every class picked for monitoring covers all CPUs and has components that correspond to the L3 caches.

Fail setting up the monitoring domain, with a warning, if the components backing its events do not all cover the same CPUs. Compare each component with the one found before it, instead of naming the events, so that the check applies to any monitoring event.

---
 drivers/resctrl/mpam_resctrl.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/resctrl/mpam_resctrl.c +6 -0
index 36a924734484..c3ea61a40bb2 100644
@@ -1664,6 +1664,12 @@ static int mpam_resctrl_setup_mon_domain(unsigned int cpu,
 		if (WARN_ON_ONCE(!mon_comp))
 			return -EFAULT;
 
+		/* All components of a monitoring domain cover the same CPUs */
+		if (WARN_ON_ONCE(any_mon_comp &&
+				 !cpumask_equal(&any_mon_comp->affinity,
+						&mon_comp->affinity)))
+			return -EFAULT;
+
 		dom->mon_comp[eventid] = mon_comp;
 		any_mon_comp = mon_comp;
 	}
Signature · 1 line
2.55.0
author reviewer
#33 lore raw

RFC PATCH v2 10/10 arm_mpam: resctrl: Update the comment on monitoring domain setup

In reply to Reinette Chatre

The comment in mpam_resctrl_setup_mon_domain() explains that the L3 component IDs need to be used for a monitoring domain because there may be no control component for the L3. It also describes searching each event's class for a component with overlapping CPUs.

Neither matches the code. The monitoring domain has its own structure and is set up independently of the control domain, so whether a control component exists has no bearing on it. Each event's class must have a component that contains the CPU, and all components of the domain must cover the same CPUs, which is stricter than overlapping.

Rewrite the comment to say where the domain's ID comes from and what is required of the components that back the domain's events.

No functional change.

---
Note to maintainers: This comment update is kept as a separate patch to make it easy to review. It can be folded into "arm_mpam: resctrl: Give the monitoring domain its own structure" and "arm_mpam: resctrl: Require monitoring components to cover the same CPUs" if preferred.

---
 drivers/resctrl/mpam_resctrl.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/resctrl/mpam_resctrl.c +6 -5
index c3ea61a40bb2..61fbde9c0960 100644
@@ -1647,11 +1647,12 @@ static int mpam_resctrl_setup_mon_domain(unsigned int cpu,
 	int err;
 
 	/*
-	 * Even if the monitor domain is backed by a different
-	 * component, the L3 component IDs need to be used... only
-	 * there may be no ctrl_comp for the L3.
-	 * Search each event's class list for a component with
-	 * overlapping CPUs and set up the dom->mon_comp array.
+	 * The monitoring domain takes the L3 cache ID as its ID even when its
+	 * events are backed by components of other classes, see
+	 * mpam_resctrl_pick_domain_id().
+	 * Find the component of each event's class that contains the CPU and
+	 * set up the dom->mon_comp array. All these components must cover the
+	 * same CPUs.
 	 */
 
 	for_each_mpam_resctrl_mon(mon, eventid) {
Signature · 1 line
2.55.0
maintainer
#34 lore raw

Re: [RFC PATCH v2 10/10] arm_mpam: resctrl: Update the comment on monitoring domain setup

Hi Reinette,

Quoted 14 lines · Reinette Chatre

The comment in mpam_resctrl_setup_mon_domain() explains that the L3 component IDs need to be used for a monitoring domain because there may be no control component for the L3. It also describes searching each event's class for a component with overlapping CPUs.

Neither matches the code. The monitoring domain has its own structure and is set up independently of the control domain, so whether a control component exists has no bearing on it. Each event's class must have a component that contains the CPU, and all components of the domain must cover the same CPUs, which is stricter than overlapping.

Rewrite the comment to say where the domain's ID comes from and what is required of the components that back the domain's events.

Quoted 8 lines

No functional change.

---
Note to maintainers: This comment update is kept as a separate patch to make it easy to review. It can be folded into "arm_mpam: resctrl: Give the monitoring domain its own structure" and "arm_mpam: resctrl: Require monitoring components to cover the same CPUs" if preferred.

Yes, I think squashing those 3 patches together would be good.

Thanks,

Ben

Quoted 26 lines
---
 drivers/resctrl/mpam_resctrl.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/resctrl/mpam_resctrl.c +6 -5
index c3ea61a40bb2..61fbde9c0960 100644
@@ -1647,11 +1647,12 @@ static int mpam_resctrl_setup_mon_domain(unsigned int cpu,
 	int err;
 
 	/*
-	 * Even if the monitor domain is backed by a different
-	 * component, the L3 component IDs need to be used... only
-	 * there may be no ctrl_comp for the L3.
-	 * Search each event's class list for a component with
-	 * overlapping CPUs and set up the dom->mon_comp array.
+	 * The monitoring domain takes the L3 cache ID as its ID even when its
+	 * events are backed by components of other classes, see
+	 * mpam_resctrl_pick_domain_id().
+	 * Find the component of each event's class that contains the CPU and
+	 * set up the dom->mon_comp array. All these components must cover the
+	 * same CPUs.
 	 */
 
 	for_each_mpam_resctrl_mon(mon, eventid) {
author reviewer
#35 lore raw

Re: [RFC PATCH v2 10/10] arm_mpam: resctrl: Update the comment on monitoring domain setup

Hi Ben,

Quoted 17 lines · Ben Horgan
Quoted 16 lines · Reinette Chatre

The comment in mpam_resctrl_setup_mon_domain() explains that the L3 component IDs need to be used for a monitoring domain because there may be no control component for the L3. It also describes searching each event's class for a component with overlapping CPUs.

Neither matches the code. The monitoring domain has its own structure and is set up independently of the control domain, so whether a control component exists has no bearing on it. Each event's class must have a component that contains the CPU, and all components of the domain must cover the same CPUs, which is stricter than overlapping.

Rewrite the comment to say where the domain's ID comes from and what is required of the components that back the domain's events.

No functional change.

Quoted 9 lines
Quoted 6 lines

---
Note to maintainers: This comment update is kept as a separate patch to make it easy to review. It can be folded into "arm_mpam: resctrl: Give the monitoring domain its own structure" and "arm_mpam: resctrl: Require monitoring components to cover the same CPUs" if preferred.

Yes, I think squashing those 3 patches together would be good.

Done. Since "arm_mpam: resctrl: Require monitoring components to cover the same CPUs" depends on "arm_mpam: resctrl: Require a component for each monitoring event" for which you provided RB separately I re-ordered "arm_mpam: resctrl: Require a component for each monitoring event" to be before "arm_mpam: resctrl: Give the monitoring domain its own structure" to support this squash.

At this point the next version of this series looks like:
arm_mpam: resctrl: Add a helper to find the component counting an event
arm_mpam: resctrl: Use find_component() when allocating a domain
arm_mpam: resctrl: Rename ctrl_comp in mpam_resctrl_alloc_domain()
arm_mpam: resctrl: Do not fail CPU online when domain setup fails
arm_mpam: resctrl: Split control and monitoring domain setup into helpers
arm_mpam: resctrl: Require a component for each monitoring event
arm_mpam: resctrl: Give the monitoring domain its own structure
arm_mpam: resctrl: Rename struct mpam_resctrl_dom to mpam_resctrl_ctrl_dom

Thank you very much for your review. Unless something shows up I plan to send the next version next week.

Reinette

maintainer
#36 lore raw
In reply to Reinette Chatre

Hi Reinette,

Quoted 43 lines · Reinette Chatre

RFC v1: https://lore.kernel.org/lkml/85ca29e89eacf12cfa7071249419e7cadb8f0691.1788220029.git.reinette.chatre@intel.com/

The MPAM driver represents a resctrl domain with a single structure, struct mpam_resctrl_dom, that holds both a control domain and a monitoring domain. On a system that supports both allocation and monitoring, one instance is created for each domain and its two domains are added to the resource's control and monitoring domain lists.

Holding both domains in one structure requires control and monitoring to be done at the same scope, and ties each control domain to a monitoring domain. This does not fit the proposed support for multiple controls per resource [1]. There, each control of a resource, for example a "min" and a "max" memory bandwidth control, has its own list of control domains while the resource keeps a single list of monitoring domains. With one structure for both, every control domain would come with a monitoring domain of its own, which does not reflect the resource.

This series gives control and monitoring domains their own structures, set up and torn down independently as CPUs come online and go offline, in preparation for supporting multiple controls per resource. Along the way it stops failing CPU online when a domain cannot be set up, and adds checks when setting up a monitoring domain.

  1-2   Preparatory cleanups of domain allocation
  3     Do not fail CPU online when domain setup fails
  4-6   Separate the control and monitoring domain structures
  7-9   Checks when setting up a monitoring domain
  10    Comment update, kept separate for review

An earlier version of the domain split was posted on its own [2]. This version incorporates the feedback from that discussion. It gives each type of domain its own structure instead of duplicating the shared one, sets up each domain independently instead of undoing one domain when setting up the other fails, and adds the checks in patches 8 and 9.

Patch 7 turns a WARN_ON_ONCE(0) into a warning that fires. It is a separate patch because it is not clear whether the silent failure was intended. If it was, the patch can instead drop the dead WARN_ON_ONCE().

Quoted 5 lines

This is an RFC because I am only able to compile test MPAM changes, which is also why the patches are small and each change is justified on its own. Patches can be squashed if preferred, for example patch 10 into patches 5 and 9. Testing on MPAM hardware would be greatly appreciated, as is any other feedback.

On an initial look through the patches everything seems sensible and in line with what we discussed previously. I've given it a quick sanity check on a couple of models and nothing goes wrong. Is there any particular shape of system needed to exercise corner cases? I'll try with monitor only systems and control only systems and do some more testing on real hardware as well.

Thank you very much for taking so much care over the MPAM side of things.

Ben

Quoted 30 lines

The series is based on the for-next/mpam branch of the arm64 tree:
git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/85ca29e89eacf12cfa7071249419e7cadb8f0691.1788220029.git.reinette.chatre@intel.com/

Reinette Chatre (10):
arm_mpam: resctrl: Use find_component() when allocating a domain
arm_mpam: resctrl: Rename ctrl_comp in mpam_resctrl_alloc_domain()
arm_mpam: resctrl: Do not fail CPU online when domain setup fails
arm_mpam: resctrl: Split control and monitoring domain setup into
helpers
arm_mpam: resctrl: Give the monitoring domain its own structure
arm_mpam: resctrl: Rename struct mpam_resctrl_dom to
mpam_resctrl_ctrl_dom
arm_mpam: resctrl: Warn when no monitoring component is found for a
CPU
arm_mpam: resctrl: Require a component for each monitoring event
arm_mpam: resctrl: Require monitoring components to cover the same
CPUs
arm_mpam: resctrl: Update the comment on monitoring domain setup

 drivers/resctrl/mpam_devices.c  |   2 +-
 drivers/resctrl/mpam_internal.h |  11 +-
 drivers/resctrl/mpam_resctrl.c  | 325 +++++++++++++++++---------------
 3 files changed, 181 insertions(+), 157 deletions(-)

base-commit: 8ea457f746d915d55f78b43d33b1cd618f3d93ad

author reviewer
#37 lore raw

Hi Ben,

Quoted 50 lines · Ben Horgan
Quoted 43 lines · Reinette Chatre

RFC v1: https://lore.kernel.org/lkml/85ca29e89eacf12cfa7071249419e7cadb8f0691.1788220029.git.reinette.chatre@intel.com/

The MPAM driver represents a resctrl domain with a single structure, struct mpam_resctrl_dom, that holds both a control domain and a monitoring domain. On a system that supports both allocation and monitoring, one instance is created for each domain and its two domains are added to the resource's control and monitoring domain lists.

Holding both domains in one structure requires control and monitoring to be done at the same scope, and ties each control domain to a monitoring domain. This does not fit the proposed support for multiple controls per resource [1]. There, each control of a resource, for example a "min" and a "max" memory bandwidth control, has its own list of control domains while the resource keeps a single list of monitoring domains. With one structure for both, every control domain would come with a monitoring domain of its own, which does not reflect the resource.

This series gives control and monitoring domains their own structures, set up and torn down independently as CPUs come online and go offline, in preparation for supporting multiple controls per resource. Along the way it stops failing CPU online when a domain cannot be set up, and adds checks when setting up a monitoring domain.

  1-2   Preparatory cleanups of domain allocation
  3     Do not fail CPU online when domain setup fails
  4-6   Separate the control and monitoring domain structures
  7-9   Checks when setting up a monitoring domain
  10    Comment update, kept separate for review

An earlier version of the domain split was posted on its own [2]. This version incorporates the feedback from that discussion. It gives each type of domain its own structure instead of duplicating the shared one, sets up each domain independently instead of undoing one domain when setting up the other fails, and adds the checks in patches 8 and 9.

Patch 7 turns a WARN_ON_ONCE(0) into a warning that fires. It is a separate patch because it is not clear whether the silent failure was intended. If it was, the patch can instead drop the dead WARN_ON_ONCE().

Quoted 5 lines

This is an RFC because I am only able to compile test MPAM changes, which is also why the patches are small and each change is justified on its own. Patches can be squashed if preferred, for example patch 10 into patches 5 and 9. Testing on MPAM hardware would be greatly appreciated, as is any other feedback.

Quoted 4 lines

On an initial look through the patches everything seems sensible and in line with what we discussed previously. I've given it a quick sanity check on a couple of models and nothing goes wrong. Is there any particular shape of system needed to exercise corner cases? I'll try with monitor only systems and control only systems and do some more testing on real hardware as well.

Thank you very much for considering this series. This is foundational to the support for multiple controls.

MPAM supports a variety of system shapes and this code made changes to most of the flows dealing with this variety. Any testing is appreciated. If possible, some scenarios that I find interesting:
- Even though you already mentioned monitor only system I would like to highlight that this is a shape of particular interest since this series no longer checks the res->class borrowed from the monitoring class and just relies on the monitoring classes themselves as we discussed during RFCv1.
- System where monitoring is from different class than the controls.
- System with L2 and L3 controls.

Shapes where multiple domains are possible are more interesting. If such testing is possible it would be great if _entire_ domain can be torn down and recreated with and without resctrl mounted (while keeping an eye on schemata file, mon_data contents, and info/ directories), ideally with as many as possible "Kernel Hacking" configuration options enabled.

Quoted 1 line

Thank you very much for taking so much care over the MPAM side of things.

You are welcome. I aimed to make the changes as small as possible but I understand this is disruptive to the MPAM design. After this lands, the remaining changes needed to support multiple controls look to be mostly mechanical.

Thank you very much for taking a look and all the testing you are doing.

Reinette

Tested-by on the v2 series
#38 lore raw
In reply to Reinette Chatre
Quoted 43 lines · Reinette Chatre

RFC v1: https://lore.kernel.org/lkml/85ca29e89eacf12cfa7071249419e7cadb8f0691.1788220029.git.reinette.chatre@intel.com/

The MPAM driver represents a resctrl domain with a single structure, struct mpam_resctrl_dom, that holds both a control domain and a monitoring domain. On a system that supports both allocation and monitoring, one instance is created for each domain and its two domains are added to the resource's control and monitoring domain lists.

Holding both domains in one structure requires control and monitoring to be done at the same scope, and ties each control domain to a monitoring domain. This does not fit the proposed support for multiple controls per resource [1]. There, each control of a resource, for example a "min" and a "max" memory bandwidth control, has its own list of control domains while the resource keeps a single list of monitoring domains. With one structure for both, every control domain would come with a monitoring domain of its own, which does not reflect the resource.

This series gives control and monitoring domains their own structures, set up and torn down independently as CPUs come online and go offline, in preparation for supporting multiple controls per resource. Along the way it stops failing CPU online when a domain cannot be set up, and adds checks when setting up a monitoring domain.

  1-2   Preparatory cleanups of domain allocation
  3     Do not fail CPU online when domain setup fails
  4-6   Separate the control and monitoring domain structures
  7-9   Checks when setting up a monitoring domain
  10    Comment update, kept separate for review

An earlier version of the domain split was posted on its own [2]. This version incorporates the feedback from that discussion. It gives each type of domain its own structure instead of duplicating the shared one, sets up each domain independently instead of undoing one domain when setting up the other fails, and adds the checks in patches 8 and 9.

Patch 7 turns a WARN_ON_ONCE(0) into a warning that fires. It is a separate patch because it is not clear whether the silent failure was intended. If it was, the patch can instead drop the dead WARN_ON_ONCE().

Quoted 5 lines

This is an RFC because I am only able to compile test MPAM changes, which is also why the patches are small and each change is justified on its own. Patches can be squashed if preferred, for example patch 10 into patches 5 and 9. Testing on MPAM hardware would be greatly appreciated, as is any other feedback.

Hi Reinette,

I tested it on a QEMU with MPAM rebased on v7.3-rc6 and all pass:

1、Resctrl mounts,L3/L2 each report 32 closids (control IDs) 2、Cache and memory bandwidth controls
3、Priority, min, max, option and hard-limit: write, read back, and the

emulated hardware shows the same value
4、CDP mode and usage/bandwidth counters
5、All builds pass without warnings: arm64/x86_64, debug on/off,
self-tests on/off, resctrl off, ACPI off

Test cases: https://github.com/ruanjinjie-eng/mpam_testcase/tree/qemu

Quoted 30 lines

The series is based on the for-next/mpam branch of the arm64 tree:
git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/85ca29e89eacf12cfa7071249419e7cadb8f0691.1788220029.git.reinette.chatre@intel.com/

Reinette Chatre (10):
arm_mpam: resctrl: Use find_component() when allocating a domain
arm_mpam: resctrl: Rename ctrl_comp in mpam_resctrl_alloc_domain()
arm_mpam: resctrl: Do not fail CPU online when domain setup fails
arm_mpam: resctrl: Split control and monitoring domain setup into
helpers
arm_mpam: resctrl: Give the monitoring domain its own structure
arm_mpam: resctrl: Rename struct mpam_resctrl_dom to
mpam_resctrl_ctrl_dom
arm_mpam: resctrl: Warn when no monitoring component is found for a
CPU
arm_mpam: resctrl: Require a component for each monitoring event
arm_mpam: resctrl: Require monitoring components to cover the same
CPUs
arm_mpam: resctrl: Update the comment on monitoring domain setup

 drivers/resctrl/mpam_devices.c  |   2 +-
 drivers/resctrl/mpam_internal.h |  11 +-
 drivers/resctrl/mpam_resctrl.c  | 325 +++++++++++++++++---------------
 3 files changed, 181 insertions(+), 157 deletions(-)

base-commit: 8ea457f746d915d55f78b43d33b1cd618f3d93ad

Signature · 2 lines
Best regards,
Jinjie
author reviewer
#39 lore raw

Hi Jinjie,

Quoted 60 lines · Jinjie Ruan
Quoted 43 lines · Reinette Chatre

RFC v1: https://lore.kernel.org/lkml/85ca29e89eacf12cfa7071249419e7cadb8f0691.1788220029.git.reinette.chatre@intel.com/

The MPAM driver represents a resctrl domain with a single structure, struct mpam_resctrl_dom, that holds both a control domain and a monitoring domain. On a system that supports both allocation and monitoring, one instance is created for each domain and its two domains are added to the resource's control and monitoring domain lists.

Holding both domains in one structure requires control and monitoring to be done at the same scope, and ties each control domain to a monitoring domain. This does not fit the proposed support for multiple controls per resource [1]. There, each control of a resource, for example a "min" and a "max" memory bandwidth control, has its own list of control domains while the resource keeps a single list of monitoring domains. With one structure for both, every control domain would come with a monitoring domain of its own, which does not reflect the resource.

This series gives control and monitoring domains their own structures, set up and torn down independently as CPUs come online and go offline, in preparation for supporting multiple controls per resource. Along the way it stops failing CPU online when a domain cannot be set up, and adds checks when setting up a monitoring domain.

  1-2   Preparatory cleanups of domain allocation
  3     Do not fail CPU online when domain setup fails
  4-6   Separate the control and monitoring domain structures
  7-9   Checks when setting up a monitoring domain
  10    Comment update, kept separate for review

An earlier version of the domain split was posted on its own [2]. This version incorporates the feedback from that discussion. It gives each type of domain its own structure instead of duplicating the shared one, sets up each domain independently instead of undoing one domain when setting up the other fails, and adds the checks in patches 8 and 9.

Patch 7 turns a WARN_ON_ONCE(0) into a warning that fires. It is a separate patch because it is not clear whether the silent failure was intended. If it was, the patch can instead drop the dead WARN_ON_ONCE().

Quoted 5 lines

This is an RFC because I am only able to compile test MPAM changes, which is also why the patches are small and each change is justified on its own. Patches can be squashed if preferred, for example patch 10 into patches 5 and 9. Testing on MPAM hardware would be greatly appreciated, as is any other feedback.

Hi Reinette,

I tested it on a QEMU with MPAM rebased on v7.3-rc6 and all pass:

1、Resctrl mounts,L3/L2 each report 32 closids (control IDs) 2、Cache and memory bandwidth controls
3、Priority, min, max, option and hard-limit: write, read back, and the

Quoted 8 lines

emulated hardware shows the same value
4、CDP mode and usage/bandwidth counters
5、All builds pass without warnings: arm64/x86_64, debug on/off,
self-tests on/off, resctrl off, ACPI off

Test cases: https://github.com/ruanjinjie-eng/mpam_testcase/tree/qemu

Thank you very much for this thorough testing. It is much appreciated.

Reinette