Skip to contentSkip to conversation

arm_mpam: Add KVM/arm64 and resctrl glue code

PATCH Superseded Ben Horgan 8 participants 73 messages Feb 24 – Mar 13

Subsystems (4)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Ben Horgan

author maintainer
#0 lore raw

v5 cover arm_mpam: Add KVM/arm64 and resctrl glue code

The main change in this version of the mpam missing pieces series is to update the cdp emulation to match the resctrl interface. L2 and L3 resources can now enable cdp separately. Cdp can't be hidden correctly for memory bandwidth allocation, as max per partid can't be emulated with more partids, and so we hide this completely when cdp is enabled. There is a little restructuring and a few smaller changes.

Changelogs in patches

It would be great to get this series merged this cycle. For that we'll need more testing and reviewing. Thanks!

From James' cover letter:

This is the missing piece to make MPAM usable resctrl in user-space. This has shed its debugfs code and the read/write 'event configuration' for the monitors to make the series smaller.

This adds the arch code and KVM support first. I anticipate the whole thing going via arm64, but if goes via tip instead, the an immutable branch with those patches should be easy to do.

Generally the resctrl glue code works by picking what MPAM features it can expose from the MPAM drive, then configuring the structs that back the resctrl helpers. If your platform is sufficiently Xeon shaped, you should be able to get L2/L3 CPOR bitmaps exposed via resctrl. CSU counters work if they are on/after the L3. MBWU counters are considerably more hairy, and depend on hueristics around the topology, and a bunch of stuff trying to emulate ABMC.
If it didn't pick what you wanted it to, please share the debug messages produced when enabling dynamic debug and booting with:
| dyndbg="file mpam_resctrl.c +pl"

I've not found a platform that can test all the behaviours around the monitors, so this is where I'd expect the most bugs.

The MPAM spec that describes all the system and MMIO registers can be found here:
https://developer.arm.com/documentation/ddi0598/db/?lang=en
(Ignored the 'RETIRED' warning - that is just arm moving the documentation around.
This document has the best overview)

Based on v7.0-rc1

The series can be retrieved from:
https://gitlab.arm.com/linux-arm/linux-bh.git mpam_resctrl_glue_v5

v4 can be found at:
https://lore.kernel.org/linux-arm-kernel/[email protected]/

v3 can be found at:
https://lore.kernel.org/linux-arm-kernel/[email protected]/

v2 can be found at:
https://lore.kernel.org/linux-arm-kernel/[email protected]/

rfc can be found at:
https://lore.kernel.org/linux-arm-kernel/[email protected]/

Ben Horgan (11):
arm64/sysreg: Add MPAMSM_EL1 register
KVM: arm64: Preserve host MPAM configuration when changing traps
KVM: arm64: Make MPAMSM_EL1 accesses UNDEF
arm64: mpam: Drop the CONFIG_EXPERT restriction
arm64: mpam: Initialise and context switch the MPAMSM_EL1 register
KVM: arm64: Use kernel-space partid configuration for hypercalls
arm_mpam: resctrl: Add rmid index helpers
arm_mpam: resctrl: Add kunit test for rmid idx conversions
arm_mpam: resctrl: Wait for cacheinfo to be ready
arm_mpam: resctrl: Add monitor initialisation and domain boilerplate
arm64: mpam: Add initial MPAM documentation

Dave Martin (2):
arm_mpam: resctrl: Convert to/from MPAMs fixed-point formats
arm_mpam: resctrl: Add kunit test for control format conversions

James Morse (24):
arm64: mpam: Context switch the MPAM registers
arm64: mpam: Re-initialise MPAM regs when CPU comes online
arm64: mpam: Advertise the CPUs MPAM limits to the driver
arm64: mpam: Add cpu_pm notifier to restore MPAM sysregs
arm64: mpam: Add helpers to change a task or cpu's MPAM PARTID/PMG
values
KVM: arm64: Force guest EL1 to use user-space's partid configuration
arm_mpam: resctrl: Add boilerplate cpuhp and domain allocation
arm_mpam: resctrl: Pick the caches we will use as resctrl resources
arm_mpam: resctrl: Implement resctrl_arch_reset_all_ctrls()
arm_mpam: resctrl: Add resctrl_arch_get_config()
arm_mpam: resctrl: Implement helpers to update configuration
arm_mpam: resctrl: Add plumbing against arm64 task and cpu hooks
arm_mpam: resctrl: Add CDP emulation
arm_mpam: resctrl: Add support for 'MB' resource
arm_mpam: resctrl: Add support for csu counters
arm_mpam: resctrl: Pick classes for use as mbm counters
arm_mpam: resctrl: Pre-allocate free running monitors
arm_mpam: resctrl: Allow resctrl to allocate monitors
arm_mpam: resctrl: Add resctrl_arch_rmid_read() and
resctrl_arch_reset_rmid()
arm_mpam: resctrl: Update the rmid reallocation limit
arm_mpam: resctrl: Add empty definitions for assorted resctrl
functions
arm64: mpam: Select ARCH_HAS_CPU_RESCTRL
arm_mpam: resctrl: Call resctrl_init() on platforms that can support
resctrl
arm_mpam: Quirk CMN-650's CSU NRDY behaviour

Shanker Donthineni (4):
arm_mpam: Add quirk framework
arm_mpam: Add workaround for T241-MPAM-1
arm_mpam: Add workaround for T241-MPAM-4
arm_mpam: Add workaround for T241-MPAM-6

 Documentation/arch/arm64/index.rst          |    1 +
 Documentation/arch/arm64/mpam.rst           |   94 +
 Documentation/arch/arm64/silicon-errata.rst |    9 +
 arch/arm64/Kconfig                          |    6 +-
 arch/arm64/include/asm/el2_setup.h          |    3 +-
 arch/arm64/include/asm/mpam.h               |   96 +
 arch/arm64/include/asm/resctrl.h            |    2 +
 arch/arm64/include/asm/thread_info.h        |    3 +
 arch/arm64/kernel/Makefile                  |    1 +
 arch/arm64/kernel/cpufeature.c              |   21 +-
 arch/arm64/kernel/mpam.c                    |   62 +
 arch/arm64/kernel/process.c                 |    7 +
 arch/arm64/kvm/hyp/include/hyp/switch.h     |   12 +-
 arch/arm64/kvm/hyp/nvhe/hyp-main.c          |    9 +
 arch/arm64/kvm/hyp/vhe/sysreg-sr.c          |   16 +
 arch/arm64/kvm/sys_regs.c                   |    2 +
 arch/arm64/tools/sysreg                     |    8 +
 drivers/resctrl/Kconfig                     |    9 +-
 drivers/resctrl/Makefile                    |    1 +
 drivers/resctrl/mpam_devices.c              |  257 ++-
 drivers/resctrl/mpam_internal.h             |  105 +-
 drivers/resctrl/mpam_resctrl.c              | 1875 +++++++++++++++++++
 drivers/resctrl/test_mpam_resctrl.c         |  364 ++++
 include/linux/arm_mpam.h                    |   32 +
 24 files changed, 2968 insertions(+), 27 deletions(-)
 create mode 100644 Documentation/arch/arm64/mpam.rst
 create mode 100644 arch/arm64/include/asm/mpam.h
 create mode 100644 arch/arm64/include/asm/resctrl.h
 create mode 100644 arch/arm64/kernel/mpam.c
 create mode 100644 drivers/resctrl/mpam_resctrl.c
 create mode 100644 drivers/resctrl/test_mpam_resctrl.c
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH v5 1/41 arm64/sysreg: Add MPAMSM_EL1 register

The MPAMSM_EL1 register determines the MPAM configuration for an SMCU. Add the register definition.

---
 arch/arm64/tools/sysreg | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm64/tools/sysreg +8 -0
index 9d1c21108057..1287cb1de6f3 100644
@@ -5172,6 +5172,14 @@ Field	31:16	PARTID_D
 Field	15:0	PARTID_I
 EndSysreg
 
+Sysreg	MPAMSM_EL1	3	0	10	5	3
+Res0	63:48
+Field	47:40	PMG_D
+Res0	39:32
+Field	31:16	PARTID_D
+Res0	15:0
+EndSysreg
+
 Sysreg	ISR_EL1	3	0	12	1	0
 Res0	63:11
 Field	10	IS
Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH v5 2/41 KVM: arm64: Preserve host MPAM configuration when changing traps

In reply to Ben Horgan

When kvm enables or disables MPAM traps to EL2 it clears all other bits in MPAM2_EL2. Notably, it clears the partition ids (PARTIDs) and performance monitoring groups (PMGs). Avoid changing these bits in anticipation of adding support for MPAM in the kernel. Otherwise, on a VHE system with the host running at EL2 where MPAM2_EL2 and MPAM1_EL1 access the same register, any attempt to use MPAM to monitor or partition resources for kernel space would be foiled by running a KVM guest. Additionally, MPAM2_EL2.EnMPAMSM is always set to 0 which causes MPAMSM_EL1 to always trap. Keep EnMPAMSM set to 1 when not in a guest so that the kernel can use MPAMSM_EL1.

---
 arch/arm64/kvm/hyp/include/hyp/switch.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
arch/arm64/kvm/hyp/include/hyp/switch.h +8 -4
index 2597e8bda867..0b50ddd530f3 100644
@@ -267,7 +267,8 @@ static inline void __deactivate_traps_hfgxtr(struct kvm_vcpu *vcpu)
 
 static inline void  __activate_traps_mpam(struct kvm_vcpu *vcpu)
 {
-	u64 r = MPAM2_EL2_TRAPMPAM0EL1 | MPAM2_EL2_TRAPMPAM1EL1;
+	u64 clr = MPAM2_EL2_EnMPAMSM;
+	u64 set = MPAM2_EL2_TRAPMPAM0EL1 | MPAM2_EL2_TRAPMPAM1EL1;
 
 	if (!system_supports_mpam())
 		return;
@@ -277,18 +278,21 @@ static inline void  __activate_traps_mpam(struct kvm_vcpu *vcpu)
 		write_sysreg_s(MPAMHCR_EL2_TRAP_MPAMIDR_EL1, SYS_MPAMHCR_EL2);
 	} else {
 		/* From v1.1 TIDR can trap MPAMIDR, set it unconditionally */
-		r |= MPAM2_EL2_TIDR;
+		set |= MPAM2_EL2_TIDR;
 	}
 
-	write_sysreg_s(r, SYS_MPAM2_EL2);
+	sysreg_clear_set_s(SYS_MPAM2_EL2, clr, set);
 }
 
 static inline void __deactivate_traps_mpam(void)
 {
+	u64 clr = MPAM2_EL2_TRAPMPAM0EL1 | MPAM2_EL2_TRAPMPAM1EL1 | MPAM2_EL2_TIDR;
+	u64 set = MPAM2_EL2_EnMPAMSM;
+
 	if (!system_supports_mpam())
 		return;
 
-	write_sysreg_s(0, SYS_MPAM2_EL2);
+	sysreg_clear_set_s(SYS_MPAM2_EL2, clr, set);
 
 	if (system_supports_mpam_hcr())
 		write_sysreg_s(MPAMHCR_HOST_FLAGS, SYS_MPAMHCR_EL2);
Signature · 1 line
2.43.0
maintainer Acked-by on v5 2/41
#3 lore raw

Re: [PATCH v5 02/41] KVM: arm64: Preserve host MPAM configuration when changing traps

Quoted 2 lines · Ben Horgan

When kvm enables or disables MPAM traps to EL2 it clears all other bits in

nit: s/kvm/KVM/g

Quoted 50 lines

MPAM2_EL2. Notably, it clears the partition ids (PARTIDs) and performance monitoring groups (PMGs). Avoid changing these bits in anticipation of adding support for MPAM in the kernel. Otherwise, on a VHE system with the host running at EL2 where MPAM2_EL2 and MPAM1_EL1 access the same register, any attempt to use MPAM to monitor or partition resources for kernel space would be foiled by running a KVM guest. Additionally, MPAM2_EL2.EnMPAMSM is always set to 0 which causes MPAMSM_EL1 to always trap. Keep EnMPAMSM set to 1 when not in a guest so that the kernel can use MPAMSM_EL1.

---
 arch/arm64/kvm/hyp/include/hyp/switch.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
arch/arm64/kvm/hyp/include/hyp/switch.h +5 -3
index 2597e8bda867..0b50ddd530f3 100644
@@ -267,7 +267,8 @@ static inline void __deactivate_traps_hfgxtr(struct kvm_vcpu *vcpu)
 
 static inline void  __activate_traps_mpam(struct kvm_vcpu *vcpu)
 {
-	u64 r = MPAM2_EL2_TRAPMPAM0EL1 | MPAM2_EL2_TRAPMPAM1EL1;
+	u64 clr = MPAM2_EL2_EnMPAMSM;
+	u64 set = MPAM2_EL2_TRAPMPAM0EL1 | MPAM2_EL2_TRAPMPAM1EL1;
 
 	if (!system_supports_mpam())
 		return;
@@ -277,18 +278,21 @@ static inline void  __activate_traps_mpam(struct kvm_vcpu *vcpu)
 		write_sysreg_s(MPAMHCR_EL2_TRAP_MPAMIDR_EL1, SYS_MPAMHCR_EL2);
 	} else {
 		/* From v1.1 TIDR can trap MPAMIDR, set it unconditionally */
-		r |= MPAM2_EL2_TIDR;
+		set |= MPAM2_EL2_TIDR;
 	}
 
-	write_sysreg_s(r, SYS_MPAM2_EL2);
+	sysreg_clear_set_s(SYS_MPAM2_EL2, clr, set);
 }
 
 static inline void __deactivate_traps_mpam(void)
 {
+	u64 clr = MPAM2_EL2_TRAPMPAM0EL1 | MPAM2_EL2_TRAPMPAM1EL1 | MPAM2_EL2_TIDR;

arch/arm64/kvm/hyp/include/hyp/switch.h static inline void __activate_traps_mpam(struct kvm_vcpu *vcpu) · line 298

Quoted 10 lines
arch/arm64/kvm/hyp/include/hyp/switch.h +3 -1
+	u64 set = MPAM2_EL2_EnMPAMSM;
+
 	if (!system_supports_mpam())
 		return;
 
-	write_sysreg_s(0, SYS_MPAM2_EL2);
+	sysreg_clear_set_s(SYS_MPAM2_EL2, clr, set);
 
 	if (system_supports_mpam_hcr())
 		write_sysreg_s(MPAMHCR_HOST_FLAGS, SYS_MPAMHCR_EL2);
	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author maintainer
#4 lore raw

PATCH v5 3/41 KVM: arm64: Make MPAMSM_EL1 accesses UNDEF

In reply to Ben Horgan

The MPAMSM_EL1 controls the MPAM labeling for an SMCU, Streaming Mode Compute Unit. As there is on MPAM support in kvm, make sure MPAMSM_EL1 accesses trigger an UNDEF.

---
Changes since v2:
Remove paragraph from commit on allowed range of values

---
 arch/arm64/kvm/sys_regs.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/kvm/sys_regs.c +2 -0
index a7cd0badc20c..2c9a52e66fe0 100644
@@ -3373,6 +3373,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {
 
 	{ SYS_DESC(SYS_MPAM1_EL1), undef_access },
 	{ SYS_DESC(SYS_MPAM0_EL1), undef_access },
+	{ SYS_DESC(SYS_MPAMSM_EL1), undef_access },
+
 	{ SYS_DESC(SYS_VBAR_EL1), access_rw, reset_val, VBAR_EL1, 0 },
 	{ SYS_DESC(SYS_DISR_EL1), NULL, reset_val, DISR_EL1, 0 },
 
Signature · 1 line
2.43.0
maintainer Acked-by on v5 3/41
#5 lore raw

Re: [PATCH v5 03/41] KVM: arm64: Make MPAMSM_EL1 accesses UNDEF

Quoted 2 lines · Ben Horgan

The MPAMSM_EL1 controls the MPAM labeling for an SMCU, Streaming Mode

nit: The MPAMSM_EL1 *register* controls...

Quoted 1 line

Compute Unit. As there is on MPAM support in kvm, make sure MPAMSM_EL1

s/on/no/, s/kvm/KVM/.

Quoted 22 lines

accesses trigger an UNDEF.

---
Changes since v2:
Remove paragraph from commit on allowed range of values

---
 arch/arm64/kvm/sys_regs.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/kvm/sys_regs.c +0 -0
index a7cd0badc20c..2c9a52e66fe0 100644

arch/arm64/kvm/sys_regs.c static const struct sys_reg_desc sys_reg_descs[] = { · line 3380

Quoted 8 lines
arch/arm64/kvm/sys_regs.c +2 -0
@@ -3373,6 +3373,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {
 
 	{ SYS_DESC(SYS_MPAM1_EL1), undef_access },
 	{ SYS_DESC(SYS_MPAM0_EL1), undef_access },
+	{ SYS_DESC(SYS_MPAMSM_EL1), undef_access },
+
 	{ SYS_DESC(SYS_VBAR_EL1), access_rw, reset_val, VBAR_EL1, 0 },
 	{ SYS_DESC(SYS_DISR_EL1), NULL, reset_val, DISR_EL1, 0 },
 
	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author maintainer
#6 lore raw

PATCH v5 4/41 arm64: mpam: Context switch the MPAM registers

In reply to Ben Horgan

From: James Morse <[email protected]>

MPAM allows traffic in the SoC to be labeled by the OS, these labels are used to apply policy in caches and bandwidth regulators, and to monitor traffic in the SoC. The label is made up of a PARTID and PMG value. The x86 equivalent calls these CLOSID and RMID, but they don't map precisely.

MPAM has two CPU system registers that is used to hold the PARTID and PMG values that traffic generated at each exception level will use. These can be set per-task by the resctrl file system. (resctrl is the defacto interface for controlling this stuff).

Add a helper to switch this.

struct task_struct's separate CLOSID and RMID fields are insufficient to implement resctrl using MPAM, as resctrl can change the PARTID (CLOSID) and PMG (sort of like the RMID) separately. On x86, the rmid is an independent number, so a race that writes a mismatched closid and rmid into hardware is benign. On arm64, the pmg bits extend the partid.
(i.e. partid-5 has a pmg-0 that is not the same as partid-6's pmg-0). In this case, mismatching the values will 'dirty' a pmg value that resctrl believes is clean, and is not tracking with its 'limbo' code.

To avoid this, the partid and pmg are always read and written as a pair. This requires a new u64 field. In struct task_struct there are two u32, rmid and closid for the x86 case, but as we can't use them here do something else. Add this new field, mpam_partid_pmg, to struct thread_info to avoid adding more architecture specific code to struct task_struct. Always use READ_ONCE()/WRITE_ONCE() when accessing this field.

Resctrl allows a per-cpu 'default' value to be set, this overrides the values when scheduling a task in the default control-group, which has PARTID 0. The way 'code data prioritisation' gets emulated means the register value for the default group needs to be a variable.

The current system register value is kept in a per-cpu variable to avoid writing to the system register if the value isn't going to change. Writes to this register may reset the hardware state for regulating bandwidth.

Finally, there is no reason to context switch these registers unless there is a driver changing the values in struct task_struct. Hide the whole thing behind a static key. This also allows the driver to disable MPAM in response to errors reported by hardware. Move the existing static key to belong to the arch code, as in the future the MPAM driver may become a loadable module.

All this should depend on whether there is an MPAM driver, hide it behind CONFIG_ARM64_MPAM.

---
Changes since rfc:
CONFIG_MPAM -> CONFIG_ARM64_MPAM in commit message Remove extra DECLARE_STATIC_KEY_FALSE
Function name in comment, __mpam_sched_in() -> mpam_thread_switch() Remove unused headers
Expand comment (Jonathan)

Changes since v2:
Tidy up ifdefs

Changes since v3:
Always set MPAMEN for MPAM1_EL1 rather than relying on it being read only.

---
 arch/arm64/Kconfig                   |  2 +
 arch/arm64/include/asm/mpam.h        | 67 ++++++++++++++++++++++++++++
 arch/arm64/include/asm/thread_info.h |  3 ++
 arch/arm64/kernel/Makefile           |  1 +
 arch/arm64/kernel/mpam.c             | 13 ++++++
 arch/arm64/kernel/process.c          |  7 +++
 drivers/resctrl/mpam_devices.c       |  2 -
 drivers/resctrl/mpam_internal.h      |  4 +-
 8 files changed, 95 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm64/include/asm/mpam.h
 create mode 100644 arch/arm64/kernel/mpam.c
arch/arm64/Kconfig +2 -0
index 38dba5f7e4d2..ecaaca13a969 100644
@@ -2039,6 +2039,8 @@ config ARM64_MPAM
 
 	  MPAM is exposed to user-space via the resctrl pseudo filesystem.
 
+	  This option enables the extra context switch code.
+
 endmenu # "ARMv8.4 architectural features"
 
 menu "ARMv8.5 architectural features"
arch/arm64/include/asm/mpam.h new file +67 -0

67 lines not on this page · raw message

arch/arm64/include/asm/thread_info.h +3 -0
index 7942478e4065..5d7fe3e153c8 100644
@@ -41,6 +41,9 @@ struct thread_info {
 #ifdef CONFIG_SHADOW_CALL_STACK
 	void			*scs_base;
 	void			*scs_sp;
+#endif
+#ifdef CONFIG_ARM64_MPAM
+	u64			mpam_partid_pmg;
 #endif
 	u32			cpu;
 };
arch/arm64/kernel/Makefile +1 -0
index 76f32e424065..15979f366519 100644
@@ -67,6 +67,7 @@ obj-$(CONFIG_CRASH_DUMP)		+= crash_dump.o
 obj-$(CONFIG_VMCORE_INFO)		+= vmcore_info.o
 obj-$(CONFIG_ARM_SDE_INTERFACE)		+= sdei.o
 obj-$(CONFIG_ARM64_PTR_AUTH)		+= pointer_auth.o
+obj-$(CONFIG_ARM64_MPAM)		+= mpam.o
 obj-$(CONFIG_ARM64_MTE)			+= mte.o
 obj-y					+= vdso-wrap.o
 obj-$(CONFIG_COMPAT_VDSO)		+= vdso32-wrap.o
arch/arm64/kernel/mpam.c new file +13 -0
new file mode 100644
index 000000000000..9866d2ca0faa
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2025 Arm Ltd. */
+
+#include <asm/mpam.h>
+
+#include <linux/jump_label.h>
+#include <linux/percpu.h>
+
+DEFINE_STATIC_KEY_FALSE(mpam_enabled);
+DEFINE_PER_CPU(u64, arm64_mpam_default);
+DEFINE_PER_CPU(u64, arm64_mpam_current);
+
+u64 arm64_mpam_global_default;
arch/arm64/kernel/process.c +7 -0
index 489554931231..47698955fa1e 100644
@@ -51,6 +51,7 @@
 #include <asm/fpsimd.h>
 #include <asm/gcs.h>
 #include <asm/mmu_context.h>
+#include <asm/mpam.h>
 #include <asm/mte.h>
 #include <asm/processor.h>
 #include <asm/pointer_auth.h>
@@ -738,6 +739,12 @@ struct task_struct *__switch_to(struct task_struct *prev,
 	if (prev->thread.sctlr_user != next->thread.sctlr_user)
 		update_sctlr_el1(next->thread.sctlr_user);
 
+	/*
+	 * MPAM thread switch happens after the DSB to ensure prev's accesses
+	 * use prev's MPAM settings.
+	 */
+	mpam_thread_switch(next);
+
 	/* the actual thread switch */
 	last = cpu_switch_to(prev, next);
 
drivers/resctrl/mpam_devices.c +0 -2
index 1eebc2602187..b400a7381d9a 100644
@@ -29,8 +29,6 @@
 
 #include "mpam_internal.h"
 
-DEFINE_STATIC_KEY_FALSE(mpam_enabled); /* This moves to arch code */
-
 /*
  * mpam_list_lock protects the SRCU lists when writing. Once the
  * mpam_enabled key is enabled these lists are read-only,
drivers/resctrl/mpam_internal.h +2 -2
index e8971842b124..4632985bcca6 100644
@@ -16,12 +16,12 @@
 #include <linux/srcu.h>
 #include <linux/types.h>
 
+#include <asm/mpam.h>
+
 #define MPAM_MSC_MAX_NUM_RIS	16
 
 struct platform_device;
 
-DECLARE_STATIC_KEY_FALSE(mpam_enabled);
-
 #ifdef CONFIG_MPAM_KUNIT_TEST
 #define PACKED_FOR_KUNIT __packed
 #else
Signature · 1 line
2.43.0
author maintainer
#7 lore raw

PATCH v5 5/41 arm64: mpam: Re-initialise MPAM regs when CPU comes online

In reply to Ben Horgan

From: James Morse <[email protected]>

Now that the MPAM system registers are expected to have values that change, reprogram them based on the previous value when a CPU is brought online.

Previously MPAM's 'default PARTID' of 0 was always used for MPAM in kernel-space as this is the PARTID that hardware guarantees to reset. Because there are a limited number of PARTID, this value is exposed to user-space, meaning resctrl changes to the resctrl default group would also affect kernel threads. Instead, use the task's PARTID value for kernel work on behalf of user-space too. The default of 0 is kept for both user-space and kernel-space when MPAM is not enabled.

---
Changes since rfc:
CONFIG_MPAM -> CONFIG_ARM64_MPAM
Check mpam_enabled
Comment about relying on ERET for synchronisation
Update commit message

Changes since v3:
Always set MPAM1_EL1.MPAMEN rather than relying on it being read only

---
 arch/arm64/kernel/cpufeature.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
arch/arm64/kernel/cpufeature.c +12 -7
index c31f8e17732a..c3f900f81653 100644
@@ -86,6 +86,7 @@
 #include <asm/kvm_host.h>
 #include <asm/mmu.h>
 #include <asm/mmu_context.h>
+#include <asm/mpam.h>
 #include <asm/mte.h>
 #include <asm/hypervisor.h>
 #include <asm/processor.h>
@@ -2492,13 +2493,17 @@ test_has_mpam(const struct arm64_cpu_capabilities *entry, int scope)
 static void
 cpu_enable_mpam(const struct arm64_cpu_capabilities *entry)
 {
-	/*
-	 * Access by the kernel (at EL1) should use the reserved PARTID
-	 * which is configured unrestricted. This avoids priority-inversion
-	 * where latency sensitive tasks have to wait for a task that has
-	 * been throttled to release the lock.
-	 */
-	write_sysreg_s(0, SYS_MPAM1_EL1);
+	int cpu = smp_processor_id();
+	u64 regval = 0;
+
+	if (IS_ENABLED(CONFIG_ARM64_MPAM) && static_branch_likely(&mpam_enabled))
+		regval = READ_ONCE(per_cpu(arm64_mpam_current, cpu));
+
+	write_sysreg_s(regval | MPAM1_EL1_MPAMEN, SYS_MPAM1_EL1);
+	isb();
+
+	/* Synchronising the EL0 write is left until the ERET to EL0 */
+	write_sysreg_s(regval, SYS_MPAM0_EL1);
 }
 
 static bool
Signature · 1 line
2.43.0
author maintainer
#8 lore raw

PATCH v5 6/41 arm64: mpam: Drop the CONFIG_EXPERT restriction

In reply to Ben Horgan

In anticipation of MPAM being useful remove the CONFIG_EXPERT restriction.

---
 arch/arm64/Kconfig      | 2 +-
 drivers/resctrl/Kconfig | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm64/Kconfig +1 -1
index ecaaca13a969..3170c67464fb 100644
@@ -2016,7 +2016,7 @@ config ARM64_TLB_RANGE
 
 config ARM64_MPAM
 	bool "Enable support for MPAM"
-	select ARM64_MPAM_DRIVER if EXPERT	# does nothing yet
+	select ARM64_MPAM_DRIVER
 	select ACPI_MPAM if ACPI
 	help
 	  Memory System Resource Partitioning and Monitoring (MPAM) is an
drivers/resctrl/Kconfig +1 -1
index c808e0470394..c34e059c6e41 100644
@@ -1,6 +1,6 @@
 menuconfig ARM64_MPAM_DRIVER
 	bool "MPAM driver"
-	depends on ARM64 && ARM64_MPAM && EXPERT
+	depends on ARM64 && ARM64_MPAM
 	help
 	  Memory System Resource Partitioning and Monitoring (MPAM) driver for
 	  System IP, e.g. caches and memory controllers.
Signature · 1 line
2.43.0
Reviewed-by on v5 6/41
#9 lore raw

Re: [PATCH v5 06/41] arm64: mpam: Drop the CONFIG_EXPERT restriction

Quoted 7 lines · Ben Horgan

In anticipation of MPAM being useful remove the CONFIG_EXPERT restriction.

Quoted 5 lines
---
  arch/arm64/Kconfig      | 2 +-
  drivers/resctrl/Kconfig | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
author maintainer
#10 lore raw

PATCH v5 7/41 arm64: mpam: Advertise the CPUs MPAM limits to the driver

In reply to Ben Horgan

From: James Morse <[email protected]>

Requestors need to populate the MPAM fields for any traffic they send on the interconnect. For the CPUs these values are taken from the corresponding MPAMy_ELx register. Each requestor may have a limit on the largest PARTID or PMG value that can be used. The MPAM driver has to determine the system-wide minimum supported PARTID and PMG values.

To do this, the driver needs to be told what each requestor's limit is.

CPUs are special, but this infrastructure is also needed for the SMMU and GIC ITS. Call the helper to tell the MPAM driver what the CPUs can do.

The return value can be ignored by the arch code as it runs well before the MPAM driver starts probing.

---
 arch/arm64/kernel/mpam.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm64/kernel/mpam.c +12 -0
index 9866d2ca0faa..e6feff2324ac 100644
@@ -3,6 +3,7 @@
 
 #include <asm/mpam.h>
 
+#include <linux/arm_mpam.h>
 #include <linux/jump_label.h>
 #include <linux/percpu.h>
 
@@ -11,3 +12,14 @@ DEFINE_PER_CPU(u64, arm64_mpam_default);
 DEFINE_PER_CPU(u64, arm64_mpam_current);
 
 u64 arm64_mpam_global_default;
+
+static int __init arm64_mpam_register_cpus(void)
+{
+	u64 mpamidr = read_sanitised_ftr_reg(SYS_MPAMIDR_EL1);
+	u16 partid_max = FIELD_GET(MPAMIDR_EL1_PARTID_MAX, mpamidr);
+	u8 pmg_max = FIELD_GET(MPAMIDR_EL1_PMG_MAX, mpamidr);
+
+	return mpam_register_requestor(partid_max, pmg_max);
+}
+/* Must occur before mpam_msc_driver_init() from subsys_initcall() */
+arch_initcall(arm64_mpam_register_cpus)
Signature · 1 line
2.43.0
Reviewed-by on v5 7/41
#11 lore raw

Re: [PATCH v5 07/41] arm64: mpam: Advertise the CPUs MPAM limits to the driver

Quoted 25 lines · Ben Horgan

From: James Morse <[email protected]>

Requestors need to populate the MPAM fields for any traffic they send on the interconnect. For the CPUs these values are taken from the corresponding MPAMy_ELx register. Each requestor may have a limit on the largest PARTID or PMG value that can be used. The MPAM driver has to determine the system-wide minimum supported PARTID and PMG values.

To do this, the driver needs to be told what each requestor's limit is.

CPUs are special, but this infrastructure is also needed for the SMMU and GIC ITS. Call the helper to tell the MPAM driver what the CPUs can do.

The return value can be ignored by the arch code as it runs well before the MPAM driver starts probing.

Quoted 4 lines
---
  arch/arm64/kernel/mpam.c | 12 ++++++++++++
  1 file changed, 12 insertions(+)
author maintainer
#12 lore raw

PATCH v5 8/41 arm64: mpam: Add cpu_pm notifier to restore MPAM sysregs

In reply to Ben Horgan

From: James Morse <[email protected]>

The MPAM system registers will be lost if the CPU is reset during PSCI's CPU_SUSPEND.

Add a PM notifier to restore them.

mpam_thread_switch(current) can't be used as this won't make any changes if the in-memory copy says the register already has the correct value. In reality the system register is UNKNOWN out of reset.

---
Changes since v3:
Always set MPAM1_EL1.MPAMEN rather than relying on it being read only Bail out early if mpam not supported (Gavin)

---
 arch/arm64/kernel/mpam.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
arch/arm64/kernel/mpam.c +33 -0
index e6feff2324ac..48ec0ffd5999 100644
@@ -4,6 +4,7 @@
 #include <asm/mpam.h>
 
 #include <linux/arm_mpam.h>
+#include <linux/cpu_pm.h>
 #include <linux/jump_label.h>
 #include <linux/percpu.h>
 
@@ -13,12 +14,44 @@ DEFINE_PER_CPU(u64, arm64_mpam_current);
 
 u64 arm64_mpam_global_default;
 
+static int mpam_pm_notifier(struct notifier_block *self,
+			    unsigned long cmd, void *v)
+{
+	u64 regval;
+	int cpu = smp_processor_id();
+
+	switch (cmd) {
+	case CPU_PM_EXIT:
+		/*
+		 * Don't use mpam_thread_switch() as the system register
+		 * value has changed under our feet.
+		 */
+		regval = READ_ONCE(per_cpu(arm64_mpam_current, cpu));
+		write_sysreg_s(regval | MPAM1_EL1_MPAMEN, SYS_MPAM1_EL1);
+		isb();
+
+		write_sysreg_s(regval, SYS_MPAM0_EL1);
+
+		return NOTIFY_OK;
+	default:
+		return NOTIFY_DONE;
+	}
+}
+
+static struct notifier_block mpam_pm_nb = {
+	.notifier_call = mpam_pm_notifier,
+};
+
 static int __init arm64_mpam_register_cpus(void)
 {
 	u64 mpamidr = read_sanitised_ftr_reg(SYS_MPAMIDR_EL1);
 	u16 partid_max = FIELD_GET(MPAMIDR_EL1_PARTID_MAX, mpamidr);
 	u8 pmg_max = FIELD_GET(MPAMIDR_EL1_PMG_MAX, mpamidr);
 
+	if (!system_supports_mpam())
+		return 0;
+
+	cpu_pm_register_notifier(&mpam_pm_nb);
 	return mpam_register_requestor(partid_max, pmg_max);
 }
 /* Must occur before mpam_msc_driver_init() from subsys_initcall() */
Signature · 1 line
2.43.0
author maintainer
#13 lore raw

PATCH v5 9/41 arm64: mpam: Initialise and context switch the MPAMSM_EL1 register

In reply to Ben Horgan

The MPAMSM_EL1 sets the MPAM labels, PMG and PARTID, for loads and stores generated by a shared SMCU. Disable the traps so the kernel can use it and set it to the same configuration as the per-EL cpu MPAM configuration.

If an SMCU is not shared with other cpus then it is implementation defined whether the configuration from MPAMSM_EL1 is used or that from the appropriate MPAMy_ELx. As we set the same, PMG_D and PARTID_D, configuration for MPAM0_EL1, MPAM1_EL1 and MPAMSM_EL1 the resulting configuration is the same regardless.

The range of valid configurations for the PARTID and PMG in MPAMSM_EL1 is not currently specified in Arm Architectural Reference Manual but the architect has confirmed that it is intended to be the same as that for the cpu configuration in the MPAMy_ELx registers.

---
Changes since v2:
Mention PMG_D and PARTID_D specifically int he commit message Add paragraph in commit message on range of MPAMSM_EL1 fields

Changes since v3:
Use cpus_have_cap() in cpu_enable_mpam()
add {}

---
 arch/arm64/include/asm/el2_setup.h | 3 ++-
 arch/arm64/include/asm/mpam.h      | 2 ++
 arch/arm64/kernel/cpufeature.c     | 2 ++
 arch/arm64/kernel/mpam.c           | 4 ++++
 4 files changed, 10 insertions(+), 1 deletion(-)
arch/arm64/include/asm/el2_setup.h +2 -1
index 85f4c1615472..4d15071a4f3f 100644
@@ -513,7 +513,8 @@
 	check_override id_aa64pfr0, ID_AA64PFR0_EL1_MPAM_SHIFT, .Linit_mpam_\@, .Lskip_mpam_\@, x1, x2
 
 .Linit_mpam_\@:
-	msr_s	SYS_MPAM2_EL2, xzr		// use the default partition
+	mov	x0, #MPAM2_EL2_EnMPAMSM_MASK
+	msr_s	SYS_MPAM2_EL2, x0		// use the default partition,
 						// and disable lower traps
 	mrs_s	x0, SYS_MPAMIDR_EL1
 	tbz	x0, #MPAMIDR_EL1_HAS_HCR_SHIFT, .Lskip_mpam_\@  // skip if no MPAMHCR reg
arch/arm64/include/asm/mpam.h +2 -0
index 0747e0526927..6bccbfdccb87 100644
@@ -53,6 +53,8 @@ static inline void mpam_thread_switch(struct task_struct *tsk)
 		return;
 
 	write_sysreg_s(regval | MPAM1_EL1_MPAMEN, SYS_MPAM1_EL1);
+	if (system_supports_sme())
+		write_sysreg_s(regval & (MPAMSM_EL1_PARTID_D | MPAMSM_EL1_PMG_D), SYS_MPAMSM_EL1);
 	isb();
 
 	/* Synchronising the EL0 write is left until the ERET to EL0 */
arch/arm64/kernel/cpufeature.c +2 -0
index c3f900f81653..4f34e7a76f64 100644
@@ -2500,6 +2500,8 @@ cpu_enable_mpam(const struct arm64_cpu_capabilities *entry)
 		regval = READ_ONCE(per_cpu(arm64_mpam_current, cpu));
 
 	write_sysreg_s(regval | MPAM1_EL1_MPAMEN, SYS_MPAM1_EL1);
+	if (cpus_have_cap(ARM64_SME))
+		write_sysreg_s(regval & (MPAMSM_EL1_PARTID_D | MPAMSM_EL1_PMG_D), SYS_MPAMSM_EL1);
 	isb();
 
 	/* Synchronising the EL0 write is left until the ERET to EL0 */
arch/arm64/kernel/mpam.c +4 -0
index 48ec0ffd5999..3a490de4fa12 100644
@@ -28,6 +28,10 @@ static int mpam_pm_notifier(struct notifier_block *self,
 		 */
 		regval = READ_ONCE(per_cpu(arm64_mpam_current, cpu));
 		write_sysreg_s(regval | MPAM1_EL1_MPAMEN, SYS_MPAM1_EL1);
+		if (system_supports_sme()) {
+			write_sysreg_s(regval & (MPAMSM_EL1_PARTID_D | MPAMSM_EL1_PMG_D),
+				       SYS_MPAMSM_EL1);
+		}
 		isb();
 
 		write_sysreg_s(regval, SYS_MPAM0_EL1);
Signature · 1 line
2.43.0
author maintainer
#14 lore raw

PATCH v5 10/41 arm64: mpam: Add helpers to change a task or cpu's MPAM PARTID/PMG values

In reply to Ben Horgan

From: James Morse <[email protected]>

Care must be taken when modifying the PARTID and PMG of a task in any per-task structure as writing these values may race with the task being scheduled in, and reading the modified values.

Add helpers to set the task properties, and the CPU default value. These use WRITE_ONCE() that pairs with the READ_ONCE() in mpam_get_regval() to avoid causing torn values.

---
Changes since rfc:
Keep comment attached to mpam_get_regval()
Add internal helper, __mpam_regval() (Jonathan)

Changes since v3:
Remove extra CONFIG_ARM64_MPAM guarding
Extend CONFIG_ARM64_MPAM guarding

---
 arch/arm64/include/asm/mpam.h | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
arch/arm64/include/asm/mpam.h +27 -1
index 6bccbfdccb87..05aa71200f61 100644
@@ -4,6 +4,7 @@
 #ifndef __ASM__MPAM_H
 #define __ASM__MPAM_H
 
+#include <linux/bitfield.h>
 #include <linux/jump_label.h>
 #include <linux/percpu.h>
 #include <linux/sched.h>
@@ -22,6 +23,23 @@ DECLARE_PER_CPU(u64, arm64_mpam_current);
  */
 extern u64 arm64_mpam_global_default;
 
+#ifdef CONFIG_ARM64_MPAM
+static inline u64 __mpam_regval(u16 partid_d, u16 partid_i, u8 pmg_d, u8 pmg_i)
+{
+	return FIELD_PREP(MPAM0_EL1_PARTID_D, partid_d) |
+	       FIELD_PREP(MPAM0_EL1_PARTID_I, partid_i) |
+	       FIELD_PREP(MPAM0_EL1_PMG_D, pmg_d) |
+	       FIELD_PREP(MPAM0_EL1_PMG_I, pmg_i);
+}
+
+static inline void mpam_set_cpu_defaults(int cpu, u16 partid_d, u16 partid_i,
+					 u8 pmg_d, u8 pmg_i)
+{
+	u64 default_val = __mpam_regval(partid_d, partid_i, pmg_d, pmg_i);
+
+	WRITE_ONCE(per_cpu(arm64_mpam_default, cpu), default_val);
+}
+
 /*
  * The resctrl filesystem writes to the partid/pmg values for threads and CPUs,
  * which may race with reads in mpam_thread_switch(). Ensure only one of the old
@@ -30,12 +48,20 @@ extern u64 arm64_mpam_global_default;
  * value to be stored with cache allocations, despite being considered 'free' by
  * resctrl.
  */
-#ifdef CONFIG_ARM64_MPAM
 static inline u64 mpam_get_regval(struct task_struct *tsk)
 {
 	return READ_ONCE(task_thread_info(tsk)->mpam_partid_pmg);
 }
 
+static inline void mpam_set_task_partid_pmg(struct task_struct *tsk,
+					    u16 partid_d, u16 partid_i,
+					    u8 pmg_d, u8 pmg_i)
+{
+	u64 regval = __mpam_regval(partid_d, partid_i, pmg_d, pmg_i);
+
+	WRITE_ONCE(task_thread_info(tsk)->mpam_partid_pmg, regval);
+}
+
 static inline void mpam_thread_switch(struct task_struct *tsk)
 {
 	u64 oldregval;
Signature · 1 line
2.43.0
Reviewed-by on v5 10/41
#15 lore raw

Re: [PATCH v5 10/41] arm64: mpam: Add helpers to change a task or cpu's MPAM PARTID/PMG values

Quoted 25 lines · Ben Horgan

From: James Morse <[email protected]>

Care must be taken when modifying the PARTID and PMG of a task in any per-task structure as writing these values may race with the task being scheduled in, and reading the modified values.

Add helpers to set the task properties, and the CPU default value. These use WRITE_ONCE() that pairs with the READ_ONCE() in mpam_get_regval() to avoid causing torn values.

---
Changes since rfc:
Keep comment attached to mpam_get_regval()
Add internal helper, __mpam_regval() (Jonathan)

Quoted 7 lines

Changes since v3:
Remove extra CONFIG_ARM64_MPAM guarding
Extend CONFIG_ARM64_MPAM guarding

---
  arch/arm64/include/asm/mpam.h | 28 +++++++++++++++++++++++++++-
  1 file changed, 27 insertions(+), 1 deletion(-)
author maintainer
#16 lore raw

PATCH v5 11/41 KVM: arm64: Force guest EL1 to use user-space's partid configuration

In reply to Ben Horgan

From: James Morse <[email protected]>

While we trap the guest's attempts to read/write the MPAM control registers, the hardware continues to use them. Guest-EL0 uses KVM's user-space's configuration, as the value is left in the register, and guest-EL1 uses either the host kernel's configuration, or in the case of VHE, the UNKNOWN reset value of MPAM1_EL1.

We want to force the guest-EL1 to use KVM's user-space's MPAM configuration. On nVHE rely on MPAM0_EL1 and MPAM1_EL1 always being programmed the same and on VHE copy MPAM0_EL1 into the guest's MPAM1_EL1. There is no need to restore as this is out of context once TGE is set.

---
Changes since rfc:
Drop the unneeded __mpam_guest_load() in nvhre and the MPAM1_EL1 save restore Defer EL2 handling until next patch

Changes since v2:
Use mask (Oliver)

Changes since v4:
Explicitly set the mpam enable bit

---
 arch/arm64/kvm/hyp/vhe/sysreg-sr.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/arm64/kvm/hyp/vhe/sysreg-sr.c +16 -0
index b254d442e54e..be685b63e8cf 100644
@@ -183,6 +183,21 @@ void sysreg_restore_guest_state_vhe(struct kvm_cpu_context *ctxt)
 }
 NOKPROBE_SYMBOL(sysreg_restore_guest_state_vhe);
 
+/*
+ * The _EL0 value was written by the host's context switch and belongs to the
+ * VMM. Copy this into the guest's _EL1 register.
+ */
+static inline void __mpam_guest_load(void)
+{
+	u64 mask = MPAM0_EL1_PARTID_D | MPAM0_EL1_PARTID_I | MPAM0_EL1_PMG_D | MPAM0_EL1_PMG_I;
+
+	if (system_supports_mpam()) {
+		u64 val = (read_sysreg_s(SYS_MPAM0_EL1) & mask) | MPAM1_EL1_MPAMEN;
+
+		write_sysreg_el1(val, SYS_MPAM1);
+	}
+}
+
 /**
  * __vcpu_load_switch_sysregs - Load guest system registers to the physical CPU
  *
@@ -222,6 +237,7 @@ void __vcpu_load_switch_sysregs(struct kvm_vcpu *vcpu)
 	 */
 	__sysreg32_restore_state(vcpu);
 	__sysreg_restore_user_state(guest_ctxt);
+	__mpam_guest_load();
 
 	if (unlikely(is_hyp_ctxt(vcpu))) {
 		__sysreg_restore_vel2_state(vcpu);
Signature · 1 line
2.43.0
maintainer Acked-by on v5 11/41
#17 lore raw

Re: [PATCH v5 11/41] KVM: arm64: Force guest EL1 to use user-space's partid configuration

Quoted 15 lines · Ben Horgan

From: James Morse <[email protected]>

While we trap the guest's attempts to read/write the MPAM control registers, the hardware continues to use them. Guest-EL0 uses KVM's user-space's configuration, as the value is left in the register, and guest-EL1 uses either the host kernel's configuration, or in the case of VHE, the UNKNOWN reset value of MPAM1_EL1.

We want to force the guest-EL1 to use KVM's user-space's MPAM configuration. On nVHE rely on MPAM0_EL1 and MPAM1_EL1 always being programmed the same and on VHE copy MPAM0_EL1 into the guest's MPAM1_EL1. There is no need to restore as this is out of context once TGE is set.

Quoted 8 lines
	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Reviewed-by on v5 11/41
#18 lore raw

Re: [PATCH v5 11/41] KVM: arm64: Force guest EL1 to use user-space's partid configuration

In reply to Ben Horgan
Quoted 27 lines · Ben Horgan

From: James Morse <[email protected]>

While we trap the guest's attempts to read/write the MPAM control registers, the hardware continues to use them. Guest-EL0 uses KVM's user-space's configuration, as the value is left in the register, and guest-EL1 uses either the host kernel's configuration, or in the case of VHE, the UNKNOWN reset value of MPAM1_EL1.

We want to force the guest-EL1 to use KVM's user-space's MPAM configuration. On nVHE rely on MPAM0_EL1 and MPAM1_EL1 always being programmed the same and on VHE copy MPAM0_EL1 into the guest's MPAM1_EL1. There is no need to restore as this is out of context once TGE is set.

---
Changes since rfc:
Drop the unneeded __mpam_guest_load() in nvhre and the MPAM1_EL1 save restore Defer EL2 handling until next patch

Quoted 9 lines

Changes since v2:
Use mask (Oliver)

Changes since v4:
Explicitly set the mpam enable bit

---
  arch/arm64/kvm/hyp/vhe/sysreg-sr.c | 16 ++++++++++++++++
  1 file changed, 16 insertions(+)
author maintainer
#19 lore raw

PATCH v5 12/41 KVM: arm64: Use kernel-space partid configuration for hypercalls

In reply to Ben Horgan

On nVHE systems whether or not MPAM is enabled, EL2 continues to use partid-0 for hypercalls, even when the host may have configured its kernel threads to use a different partid. 0 may have been assigned to another task. Copy the EL1 MPAM register to EL2. This ensures hypercalls use the same partid as the kernel thread does on the host.

---
Changes since v2:
Use mask
Use read_sysreg_el1 to cope with hvhe

Changes since v3:
Set MPAM2_EL2.MPAMEN to 1 as we rely on that before and after

---
 arch/arm64/kvm/hyp/nvhe/hyp-main.c | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm64/kvm/hyp/nvhe/hyp-main.c +9 -0
index e7790097db93..80e71eeddc03 100644
@@ -638,6 +638,15 @@ static void handle_host_hcall(struct kvm_cpu_context *host_ctxt)
 	unsigned long hcall_min = 0;
 	hcall_t hfn;
 
+	if (system_supports_mpam()) {
+		u64 mask = MPAM1_EL1_PARTID_D | MPAM1_EL1_PARTID_I |
+			MPAM1_EL1_PMG_D | MPAM1_EL1_PMG_I;
+		u64 val = MPAM2_EL2_MPAMEN | (read_sysreg_el1(SYS_MPAM1) & mask);
+
+		write_sysreg_s(val, SYS_MPAM2_EL2);
+		isb();
+	}
+
 	/*
 	 * If pKVM has been initialised then reject any calls to the
 	 * early "privileged" hypercalls. Note that we cannot reject
Signature · 1 line
2.43.0
maintainer
#20 lore raw

Re: [PATCH v5 12/41] KVM: arm64: Use kernel-space partid configuration for hypercalls

Quoted 35 lines · Ben Horgan

On nVHE systems whether or not MPAM is enabled, EL2 continues to use partid-0 for hypercalls, even when the host may have configured its kernel threads to use a different partid. 0 may have been assigned to another task. Copy the EL1 MPAM register to EL2. This ensures hypercalls use the same partid as the kernel thread does on the host.

---
Changes since v2:
Use mask
Use read_sysreg_el1 to cope with hvhe

Changes since v3:
Set MPAM2_EL2.MPAMEN to 1 as we rely on that before and after

---
 arch/arm64/kvm/hyp/nvhe/hyp-main.c | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm64/kvm/hyp/nvhe/hyp-main.c +2 -0
index e7790097db93..80e71eeddc03 100644
@@ -638,6 +638,15 @@ static void handle_host_hcall(struct kvm_cpu_context *host_ctxt)
 	unsigned long hcall_min = 0;
 	hcall_t hfn;
 
+	if (system_supports_mpam()) {
+		u64 mask = MPAM1_EL1_PARTID_D | MPAM1_EL1_PARTID_I |

arch/arm64/kvm/hyp/nvhe/hyp-main.c static void handle_host_hcall(struct kvm_cpu_context *host_ctxt) · line 652

Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +7 -0
+			MPAM1_EL1_PMG_D | MPAM1_EL1_PMG_I;
+		u64 val = MPAM2_EL2_MPAMEN | (read_sysreg_el1(SYS_MPAM1) & mask);
+
+		write_sysreg_s(val, SYS_MPAM2_EL2);
+		isb();
+	}
+
 	/*
 	 * If pKVM has been initialised then reject any calls to the
 	 * early "privileged" hypercalls. Note that we cannot reject

It is extremely debatable whether this is desirable:

- pKVM really shouldn't be influenced by what the host does, which means reserving PARTIDs and indirecting what the host sees. This can be deferred until pKVM is actually useful upstream.

- repeatedly hammering that register plus an ISB on the hot path of a hypercall is a sure way to make things worse than they should be, and that should be fixed now.

Do you really expect the EL1 settings to change on a regular basis? If so, I'd rather you use a specific host hypercall, or even a trap to propagate the EL1 configuration. If not, just set it as part of the KVM init and be done with it.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author maintainer
#21 lore raw

Re: [PATCH v5 12/41] KVM: arm64: Use kernel-space partid configuration for hypercalls

Hi Marc,

Quoted 50 lines · Marc Zyngier
Quoted 35 lines · Ben Horgan

On nVHE systems whether or not MPAM is enabled, EL2 continues to use partid-0 for hypercalls, even when the host may have configured its kernel threads to use a different partid. 0 may have been assigned to another task. Copy the EL1 MPAM register to EL2. This ensures hypercalls use the same partid as the kernel thread does on the host.

---
Changes since v2:
Use mask
Use read_sysreg_el1 to cope with hvhe

Changes since v3:
Set MPAM2_EL2.MPAMEN to 1 as we rely on that before and after

---
 arch/arm64/kvm/hyp/nvhe/hyp-main.c | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm64/kvm/hyp/nvhe/hyp-main.c +2 -0
index e7790097db93..80e71eeddc03 100644
@@ -638,6 +638,15 @@ static void handle_host_hcall(struct kvm_cpu_context *host_ctxt)
 	unsigned long hcall_min = 0;
 	hcall_t hfn;
 
+	if (system_supports_mpam()) {
+		u64 mask = MPAM1_EL1_PARTID_D | MPAM1_EL1_PARTID_I |

arch/arm64/kvm/hyp/nvhe/hyp-main.c static void handle_host_hcall(struct kvm_cpu_context *host_ctxt) · line 652

Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +7 -0
+			MPAM1_EL1_PMG_D | MPAM1_EL1_PMG_I;
+		u64 val = MPAM2_EL2_MPAMEN | (read_sysreg_el1(SYS_MPAM1) & mask);
+
+		write_sysreg_s(val, SYS_MPAM2_EL2);
+		isb();
+	}
+
 	/*
 	 * If pKVM has been initialised then reject any calls to the
 	 * early "privileged" hypercalls. Note that we cannot reject

It is extremely debatable whether this is desirable:

Quoted 7 lines

- pKVM really shouldn't be influenced by what the host does, which means reserving PARTIDs and indirecting what the host sees. This can be deferred until pKVM is actually useful upstream.

- repeatedly hammering that register plus an ISB on the hot path of a hypercall is a sure way to make things worse than they should be, and that should be fixed now.

Would a read modify write be preferable?

Quoted 2 lines

Do you really expect the EL1 settings to change on a regular basis? If

The MPAM EL1 partid/pmg configuration is kept in sync with the MPAM EL0 partid/pmg configuration (see mpam_thread_switch() in patch 4) which means that the EL1 configuration will change whenever the user changes the EL0 configuration.

Quoted 2 lines

so, I'd rather you use a specific host hypercall, or even a trap to propagate the EL1 configuration. If not, just set it as part of the

I think this ends up trapping context switch which doesn't seem any more desirable.

Quoted 1 line

KVM init and be done with it.

If we just forego this patch then the MPAM configuration for el2 as initially configured, partid=0, pmg=0 would be used. This is also the default for requestors that aren't MPAM aware or unconfigured, like trusted firmware, its, gpu. VHE mode (required from 8.1?) should be available in any platform that has MPAM (introduced in 8.4, back portable to 8.3) and so using nvhe with MPAM seems unlikely and the amount of data should be small enough. That leaves pKVM for which, perhaps, doing nothing is also the correct answer.

What do you think? Drop, read modify write, or something else?

Quoted 5 lines

Thanks,

	M.

Thanks,

Ben

author maintainer
#22 lore raw

Re: [PATCH v5 12/41] KVM: arm64: Use kernel-space partid configuration for hypercalls

Quoted 88 lines · Ben Horgan

Hi Marc,

Quoted 50 lines · Marc Zyngier
Quoted 35 lines · Ben Horgan

On nVHE systems whether or not MPAM is enabled, EL2 continues to use partid-0 for hypercalls, even when the host may have configured its kernel threads to use a different partid. 0 may have been assigned to another task. Copy the EL1 MPAM register to EL2. This ensures hypercalls use the same partid as the kernel thread does on the host.

---
Changes since v2:
Use mask
Use read_sysreg_el1 to cope with hvhe

Changes since v3:
Set MPAM2_EL2.MPAMEN to 1 as we rely on that before and after

---
 arch/arm64/kvm/hyp/nvhe/hyp-main.c | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm64/kvm/hyp/nvhe/hyp-main.c +2 -0
index e7790097db93..80e71eeddc03 100644
@@ -638,6 +638,15 @@ static void handle_host_hcall(struct kvm_cpu_context *host_ctxt)
 	unsigned long hcall_min = 0;
 	hcall_t hfn;
 
+	if (system_supports_mpam()) {
+		u64 mask = MPAM1_EL1_PARTID_D | MPAM1_EL1_PARTID_I |

arch/arm64/kvm/hyp/nvhe/hyp-main.c static void handle_host_hcall(struct kvm_cpu_context *host_ctxt) · line 652

Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +7 -0
+			MPAM1_EL1_PMG_D | MPAM1_EL1_PMG_I;
+		u64 val = MPAM2_EL2_MPAMEN | (read_sysreg_el1(SYS_MPAM1) & mask);
+
+		write_sysreg_s(val, SYS_MPAM2_EL2);
+		isb();
+	}
+
 	/*
 	 * If pKVM has been initialised then reject any calls to the
 	 * early "privileged" hypercalls. Note that we cannot reject

It is extremely debatable whether this is desirable:

Quoted 7 lines

- pKVM really shouldn't be influenced by what the host does, which means reserving PARTIDs and indirecting what the host sees. This can be deferred until pKVM is actually useful upstream.

- repeatedly hammering that register plus an ISB on the hot path of a hypercall is a sure way to make things worse than they should be, and that should be fixed now.

Would a read modify write be preferable?

Quoted 2 lines

Do you really expect the EL1 settings to change on a regular basis? If

The MPAM EL1 partid/pmg configuration is kept in sync with the MPAM EL0 partid/pmg configuration (see mpam_thread_switch() in patch 4) which means that the EL1 configuration will change whenever the user changes the EL0 configuration.

Quoted 2 lines

so, I'd rather you use a specific host hypercall, or even a trap to propagate the EL1 configuration. If not, just set it as part of the

I think this ends up trapping context switch which doesn't seem any more desirable.

Quoted 1 line

KVM init and be done with it.

If we just forego this patch then the MPAM configuration for el2 as initially configured, partid=0, pmg=0 would be used. This is also the default for requestors that aren't MPAM aware or unconfigured, like trusted firmware, its, gpu. VHE mode (required from 8.1?) should be available in any platform that has MPAM (introduced in 8.4, back portable to 8.3) and so using nvhe with MPAM seems unlikely and the amount of data should be small enough. That leaves pKVM for which, perhaps, doing nothing is also the correct answer.

Quoted 1 line

What do you think? Drop, read modify write, or something else?

As discussed offline, I'll drop this patch.

Thanks,

Ben

author maintainer
#23 lore raw

PATCH v5 13/41 arm_mpam: resctrl: Add boilerplate cpuhp and domain allocation

In reply to Ben Horgan

From: James Morse <[email protected]>

resctrl has its own data structures to describe its resources. We can't use these directly as we play tricks with the 'MBA' resource, picking the MPAM controls or monitors that best apply. We may export the same component as both L3 and MBA.

Add mpam_resctrl_res[] as the array of class->resctrl mappings we are exporting, and add the cpuhp hooks that allocated and free the resctrl domain structures. Only the mpam control feature are considered here and monitor support will be added later.

While we're here, plumb in a few other obvious things.

CONFIG_ARM_CPU_RESCTRL is used to allow this code to be built even though it can't yet be linked against resctrl.

---
Changes since rfc:
Domain list is an rcu list
Add synchronize_rcu() to free the deleted element
Code flow simplification (Jonathan)

Changes since v2:
Iterate over mpam_resctrl_dom directly (Jonathan)
Code flow clarification
Comment tidying
Remove power of 2 check as no longer creates holes in rmid indices Remove unused type argument
add macro helper for_each_mpam_resctrl_control

Changes since v3:
Add and use mpam_resctrl_online_domain_hdr() mpam_resctrl_alloc_domain() error paths (Reinette)
rebase on x86/cache changes rdt_mon_domain becomes rdt_l3_mon_domain etc

Changes since v4:
Set rid in domain_hdr
Use rescctrl_res.alloc_capable to determine if alloc_capable as the decision may depend on the resctrl mount options (cdp) Squash in arm_mpam: resctrl: Sort the order of the domain lists Move out monitor/counter changes to a separate patch Commit message update

---
 drivers/resctrl/Makefile        |   1 +
 drivers/resctrl/mpam_devices.c  |  12 ++
 drivers/resctrl/mpam_internal.h |  21 ++
 drivers/resctrl/mpam_resctrl.c  | 327 ++++++++++++++++++++++++++++++++
 include/linux/arm_mpam.h        |   3 +
 5 files changed, 364 insertions(+)
 create mode 100644 drivers/resctrl/mpam_resctrl.c
drivers/resctrl/Makefile +1 -0
index 898199dcf80d..40beaf999582 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_ARM64_MPAM_DRIVER)			+= mpam.o
 mpam-y						+= mpam_devices.o
+mpam-$(CONFIG_ARM_CPU_RESCTRL)			+= mpam_resctrl.o
 
 ccflags-$(CONFIG_ARM64_MPAM_DRIVER_DEBUG)	+= -DDEBUG
drivers/resctrl/mpam_devices.c +12 -0
index b400a7381d9a..b45743c5fb46 100644
@@ -1628,6 +1628,9 @@ static int mpam_cpu_online(unsigned int cpu)
 			mpam_reprogram_msc(msc);
 	}
 
+	if (mpam_is_enabled())
+		return mpam_resctrl_online_cpu(cpu);
+
 	return 0;
 }
 
@@ -1671,6 +1674,9 @@ static int mpam_cpu_offline(unsigned int cpu)
 {
 	struct mpam_msc *msc;
 
+	if (mpam_is_enabled())
+		mpam_resctrl_offline_cpu(cpu);
+
 	guard(srcu)(&mpam_srcu);
 	list_for_each_entry_srcu(msc, &mpam_all_msc, all_msc_list,
 				 srcu_read_lock_held(&mpam_srcu)) {
@@ -2516,6 +2522,12 @@ static void mpam_enable_once(void)
 	mutex_unlock(&mpam_list_lock);
 	cpus_read_unlock();
 
+	if (!err) {
+		err = mpam_resctrl_setup();
+		if (err)
+			pr_err("Failed to initialise resctrl: %d\n", err);
+	}
+
 	if (err) {
 		mpam_disable_reason = "Failed to enable.";
 		schedule_work(&mpam_broken_work);
drivers/resctrl/mpam_internal.h +21 -0
index 4632985bcca6..28ac501e1ac3 100644
@@ -12,6 +12,7 @@
 #include <linux/jump_label.h>
 #include <linux/llist.h>
 #include <linux/mutex.h>
+#include <linux/resctrl.h>
 #include <linux/spinlock.h>
 #include <linux/srcu.h>
 #include <linux/types.h>
@@ -337,6 +338,16 @@ struct mpam_msc_ris {
 	struct mpam_garbage	garbage;
 };
 
+struct mpam_resctrl_dom {
+	struct mpam_component		*ctrl_comp;
+	struct rdt_ctrl_domain		resctrl_ctrl_dom;
+};
+
+struct mpam_resctrl_res {
+	struct mpam_class	*class;
+	struct rdt_resource	resctrl_res;
+};
+
 static inline int mpam_alloc_csu_mon(struct mpam_class *class)
 {
 	struct mpam_props *cprops = &class->props;
@@ -391,6 +402,16 @@ void mpam_msmon_reset_mbwu(struct mpam_component *comp, struct mon_cfg *ctx);
 int mpam_get_cpumask_from_cache_id(unsigned long cache_id, u32 cache_level,
 				   cpumask_t *affinity);
 
+#ifdef CONFIG_RESCTRL_FS
+int mpam_resctrl_setup(void);
+int mpam_resctrl_online_cpu(unsigned int cpu);
+void mpam_resctrl_offline_cpu(unsigned int cpu);
+#else
+static inline int mpam_resctrl_setup(void) { return 0; }
+static inline int mpam_resctrl_online_cpu(unsigned int cpu) { return 0; }
+static inline void mpam_resctrl_offline_cpu(unsigned int cpu) { }
+#endif /* CONFIG_RESCTRL_FS */
+
 /*
  * MPAM MSCs have the following register layout. See:
  * Arm Memory System Resource Partitioning and Monitoring (MPAM) System
drivers/resctrl/mpam_resctrl.c new file +327 -0

327 lines not on this page · raw message

include/linux/arm_mpam.h +3 -0
index 7f00c5285a32..2c7d1413a401 100644
@@ -49,6 +49,9 @@ static inline int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
 }
 #endif
 
+bool resctrl_arch_alloc_capable(void);
+bool resctrl_arch_mon_capable(void);
+
 /**
  * mpam_register_requestor() - Register a requestor with the MPAM driver
  * @partid_max:		The maximum PARTID value the requestor can generate.
Signature · 1 line
2.43.0
#24 lore raw

Re: [PATCH v5 13/41] arm_mpam: resctrl: Add boilerplate cpuhp and domain allocation

Hi Ben,

Quoted 12 lines · Ben Horgan

From: James Morse <[email protected]>

resctrl has its own data structures to describe its resources. We can't use these directly as we play tricks with the 'MBA' resource, picking the MPAM controls or monitors that best apply. We may export the same component as both L3 and MBA.

Add mpam_resctrl_res[] as the array of class->resctrl mappings we are exporting, and add the cpuhp hooks that allocated and free the resctrl domain structures. Only the mpam control feature are considered here and monitor support will be added later.

Quoted 5 lines

While we're here, plumb in a few other obvious things.

CONFIG_ARM_CPU_RESCTRL is used to allow this code to be built even though it can't yet be linked against resctrl.

CONFIG_ARM_CPU_RESCTRL isn't valid. I guess you're probably mentioning CONFIG_ARCH_HAS_CPU_RESCTRL?

Quoted 154 lines

---
Changes since rfc:
Domain list is an rcu list
Add synchronize_rcu() to free the deleted element
Code flow simplification (Jonathan)

Changes since v2:
Iterate over mpam_resctrl_dom directly (Jonathan)
Code flow clarification
Comment tidying
Remove power of 2 check as no longer creates holes in rmid indices Remove unused type argument
add macro helper for_each_mpam_resctrl_control

Changes since v3:
Add and use mpam_resctrl_online_domain_hdr() mpam_resctrl_alloc_domain() error paths (Reinette)
rebase on x86/cache changes rdt_mon_domain becomes rdt_l3_mon_domain etc

Changes since v4:
Set rid in domain_hdr
Use rescctrl_res.alloc_capable to determine if alloc_capable as the decision may depend on the resctrl mount options (cdp) Squash in arm_mpam: resctrl: Sort the order of the domain lists Move out monitor/counter changes to a separate patch Commit message update

---
  drivers/resctrl/Makefile        |   1 +
  drivers/resctrl/mpam_devices.c  |  12 ++
  drivers/resctrl/mpam_internal.h |  21 ++
  drivers/resctrl/mpam_resctrl.c  | 327 ++++++++++++++++++++++++++++++++
  include/linux/arm_mpam.h        |   3 +
  5 files changed, 364 insertions(+)

create mode 100644 drivers/resctrl/mpam_resctrl.c

drivers/resctrl/Makefile +1 -0
index 898199dcf80d..40beaf999582 100644
@@ -1,4 +1,5 @@
  obj-$(CONFIG_ARM64_MPAM_DRIVER)			+= mpam.o
  mpam-y						+= mpam_devices.o
+mpam-$(CONFIG_ARM_CPU_RESCTRL)			+= mpam_resctrl.o
 
  ccflags-$(CONFIG_ARM64_MPAM_DRIVER_DEBUG)	+= -DDEBUG
drivers/resctrl/mpam_devices.c +12 -0
index b400a7381d9a..b45743c5fb46 100644
@@ -1628,6 +1628,9 @@ static int mpam_cpu_online(unsigned int cpu)
  			mpam_reprogram_msc(msc);
  	}
 
+	if (mpam_is_enabled())
+		return mpam_resctrl_online_cpu(cpu);
+
  	return 0;
  }
 
@@ -1671,6 +1674,9 @@ static int mpam_cpu_offline(unsigned int cpu)
  {
  	struct mpam_msc *msc;
 
+	if (mpam_is_enabled())
+		mpam_resctrl_offline_cpu(cpu);
+
  	guard(srcu)(&mpam_srcu);
  	list_for_each_entry_srcu(msc, &mpam_all_msc, all_msc_list,
  				 srcu_read_lock_held(&mpam_srcu)) {
@@ -2516,6 +2522,12 @@ static void mpam_enable_once(void)
  	mutex_unlock(&mpam_list_lock);
  	cpus_read_unlock();
 
+	if (!err) {
+		err = mpam_resctrl_setup();
+		if (err)
+			pr_err("Failed to initialise resctrl: %d\n", err);
+	}
+
  	if (err) {
  		mpam_disable_reason = "Failed to enable.";
  		schedule_work(&mpam_broken_work);
drivers/resctrl/mpam_internal.h +21 -0
index 4632985bcca6..28ac501e1ac3 100644
@@ -12,6 +12,7 @@
  #include <linux/jump_label.h>
  #include <linux/llist.h>
  #include <linux/mutex.h>
+#include <linux/resctrl.h>
  #include <linux/spinlock.h>
  #include <linux/srcu.h>
  #include <linux/types.h>
@@ -337,6 +338,16 @@ struct mpam_msc_ris {
  	struct mpam_garbage	garbage;
  };
 
+struct mpam_resctrl_dom {
+	struct mpam_component		*ctrl_comp;
+	struct rdt_ctrl_domain		resctrl_ctrl_dom;
+};
+
+struct mpam_resctrl_res {
+	struct mpam_class	*class;
+	struct rdt_resource	resctrl_res;
+};
+
  static inline int mpam_alloc_csu_mon(struct mpam_class *class)
  {
  	struct mpam_props *cprops = &class->props;
@@ -391,6 +402,16 @@ void mpam_msmon_reset_mbwu(struct mpam_component *comp, struct mon_cfg *ctx);
  int mpam_get_cpumask_from_cache_id(unsigned long cache_id, u32 cache_level,
  				   cpumask_t *affinity);
 
+#ifdef CONFIG_RESCTRL_FS
+int mpam_resctrl_setup(void);
+int mpam_resctrl_online_cpu(unsigned int cpu);
+void mpam_resctrl_offline_cpu(unsigned int cpu);
+#else
+static inline int mpam_resctrl_setup(void) { return 0; }
+static inline int mpam_resctrl_online_cpu(unsigned int cpu) { return 0; }
+static inline void mpam_resctrl_offline_cpu(unsigned int cpu) { }
+#endif /* CONFIG_RESCTRL_FS */
+
  /*
   * MPAM MSCs have the following register layout. See:
   * Arm Memory System Resource Partitioning and Monitoring (MPAM) System
drivers/resctrl/mpam_resctrl.c new file +11 -0
new file mode 100644
index 000000000000..2ffba7a15d6a
@@ -0,0 +1,327 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2025 Arm Ltd.
+
+#define pr_fmt(fmt) "%s:%s: " fmt, KBUILD_MODNAME, __func__
+
+#include <linux/arm_mpam.h>
+#include <linux/cacheinfo.h>
+#include <linux/cpu.h>
+#include <linux/cpumask.h>
+#include <linux/errno.h>
+#include <linux/list.h>

drivers/resctrl/mpam_resctrl.c line 21

Quoted 10 lines
drivers/resctrl/mpam_resctrl.c new file +10 -0
+#include <linux/printk.h>
+#include <linux/rculist.h>
+#include <linux/resctrl.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+
+#include <asm/mpam.h>
+
+#include "mpam_internal.h"
+

The list of included headers could be simplified since several header files have been included to mpam_internal.h, for example <linux/arm_mpam.h>, <linux/cpumask.h>, <asm/mpam.h> and others.

Quoted 81 lines
drivers/resctrl/mpam_resctrl.c new file +81 -0
+/*
+ * The classes we've picked to map to resctrl resources, wrapped
+ * in with their resctrl structure.
+ * Class pointer may be NULL.
+ */
+static struct mpam_resctrl_res mpam_resctrl_controls[RDT_NUM_RESOURCES];
+
+#define for_each_mpam_resctrl_control(res, rid)					\
+	for (rid = 0, res = &mpam_resctrl_controls[rid];			\
+	     rid < RDT_NUM_RESOURCES;						\
+	     rid++, res = &mpam_resctrl_controls[rid])
+
+/* The lock for modifying resctrl's domain lists from cpuhp callbacks. */
+static DEFINE_MUTEX(domain_list_lock);
+
+bool resctrl_arch_alloc_capable(void)
+{
+	struct mpam_resctrl_res *res;
+	enum resctrl_res_level rid;
+
+	for_each_mpam_resctrl_control(res, rid) {
+		if (res->resctrl_res.alloc_capable)
+			return true;
+	}
+
+	return false;
+}
+
+/*
+ * MSC may raise an error interrupt if it sees an out or range partid/pmg,
+ * and go on to truncate the value. Regardless of what the hardware supports,
+ * only the system wide safe value is safe to use.
+ */
+u32 resctrl_arch_get_num_closid(struct rdt_resource *ignored)
+{
+	return mpam_partid_max + 1;
+}
+
+struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l)
+{
+	if (l >= RDT_NUM_RESOURCES)
+		return NULL;
+
+	return &mpam_resctrl_controls[l].resctrl_res;
+}
+
+static int mpam_resctrl_control_init(struct mpam_resctrl_res *res)
+{
+	/* TODO: initialise the resctrl resources */
+
+	return 0;
+}
+
+static int mpam_resctrl_pick_domain_id(int cpu, struct mpam_component *comp)
+{
+	struct mpam_class *class = comp->class;
+
+	if (class->type == MPAM_CLASS_CACHE)
+		return comp->comp_id;
+
+	/* TODO: repaint domain ids to match the L3 domain ids */
+	/* Otherwise, expose the ID used by the firmware table code. */
+	return comp->comp_id;
+}
+
+static void mpam_resctrl_domain_hdr_init(int cpu, struct mpam_component *comp,
+					 enum resctrl_res_level rid,
+					 struct rdt_domain_hdr *hdr)
+{
+	lockdep_assert_cpus_held();
+
+	INIT_LIST_HEAD(&hdr->list);
+	hdr->id = mpam_resctrl_pick_domain_id(cpu, comp);
+	hdr->rid = rid;
+	cpumask_set_cpu(cpu, &hdr->cpu_mask);
+}
+
+static void mpam_resctrl_online_domain_hdr(unsigned int cpu,
+					   struct rdt_domain_hdr *hdr)
+{
+	lockdep_assert_cpus_held();

drivers/resctrl/mpam_resctrl.c line 112

Quoted 10 lines
drivers/resctrl/mpam_resctrl.c new file +10 -0
+
+	cpumask_set_cpu(cpu, &hdr->cpu_mask);
+}
+
+/**
+ * mpam_resctrl_offline_domain_hdr() - Update the domain header to remove a CPU.
+ * @cpu:	The CPU to remove from the domain.
+ * @hdr:	The domain's header.
+ *
+ * Removes @cpu from the header mask. If this was the last CPU in the domain,
                                                 ^^^
                                                 is
Quoted 195 lines
drivers/resctrl/mpam_resctrl.c new file +195 -0
+ * the domain header is removed from its parent list and true is returned,
+ * indicating the parent structure can be freed.
+ * If there are other CPUs in the domain, returns false.
+ */
+static bool mpam_resctrl_offline_domain_hdr(unsigned int cpu,
+					    struct rdt_domain_hdr *hdr)
+{
+	lockdep_assert_held(&domain_list_lock);
+
+	cpumask_clear_cpu(cpu, &hdr->cpu_mask);
+	if (cpumask_empty(&hdr->cpu_mask)) {
+		list_del_rcu(&hdr->list);
+		synchronize_rcu();
+		return true;
+	}
+
+	return false;
+}
+
+static void 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;
+
+	list_add_tail_rcu(&new->list, pos);
+}
+
+static struct mpam_resctrl_dom *
+mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
+{
+	int err;
+	struct mpam_resctrl_dom *dom;
+	struct rdt_ctrl_domain *ctrl_d;
+	struct mpam_class *class = res->class;
+	struct mpam_component *comp_iter, *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;
+		}
+	}
+
+	/* class has no component for this CPU */
+	if (WARN_ON_ONCE(!ctrl_comp))
+		return ERR_PTR(-EINVAL);
+
+	dom = kzalloc_node(sizeof(*dom), GFP_KERNEL, cpu_to_node(cpu));
+	if (!dom)
+		return ERR_PTR(-ENOMEM);
+
+	if (resctrl_arch_alloc_capable()) {
+		dom->ctrl_comp = ctrl_comp;
+
+		ctrl_d = &dom->resctrl_ctrl_dom;
+		mpam_resctrl_domain_hdr_init(cpu, ctrl_comp, r->rid, &ctrl_d->hdr);
+		ctrl_d->hdr.type = RESCTRL_CTRL_DOMAIN;
+		err = resctrl_online_ctrl_domain(r, ctrl_d);
+		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");
+	}
+	return dom;
+
+offline_ctrl_domain:
+	if (resctrl_arch_alloc_capable()) {
+		mpam_resctrl_offline_domain_hdr(cpu, &ctrl_d->hdr);
+		resctrl_offline_ctrl_domain(r, ctrl_d);
+	}
+free_domain:
+	kfree(dom);
+	dom = ERR_PTR(err);
+
+	return dom;
+}
+
+static struct mpam_resctrl_dom *
+mpam_resctrl_get_domain_from_cpu(int cpu, struct mpam_resctrl_res *res)
+{
+	struct mpam_resctrl_dom *dom;
+	struct rdt_resource *r = &res->resctrl_res;
+
+	lockdep_assert_cpus_held();
+
+	list_for_each_entry_rcu(dom, &r->ctrl_domains, resctrl_ctrl_dom.hdr.list) {
+		if (cpumask_test_cpu(cpu, &dom->ctrl_comp->affinity))
+			return dom;
+	}
+
+	return NULL;
+}
+
+int mpam_resctrl_online_cpu(unsigned int cpu)
+{
+	struct mpam_resctrl_res *res;
+	enum resctrl_res_level rid;
+
+	guard(mutex)(&domain_list_lock);
+	for_each_mpam_resctrl_control(res, rid) {
+		struct mpam_resctrl_dom *dom;
+
+		if (!res->class)
+			continue;	// dummy_resource;
+
+		dom = mpam_resctrl_get_domain_from_cpu(cpu, res);
+		if (!dom) {
+			dom = mpam_resctrl_alloc_domain(cpu, res);
+		} else {
+			if (resctrl_arch_alloc_capable()) {
+				struct rdt_ctrl_domain *ctrl_d = &dom->resctrl_ctrl_dom;
+
+				mpam_resctrl_online_domain_hdr(cpu, &ctrl_d->hdr);
+			}
+		}
+		if (IS_ERR(dom))
+			return PTR_ERR(dom);
+	}
+
+	resctrl_online_cpu(cpu);
+
+	return 0;
+}
+
+void mpam_resctrl_offline_cpu(unsigned int cpu)
+{
+	struct mpam_resctrl_res *res;
+	enum resctrl_res_level rid;
+
+	resctrl_offline_cpu(cpu);
+
+	guard(mutex)(&domain_list_lock);
+	for_each_mpam_resctrl_control(res, rid) {
+		struct mpam_resctrl_dom *dom;
+		struct rdt_ctrl_domain *ctrl_d;
+		bool ctrl_dom_empty;
+
+		if (!res->class)
+			continue;	// dummy resource
+
+		dom = mpam_resctrl_get_domain_from_cpu(cpu, res);
+		if (WARN_ON_ONCE(!dom))
+			continue;
+
+		if (resctrl_arch_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 (ctrl_dom_empty)
+			kfree(dom);
+	}
+}
+
+int mpam_resctrl_setup(void)
+{
+	int err = 0;
+	struct mpam_resctrl_res *res;
+	enum resctrl_res_level rid;
+
+	cpus_read_lock();
+	for_each_mpam_resctrl_control(res, rid) {
+		INIT_LIST_HEAD_RCU(&res->resctrl_res.ctrl_domains);
+		res->resctrl_res.rid = rid;
+	}
+
+	/* TODO: pick MPAM classes to map to resctrl resources */
+
+	/* Initialise the resctrl structures from the classes */
+	for_each_mpam_resctrl_control(res, rid) {
+		if (!res->class)
+			continue;	// dummy resource
+
+		err = mpam_resctrl_control_init(res);
+		if (err) {
+			pr_debug("Failed to initialise rid %u\n", rid);

drivers/resctrl/mpam_resctrl.c line 317

Quoted 10 lines
drivers/resctrl/mpam_resctrl.c new file +10 -0
+			break;
+		}
+	}
+	cpus_read_unlock();
+
+	if (err) {
+		pr_debug("Internal error %d - resctrl not supported\n", err);
+		return err;
+	}
+

This pr_debug() could be dropped since @err is set to true only when a error is returned from mpam_resctrl_control_init(), we already had a pr_debug() for the reported error.

Quoted 15 lines
drivers/resctrl/mpam_resctrl.c new file +10 -0
+	if (!resctrl_arch_alloc_capable()) {
+		pr_debug("No alloc(%u) found - resctrl not supported\n",
+			 resctrl_arch_alloc_capable());
+		return -EOPNOTSUPP;
+	}
+
+	/* TODO: call resctrl_init() */
+
+	return 0;
+}
include/linux/arm_mpam.h +0 -0
index 7f00c5285a32..2c7d1413a401 100644

include/linux/arm_mpam.h static inline int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx, · line 57

Quoted 9 lines
include/linux/arm_mpam.h +3 -0
@@ -49,6 +49,9 @@ static inline int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
  }
  #endif
 
+bool resctrl_arch_alloc_capable(void);
+bool resctrl_arch_mon_capable(void);
+
  /**
   * mpam_register_requestor() - Register a requestor with the MPAM driver
   * @partid_max:		The maximum PARTID value the requestor can generate.

Thanks,
Gavin

author maintainer
#25 lore raw

Re: [PATCH v5 13/41] arm_mpam: resctrl: Add boilerplate cpuhp and domain allocation

Hi Gavin,

Quoted 17 lines · Gavin Shan

Hi Ben,

Quoted 14 lines · Ben Horgan

From: James Morse <[email protected]>

resctrl has its own data structures to describe its resources. We can't use
these directly as we play tricks with the 'MBA' resource, picking the MPAM
controls or monitors that best apply. We may export the same component as both L3 and MBA.

Add mpam_resctrl_res[] as the array of class->resctrl mappings we are exporting, and add the cpuhp hooks that allocated and free the resctrl domain structures. Only the mpam control feature are considered here and monitor support will be added later.

Quoted 8 lines
Quoted 5 lines

While we're here, plumb in a few other obvious things.

CONFIG_ARM_CPU_RESCTRL is used to allow this code to be built even though it can't yet be linked against resctrl.

CONFIG_ARM_CPU_RESCTRL isn't valid. I guess you're probably mentioning CONFIG_ARCH_HAS_CPU_RESCTRL?

CONFIG_ARM_CPU_RESCTRL is added in the Makefile in this patch. As stated, this is just to allow build testing and the link will fail. E.g.

$ CONFIG_ARM_CPU_RESCTRL=y make O=out drivers/resctrl/

Trying this now I note there is also a build warning about the 'offline_ctrl_domain' label being unused which I'll fix.

Quoted 45 lines
Quoted 45 lines

---
Changes since rfc:
Domain list is an rcu list
Add synchronize_rcu() to free the deleted element
Code flow simplification (Jonathan)

Changes since v2:
Iterate over mpam_resctrl_dom directly (Jonathan)
Code flow clarification
Comment tidying
Remove power of 2 check as no longer creates holes in rmid indices Remove unused type argument
add macro helper for_each_mpam_resctrl_control

Changes since v3:
Add and use mpam_resctrl_online_domain_hdr() mpam_resctrl_alloc_domain() error paths (Reinette)
rebase on x86/cache changes rdt_mon_domain becomes rdt_l3_mon_domain etc

Changes since v4:
Set rid in domain_hdr
Use rescctrl_res.alloc_capable to determine if alloc_capable as the decision may depend on the resctrl mount options (cdp) Squash in arm_mpam: resctrl: Sort the order of the domain lists Move out monitor/counter changes to a separate patch
Commit message update
---
  drivers/resctrl/Makefile        |   1 + drivers/resctrl/mpam_devices.c  |  12 ++ drivers/resctrl/mpam_internal.h |  21 ++ drivers/resctrl/mpam_resctrl.c  | 327 ++++++++++++++++++++++++++++++++ include/linux/arm_mpam.h        |   3 +

  5 files changed, 364 insertions(+)

  create mode 100644 drivers/resctrl/mpam_resctrl.c

Quoted 8 lines
Quoted 8 lines
drivers/resctrl/Makefile +0 -0
index 898199dcf80d..40beaf999582 100644
@@ -1,4 +1,5 @@

  obj-$(CONFIG_ARM64_MPAM_DRIVER)            += mpam.o mpam-y                        += mpam_devices.o +mpam-$(CONFIG_ARM_CPU_RESCTRL)            += mpam_resctrl.o

Here.

Quoted 107 lines
Quoted 107 lines

    ccflags-$(CONFIG_ARM64_MPAM_DRIVER_DEBUG)    += -DDEBUG

drivers/resctrl/ renamed from drivers/resctrl/mpam_devices.c +0 -0

mpam_devices.c
index b400a7381d9a..b45743c5fb46 100644

drivers/resctrl/mpam_devices.c +2 -0
@@ -1628,6 +1628,9 @@ static int mpam_cpu_online(unsigned int cpu)
               mpam_reprogram_msc(msc);
       }
   +    if (mpam_is_enabled())
+        return mpam_resctrl_online_cpu(cpu);
+
       return 0;
   }
   @@ -1671,6 +1674,9 @@ static int mpam_cpu_offline(unsigned int cpu)

  {
      struct mpam_msc *msc;
  +    if (mpam_is_enabled())
+        mpam_resctrl_offline_cpu(cpu);
+
      guard(srcu)(&mpam_srcu); list_for_each_entry_srcu(msc, &mpam_all_msc, all_msc_list, srcu_read_lock_held(&mpam_srcu)) {

drivers/resctrl/mpam_devices.c +5 -0
@@ -2516,6 +2522,12 @@ static void mpam_enable_once(void)
       mutex_unlock(&mpam_list_lock);
       cpus_read_unlock();
   +    if (!err) {
+        err = mpam_resctrl_setup();
+        if (err)
+            pr_err("Failed to initialise resctrl: %d\n", err);
+    }
+
       if (err) {
           mpam_disable_reason = "Failed to enable.";
           schedule_work(&mpam_broken_work);
drivers/resctrl/ renamed from drivers/resctrl/mpam_internal.h +0 -0

mpam_internal.h
index 4632985bcca6..28ac501e1ac3 100644

drivers/resctrl/mpam_internal.h +10 -0
@@ -12,6 +12,7 @@
   #include <linux/jump_label.h>
   #include <linux/llist.h>
   #include <linux/mutex.h>
+#include <linux/resctrl.h>
   #include <linux/spinlock.h>
   #include <linux/srcu.h>
   #include <linux/types.h>
@@ -337,6 +338,16 @@ struct mpam_msc_ris {
       struct mpam_garbage    garbage;
   };
   +struct mpam_resctrl_dom {
+    struct mpam_component        *ctrl_comp;
+    struct rdt_ctrl_domain        resctrl_ctrl_dom;
+};
+
+struct mpam_resctrl_res {
+    struct mpam_class    *class;
+    struct rdt_resource    resctrl_res;
+};
+
   static inline int mpam_alloc_csu_mon(struct mpam_class *class)
   {
       struct mpam_props *cprops = &class->props;
@@ -391,6 +402,16 @@ void mpam_msmon_reset_mbwu(struct mpam_component
 *comp, struct mon_cfg *ctx);

  int mpam_get_cpumask_from_cache_id(unsigned long cache_id, u32 cache_level,
                     cpumask_t *affinity);
  +#ifdef CONFIG_RESCTRL_FS

drivers/resctrl/mpam_internal.h +6 -0
+int mpam_resctrl_setup(void);
+int mpam_resctrl_online_cpu(unsigned int cpu);
+void mpam_resctrl_offline_cpu(unsigned int cpu);
+#else
+static inline int mpam_resctrl_setup(void) { return 0; }
+static inline int mpam_resctrl_online_cpu(unsigned int cpu) { return

0; }

drivers/resctrl/mpam_internal.h +3 -0
+static inline void mpam_resctrl_offline_cpu(unsigned int cpu) { }
+#endif /* CONFIG_RESCTRL_FS */
+

  /*
   * MPAM MSCs have the following register layout. See:
   * Arm Memory System Resource Partitioning and Monitoring (MPAM) System

drivers/resctrl/ renamed from drivers/resctrl/mpam_resctrl.c +0 -0

mpam_resctrl.c
new file mode 100644
index 000000000000..2ffba7a15d6a

drivers/resctrl/mpam_resctrl.c new file +17 -0
@@ -0,0 +1,327 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2025 Arm Ltd.
+
+#define pr_fmt(fmt) "%s:%s: " fmt, KBUILD_MODNAME, __func__
+
+#include <linux/arm_mpam.h>
+#include <linux/cacheinfo.h>
+#include <linux/cpu.h>
+#include <linux/cpumask.h>
+#include <linux/errno.h>
+#include <linux/list.h>
+#include <linux/printk.h>
+#include <linux/rculist.h>
+#include <linux/resctrl.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+
Quoted 8 lines

drivers/resctrl/mpam_resctrl.c line 21

Quoted 4 lines
drivers/resctrl/mpam_resctrl.c new file +4 -0
+#include <asm/mpam.h>
+
+#include "mpam_internal.h"
+

The list of included headers could be simplified since several header files have been included to mpam_internal.h, for example <linux/arm_mpam.h>, <linux/cpumask.h>, <asm/mpam.h> and others.

Could be but it is a deliberate choice to where practical include the header where the symbols are defined rather than relying on the indirect includes.

Quoted 308 lines
Quoted 93 lines
drivers/resctrl/mpam_resctrl.c new file +13 -0
+/*
+ * The classes we've picked to map to resctrl resources, wrapped
+ * in with their resctrl structure.
+ * Class pointer may be NULL.
+ */
+static struct mpam_resctrl_res mpam_resctrl_controls[RDT_NUM_RESOURCES];
+
+#define for_each_mpam_resctrl_control(res, rid)                    \
+    for (rid = 0, res = &mpam_resctrl_controls[rid];            \
+         rid < RDT_NUM_RESOURCES;                        \
+         rid++, res = &mpam_resctrl_controls[rid])
+
+/* The lock for modifying resctrl's domain lists from cpuhp

callbacks. */

drivers/resctrl/mpam_resctrl.c new file +17 -0
+static DEFINE_MUTEX(domain_list_lock);
+
+bool resctrl_arch_alloc_capable(void)
+{
+    struct mpam_resctrl_res *res;
+    enum resctrl_res_level rid;
+
+    for_each_mpam_resctrl_control(res, rid) {
+        if (res->resctrl_res.alloc_capable)
+            return true;
+    }
+
+    return false;
+}
+
+/*
+ * MSC may raise an error interrupt if it sees an out or range

partid/pmg,
+ * and go on to truncate the value. Regardless of what the hardware supports,
+ * only the system wide safe value is safe to use.
+ */

drivers/resctrl/mpam_resctrl.c new file +21 -0
+u32 resctrl_arch_get_num_closid(struct rdt_resource *ignored)
+{
+    return mpam_partid_max + 1;
+}
+
+struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l)
+{
+    if (l >= RDT_NUM_RESOURCES)
+        return NULL;
+
+    return &mpam_resctrl_controls[l].resctrl_res;
+}
+
+static int mpam_resctrl_control_init(struct mpam_resctrl_res *res)
+{
+    /* TODO: initialise the resctrl resources */
+
+    return 0;
+}
+
+static int mpam_resctrl_pick_domain_id(int cpu, struct mpam_component

*comp)

drivers/resctrl/mpam_resctrl.c new file +12 -0
+{
+    struct mpam_class *class = comp->class;
+
+    if (class->type == MPAM_CLASS_CACHE)
+        return comp->comp_id;
+
+    /* TODO: repaint domain ids to match the L3 domain ids */
+    /* Otherwise, expose the ID used by the firmware table code. */
+    return comp->comp_id;
+}
+
+static void mpam_resctrl_domain_hdr_init(int cpu, struct

mpam_component *comp,
+                     enum resctrl_res_level rid,
+                     struct rdt_domain_hdr *hdr)

drivers/resctrl/mpam_resctrl.c new file +19 -0
+{
+    lockdep_assert_cpus_held();
+
+    INIT_LIST_HEAD(&hdr->list);
+    hdr->id = mpam_resctrl_pick_domain_id(cpu, comp);
+    hdr->rid = rid;
+    cpumask_set_cpu(cpu, &hdr->cpu_mask);
+}
+
+static void mpam_resctrl_online_domain_hdr(unsigned int cpu,
+                       struct rdt_domain_hdr *hdr)
+{
+    lockdep_assert_cpus_held();
+
+    cpumask_set_cpu(cpu, &hdr->cpu_mask);
+}
+
+/**
+ * mpam_resctrl_offline_domain_hdr() - Update the domain header to
Quoted 6 lines

remove a CPU.
+ * @cpu:    The CPU to remove from the domain.
+ * @hdr:    The domain's header.
+ *
+ * Removes @cpu from the header mask. If this was the last CPU in the domain,

                                                 ^^^ is

Quoted 206 lines

+ * the domain header is removed from its parent list and true is returned,
+ * indicating the parent structure can be freed.
+ * If there are other CPUs in the domain, returns false.
+ */

drivers/resctrl/mpam_resctrl.c new file +32 -0
+static bool mpam_resctrl_offline_domain_hdr(unsigned int cpu,
+                        struct rdt_domain_hdr *hdr)
+{
+    lockdep_assert_held(&domain_list_lock);
+
+    cpumask_clear_cpu(cpu, &hdr->cpu_mask);
+    if (cpumask_empty(&hdr->cpu_mask)) {
+        list_del_rcu(&hdr->list);
+        synchronize_rcu();
+        return true;
+    }
+
+    return false;
+}
+
+static void 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;
+
+    list_add_tail_rcu(&new->list, pos);
+}
+
+static struct mpam_resctrl_dom *
+mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res

*res)

drivers/resctrl/mpam_resctrl.c new file +33 -0
+{
+    int err;
+    struct mpam_resctrl_dom *dom;
+    struct rdt_ctrl_domain *ctrl_d;
+    struct mpam_class *class = res->class;
+    struct mpam_component *comp_iter, *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;
+        }
+    }
+
+    /* class has no component for this CPU */
+    if (WARN_ON_ONCE(!ctrl_comp))
+        return ERR_PTR(-EINVAL);
+
+    dom = kzalloc_node(sizeof(*dom), GFP_KERNEL, cpu_to_node(cpu));
+    if (!dom)
+        return ERR_PTR(-ENOMEM);
+
+    if (resctrl_arch_alloc_capable()) {
+        dom->ctrl_comp = ctrl_comp;
+
+        ctrl_d = &dom->resctrl_ctrl_dom;
+        mpam_resctrl_domain_hdr_init(cpu, ctrl_comp, r->rid, &ctrl_d-
Quoted 1 line

hdr);

+        ctrl_d->hdr.type = RESCTRL_CTRL_DOMAIN; +        err = resctrl_online_ctrl_domain(r, ctrl_d); +        if (err)
+            goto free_domain;

drivers/resctrl/mpam_resctrl.c new file +28 -0
+
+        mpam_resctrl_domain_insert(&r->ctrl_domains, &ctrl_d->hdr);
+    } else {
+        pr_debug("Skipped control domain online - no controls\n");
+    }
+    return dom;
+
+offline_ctrl_domain:
+    if (resctrl_arch_alloc_capable()) {
+        mpam_resctrl_offline_domain_hdr(cpu, &ctrl_d->hdr);
+        resctrl_offline_ctrl_domain(r, ctrl_d);
+    }
+free_domain:
+    kfree(dom);
+    dom = ERR_PTR(err);
+
+    return dom;
+}
+
+static struct mpam_resctrl_dom *
+mpam_resctrl_get_domain_from_cpu(int cpu, struct mpam_resctrl_res *res)
+{
+    struct mpam_resctrl_dom *dom;
+    struct rdt_resource *r = &res->resctrl_res;
+
+    lockdep_assert_cpus_held();
+
+    list_for_each_entry_rcu(dom, &r->ctrl_domains,

resctrl_ctrl_dom.hdr.list) {
+        if (cpumask_test_cpu(cpu, &dom->ctrl_comp->affinity)) +            return dom;
+    }

drivers/resctrl/mpam_resctrl.c new file +58 -0
+
+    return NULL;
+}
+
+int mpam_resctrl_online_cpu(unsigned int cpu)
+{
+    struct mpam_resctrl_res *res;
+    enum resctrl_res_level rid;
+
+    guard(mutex)(&domain_list_lock);
+    for_each_mpam_resctrl_control(res, rid) {
+        struct mpam_resctrl_dom *dom;
+
+        if (!res->class)
+            continue;    // dummy_resource;
+
+        dom = mpam_resctrl_get_domain_from_cpu(cpu, res);
+        if (!dom) {
+            dom = mpam_resctrl_alloc_domain(cpu, res);
+        } else {
+            if (resctrl_arch_alloc_capable()) {
+                struct rdt_ctrl_domain *ctrl_d = &dom->resctrl_ctrl_dom;
+
+                mpam_resctrl_online_domain_hdr(cpu, &ctrl_d->hdr);
+            }
+        }
+        if (IS_ERR(dom))
+            return PTR_ERR(dom);
+    }
+
+    resctrl_online_cpu(cpu);
+
+    return 0;
+}
+
+void mpam_resctrl_offline_cpu(unsigned int cpu)
+{
+    struct mpam_resctrl_res *res;
+    enum resctrl_res_level rid;
+
+    resctrl_offline_cpu(cpu);
+
+    guard(mutex)(&domain_list_lock);
+    for_each_mpam_resctrl_control(res, rid) {
+        struct mpam_resctrl_dom *dom;
+        struct rdt_ctrl_domain *ctrl_d;
+        bool ctrl_dom_empty;
+
+        if (!res->class)
+            continue;    // dummy resource
+
+        dom = mpam_resctrl_get_domain_from_cpu(cpu, res);
+        if (WARN_ON_ONCE(!dom))
+            continue;
+
+        if (resctrl_arch_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;
+        }

drivers/resctrl/mpam_resctrl.c new file +34 -0
+
+        if (ctrl_dom_empty)
+            kfree(dom);
+    }
+}
+
+int mpam_resctrl_setup(void)
+{
+    int err = 0;
+    struct mpam_resctrl_res *res;
+    enum resctrl_res_level rid;
+
+    cpus_read_lock();
+    for_each_mpam_resctrl_control(res, rid) {
+        INIT_LIST_HEAD_RCU(&res->resctrl_res.ctrl_domains);
+        res->resctrl_res.rid = rid;
+    }
+
+    /* TODO: pick MPAM classes to map to resctrl resources */
+
+    /* Initialise the resctrl structures from the classes */
+    for_each_mpam_resctrl_control(res, rid) {
+        if (!res->class)
+            continue;    // dummy resource
+
+        err = mpam_resctrl_control_init(res);
+        if (err) {
+            pr_debug("Failed to initialise rid %u\n", rid);
+            break;
+        }
+    }
+    cpus_read_unlock();
+
+    if (err) {
Quoted 8 lines
Quoted 4 lines

+        pr_debug("Internal error %d - resctrl not supported\n", err); +        return err;
+    }
+

This pr_debug() could be dropped since @err is set to true only when a error is returned from mpam_resctrl_control_init(), we already had a pr_debug() for the reported error.

Later in the series this can be an error from mpam_resctrl_monitor_init() which does also have an associated pr_debug() but to me it seems reasonable to have this extra message to make the severity clearer.

Thanks,

Ben

author maintainer
#26 lore raw

PATCH v5 14/41 arm_mpam: resctrl: Pick the caches we will use as resctrl resources

In reply to Ben Horgan

From: James Morse <[email protected]>

Systems with MPAM support may have a variety of control types at any point of their system layout. We can only expose certain types of control, and only if they exist at particular locations.

Start with the well-known caches. These have to be depth 2 or 3 and support MPAM's cache portion bitmap controls, with a number of portions fewer than resctrl's limit.

---
Changes since rfc:
Jonathan:
Remove brackets
Compress debug message
Use temp var, r

Changes since v2:
Return -EINVAL in mpam_resctrl_control_init() for unknown rid

Changes since v4:
Set alloc_capable after other settings (Reinette)

---
 drivers/resctrl/mpam_resctrl.c | 89 +++++++++++++++++++++++++++++++++-
 1 file changed, 87 insertions(+), 2 deletions(-)
drivers/resctrl/mpam_resctrl.c +87 -2
index 2ffba7a15d6a..fe566e39aa4d 100644
@@ -65,9 +65,93 @@ struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l)
 	return &mpam_resctrl_controls[l].resctrl_res;
 }
 
+static bool cache_has_usable_cpor(struct mpam_class *class)
+{
+	struct mpam_props *cprops = &class->props;
+
+	if (!mpam_has_feature(mpam_feat_cpor_part, cprops))
+		return false;
+
+	/* resctrl uses u32 for all bitmap configurations */
+	return class->props.cpbm_wd <= 32;
+}
+
+/* Test whether we can export MPAM_CLASS_CACHE:{2,3}? */
+static void mpam_resctrl_pick_caches(void)
+{
+	struct mpam_class *class;
+	struct mpam_resctrl_res *res;
+
+	lockdep_assert_cpus_held();
+
+	guard(srcu)(&mpam_srcu);
+	list_for_each_entry_srcu(class, &mpam_classes, classes_list,
+				 srcu_read_lock_held(&mpam_srcu)) {
+		if (class->type != MPAM_CLASS_CACHE) {
+			pr_debug("class %u is not a cache\n", class->level);
+			continue;
+		}
+
+		if (class->level != 2 && class->level != 3) {
+			pr_debug("class %u is not L2 or L3\n", class->level);
+			continue;
+		}
+
+		if (!cache_has_usable_cpor(class)) {
+			pr_debug("class %u cache misses CPOR\n", class->level);
+			continue;
+		}
+
+		if (!cpumask_equal(&class->affinity, cpu_possible_mask)) {
+			pr_debug("class %u has missing CPUs, mask %*pb != %*pb\n", class->level,
+				 cpumask_pr_args(&class->affinity),
+				 cpumask_pr_args(cpu_possible_mask));
+			continue;
+		}
+
+		if (class->level == 2)
+			res = &mpam_resctrl_controls[RDT_RESOURCE_L2];
+		else
+			res = &mpam_resctrl_controls[RDT_RESOURCE_L3];
+		res->class = class;
+	}
+}
+
 static int mpam_resctrl_control_init(struct mpam_resctrl_res *res)
 {
-	/* TODO: initialise the resctrl resources */
+	struct mpam_class *class = res->class;
+	struct rdt_resource *r = &res->resctrl_res;
+
+	switch (r->rid) {
+	case RDT_RESOURCE_L2:
+	case RDT_RESOURCE_L3:
+		r->schema_fmt = RESCTRL_SCHEMA_BITMAP;
+		r->cache.arch_has_sparse_bitmasks = true;
+
+		r->cache.cbm_len = class->props.cpbm_wd;
+		/* mpam_devices will reject empty bitmaps */
+		r->cache.min_cbm_bits = 1;
+
+		if (r->rid == RDT_RESOURCE_L2) {
+			r->name = "L2";
+			r->ctrl_scope = RESCTRL_L2_CACHE;
+		} else {
+			r->name = "L3";
+			r->ctrl_scope = RESCTRL_L3_CACHE;
+		}
+
+		/*
+		 * Which bits are shared with other ...things...
+		 * Unknown devices use partid-0 which uses all the bitmap
+		 * fields. Until we configured the SMMU and GIC not to do this
+		 * 'all the bits' is the correct answer here.
+		 */
+		r->cache.shareable_bits = resctrl_get_default_ctrl(r);
+		r->alloc_capable = true;
+		break;
+	default:
+		return -EINVAL;
+	}
 
 	return 0;
 }
@@ -295,7 +379,8 @@ int mpam_resctrl_setup(void)
 		res->resctrl_res.rid = rid;
 	}
 
-	/* TODO: pick MPAM classes to map to resctrl resources */
+	/* Find some classes to use for controls */
+	mpam_resctrl_pick_caches();
 
 	/* Initialise the resctrl structures from the classes */
 	for_each_mpam_resctrl_control(res, rid) {
Signature · 1 line
2.43.0
author maintainer
#27 lore raw

PATCH v5 15/41 arm_mpam: resctrl: Implement resctrl_arch_reset_all_ctrls()

In reply to Ben Horgan

From: James Morse <[email protected]>

We already have a helper for resetting an mpam class and component. Hook it up to resctrl_arch_reset_all_ctrls() and the domain offline path.

---
Changes since v2:
Don't expose unlocked reset

Changes since v3:
Don't use or expose mpam_reset_component_locked()

---
 drivers/resctrl/mpam_devices.c  |  2 +-
 drivers/resctrl/mpam_internal.h |  3 +++
 drivers/resctrl/mpam_resctrl.c  | 13 +++++++++++++
 3 files changed, 17 insertions(+), 1 deletion(-)
drivers/resctrl/mpam_devices.c +1 -1
index b45743c5fb46..e4a302a53991 100644
@@ -2567,7 +2567,7 @@ static void mpam_reset_component_locked(struct mpam_component *comp)
 	}
 }
 
-static void mpam_reset_class_locked(struct mpam_class *class)
+void mpam_reset_class_locked(struct mpam_class *class)
 {
 	struct mpam_component *comp;
 
drivers/resctrl/mpam_internal.h +3 -0
index 28ac501e1ac3..e2704f678af5 100644
@@ -392,6 +392,9 @@ extern u8 mpam_pmg_max;
 void mpam_enable(struct work_struct *work);
 void mpam_disable(struct work_struct *work);
 
+/* Reset all the RIS in a class under cpus_read_lock() */
+void mpam_reset_class_locked(struct mpam_class *class);
+
 int mpam_apply_config(struct mpam_component *comp, u16 partid,
 		      struct mpam_config *cfg);
 
drivers/resctrl/mpam_resctrl.c +13 -0
index fe566e39aa4d..5f482c6293e7 100644
@@ -168,6 +168,19 @@ static int mpam_resctrl_pick_domain_id(int cpu, struct mpam_component *comp)
 	return comp->comp_id;
 }
 
+void resctrl_arch_reset_all_ctrls(struct rdt_resource *r)
+{
+	struct mpam_resctrl_res *res;
+
+	lockdep_assert_cpus_held();
+
+	if (!mpam_is_enabled())
+		return;
+
+	res = container_of(r, struct mpam_resctrl_res, resctrl_res);
+	mpam_reset_class_locked(res->class);
+}
+
 static void mpam_resctrl_domain_hdr_init(int cpu, struct mpam_component *comp,
 					 enum resctrl_res_level rid,
 					 struct rdt_domain_hdr *hdr)
Signature · 1 line
2.43.0
Reviewed-by on v5 15/41
#28 lore raw

Re: [PATCH v5 15/41] arm_mpam: resctrl: Implement resctrl_arch_reset_all_ctrls()

Quoted 5 lines · On Tue, 24 Feb 2026 17:56:54 +0000 Ben Horgan <[email protected]> wrote:

From: James Morse <[email protected]>

We already have a helper for resetting an mpam class and component. Hook it up to resctrl_arch_reset_all_ctrls() and the domain offline path.

Quoted 8 lines
author maintainer
#29 lore raw

PATCH v5 16/41 arm_mpam: resctrl: Add resctrl_arch_get_config()

In reply to Ben Horgan

From: James Morse <[email protected]>

Implement resctrl_arch_get_config() by testing the live configuration for a CPOR bitmap. For any other configuration type return the default.

---
 drivers/resctrl/mpam_resctrl.c | 43 ++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
drivers/resctrl/mpam_resctrl.c +43 -0
index 5f482c6293e7..d5caab6b8545 100644
@@ -168,6 +168,49 @@ static int mpam_resctrl_pick_domain_id(int cpu, struct mpam_component *comp)
 	return comp->comp_id;
 }
 
+u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d,
+			    u32 closid, enum resctrl_conf_type type)
+{
+	u32 partid;
+	struct mpam_config *cfg;
+	struct mpam_props *cprops;
+	struct mpam_resctrl_res *res;
+	struct mpam_resctrl_dom *dom;
+	enum mpam_device_features configured_by;
+
+	lockdep_assert_cpus_held();
+
+	if (!mpam_is_enabled())
+		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);
+	cprops = &res->class->props;
+
+	partid = resctrl_get_config_index(closid, type);
+	cfg = &dom->ctrl_comp->cfg[partid];
+
+	switch (r->rid) {
+	case RDT_RESOURCE_L2:
+	case RDT_RESOURCE_L3:
+		configured_by = mpam_feat_cpor_part;
+		break;
+	default:
+		return resctrl_get_default_ctrl(r);
+	}
+
+	if (!r->alloc_capable || partid >= resctrl_arch_get_num_closid(r) ||
+	    !mpam_has_feature(configured_by, cfg))
+		return resctrl_get_default_ctrl(r);
+
+	switch (configured_by) {
+	case mpam_feat_cpor_part:
+		return cfg->cpbm;
+	default:
+		return resctrl_get_default_ctrl(r);
+	}
+}
+
 void resctrl_arch_reset_all_ctrls(struct rdt_resource *r)
 {
 	struct mpam_resctrl_res *res;
Signature · 1 line
2.43.0
author maintainer
#30 lore raw

PATCH v5 17/41 arm_mpam: resctrl: Implement helpers to update configuration

In reply to Ben Horgan

From: James Morse <[email protected]>

resctrl has two helpers for updating the configuration. resctrl_arch_update_one() updates a single value, and is used by the software-controller to apply feedback to the bandwidth controls, it has to be called on one of the CPUs in the resctrl:domain.

resctrl_arch_update_domains() copies multiple staged configurations, it can be called from anywhere.

Both helpers should update any changes to the underlying hardware.

Implement resctrl_arch_update_domains() to use resctrl_arch_update_one(). Neither need to be called on a specific CPU as the mpam driver will send IPIs as needed.

---
Changes since rfc:
list_for_each_entry -> list_for_each_entry_rcu
return 0
Restrict scope of local variables

Changes since v2:
whitespace fix

---
 drivers/resctrl/mpam_resctrl.c | 70 ++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)
drivers/resctrl/mpam_resctrl.c +70 -0
index d5caab6b8545..3ca762c3fae6 100644
@@ -211,6 +211,76 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d,
 	}
 }
 
+int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d,
+			    u32 closid, enum resctrl_conf_type t, u32 cfg_val)
+{
+	u32 partid;
+	struct mpam_config cfg;
+	struct mpam_props *cprops;
+	struct mpam_resctrl_res *res;
+	struct mpam_resctrl_dom *dom;
+
+	lockdep_assert_cpus_held();
+	lockdep_assert_irqs_enabled();
+
+	/*
+	 * No need to check the CPU as mpam_apply_config() doesn't care, and
+	 * 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);
+	cprops = &res->class->props;
+
+	partid = resctrl_get_config_index(closid, t);
+	if (!r->alloc_capable || partid >= resctrl_arch_get_num_closid(r)) {
+		pr_debug("Not alloc capable or computed PARTID out of range\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Copy the current config to avoid clearing other resources when the
+	 * same component is exposed multiple times through resctrl.
+	 */
+	cfg = dom->ctrl_comp->cfg[partid];
+
+	switch (r->rid) {
+	case RDT_RESOURCE_L2:
+	case RDT_RESOURCE_L3:
+		cfg.cpbm = cfg_val;
+		mpam_set_feature(mpam_feat_cpor_part, &cfg);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return mpam_apply_config(dom->ctrl_comp, partid, &cfg);
+}
+
+int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)
+{
+	int err;
+	struct rdt_ctrl_domain *d;
+
+	lockdep_assert_cpus_held();
+	lockdep_assert_irqs_enabled();
+
+	list_for_each_entry_rcu(d, &r->ctrl_domains, hdr.list) {
+		for (enum resctrl_conf_type t = 0; t < CDP_NUM_TYPES; t++) {
+			struct resctrl_staged_config *cfg = &d->staged_config[t];
+
+			if (!cfg->have_new_ctrl)
+				continue;
+
+			err = resctrl_arch_update_one(r, d, closid, t,
+						      cfg->new_ctrl);
+			if (err)
+				return err;
+		}
+	}
+
+	return 0;
+}
+
 void resctrl_arch_reset_all_ctrls(struct rdt_resource *r)
 {
 	struct mpam_resctrl_res *res;
Signature · 1 line
2.43.0
author maintainer
#31 lore raw

PATCH v5 18/41 arm_mpam: resctrl: Add plumbing against arm64 task and cpu hooks

In reply to Ben Horgan

From: James Morse <[email protected]>

arm64 provides helpers for changing a task's and a cpu's mpam partid/pmg values.

These are used to back a number of resctrl_arch_ functions. Connect them up.

---
Changes since v2:
apostrophes in commit message

---
 drivers/resctrl/mpam_resctrl.c | 58 ++++++++++++++++++++++++++++++++++
 include/linux/arm_mpam.h       |  5 +++
 2 files changed, 63 insertions(+)
drivers/resctrl/mpam_resctrl.c +58 -0
index 3ca762c3fae6..5551e5416620 100644
@@ -8,6 +8,7 @@
 #include <linux/cpu.h>
 #include <linux/cpumask.h>
 #include <linux/errno.h>
+#include <linux/limits.h>
 #include <linux/list.h>
 #include <linux/printk.h>
 #include <linux/rculist.h>
@@ -34,6 +35,8 @@ static struct mpam_resctrl_res mpam_resctrl_controls[RDT_NUM_RESOURCES];
 /* The lock for modifying resctrl's domain lists from cpuhp callbacks. */
 static DEFINE_MUTEX(domain_list_lock);
 
+static bool cdp_enabled;
+
 bool resctrl_arch_alloc_capable(void)
 {
 	struct mpam_resctrl_res *res;
@@ -57,6 +60,61 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *ignored)
 	return mpam_partid_max + 1;
 }
 
+void resctrl_arch_sched_in(struct task_struct *tsk)
+{
+	lockdep_assert_preemption_disabled();
+
+	mpam_thread_switch(tsk);
+}
+
+void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid, u32 rmid)
+{
+	WARN_ON_ONCE(closid > U16_MAX);
+	WARN_ON_ONCE(rmid > U8_MAX);
+
+	if (!cdp_enabled) {
+		mpam_set_cpu_defaults(cpu, closid, closid, rmid, rmid);
+	} else {
+		/*
+		 * When CDP is enabled, resctrl halves the closid range and we
+		 * use odd/even partid for one closid.
+		 */
+		u32 partid_d = resctrl_get_config_index(closid, CDP_DATA);
+		u32 partid_i = resctrl_get_config_index(closid, CDP_CODE);
+
+		mpam_set_cpu_defaults(cpu, partid_d, partid_i, rmid, rmid);
+	}
+}
+
+void resctrl_arch_sync_cpu_closid_rmid(void *info)
+{
+	struct resctrl_cpu_defaults *r = info;
+
+	lockdep_assert_preemption_disabled();
+
+	if (r) {
+		resctrl_arch_set_cpu_default_closid_rmid(smp_processor_id(),
+							 r->closid, r->rmid);
+	}
+
+	resctrl_arch_sched_in(current);
+}
+
+void resctrl_arch_set_closid_rmid(struct task_struct *tsk, u32 closid, u32 rmid)
+{
+	WARN_ON_ONCE(closid > U16_MAX);
+	WARN_ON_ONCE(rmid > U8_MAX);
+
+	if (!cdp_enabled) {
+		mpam_set_task_partid_pmg(tsk, closid, closid, rmid, rmid);
+	} else {
+		u32 partid_d = resctrl_get_config_index(closid, CDP_DATA);
+		u32 partid_i = resctrl_get_config_index(closid, CDP_CODE);
+
+		mpam_set_task_partid_pmg(tsk, partid_d, partid_i, rmid, rmid);
+	}
+}
+
 struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l)
 {
 	if (l >= RDT_NUM_RESOURCES)
include/linux/arm_mpam.h +5 -0
index 2c7d1413a401..5a78299ec464 100644
@@ -52,6 +52,11 @@ static inline int mpam_ris_create(struct mpam_msc *msc, u8 ris_idx,
 bool resctrl_arch_alloc_capable(void);
 bool resctrl_arch_mon_capable(void);
 
+void resctrl_arch_set_cpu_default_closid(int cpu, u32 closid);
+void resctrl_arch_set_closid_rmid(struct task_struct *tsk, u32 closid, u32 rmid);
+void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid, u32 rmid);
+void resctrl_arch_sched_in(struct task_struct *tsk);
+
 /**
  * mpam_register_requestor() - Register a requestor with the MPAM driver
  * @partid_max:		The maximum PARTID value the requestor can generate.
Signature · 1 line
2.43.0
author maintainer
#32 lore raw

PATCH v5 19/41 arm_mpam: resctrl: Add CDP emulation

In reply to Ben Horgan

From: James Morse <[email protected]>

Intel RDT's CDP feature allows the cache to use a different control value depending on whether the accesses was for instruction fetch or a data access. MPAM's equivalent feature is the other way up: the CPU assigns a different partid label to traffic depending on whether it was instruction fetch or a data access, which causes the cache to use a different control value based solely on the partid.

MPAM can emulate CDP, with the side effect that the alternative partid is seen by all MSC, it can't be enabled per-MSC.

Add the resctrl hooks to turn this on or off. Add the helpers that match a closid against a task, which need to be aware that the value written to hardware is not the same as the one resctrl is using.

Update the 'arm64_mpam_global_default' variable the arch code uses during context switch to know when the per-cpu value should be used instead. Also, update these per-cpu values and sync the resulting mpam partid/pmg configuration to hardware.

resctrl can enable CDP for L2 caches, L3 caches or both. When it is enabled by one and not the other MPAM globally enabled CDP but hides the effect on the other cache resource. This hiding is possible as CPOR is the only supported cache control and that uses a resource bitmap; two partids with the same bitmap act as one.

Awkwardly, the MB controls don't implement CDP and CDP can't be hidden as the memory bandwidth control is a maximum per partid which can't be modelled with more partids. If the total maximum is used for both the data and instruction partids then then the maximum may be exceeded and if it is split in two then the one using more bandwidth will hit a lower limit. Hence, hide the MB controls completely if CDP is enabled for any resource.

---
Changes since rfc:
Fail cdp initialisation if there is only one partid Correct data/code confusion

Changes since v2:
Don't include unused header

Changes since v3:
Update the per-cpu values and sync to h/w

Changes since v4:
Enable separately for L2 and L3
Disable MB controls if CDP enabled
Consider cdp hiding in resctrl_arch_update_one()

---
 arch/arm64/include/asm/mpam.h   |   1 +
 drivers/resctrl/mpam_internal.h |   1 +
 drivers/resctrl/mpam_resctrl.c  | 119 ++++++++++++++++++++++++++++++++
 include/linux/arm_mpam.h        |   2 +
 4 files changed, 123 insertions(+)
arch/arm64/include/asm/mpam.h +1 -0
index 05aa71200f61..70d396e7b6da 100644
@@ -4,6 +4,7 @@
 #ifndef __ASM__MPAM_H
 #define __ASM__MPAM_H
 
+#include <linux/arm_mpam.h>
 #include <linux/bitfield.h>
 #include <linux/jump_label.h>
 #include <linux/percpu.h>
drivers/resctrl/mpam_internal.h +1 -0
index e2704f678af5..57c3d9b962b9 100644
@@ -346,6 +346,7 @@ struct mpam_resctrl_dom {
 struct mpam_resctrl_res {
 	struct mpam_class	*class;
 	struct rdt_resource	resctrl_res;
+	bool			cdp_enabled;
 };
 
 static inline int mpam_alloc_csu_mon(struct mpam_class *class)
drivers/resctrl/mpam_resctrl.c +119 -0

161 lines not on this page · raw message

include/linux/arm_mpam.h +2 -0
index 5a78299ec464..d329b1dc148b 100644
@@ -56,6 +56,8 @@ void resctrl_arch_set_cpu_default_closid(int cpu, u32 closid);
 void resctrl_arch_set_closid_rmid(struct task_struct *tsk, u32 closid, u32 rmid);
 void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid, u32 rmid);
 void resctrl_arch_sched_in(struct task_struct *tsk);
+bool resctrl_arch_match_closid(struct task_struct *tsk, u32 closid);
+bool resctrl_arch_match_rmid(struct task_struct *tsk, u32 closid, u32 rmid);
 
 /**
  * mpam_register_requestor() - Register a requestor with the MPAM driver
Signature · 1 line
2.43.0
Reviewed-by on v5 19/41
#33 lore raw

Re: [PATCH v5 19/41] arm_mpam: resctrl: Add CDP emulation

Quoted 53 lines · Ben Horgan

From: James Morse <[email protected]>

Intel RDT's CDP feature allows the cache to use a different control value depending on whether the accesses was for instruction fetch or a data access. MPAM's equivalent feature is the other way up: the CPU assigns a different partid label to traffic depending on whether it was instruction fetch or a data access, which causes the cache to use a different control value based solely on the partid.

MPAM can emulate CDP, with the side effect that the alternative partid is seen by all MSC, it can't be enabled per-MSC.

Add the resctrl hooks to turn this on or off. Add the helpers that match a closid against a task, which need to be aware that the value written to hardware is not the same as the one resctrl is using.

Update the 'arm64_mpam_global_default' variable the arch code uses during context switch to know when the per-cpu value should be used instead. Also, update these per-cpu values and sync the resulting mpam partid/pmg configuration to hardware.

resctrl can enable CDP for L2 caches, L3 caches or both. When it is enabled by one and not the other MPAM globally enabled CDP but hides the effect on the other cache resource. This hiding is possible as CPOR is the only supported cache control and that uses a resource bitmap; two partids with the same bitmap act as one.

Awkwardly, the MB controls don't implement CDP and CDP can't be hidden as the memory bandwidth control is a maximum per partid which can't be modelled with more partids. If the total maximum is used for both the data and instruction partids then then the maximum may be exceeded and if it is split in two then the one using more bandwidth will hit a lower limit. Hence, hide the MB controls completely if CDP is enabled for any resource.

---
Changes since rfc:
Fail cdp initialisation if there is only one partid Correct data/code confusion

Changes since v2:
Don't include unused header

Quoted 7 lines

Changes since v3:
Update the per-cpu values and sync to h/w

Changes since v4:
Enable separately for L2 and L3
Disable MB controls if CDP enabled
Consider cdp hiding in resctrl_arch_update_one()

[...]

@ -245,6 +338,14 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d,

drivers/resctrl/mpam_resctrl.c u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d, · line 348

Quoted 11 lines
  	dom = container_of(d, struct mpam_resctrl_dom, resctrl_ctrl_dom);
  	cprops = &res->class->props;
drivers/resctrl/mpam_resctrl.c +8 -0
+	/*
+	 * When CDP is enabled, but the resource doesn't support it,
+	 * the control is cloned across both partids.
+	 * Pick one at random to read:
+	 */
+	if (mpam_resctrl_hide_cdp(r->rid))
+		type = CDP_DATA;
+

Yes, I have observed that this issue had already been addressed in resctrl_arch_get_config() before the mpam_resctrl_glue_v4 release.

Quoted 12 lines
  	partid = resctrl_get_config_index(closid, type);
  	cfg = &dom->ctrl_comp->cfg[partid];
drivers/resctrl/mpam_resctrl.c +1 -0
@@ -272,6 +373,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d,
  int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d,
  			    u32 closid, enum resctrl_conf_type t, u32 cfg_val)
  {
+	int err;
  	u32 partid;
  	struct mpam_config cfg;
  	struct mpam_props *cprops;

drivers/resctrl/mpam_resctrl.c int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d, · line 396

Quoted 6 lines
drivers/resctrl/mpam_resctrl.c +3 -0
@@ -289,6 +391,9 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d,
  	dom = container_of(d, struct mpam_resctrl_dom, resctrl_ctrl_dom);
  	cprops = &res->class->props;
 
+	if (mpam_resctrl_hide_cdp(r->rid))
+		t = CDP_DATA;
+

Fix for resctrl_arch_update_one() has been confirmed.

Best regards,
Zeng Heng

author maintainer
#34 lore raw

PATCH v5 20/41 arm_mpam: resctrl: Convert to/from MPAMs fixed-point formats

In reply to Ben Horgan

From: Dave Martin <[email protected]>

MPAM uses a fixed-point formats for some hardware controls. Resctrl provides the bandwidth controls as a percentage. Add helpers to convert between these.

Ensure bwa_wd is at most 16 to make it clear higher values have no meaning.

---
Changes since v2:
Ensure bwa_wd is at most 16 (moved from patch 40: arm_mpam: Generate a configuration for min controls)
Expand comments

---
 drivers/resctrl/mpam_devices.c |  7 +++++
 drivers/resctrl/mpam_resctrl.c | 51 ++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)
drivers/resctrl/mpam_devices.c +7 -0
index e4a302a53991..90d69091e0b9 100644
@@ -713,6 +713,13 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris)
 			mpam_set_feature(mpam_feat_mbw_part, props);
 
 		props->bwa_wd = FIELD_GET(MPAMF_MBW_IDR_BWA_WD, mbw_features);
+
+		/*
+		 * The BWA_WD field can represent 0-63, but the control fields it
+		 * describes have a maximum of 16 bits.
+		 */
+		props->bwa_wd = min(props->bwa_wd, 16);
+
 		if (props->bwa_wd && FIELD_GET(MPAMF_MBW_IDR_HAS_MAX, mbw_features))
 			mpam_set_feature(mpam_feat_mbw_max, props);
 
drivers/resctrl/mpam_resctrl.c +51 -0

63 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#35 lore raw

PATCH v5 21/41 arm_mpam: resctrl: Add kunit test for control format conversions

In reply to Ben Horgan

From: Dave Martin <[email protected]>

resctrl specifies the format of the control schemes, and these don't match the hardware.

Some of the conversions are a bit hairy - add some kunit tests.

---
Changes since v2:
Include additional values from the latest spec

---
 drivers/resctrl/mpam_resctrl.c      |   4 +
 drivers/resctrl/test_mpam_resctrl.c | 315 ++++++++++++++++++++++++++++
 2 files changed, 319 insertions(+)
 create mode 100644 drivers/resctrl/test_mpam_resctrl.c
drivers/resctrl/mpam_resctrl.c +4 -0
index 38d1b7f48ecf..ded18a9d4cd4 100644
@@ -764,3 +764,7 @@ int mpam_resctrl_setup(void)
 
 	return 0;
 }
+
+#ifdef CONFIG_MPAM_KUNIT_TEST
+#include "test_mpam_resctrl.c"
+#endif
drivers/resctrl/test_mpam_resctrl.c new file +315 -0

315 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#36 lore raw

PATCH v5 22/41 arm_mpam: resctrl: Add rmid index helpers

In reply to Ben Horgan

Because MPAM's pmg aren't identical to RDT's rmid, resctrl handles some data structures by index. This allows x86 to map indexes to RMID, and MPAM to map them to partid-and-pmg.

Add the helpers to do this.

---
Changes since rfc:
Use ~0U instead of ~0 in lhs of left shift

Changes since v2:
Drop changes signed-off-by as reworked patch Use multiply and add rather than shift to avoid holes

---
 drivers/resctrl/mpam_resctrl.c | 16 ++++++++++++++++
 include/linux/arm_mpam.h       |  3 +++
 2 files changed, 19 insertions(+)
drivers/resctrl/mpam_resctrl.c +16 -0
index ded18a9d4cd4..48f96d7f9109 100644
@@ -130,6 +130,22 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *ignored)
 	return mpam_partid_max + 1;
 }
 
+u32 resctrl_arch_system_num_rmid_idx(void)
+{
+	return (mpam_pmg_max + 1) * (mpam_partid_max + 1);
+}
+
+u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid)
+{
+	return closid * (mpam_pmg_max + 1) + rmid;
+}
+
+void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid)
+{
+	*closid = idx / (mpam_pmg_max + 1);
+	*rmid = idx % (mpam_pmg_max + 1);
+}
+
 void resctrl_arch_sched_in(struct task_struct *tsk)
 {
 	lockdep_assert_preemption_disabled();
include/linux/arm_mpam.h +3 -0
index d329b1dc148b..7d23c90f077d 100644
@@ -58,6 +58,9 @@ void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid, u32 rmid);
 void resctrl_arch_sched_in(struct task_struct *tsk);
 bool resctrl_arch_match_closid(struct task_struct *tsk, u32 closid);
 bool resctrl_arch_match_rmid(struct task_struct *tsk, u32 closid, u32 rmid);
+u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid);
+void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid);
+u32 resctrl_arch_system_num_rmid_idx(void);
 
 /**
  * mpam_register_requestor() - Register a requestor with the MPAM driver
Signature · 1 line
2.43.0
author maintainer
#37 lore raw

PATCH v5 23/41 arm_mpam: resctrl: Add kunit test for rmid idx conversions

In reply to Ben Horgan

As MPAM's pmg are scoped by partid and RDT's rmid are global the rescrl mapping to an index needs to differ.

Add some tests for the MPAM rmid mapping.

---
 drivers/resctrl/test_mpam_resctrl.c | 49 +++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
drivers/resctrl/test_mpam_resctrl.c +49 -0
index b93d6ad87e43..a20da161d965 100644
@@ -296,6 +296,54 @@ static void test_percent_to_max_rounding(struct kunit *test)
 	KUNIT_EXPECT_LE(test, 4 * num_rounded_up, 3 * total);
 }
 
+struct rmid_idx_case {
+	u32 max_partid;
+	u32 max_pmg;
+};
+
+static const struct rmid_idx_case rmid_idx_cases[] = {
+	{0, 0}, {1, 4}, {3, 1}, {5, 9}, {4, 4}, {100, 11}, {0xFFFF, 0xFF},
+};
+
+static void test_rmid_idx_desc(const struct rmid_idx_case *param, char *desc)
+{
+	snprintf(desc, KUNIT_PARAM_DESC_SIZE, "max_partid=%d, max_pmg=%d\n",
+		 param->max_partid, param->max_pmg);
+}
+
+KUNIT_ARRAY_PARAM(test_rmid_idx, rmid_idx_cases, test_rmid_idx_desc);
+
+static void test_rmid_idx_encoding(struct kunit *test)
+{
+	u32 orig_mpam_partid_max = mpam_partid_max;
+	u32 orig_mpam_pmg_max = mpam_pmg_max;
+	const struct rmid_idx_case *param = test->param_value;
+	u32 idx, num_idx, count = 0;
+
+	mpam_partid_max = param->max_partid;
+	mpam_pmg_max = param->max_pmg;
+
+	for (u32 partid = 0; partid <= mpam_partid_max; partid++) {
+		for (u32 pmg = 0; pmg <= mpam_pmg_max; pmg++) {
+			u32 partid_out, pmg_out;
+
+			idx = resctrl_arch_rmid_idx_encode(partid, pmg);
+			/* Confirm there are no holes in the rmid idx range */
+			KUNIT_EXPECT_EQ(test, count, idx);
+			count++;
+			resctrl_arch_rmid_idx_decode(idx, &partid_out, &pmg_out);
+			KUNIT_EXPECT_EQ(test, pmg, pmg_out);
+			KUNIT_EXPECT_EQ(test, partid, partid_out);
+		}
+	}
+	num_idx = resctrl_arch_system_num_rmid_idx();
+	KUNIT_EXPECT_EQ(test, idx + 1, num_idx);
+
+	/* Restore global variables that were messed with */
+	mpam_partid_max = orig_mpam_partid_max;
+	mpam_pmg_max = orig_mpam_pmg_max;
+}
+
 static struct kunit_case mpam_resctrl_test_cases[] = {
 	KUNIT_CASE(test_get_mba_granularity),
 	KUNIT_CASE_PARAM(test_mbw_max_to_percent, test_percent_value_gen_params),
@@ -304,6 +352,7 @@ static struct kunit_case mpam_resctrl_test_cases[] = {
 	KUNIT_CASE(test_percent_to_max_rounding),
 	KUNIT_CASE_PARAM(test_percent_max_roundtrip_stability,
 			 test_all_bwa_wd_gen_params),
+	KUNIT_CASE_PARAM(test_rmid_idx_encoding, test_rmid_idx_gen_params),
 	{}
 };
 
Signature · 1 line
2.43.0
author maintainer
#38 lore raw

PATCH v5 24/41 arm_mpam: resctrl: Wait for cacheinfo to be ready

In reply to Ben Horgan

In order to calculate the rmid realloc threshold the size of the cache needs to be known. Cache domains will also be named after the cache id. So that this information can be extracted from cacheinfo we need to wait for it to be ready. The cacheinfo information is populated in device_initcall() so we wait for that.

---
This is moved into it's own patch to allow all uses of cacheinfo to be valid when they are introduced.

---
 drivers/resctrl/mpam_resctrl.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/resctrl/mpam_resctrl.c +19 -0
index 48f96d7f9109..fc5877eb5970 100644
@@ -16,6 +16,7 @@
 #include <linux/resctrl.h>
 #include <linux/slab.h>
 #include <linux/types.h>
+#include <linux/wait.h>
 
 #include <asm/mpam.h>
 
@@ -42,6 +43,13 @@ static DEFINE_MUTEX(domain_list_lock);
  */
 static bool cdp_enabled;
 
+/*
+ * We use cacheinfo to discover the size of the caches and their id. cacheinfo
+ * populates this from a device_initcall(). mpam_resctrl_setup() must wait.
+ */
+static bool cacheinfo_ready;
+static DECLARE_WAIT_QUEUE_HEAD(wait_cacheinfo_ready);
+
 bool resctrl_arch_alloc_capable(void)
 {
 	struct mpam_resctrl_res *res;
@@ -743,6 +751,8 @@ int mpam_resctrl_setup(void)
 	struct mpam_resctrl_res *res;
 	enum resctrl_res_level rid;
 
+	wait_event(wait_cacheinfo_ready, cacheinfo_ready);
+
 	cpus_read_lock();
 	for_each_mpam_resctrl_control(res, rid) {
 		INIT_LIST_HEAD_RCU(&res->resctrl_res.ctrl_domains);
@@ -781,6 +791,15 @@ int mpam_resctrl_setup(void)
 	return 0;
 }
 
+static int __init __cacheinfo_ready(void)
+{
+	cacheinfo_ready = true;
+	wake_up(&wait_cacheinfo_ready);
+
+	return 0;
+}
+device_initcall_sync(__cacheinfo_ready);
+
 #ifdef CONFIG_MPAM_KUNIT_TEST
 #include "test_mpam_resctrl.c"
 #endif
Signature · 1 line
2.43.0
author maintainer
#39 lore raw

PATCH v5 25/41 arm_mpam: resctrl: Add support for 'MB' resource

In reply to Ben Horgan

From: James Morse <[email protected]>

resctrl supports 'MB', as a percentage throttling of traffic from the L3. This is the control that mba_sc uses, so ideally the class chosen should be as close as possible to the counters used for mbm_total. If there is a single L3 and the topology of the memory matches then the traffic at the memory controller will be equivalent to that at egress of the L3. If these conditions are met allow the memory class to back MB.

MB's percentage control should be backed either with the fixed point fraction MBW_MAX or bandwidth portion bitmaps. The bandwidth portion bitmaps is not used as its tricky to pick which bits to use to avoid contention, and may be possible to expose this as something other than a percentage in the future.

---
Changes since v2:
Code flow change
Commit message 'or'

Changes since v3:
initialise tmp_cpumask
update commit message
check the traffic matches l3
update comment on candidate_class update, only mbm_total drop tags due to rework

Changes since v4:
Move __free declarations to point of first use
New line for a '{'
set r->alloc_capable last (Reinette)

---
 drivers/resctrl/mpam_resctrl.c | 275 ++++++++++++++++++++++++++++++++-
 1 file changed, 274 insertions(+), 1 deletion(-)
drivers/resctrl/mpam_resctrl.c +274 -1
index fc5877eb5970..29efcad163e6 100644
@@ -252,6 +252,33 @@ static bool cache_has_usable_cpor(struct mpam_class *class)
 	return class->props.cpbm_wd <= 32;
 }
 
+static bool mba_class_use_mbw_max(struct mpam_props *cprops)
+{
+	return (mpam_has_feature(mpam_feat_mbw_max, cprops) &&
+		cprops->bwa_wd);
+}
+
+static bool class_has_usable_mba(struct mpam_props *cprops)
+{
+	return mba_class_use_mbw_max(cprops);
+}
+
+/*
+ * Calculate the worst-case percentage change from each implemented step
+ * in the control.
+ */
+static u32 get_mba_granularity(struct mpam_props *cprops)
+{
+	if (!mba_class_use_mbw_max(cprops))
+		return 0;
+
+	/*
+	 * bwa_wd is the number of bits implemented in the 0.xxx
+	 * fixed point fraction. 1 bit is 50%, 2 is 25% etc.
+	 */
+	return DIV_ROUND_UP(MAX_MBA_BW, 1 << cprops->bwa_wd);
+}
+
 /*
  * Each fixed-point hardware value architecturally represents a range
  * of values: the full range 0% - 100% is split contiguously into
@@ -302,6 +329,154 @@ static u16 percent_to_mbw_max(u8 pc, struct mpam_props *cprops)
 	return val;
 }
 
+static u32 get_mba_min(struct mpam_props *cprops)
+{
+	if (!mba_class_use_mbw_max(cprops)) {
+		WARN_ON_ONCE(1);
+		return 0;
+	}
+
+	return mbw_max_to_percent(0, cprops);
+}
+
+/* Find the L3 cache that has affinity with this CPU */
+static int find_l3_equivalent_bitmask(int cpu, cpumask_var_t tmp_cpumask)
+{
+	u32 cache_id = get_cpu_cacheinfo_id(cpu, 3);
+
+	lockdep_assert_cpus_held();
+
+	return mpam_get_cpumask_from_cache_id(cache_id, 3, tmp_cpumask);
+}
+
+/*
+ * topology_matches_l3() - Is the provided class the same shape as L3
+ * @victim:		The class we'd like to pretend is L3.
+ *
+ * resctrl expects all the world's a Xeon, and all counters are on the
+ * L3. We allow some mapping counters on other classes. This requires
+ * that the CPU->domain mapping is the same kind of shape.
+ *
+ * Using cacheinfo directly would make this work even if resctrl can't
+ * use the L3 - but cacheinfo can't tell us anything about offline CPUs.
+ * Using the L3 resctrl domain list also depends on CPUs being online.
+ * Using the mpam_class we picked for L3 so we can use its domain list
+ * assumes that there are MPAM controls on the L3.
+ * Instead, this path eventually uses the mpam_get_cpumask_from_cache_id()
+ * helper which can tell us about offline CPUs ... but getting the cache_id
+ * to start with relies on at least one CPU per L3 cache being online at
+ * boot.
+ *
+ * Walk the victim component list and compare the affinity mask with the
+ * corresponding L3. The topology matches if each victim:component's affinity
+ * mask is the same as the CPU's corresponding L3's. These lists/masks are
+ * computed from firmware tables so don't change at runtime.
+ */
+static bool topology_matches_l3(struct mpam_class *victim)
+{
+	int cpu, err;
+	struct mpam_component *victim_iter;
+
+	lockdep_assert_cpus_held();
+
+	cpumask_var_t __free(free_cpumask_var) tmp_cpumask = CPUMASK_VAR_NULL;
+	if (!alloc_cpumask_var(&tmp_cpumask, GFP_KERNEL))
+		return false;
+
+	guard(srcu)(&mpam_srcu);
+	list_for_each_entry_srcu(victim_iter, &victim->components, class_list,
+				 srcu_read_lock_held(&mpam_srcu)) {
+		if (cpumask_empty(&victim_iter->affinity)) {
+			pr_debug("class %u has CPU-less component %u - can't match L3!\n",
+				 victim->level, victim_iter->comp_id);
+			return false;
+		}
+
+		cpu = cpumask_any_and(&victim_iter->affinity, cpu_online_mask);
+		if (WARN_ON_ONCE(cpu >= nr_cpu_ids))
+			return false;
+
+		cpumask_clear(tmp_cpumask);
+		err = find_l3_equivalent_bitmask(cpu, tmp_cpumask);
+		if (err) {
+			pr_debug("Failed to find L3's equivalent component to class %u component %u\n",
+				 victim->level, victim_iter->comp_id);
+			return false;
+		}
+
+		/* Any differing bits in the affinity mask? */
+		if (!cpumask_equal(tmp_cpumask, &victim_iter->affinity)) {
+			pr_debug("class %u component %u has Mismatched CPU mask with L3 equivalent\n"
+				 "L3:%*pbl != victim:%*pbl\n",
+				 victim->level, victim_iter->comp_id,
+				 cpumask_pr_args(tmp_cpumask),
+				 cpumask_pr_args(&victim_iter->affinity));
+
+			return false;
+		}
+	}
+
+	return true;
+}
+
+/*
+ * Test if the traffic for a class matches that at egress from the L3. For
+ * MSC at memory controllers this is only possible if there is a single L3
+ * as otherwise the counters at the memory can include bandwidth from the
+ * non-local L3.
+ */
+static bool traffic_matches_l3(struct mpam_class *class)
+{
+	int err, cpu;
+
+	lockdep_assert_cpus_held();
+
+	if (class->type == MPAM_CLASS_CACHE && class->level == 3)
+		return true;
+
+	if (class->type == MPAM_CLASS_CACHE && class->level != 3) {
+		pr_debug("class %u is a different cache from L3\n", class->level);
+		return false;
+	}
+
+	if (class->type != MPAM_CLASS_MEMORY) {
+		pr_debug("class %u is neither of type cache or memory\n", class->level);
+		return false;
+	}
+
+	cpumask_var_t __free(free_cpumask_var) tmp_cpumask = CPUMASK_VAR_NULL;
+	if (!alloc_cpumask_var(&tmp_cpumask, GFP_KERNEL)) {
+		pr_debug("cpumask allocation failed\n");
+		return false;
+	}
+
+	if (class->type != MPAM_CLASS_MEMORY) {
+		pr_debug("class %u is neither of type cache or memory\n",
+			 class->level);
+		return false;
+	}
+
+	cpu = cpumask_any_and(&class->affinity, cpu_online_mask);
+	err = find_l3_equivalent_bitmask(cpu, tmp_cpumask);
+	if (err) {
+		pr_debug("Failed to find L3 downstream to cpu %d\n", cpu);
+		return false;
+	}
+
+	if (!cpumask_equal(tmp_cpumask, cpu_possible_mask)) {
+		pr_debug("There is more than one L3\n");
+		return false;
+	}
+
+	/* Be strict; the traffic might stop in the intermediate cache. */
+	if (get_cpu_cacheinfo_id(cpu, 4) != -1) {
+		pr_debug("L3 isn't the last level of cache\n");
+		return false;
+	}
+
+	return true;
+}
+
 /* Test whether we can export MPAM_CLASS_CACHE:{2,3}? */
 static void mpam_resctrl_pick_caches(void)
 {
@@ -343,9 +518,68 @@ static void mpam_resctrl_pick_caches(void)
 	}
 }
 
+static void mpam_resctrl_pick_mba(void)
+{
+	struct mpam_class *class, *candidate_class = NULL;
+	struct mpam_resctrl_res *res;
+
+	lockdep_assert_cpus_held();
+
+	guard(srcu)(&mpam_srcu);
+	list_for_each_entry_srcu(class, &mpam_classes, classes_list,
+				 srcu_read_lock_held(&mpam_srcu)) {
+		struct mpam_props *cprops = &class->props;
+
+		if (class->level != 3 && class->type == MPAM_CLASS_CACHE) {
+			pr_debug("class %u is a cache but not the L3\n", class->level);
+			continue;
+		}
+
+		if (!class_has_usable_mba(cprops)) {
+			pr_debug("class %u has no bandwidth control\n",
+				 class->level);
+			continue;
+		}
+
+		if (!cpumask_equal(&class->affinity, cpu_possible_mask)) {
+			pr_debug("class %u has missing CPUs\n", class->level);
+			continue;
+		}
+
+		if (!topology_matches_l3(class)) {
+			pr_debug("class %u topology doesn't match L3\n",
+				 class->level);
+			continue;
+		}
+
+		if (!traffic_matches_l3(class)) {
+			pr_debug("class %u traffic doesn't match L3 egress\n",
+				 class->level);
+			continue;
+		}
+
+		/*
+		 * Pick a resource to be MBA that as close as possible to
+		 * the L3. mbm_total counts the bandwidth leaving the L3
+		 * cache and MBA should correspond as closely as possible
+		 * for proper operation of mba_sc.
+		 */
+		if (!candidate_class || class->level < candidate_class->level)
+			candidate_class = class;
+	}
+
+	if (candidate_class) {
+		pr_debug("selected class %u to back MBA\n",
+			 candidate_class->level);
+		res = &mpam_resctrl_controls[RDT_RESOURCE_MBA];
+		res->class = candidate_class;
+	}
+}
+
 static int mpam_resctrl_control_init(struct mpam_resctrl_res *res)
 {
 	struct mpam_class *class = res->class;
+	struct mpam_props *cprops = &class->props;
 	struct rdt_resource *r = &res->resctrl_res;
 
 	switch (r->rid) {
@@ -375,6 +609,19 @@ static int mpam_resctrl_control_init(struct mpam_resctrl_res *res)
 		r->cache.shareable_bits = resctrl_get_default_ctrl(r);
 		r->alloc_capable = true;
 		break;
+	case RDT_RESOURCE_MBA:
+		r->schema_fmt = RESCTRL_SCHEMA_RANGE;
+		r->ctrl_scope = RESCTRL_L3_CACHE;
+
+		r->membw.delay_linear = true;
+		r->membw.throttle_mode = THREAD_THROTTLE_UNDEFINED;
+		r->membw.min_bw = get_mba_min(cprops);
+		r->membw.max_bw = MAX_MBA_BW;
+		r->membw.bw_gran = get_mba_granularity(cprops);
+
+		r->name = "MB";
+		r->alloc_capable = true;
+		break;
 	default:
 		return -EINVAL;
 	}
@@ -389,7 +636,17 @@ static int mpam_resctrl_pick_domain_id(int cpu, struct mpam_component *comp)
 	if (class->type == MPAM_CLASS_CACHE)
 		return comp->comp_id;
 
-	/* TODO: repaint domain ids to match the L3 domain ids */
+	if (topology_matches_l3(class)) {
+		/* Use the corresponding L3 component ID as the domain ID */
+		int id = get_cpu_cacheinfo_id(cpu, 3);
+
+		/* Implies topology_matches_l3() made a mistake */
+		if (WARN_ON_ONCE(id == -1))
+			return comp->comp_id;
+
+		return id;
+	}
+
 	/* Otherwise, expose the ID used by the firmware table code. */
 	return comp->comp_id;
 }
@@ -429,6 +686,12 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d,
 	case RDT_RESOURCE_L3:
 		configured_by = mpam_feat_cpor_part;
 		break;
+	case RDT_RESOURCE_MBA:
+		if (mpam_has_feature(mpam_feat_mbw_max, cprops)) {
+			configured_by = mpam_feat_mbw_max;
+			break;
+		}
+		fallthrough;
 	default:
 		return resctrl_get_default_ctrl(r);
 	}
@@ -440,6 +703,8 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d,
 	switch (configured_by) {
 	case mpam_feat_cpor_part:
 		return cfg->cpbm;
+	case mpam_feat_mbw_max:
+		return mbw_max_to_percent(cfg->mbw_max, cprops);
 	default:
 		return resctrl_get_default_ctrl(r);
 	}
@@ -487,6 +752,13 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d,
 		cfg.cpbm = cfg_val;
 		mpam_set_feature(mpam_feat_cpor_part, &cfg);
 		break;
+	case RDT_RESOURCE_MBA:
+		if (mpam_has_feature(mpam_feat_mbw_max, cprops)) {
+			cfg.mbw_max = percent_to_mbw_max(cfg_val, cprops);
+			mpam_set_feature(mpam_feat_mbw_max, &cfg);
+			break;
+		}
+		fallthrough;
 	default:
 		return -EINVAL;
 	}
@@ -761,6 +1033,7 @@ int mpam_resctrl_setup(void)
 
 	/* Find some classes to use for controls */
 	mpam_resctrl_pick_caches();
+	mpam_resctrl_pick_mba();
 
 	/* Initialise the resctrl structures from the classes */
 	for_each_mpam_resctrl_control(res, rid) {
Signature · 1 line
2.43.0
author maintainer
#40 lore raw

PATCH v5 26/41 arm_mpam: resctrl: Add monitor initialisation and domain boilerplate

In reply to Ben Horgan

Add the boilerplate that tells resctrl about the mpam monitors that are available. resctrl expects all (non-telemetry) monitors to be on the L3 and so advertise them there and invent an L3 resctrl resource if required. The L3 cache itself has to exist as the cache ids are used as the domain ids.

Bring the resctrl monitor domains online and offline based on the cpus they contain.

Support for specific monitor types is left to later.

---
New patch but mostly moved from the existing patches to separate the monitors from the controls and the boilerplate from the specific counters.
Use l3->mon_capable in resctrl_arch_mon_capable() as resctrl_enable_mon_event() now returns a bool.

---
 drivers/resctrl/mpam_internal.h |   7 ++
 drivers/resctrl/mpam_resctrl.c  | 142 +++++++++++++++++++++++++++++---
 2 files changed, 139 insertions(+), 10 deletions(-)
drivers/resctrl/mpam_internal.h +7 -0
index 57c3d9b962b9..472bd5d27baa 100644
@@ -341,6 +341,7 @@ struct mpam_msc_ris {
 struct mpam_resctrl_dom {
 	struct mpam_component		*ctrl_comp;
 	struct rdt_ctrl_domain		resctrl_ctrl_dom;
+	struct rdt_l3_mon_domain	resctrl_mon_dom;
 };
 
 struct mpam_resctrl_res {
@@ -349,6 +350,12 @@ struct mpam_resctrl_res {
 	bool			cdp_enabled;
 };
 
+struct mpam_resctrl_mon {
+	struct mpam_class	*class;
+
+	/* per-class data that resctrl needs will live here */
+};
+
 static inline int mpam_alloc_csu_mon(struct mpam_class *class)
 {
 	struct mpam_props *cprops = &class->props;
drivers/resctrl/mpam_resctrl.c +132 -10

220 lines not on this page · raw message

Signature · 1 line
2.43.0
Reviewed-by on v5 26/41
#41 lore raw

Re: [PATCH v5 26/41] arm_mpam: resctrl: Add monitor initialisation and domain boilerplate

Quoted 11 lines · On Tue, 24 Feb 2026 17:57:05 +0000 Ben Horgan <[email protected]> wrote:

Add the boilerplate that tells resctrl about the mpam monitors that are available. resctrl expects all (non-telemetry) monitors to be on the L3 and so advertise them there and invent an L3 resctrl resource if required. The L3 cache itself has to exist as the cache ids are used as the domain ids.

Bring the resctrl monitor domains online and offline based on the cpus they contain.

Support for specific monitor types is left to later.

Quoted 7 lines

---
New patch but mostly moved from the existing patches to separate the monitors from the controls and the boilerplate from the specific counters.
Use l3->mon_capable in resctrl_arch_mon_capable() as resctrl_enable_mon_event() now returns a bool.

Just one trivial comment on short line wrap. I'm not that fussed though so I don't mind if you only tidy that up if doing a v6.

Quoted 8 lines
drivers/resctrl/mpam_resctrl.c +3 -0
index 29efcad163e6..c14e59e8586d 100644
 
+static int mpam_resctrl_monitor_init(struct mpam_resctrl_mon *mon,
+				     enum resctrl_event_id type)
+{

...

drivers/resctrl/mpam_resctrl.c static int mpam_resctrl_pick_domain_id(int cpu, struct mpam_component *comp) · line 721

Quoted 9 lines
drivers/resctrl/mpam_resctrl.c +9 -0
+
+	/*
+	 * num-rmid is the upper bound for the number of monitoring
+	 * groups that can exist simultaneously, including the
+	 * default monitoring group for each control group. Hence,
+	 * advertise the whole rmid_idx space even though each
+	 * control group has its own pmg/rmid space. Unfortunately,
+	 * this does mean userspace needs to know the architecture
+	 * to correctly interpret this value.

Trivial but that's an oddly short wrap. Should be.
* num-rmid is the upper bound for the number of monitoring groups that
* can exist simultaneously, including the default monitoring group for
* each control group. Hence, advertise the whole rmid_idx space even
* though each control group has its own pmg/rmid space. Unfortunately,
* this does mean userspace needs to know the architecture to correctly
* interpret this value.

The wonder of an email client with rulers :)

J

Quoted 8 lines
drivers/resctrl/mpam_resctrl.c +8 -0
+	 */
+	l3->mon.num_rmid = resctrl_arch_system_num_rmid_idx();
+
+	if (resctrl_enable_mon_event(type, false, 0, NULL))
+		l3->mon_capable = true;
+
+	return 0;
+}
#42 lore raw

Re: [PATCH v5 26/41] arm_mpam: resctrl: Add monitor initialisation and domain boilerplate

In reply to Ben Horgan

Hi Ben,

Quoted 23 lines · Ben Horgan

Add the boilerplate that tells resctrl about the mpam monitors that are available. resctrl expects all (non-telemetry) monitors to be on the L3 and so advertise them there and invent an L3 resctrl resource if required. The L3 cache itself has to exist as the cache ids are used as the domain ids.

Bring the resctrl monitor domains online and offline based on the cpus they contain.

Support for specific monitor types is left to later.

---
New patch but mostly moved from the existing patches to separate the monitors from the controls and the boilerplate from the specific counters.
Use l3->mon_capable in resctrl_arch_mon_capable() as resctrl_enable_mon_event() now returns a bool.

---
  drivers/resctrl/mpam_internal.h |   7 ++
  drivers/resctrl/mpam_resctrl.c  | 142 +++++++++++++++++++++++++++++---
  2 files changed, 139 insertions(+), 10 deletions(-)

[...]

Quoted 10 lines
(quoted diff) +6 -0
@@ -922,6 +1000,20 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
  	} else {
  		pr_debug("Skipped control domain online - no controls\n");
  	}
+
+	if (resctrl_arch_mon_capable()) {
+		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);

Review mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res) · line 1018

Quoted 10 lines
(quoted diff) +8 -0
+		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");
+	}
+
  	return dom;
 

I noticed that resctrl_arch_mon_capable() only performs checks for L3 monitoring functionality. This leads to an issue on platforms that include L2 monitoring capabilities, where the code incorrectly enters this branch and triggers the following warning by mpam_resctrl_domain_insert():

[   22.867070] ------------[ cut here ]------------
[   22.867073] WARNING: drivers/resctrl/mpam_resctrl.c:1495 at mpam_resctrl_domain_insert+0x74/0x80, CPU#2: cpuhp/2/25
[   29.376035] Modules linked in:
[   29.379080] CPU: 2 UID: 0 PID: 25 Comm: cpuhp/2 Not tainted 7.0.0-rc1-g4288ec146462 #30 PREEMPT
[   29.387853] Hardware name: To Be Filled By O.E.M. 183.0/To Be Filled By O.E.M., BIOS 183.0 02/12/2026
[   29.397058] pstate: 61400009 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--)
[   29.404007] pc : mpam_resctrl_domain_insert+0x74/0x80
[   29.409048] lr : mpam_resctrl_domain_insert+0x34/0x80
[   29.414088] sp : ffff8000876abc60
 ...
[   29.488625] Call trace:
[   29.491060]  mpam_resctrl_domain_insert+0x74/0x80 (P)
[   29.496100]  mpam_resctrl_online_cpu+0x2b4/0x428
[   29.500706]  mpam_cpu_online+0x274/0x298
[   29.504618]  cpuhp_invoke_callback+0x104/0x20c
[   29.509052]  cpuhp_thread_fun+0xa4/0x17c
[   29.512963]  smpboot_thread_fn+0x220/0x24c
[   29.517048]  kthread+0x120/0x12c
[   29.520265]  ret_from_fork+0x10/0x20
[   29.523830] ---[ end trace 0000000000000000 ]---

To preserve the existing public interface of resctrl_arch_mon_capable(), please consider the following approach:

drivers/resctrl/mpam_resctrl.c +3 -0
index 694ea8548a05..b06a89494ff0 100644
@@ -1563,6 +1563,10 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
        if (resctrl_arch_mon_capable()) {
                struct mpam_component *any_mon_comp;
                struct mpam_resctrl_mon *mon;
                enum resctrl_event_id eventid;
 
+               /* TODO: Only supports L3 monitor type currently. */
+               if (r->rid != RDT_RESOURCE_L3)
+                       return dom;
 

Best regards,
Zeng Heng

author maintainer
#43 lore raw

Re: [PATCH v5 26/41] arm_mpam: resctrl: Add monitor initialisation and domain boilerplate

Hi Zeng,

Quoted 76 lines · Zeng Heng

Hi Ben,

Quoted 25 lines · Ben Horgan

Add the boilerplate that tells resctrl about the mpam monitors that are available. resctrl expects all (non-telemetry) monitors to be on the L3 and
so advertise them there and invent an L3 resctrl resource if required. The
L3 cache itself has to exist as the cache ids are used as the domain ids.

Bring the resctrl monitor domains online and offline based on the cpus they contain.

Support for specific monitor types is left to later.

---
New patch but mostly moved from the existing patches to separate the monitors from the controls and the boilerplate from the specific counters.
Use l3->mon_capable in resctrl_arch_mon_capable() as resctrl_enable_mon_event() now returns a bool.
---
  drivers/resctrl/mpam_internal.h |   7 ++ drivers/resctrl/mpam_resctrl.c  | 142 +++++++++++++++++++++++++++++---

  2 files changed, 139 insertions(+), 10 deletions(-)

[...]

Quoted 21 lines
(quoted diff) +14 -0
@@ -922,6 +1000,20 @@ mpam_resctrl_alloc_domain(unsigned int cpu,
 struct mpam_resctrl_res *res)
       } else {
           pr_debug("Skipped control domain online - no controls\n");
       }
+
+    if (resctrl_arch_mon_capable()) {
+        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);
+        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");
+    }
+
       return dom;
Quoted 1 line

I noticed that resctrl_arch_mon_capable() only performs checks for L3 monitoring functionality. This leads to an issue on platforms that include L2 monitoring capabilities, where the code incorrectly enters this branch and triggers the following warning by mpam_resctrl_domain_insert():

[   22.867070] ------------[ cut here ]------------
[   22.867073] WARNING: drivers/resctrl/mpam_resctrl.c:1495 at mpam_resctrl_domain_insert+0x74/0x80, CPU#2: cpuhp/2/25
[   29.376035] Modules linked in:
[   29.379080] CPU: 2 UID: 0 PID: 25 Comm: cpuhp/2 Not tainted 7.0.0- rc1-g4288ec146462 #30 PREEMPT
[   29.387853] Hardware name: To Be Filled By O.E.M. 183.0/To Be Filled By O.E.M., BIOS 183.0 02/12/2026
[   29.397058] pstate: 61400009 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--)
[   29.404007] pc : mpam_resctrl_domain_insert+0x74/0x80
[   29.409048] lr : mpam_resctrl_domain_insert+0x34/0x80
[   29.414088] sp : ffff8000876abc60
 ...
[   29.488625] Call trace:
[   29.491060]  mpam_resctrl_domain_insert+0x74/0x80 (P)

Quoted 8 lines

[   29.496100]  mpam_resctrl_online_cpu+0x2b4/0x428 [   29.500706]  mpam_cpu_online+0x274/0x298 [   29.504618]  cpuhp_invoke_callback+0x104/0x20c [   29.509052]  cpuhp_thread_fun+0xa4/0x17c [   29.512963]  smpboot_thread_fn+0x220/0x24c [   29.517048]  kthread+0x120/0x12c
[   29.520265]  ret_from_fork+0x10/0x20
[   29.523830] ---[ end trace 0000000000000000 ]---

Thanks for reporting this bug. It looks to be because resctrl_arch_mon_capable() is telling us if there is any mon capable resource when really what we want to know is if this resource is mon capable. The pattern occurs in a few places. Does this diff help?

drivers/resctrl/mpam_resctrl.c +9 -7
index 694ea8548a05..19b306017845 100644
@@ -1543,7 +1543,7 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 	if (!dom)
 		return ERR_PTR(-ENOMEM);
 
-	if (resctrl_arch_alloc_capable()) {
+	if (r->alloc_capable) {
 		dom->ctrl_comp = ctrl_comp;
 
 		ctrl_d = &dom->resctrl_ctrl_dom;
@@ -1558,7 +1558,7 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 		pr_debug("Skipped control domain online - no controls\n");
 	}
 
-	if (resctrl_arch_mon_capable()) {
+	if (r->mon_capable) {
 		struct mpam_component *any_mon_comp;
 		struct mpam_resctrl_mon *mon;
 		enum resctrl_event_id eventid;
@@ -1603,7 +1603,7 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
 	return dom;
 
 offline_ctrl_domain:
-	if (resctrl_arch_alloc_capable()) {
+	if (r->alloc_capable) {
 		mpam_resctrl_offline_domain_hdr(cpu, &ctrl_d->hdr);
 		resctrl_offline_ctrl_domain(r, ctrl_d);
 	}
@@ -1671,6 +1671,7 @@ int 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;
@@ -1679,12 +1680,12 @@ int mpam_resctrl_online_cpu(unsigned int cpu)
 		if (!dom) {
 			dom = mpam_resctrl_alloc_domain(cpu, res);
 		} else {
-			if (resctrl_arch_alloc_capable()) {
+			if (r->alloc_capable) {
 				struct rdt_ctrl_domain *ctrl_d = &dom->resctrl_ctrl_dom;
 
 				mpam_resctrl_online_domain_hdr(cpu, &ctrl_d->hdr);
 			}
-			if (resctrl_arch_mon_capable()) {
+			if (r->mon_capable) {
 				struct rdt_l3_mon_domain *mon_d = &dom->resctrl_mon_dom;
 
 				mpam_resctrl_online_domain_hdr(cpu, &mon_d->hdr);
@@ -1712,6 +1713,7 @@ void mpam_resctrl_offline_cpu(unsigned int cpu)
 		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
@@ -1720,7 +1722,7 @@ void mpam_resctrl_offline_cpu(unsigned int cpu)
 		if (WARN_ON_ONCE(!dom))
 			continue;
 
-		if (resctrl_arch_alloc_capable()) {
+		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)
@@ -1729,7 +1731,7 @@ void mpam_resctrl_offline_cpu(unsigned int cpu)
 			ctrl_dom_empty = true;
 		}
 
-		if (resctrl_arch_mon_capable()) {
+		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)
Quoted 23 lines

To preserve the existing public interface of resctrl_arch_mon_capable(), please consider the following approach:

drivers/resctrl/ renamed from drivers/resctrl/mpam_resctrl.c +0 -0

mpam_resctrl.c
index 694ea8548a05..b06a89494ff0 100644

drivers/resctrl/mpam_resctrl.c +3 -0
@@ -1563,6 +1563,10 @@ mpam_resctrl_alloc_domain(unsigned int cpu,
 struct mpam_resctrl_res *res)
         if (resctrl_arch_mon_capable()) {
                 struct mpam_component *any_mon_comp;
                 struct mpam_resctrl_mon *mon;
                 enum resctrl_event_id eventid;
 
+               /* TODO: Only supports L3 monitor type currently. */
+               if (r->rid != RDT_RESOURCE_L3)
+                       return dom;
Quoted 2 lines

Best regards,
Zeng Heng

Thanks,

Ben

Reviewed-by
#44 lore raw

Re: [PATCH v5 26/41] arm_mpam: resctrl: Add monitor initialisation and domain boilerplate

Hi Ben,

Quoted 88 lines · Ben Horgan

Hi Zeng,

Quoted 76 lines · Zeng Heng

Hi Ben,

Quoted 25 lines · Ben Horgan

Add the boilerplate that tells resctrl about the mpam monitors that are available. resctrl expects all (non-telemetry) monitors to be on the L3 and
so advertise them there and invent an L3 resctrl resource if required. The
L3 cache itself has to exist as the cache ids are used as the domain ids.

Bring the resctrl monitor domains online and offline based on the cpus they contain.

Support for specific monitor types is left to later.

---
New patch but mostly moved from the existing patches to separate the monitors from the controls and the boilerplate from the specific counters.
Use l3->mon_capable in resctrl_arch_mon_capable() as resctrl_enable_mon_event() now returns a bool.

---
   drivers/resctrl/mpam_internal.h |   7 ++
   drivers/resctrl/mpam_resctrl.c  | 142 +++++++++++++++++++++++++++++---
   2 files changed, 139 insertions(+), 10 deletions(-)

[...]

Quoted 12 lines
(quoted diff) +5 -0
@@ -922,6 +1000,20 @@ mpam_resctrl_alloc_domain(unsigned int cpu,
 struct mpam_resctrl_res *res)
       } else {
           pr_debug("Skipped control domain online - no controls\n");
       }
+
+    if (resctrl_arch_mon_capable()) {
+        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;

Review mpam_resctrl_alloc_domain(unsigned int cpu, · line 1019

Quoted 10 lines
(quoted diff) +9 -0
+        err = resctrl_online_mon_domain(r, &mon_d->hdr);
+        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");
+    }
+
       return dom;

I noticed that resctrl_arch_mon_capable() only performs checks for L3 monitoring functionality. This leads to an issue on platforms that include L2 monitoring capabilities, where the code incorrectly enters this branch and triggers the following warning by mpam_resctrl_domain_insert():

[   22.867070] ------------[ cut here ]------------
[   22.867073] WARNING: drivers/resctrl/mpam_resctrl.c:1495 at mpam_resctrl_domain_insert+0x74/0x80, CPU#2: cpuhp/2/25
[   29.376035] Modules linked in:
[   29.379080] CPU: 2 UID: 0 PID: 25 Comm: cpuhp/2 Not tainted 7.0.0- rc1-g4288ec146462 #30 PREEMPT
[   29.387853] Hardware name: To Be Filled By O.E.M. 183.0/To Be Filled By O.E.M., BIOS 183.0 02/12/2026
[   29.397058] pstate: 61400009 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--)
[   29.404007] pc : mpam_resctrl_domain_insert+0x74/0x80
[   29.409048] lr : mpam_resctrl_domain_insert+0x34/0x80
[   29.414088] sp : ffff8000876abc60
 ...
[   29.488625] Call trace:
[   29.491060]  mpam_resctrl_domain_insert+0x74/0x80 (P)

Quoted 8 lines

[   29.496100]  mpam_resctrl_online_cpu+0x2b4/0x428 [   29.500706]  mpam_cpu_online+0x274/0x298 [   29.504618]  cpuhp_invoke_callback+0x104/0x20c [   29.509052]  cpuhp_thread_fun+0xa4/0x17c [   29.512963]  smpboot_thread_fn+0x220/0x24c [   29.517048]  kthread+0x120/0x12c
[   29.520265]  ret_from_fork+0x10/0x20
[   29.523830] ---[ end trace 0000000000000000 ]---

Quoted 4 lines

Thanks for reporting this bug. It looks to be because resctrl_arch_mon_capable() is telling us if there is any mon capable resource when really what we want to know is if this resource is mon capable. The pattern occurs in a few places. Does this diff help?

I've adapted to the changes and local verification passes also.

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

Quoted 10 lines
drivers/resctrl/mpam_resctrl.c +1 -1
index 694ea8548a05..19b306017845 100644
@@ -1543,7 +1543,7 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
  	if (!dom)
  		return ERR_PTR(-ENOMEM);
 
-	if (resctrl_arch_alloc_capable()) {
+	if (r->alloc_capable) {

Yes, using r->alloc_capable and r->mon_capable here is indeed more accurate and appropriate. I should have noticed this when reviewing resctrl_arch_alloc_capable() and resctrl_arch_mon_capable().

Thanks,
Zeng Heng

Quoted 104 lines
drivers/resctrl/mpam_resctrl.c +8 -6
  		dom->ctrl_comp = ctrl_comp;
 
  		ctrl_d = &dom->resctrl_ctrl_dom;
@@ -1558,7 +1558,7 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
  		pr_debug("Skipped control domain online - no controls\n");
  	}
 
-	if (resctrl_arch_mon_capable()) {
+	if (r->mon_capable) {
  		struct mpam_component *any_mon_comp;
  		struct mpam_resctrl_mon *mon;
  		enum resctrl_event_id eventid;
@@ -1603,7 +1603,7 @@ mpam_resctrl_alloc_domain(unsigned int cpu, struct mpam_resctrl_res *res)
  	return dom;
 
  offline_ctrl_domain:
-	if (resctrl_arch_alloc_capable()) {
+	if (r->alloc_capable) {
  		mpam_resctrl_offline_domain_hdr(cpu, &ctrl_d->hdr);
  		resctrl_offline_ctrl_domain(r, ctrl_d);
  	}
@@ -1671,6 +1671,7 @@ int 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;
@@ -1679,12 +1680,12 @@ int mpam_resctrl_online_cpu(unsigned int cpu)
  		if (!dom) {
  			dom = mpam_resctrl_alloc_domain(cpu, res);
  		} else {
-			if (resctrl_arch_alloc_capable()) {
+			if (r->alloc_capable) {
  				struct rdt_ctrl_domain *ctrl_d = &dom->resctrl_ctrl_dom;
 
  				mpam_resctrl_online_domain_hdr(cpu, &ctrl_d->hdr);
  			}
-			if (resctrl_arch_mon_capable()) {
+			if (r->mon_capable) {
  				struct rdt_l3_mon_domain *mon_d = &dom->resctrl_mon_dom;
 
  				mpam_resctrl_online_domain_hdr(cpu, &mon_d->hdr);
@@ -1712,6 +1713,7 @@ void mpam_resctrl_offline_cpu(unsigned int cpu)
  		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
@@ -1720,7 +1722,7 @@ void mpam_resctrl_offline_cpu(unsigned int cpu)
  		if (WARN_ON_ONCE(!dom))
  			continue;
 
-		if (resctrl_arch_alloc_capable()) {
+		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)
@@ -1729,7 +1731,7 @@ void mpam_resctrl_offline_cpu(unsigned int cpu)
  			ctrl_dom_empty = true;
  		}
 
-		if (resctrl_arch_mon_capable()) {
+		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)
Quoted 25 lines

To preserve the existing public interface of resctrl_arch_mon_capable(), please consider the following approach:

drivers/resctrl/ renamed from drivers/resctrl/mpam_resctrl.c +0 -0

mpam_resctrl.c
index 694ea8548a05..b06a89494ff0 100644

drivers/resctrl/mpam_resctrl.c +3 -0
@@ -1563,6 +1563,10 @@ mpam_resctrl_alloc_domain(unsigned int cpu,
 struct mpam_resctrl_res *res)
         if (resctrl_arch_mon_capable()) {
                 struct mpam_component *any_mon_comp;
                 struct mpam_resctrl_mon *mon;
                 enum resctrl_event_id eventid;
 
+               /* TODO: Only supports L3 monitor type currently. */
+               if (r->rid != RDT_RESOURCE_L3)
+                       return dom;
Quoted 2 lines

Best regards,
Zeng Heng

Thanks,

Ben

author maintainer
#45 lore raw

PATCH v5 27/41 arm_mpam: resctrl: Add support for csu counters

In reply to Ben Horgan

From: James Morse <[email protected]>

resctrl exposes a counter via a file named llc_occupancy. This isn't really a counter as its value goes up and down, this is a snapshot of the cache storage usage monitor.

Add some picking code which will only find an L3. The resctrl counter file is called llc_occupancy but we don't check it is the last one as it is already identified as L3.

---
Changes since rfc:
Allow csu counters however many partid or pmg there are else if -> if
reduce scope of local variables
drop has_csu

Changes since v2:
return -> break so works for mbwu in later patch
add for_each_mpam_resctrl_mon
return error from mpam_resctrl_monitor_init(). It may fail when is abmc allocation introduced in a later patch.
Squashed in patch from Dave Martin:
https://lore.kernel.org/lkml/[email protected]/

Changes since v3:
resctrl_enable_mon_event() signature update
Restrict the events considered
num-rmid update
Use raw_smp_processor_id()
Tighten heuristics:
Make sure it is the L3
Please shout if this means the counters aren't exposed on any platforms
Drop tags due to change in policy/rework

Changes since v4:
Move generic monitor boilerplate to separate patch

---
 drivers/resctrl/mpam_resctrl.c | 83 ++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)
drivers/resctrl/mpam_resctrl.c +83 -0
index c14e59e8586d..a570cdf06feb 100644
@@ -289,6 +289,28 @@ static bool class_has_usable_mba(struct mpam_props *cprops)
 	return mba_class_use_mbw_max(cprops);
 }
 
+static bool cache_has_usable_csu(struct mpam_class *class)
+{
+	struct mpam_props *cprops;
+
+	if (!class)
+		return false;
+
+	cprops = &class->props;
+
+	if (!mpam_has_feature(mpam_feat_msmon_csu, cprops))
+		return false;
+
+	/*
+	 * CSU counters settle on the value, so we can get away with
+	 * having only one.
+	 */
+	if (!cprops->num_csu_mon)
+		return false;
+
+	return true;
+}
+
 /*
  * Calculate the worst-case percentage change from each implemented step
  * in the control.
@@ -602,6 +624,64 @@ static void mpam_resctrl_pick_mba(void)
 	}
 }
 
+static void counter_update_class(enum resctrl_event_id evt_id,
+				 struct mpam_class *class)
+{
+	struct mpam_class *existing_class = mpam_resctrl_counters[evt_id].class;
+
+	if (existing_class) {
+		if (class->level == 3) {
+			pr_debug("Existing class is L3 - L3 wins\n");
+			return;
+		}
+
+		if (existing_class->level < class->level) {
+			pr_debug("Existing class is closer to L3, %u versus %u - closer is better\n",
+				 existing_class->level, class->level);
+			return;
+		}
+	}
+
+	mpam_resctrl_counters[evt_id].class = class;
+}
+
+static void mpam_resctrl_pick_counters(void)
+{
+	struct mpam_class *class;
+
+	lockdep_assert_cpus_held();
+
+	guard(srcu)(&mpam_srcu);
+	list_for_each_entry_srcu(class, &mpam_classes, classes_list,
+				 srcu_read_lock_held(&mpam_srcu)) {
+		/* The name of the resource is L3... */
+		if (class->type == MPAM_CLASS_CACHE && class->level != 3) {
+			pr_debug("class %u is a cache but not the L3", class->level);
+			continue;
+		}
+
+		if (!cpumask_equal(&class->affinity, cpu_possible_mask)) {
+			pr_debug("class %u does not cover all CPUs",
+				 class->level);
+			continue;
+		}
+
+		if (cache_has_usable_csu(class)) {
+			pr_debug("class %u has usable CSU",
+				 class->level);
+
+			/* CSU counters only make sense on a cache. */
+			switch (class->type) {
+			case MPAM_CLASS_CACHE:
+				counter_update_class(QOS_L3_OCCUP_EVENT_ID, class);
+				break;
+			default:
+				break;
+			}
+		}
+	}
+}
+
 static int mpam_resctrl_control_init(struct mpam_resctrl_res *res)
 {
 	struct mpam_class *class = res->class;
@@ -1157,6 +1237,9 @@ int mpam_resctrl_setup(void)
 		}
 	}
 
+	/* Find some classes to use for monitors */
+	mpam_resctrl_pick_counters();
+
 	for_each_mpam_resctrl_mon(mon, eventid) {
 		if (!mon->class)
 			continue;	// dummy resource
Signature · 1 line
2.43.0
author maintainer
#46 lore raw

PATCH v5 28/41 arm_mpam: resctrl: Pick classes for use as mbm counters

In reply to Ben Horgan

From: James Morse <[email protected]>

resctrl has two types of counters, NUMA-local and global. MPAM can only count global either using MSC at the L3 cache or in the memory controllers. When global and local equate to the same thing continue just to call it global.

Because the class or component backing the event may not be 'the L3', it is necessary for mpam_resctrl_get_domain_from_cpu() to search the monitor domains too. This matters the most for 'monitor only' systems, where 'the L3' control domains may be empty, and the ctrl_comp pointer NULL.

resctrl expects there to be enough monitors for every possible control and monitor group to have one. Such a system gets called 'free running' as the monitors can be programmed once and left running. Any other platform will need to emulate ABMC.

---
Changes since rfc:
drop has_mbwu

Changes since v2:
Iterate over mpam_resctrl_dom directly (Jonathan)
Use for_each_mpam_resctrl_mon

Changes since v3:
Don't continue if mon not found to avoid NULL pointer deref use int for cache_id in mpam_resctrl_alloc_domain() Update commit message
Take traffic into account
Only use mbm_total.

Drop tags due to rework

Changes since v4:
Add debug log when insufficient free running counters (added as abmc dropped for now)

---
 drivers/resctrl/mpam_internal.h |   8 +++
 drivers/resctrl/mpam_resctrl.c  | 124 +++++++++++++++++++++++++++++++-
 2 files changed, 131 insertions(+), 1 deletion(-)
drivers/resctrl/mpam_internal.h +8 -0
index 472bd5d27baa..d58428ba2005 100644
@@ -340,6 +340,14 @@ struct mpam_msc_ris {
 
 struct mpam_resctrl_dom {
 	struct mpam_component		*ctrl_comp;
+
+	/*
+	 * 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 +123 -1

166 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#47 lore raw

PATCH v5 29/41 arm_mpam: resctrl: Pre-allocate free running monitors

In reply to Ben Horgan

From: James Morse <[email protected]>

When there are enough monitors, the resctrl mbm local and total files can be exposed. These need all the monitors that resctrl may use to be allocated up front.

Add helpers to do this.

If a different candidate class is discovered, the old array should be free'd and the allocated monitors returned to the driver.

---
Changes since v2:
Code flow tidying (Jonathan)

---
 drivers/resctrl/mpam_internal.h |  3 +-
 drivers/resctrl/mpam_resctrl.c  | 81 ++++++++++++++++++++++++++++++++-
 2 files changed, 81 insertions(+), 3 deletions(-)
drivers/resctrl/mpam_internal.h +2 -1
index d58428ba2005..f278fa7307af 100644
@@ -361,7 +361,8 @@ struct mpam_resctrl_res {
 struct mpam_resctrl_mon {
 	struct mpam_class	*class;
 
-	/* per-class data that resctrl needs will live here */
+	/* Array of allocated MBWU monitors, indexed by (closid, rmid). */
+	int			*mbwu_idx_to_mon;
 };
 
 static inline int mpam_alloc_csu_mon(struct mpam_class *class)
drivers/resctrl/mpam_resctrl.c +79 -2

96 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#48 lore raw

PATCH v5 30/41 arm_mpam: resctrl: Allow resctrl to allocate monitors

In reply to Ben Horgan

From: James Morse <[email protected]>

When resctrl wants to read a domain's 'QOS_L3_OCCUP', it needs to allocate a monitor on the corresponding resource. Monitors are allocated by class instead of component.

If there are enough MBM monitors, they will be pre-allocated and free-running.

Add helpers to allocate a CSU monitor. These helper return an out of range value for MBM counters.

Allocating a montitor context is expected to block until hardware resources become available. This only makes sense for QOS_L3_OCCUP as unallocated MBM counters are losing data.

---
Changes since rfc:
USE_RMID_IDX -> USE_PRE_ALLOCATED in comment
Remove unnecessary arch_mon_ctx = NULL

Changes since v2:
Add include of resctrl_types.h as dropped from earlier patch

Changes since v3:
Don't mention ABMC in commit message

---
 drivers/resctrl/mpam_internal.h | 14 ++++++-
 drivers/resctrl/mpam_resctrl.c  | 67 +++++++++++++++++++++++++++++++++
 include/linux/arm_mpam.h        |  5 +++
 3 files changed, 85 insertions(+), 1 deletion(-)
drivers/resctrl/mpam_internal.h +13 -1
index f278fa7307af..5fac8fa115ff 100644
@@ -29,6 +29,14 @@ struct platform_device;
 #define PACKED_FOR_KUNIT
 #endif
 
+/*
+ * This 'mon' values must not alias an actual monitor, so must be larger than
+ * U16_MAX, but not be confused with an errno value, so smaller than
+ * (u32)-SZ_4K.
+ * USE_PRE_ALLOCATED is used to avoid confusion with an actual monitor.
+ */
+#define USE_PRE_ALLOCATED	(U16_MAX + 1)
+
 static inline bool mpam_is_enabled(void)
 {
 	return static_branch_likely(&mpam_enabled);
@@ -216,7 +224,11 @@ enum mon_filter_options {
 };
 
 struct mon_cfg {
-	u16			mon;
+	/*
+	 * mon must be large enough to hold out of range values like
+	 * USE_PRE_ALLOCATED
+	 */
+	u32			mon;
 	u8			pmg;
 	bool			match_pmg;
 	bool			csu_exclude_clean;
drivers/resctrl/mpam_resctrl.c +67 -0

79 lines not on this page · raw message

include/linux/arm_mpam.h +5 -0
index 7d23c90f077d..e1461e32af75 100644
@@ -5,6 +5,7 @@
 #define __LINUX_ARM_MPAM_H
 
 #include <linux/acpi.h>
+#include <linux/resctrl_types.h>
 #include <linux/types.h>
 
 struct mpam_msc;
@@ -62,6 +63,10 @@ u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid);
 void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid);
 u32 resctrl_arch_system_num_rmid_idx(void);
 
+struct rdt_resource;
+void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r, enum resctrl_event_id evtid);
+void resctrl_arch_mon_ctx_free(struct rdt_resource *r, enum resctrl_event_id evtid, void *ctx);
+
 /**
  * mpam_register_requestor() - Register a requestor with the MPAM driver
  * @partid_max:		The maximum PARTID value the requestor can generate.
Signature · 1 line
2.43.0
author maintainer
#49 lore raw

PATCH v5 31/41 arm_mpam: resctrl: Add resctrl_arch_rmid_read() and resctrl_arch_reset_rmid()

In reply to Ben Horgan

From: James Morse <[email protected]>

resctrl uses resctrl_arch_rmid_read() to read counters. CDP emulation means the counter may need reading in three different ways. The same goes for reset.

The helpers behind the resctrl_arch_ functions will be re-used for the ABMC equivalent functions.

Add the rounding helper for checking monitor values while we're here.

---
Changes since rfc:
cfg initialisation style
code flow at end of read_mon_cdp_safe()

Changes since v2:
Whitespace changes

Changes since v3:
Update function signatures
Remove abmc check

---
 drivers/resctrl/mpam_resctrl.c | 153 +++++++++++++++++++++++++++++++++
 include/linux/arm_mpam.h       |   5 ++
 2 files changed, 158 insertions(+)
drivers/resctrl/mpam_resctrl.c +153 -0
index ce261af2ca2c..99b6ad89f1ab 100644
@@ -342,6 +342,159 @@ void resctrl_arch_mon_ctx_free(struct rdt_resource *r,
 	resctrl_arch_mon_ctx_free_no_wait(evtid, mon_idx);
 }
 
+static int __read_mon(struct mpam_resctrl_mon *mon, struct mpam_component *mon_comp,
+		      enum mpam_device_features mon_type,
+		      int mon_idx,
+		      enum resctrl_conf_type cdp_type, u32 closid, u32 rmid, u64 *val)
+{
+	struct mon_cfg cfg;
+
+	if (!mpam_is_enabled())
+		return -EINVAL;
+
+	/* Shift closid to account for CDP */
+	closid = resctrl_get_config_index(closid, cdp_type);
+
+	if (mon_idx == USE_PRE_ALLOCATED) {
+		int mbwu_idx = resctrl_arch_rmid_idx_encode(closid, rmid);
+
+		mon_idx = mon->mbwu_idx_to_mon[mbwu_idx];
+		if (mon_idx == -1)
+			return -EINVAL;
+	}
+
+	if (irqs_disabled()) {
+		/* Check if we can access this domain without an IPI */
+		return -EIO;
+	}
+
+	cfg = (struct mon_cfg) {
+		.mon = mon_idx,
+		.match_pmg = true,
+		.partid = closid,
+		.pmg = rmid,
+	};
+
+	return mpam_msmon_read(mon_comp, &cfg, mon_type, val);
+}
+
+static int read_mon_cdp_safe(struct mpam_resctrl_mon *mon, struct mpam_component *mon_comp,
+			     enum mpam_device_features mon_type,
+			     int mon_idx, u32 closid, u32 rmid, u64 *val)
+{
+	if (cdp_enabled) {
+		u64 code_val = 0, data_val = 0;
+		int err;
+
+		err = __read_mon(mon, mon_comp, mon_type, mon_idx,
+				 CDP_CODE, closid, rmid, &code_val);
+		if (err)
+			return err;
+
+		err = __read_mon(mon, mon_comp, mon_type, mon_idx,
+				 CDP_DATA, closid, rmid, &data_val);
+		if (err)
+			return err;
+
+		*val += code_val + data_val;
+		return 0;
+	}
+
+	return __read_mon(mon, mon_comp, mon_type, mon_idx,
+			  CDP_NONE, closid, rmid, val);
+}
+
+/* MBWU when not in ABMC mode, and CSU counters. */
+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_component *mon_comp;
+	u32 mon_idx = *(u32 *)arch_mon_ctx;
+	enum mpam_device_features mon_type;
+	struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
+
+	resctrl_arch_rmid_read_context_check();
+
+	if (eventid >= QOS_NUM_EVENTS || !mon->class)
+		return -EINVAL;
+
+	l3_dom = container_of(hdr, struct mpam_resctrl_dom, resctrl_mon_dom.hdr);
+	mon_comp = l3_dom->mon_comp[eventid];
+
+	switch (eventid) {
+	case QOS_L3_OCCUP_EVENT_ID:
+		mon_type = mpam_feat_msmon_csu;
+		break;
+	case QOS_L3_MBM_LOCAL_EVENT_ID:
+	case QOS_L3_MBM_TOTAL_EVENT_ID:
+		mon_type = mpam_feat_msmon_mbwu;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return read_mon_cdp_safe(mon, mon_comp, mon_type, mon_idx,
+				 closid, rmid, val);
+}
+
+static void __reset_mon(struct mpam_resctrl_mon *mon, struct mpam_component *mon_comp,
+			int mon_idx,
+			enum resctrl_conf_type cdp_type, u32 closid, u32 rmid)
+{
+	struct mon_cfg cfg = { };
+
+	if (!mpam_is_enabled())
+		return;
+
+	/* Shift closid to account for CDP */
+	closid = resctrl_get_config_index(closid, cdp_type);
+
+	if (mon_idx == USE_PRE_ALLOCATED) {
+		int mbwu_idx = resctrl_arch_rmid_idx_encode(closid, rmid);
+
+		mon_idx = mon->mbwu_idx_to_mon[mbwu_idx];
+	}
+
+	if (mon_idx == -1)
+		return;
+	cfg.mon = mon_idx;
+	mpam_msmon_reset_mbwu(mon_comp, &cfg);
+}
+
+static void reset_mon_cdp_safe(struct mpam_resctrl_mon *mon, struct mpam_component *mon_comp,
+			       int mon_idx, u32 closid, u32 rmid)
+{
+	if (cdp_enabled) {
+		__reset_mon(mon, mon_comp, mon_idx, CDP_CODE, closid, rmid);
+		__reset_mon(mon, mon_comp, mon_idx, CDP_DATA, closid, rmid);
+	} else {
+		__reset_mon(mon, mon_comp, mon_idx, CDP_NONE, closid, rmid);
+	}
+}
+
+/* Called via IPI. Call with read_cpus_lock() held. */
+void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
+			     u32 closid, u32 rmid, enum resctrl_event_id eventid)
+{
+	struct mpam_resctrl_dom *l3_dom;
+	struct mpam_component *mon_comp;
+	struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
+
+	if (!mpam_is_enabled())
+		return;
+
+	/* Only MBWU counters are relevant, and for supported event types. */
+	if (eventid == QOS_L3_OCCUP_EVENT_ID || !mon->class)
+		return;
+
+	l3_dom = container_of(d, struct mpam_resctrl_dom, resctrl_mon_dom);
+	mon_comp = l3_dom->mon_comp[eventid];
+
+	reset_mon_cdp_safe(mon, mon_comp, USE_PRE_ALLOCATED, closid, rmid);
+}
+
 static bool cache_has_usable_cpor(struct mpam_class *class)
 {
 	struct mpam_props *cprops = &class->props;
include/linux/arm_mpam.h +5 -0
index e1461e32af75..86d5e326d2bd 100644
@@ -67,6 +67,11 @@ struct rdt_resource;
 void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r, enum resctrl_event_id evtid);
 void resctrl_arch_mon_ctx_free(struct rdt_resource *r, enum resctrl_event_id evtid, void *ctx);
 
+static inline unsigned int resctrl_arch_round_mon_val(unsigned int val)
+{
+	return val;
+}
+
 /**
  * mpam_register_requestor() - Register a requestor with the MPAM driver
  * @partid_max:		The maximum PARTID value the requestor can generate.
Signature · 1 line
2.43.0
#50 lore raw

Re: [PATCH v5 31/41] arm_mpam: resctrl: Add resctrl_arch_rmid_read() and resctrl_arch_reset_rmid()

Hi Ben,

Quoted 20 lines · Ben Horgan

From: James Morse <[email protected]>

resctrl uses resctrl_arch_rmid_read() to read counters. CDP emulation means the counter may need reading in three different ways. The same goes for reset.

The helpers behind the resctrl_arch_ functions will be re-used for the ABMC equivalent functions.

Add the rounding helper for checking monitor values while we're here.

---

[...]

drivers/resctrl/mpam_resctrl.c void resctrl_arch_mon_ctx_free(struct rdt_resource *r, · line 385

Quoted 6 lines
drivers/resctrl/mpam_resctrl.c +6 -0
+
+static int read_mon_cdp_safe(struct mpam_resctrl_mon *mon, struct mpam_component *mon_comp,
+			     enum mpam_device_features mon_type,
+			     int mon_idx, u32 closid, u32 rmid, u64 *val)
+{
+	if (cdp_enabled) {

While reviewing the resctrl limbo handling code, I noticed a issue in __check_limbo() that could lead to premature RMID release when CDP is enabled.

In __check_limbo(), RMIDs in limbo state undergo L3 occupancy checks before being released. This check is performed via resctrl_arch_rmid_read(), on arm64 MPAM, which relies on the cdp_enabled state to determine to check which PARTID.

The concern arises in the following scenario: Filesystem is mounted with CDP enabled. During normal operation, some RMIDs enter limbo. On umount, cdp_enabled is reset to false. __check_limbo() may then run and perform L3 checks with cdp_enabled = false. This could cause RMIDs to be incorrectly released from limbo while still effectively busy after remount.

Apologies for not providing a ready-made fix in this email. However, I would appreciate to hear the community's thoughts on this issue.

Quoted 46 lines
drivers/resctrl/mpam_resctrl.c +46 -0
+		u64 code_val = 0, data_val = 0;
+		int err;
+
+		err = __read_mon(mon, mon_comp, mon_type, mon_idx,
+				 CDP_CODE, closid, rmid, &code_val);
+		if (err)
+			return err;
+
+		err = __read_mon(mon, mon_comp, mon_type, mon_idx,
+				 CDP_DATA, closid, rmid, &data_val);
+		if (err)
+			return err;
+
+		*val += code_val + data_val;
+		return 0;
+	}
+
+	return __read_mon(mon, mon_comp, mon_type, mon_idx,
+			  CDP_NONE, closid, rmid, val);
+}
+
+/* MBWU when not in ABMC mode, and CSU counters. */
+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_component *mon_comp;
+	u32 mon_idx = *(u32 *)arch_mon_ctx;
+	enum mpam_device_features mon_type;
+	struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
+
+	resctrl_arch_rmid_read_context_check();
+
+	if (eventid >= QOS_NUM_EVENTS || !mon->class)
+		return -EINVAL;
+
+	l3_dom = container_of(hdr, struct mpam_resctrl_dom, resctrl_mon_dom.hdr);
+	mon_comp = l3_dom->mon_comp[eventid];
+
+	switch (eventid) {
+	case QOS_L3_OCCUP_EVENT_ID:
+		mon_type = mpam_feat_msmon_csu;
+		break;
+	case QOS_L3_MBM_LOCAL_EVENT_ID:
+	case QOS_L3_MBM_TOTAL_EVENT_ID:

drivers/resctrl/mpam_resctrl.c void resctrl_arch_mon_ctx_free(struct rdt_resource *r, · line 441

Quoted 10 lines
drivers/resctrl/mpam_resctrl.c +10 -0
+		mon_type = mpam_feat_msmon_mbwu;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return read_mon_cdp_safe(mon, mon_comp, mon_type, mon_idx,
+				 closid, rmid, val);
+}
+

Best regards,
Zeng Heng

author maintainer
#51 lore raw

Re: [PATCH v5 31/41] arm_mpam: resctrl: Add resctrl_arch_rmid_read() and resctrl_arch_reset_rmid()

Hi Zeng,

Quoted 45 lines · Zeng Heng

Hi Ben,

Quoted 22 lines · Ben Horgan

From: James Morse <[email protected]>

resctrl uses resctrl_arch_rmid_read() to read counters. CDP emulation means
the counter may need reading in three different ways. The same goes for reset.

The helpers behind the resctrl_arch_ functions will be re-used for the ABMC
equivalent functions.

Add the rounding helper for checking monitor values while we're here.

---

[...]

Quoted 7 lines
(quoted diff) +2 -0
+
+static int read_mon_cdp_safe(struct mpam_resctrl_mon *mon, struct

mpam_component *mon_comp,
+                 enum mpam_device_features mon_type, +                 int mon_idx, u32 closid, u32 rmid, u64 *val) +{
+    if (cdp_enabled) {

While reviewing the resctrl limbo handling code, I noticed a issue in __check_limbo() that could lead to premature RMID release when CDP is enabled.

In __check_limbo(), RMIDs in limbo state undergo L3 occupancy checks before being released. This check is performed via resctrl_arch_rmid_read(), on arm64 MPAM, which relies on the cdp_enabled state to determine to check which PARTID.

Quoted 6 lines

The concern arises in the following scenario: Filesystem is mounted with CDP enabled. During normal operation, some RMIDs enter limbo. On umount, cdp_enabled is reset to false. __check_limbo() may then run and perform L3 checks with cdp_enabled = false. This could cause RMIDs to be incorrectly released from limbo while still effectively busy after remount.

I think a stale limbo list cause more problems than that. If you mount with cdp disabled, cause some rmids to be dirty, unmount and then remount with cdp enabled then you may have some of the entries in upper half marked as busy but when the limbo code checks them it ends up using an out of range partid and may trigger an mpam error interrupt.

To avoid a stale list we could disable the limbo checking at unmount and at remount remake the bitmap. This would involve some resctrl changes which I will have a further look into. For now, to avoid the dependency without a lot of patch churn in this series I think we can hide the cdp enablement behind CONFIG_EXPERT. Does that sound ok to you?

Thanks,

Ben

Quoted 67 lines

Apologies for not providing a ready-made fix in this email. However, I would appreciate to hear the community's thoughts on this issue.

Quoted 48 lines

+        u64 code_val = 0, data_val = 0;
+        int err;

drivers/resctrl/mpam_resctrl.c +21 -0
+
+        err = __read_mon(mon, mon_comp, mon_type, mon_idx,
+                 CDP_CODE, closid, rmid, &code_val);
+        if (err)
+            return err;
+
+        err = __read_mon(mon, mon_comp, mon_type, mon_idx,
+                 CDP_DATA, closid, rmid, &data_val);
+        if (err)
+            return err;
+
+        *val += code_val + data_val;
+        return 0;
+    }
+
+    return __read_mon(mon, mon_comp, mon_type, mon_idx,
+              CDP_NONE, closid, rmid, val);
+}
+
+/* MBWU when not in ABMC mode, and CSU counters. */
+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)

drivers/resctrl/mpam_resctrl.c +13 -0
+{
+    struct mpam_resctrl_dom *l3_dom;
+    struct mpam_component *mon_comp;
+    u32 mon_idx = *(u32 *)arch_mon_ctx;
+    enum mpam_device_features mon_type;
+    struct mpam_resctrl_mon *mon = &mpam_resctrl_counters[eventid];
+
+    resctrl_arch_rmid_read_context_check();
+
+    if (eventid >= QOS_NUM_EVENTS || !mon->class)
+        return -EINVAL;
+
+    l3_dom = container_of(hdr, struct mpam_resctrl_dom,

resctrl_mon_dom.hdr);
+    mon_comp = l3_dom->mon_comp[eventid];

drivers/resctrl/mpam_resctrl.c +7 -0
+
+    switch (eventid) {
+    case QOS_L3_OCCUP_EVENT_ID:
+        mon_type = mpam_feat_msmon_csu;
+        break;
+    case QOS_L3_MBM_LOCAL_EVENT_ID:
+    case QOS_L3_MBM_TOTAL_EVENT_ID:

drivers/resctrl/mpam_resctrl.c void resctrl_arch_mon_ctx_free(struct rdt_resource *r, · line 441

Quoted 10 lines
drivers/resctrl/mpam_resctrl.c +10 -0
+        mon_type = mpam_feat_msmon_mbwu;
+        break;
+    default:
+        return -EINVAL;
+    }
+
+    return read_mon_cdp_safe(mon, mon_comp, mon_type, mon_idx,
+                 closid, rmid, val);
+}
+

Best regards,
Zeng Heng

#52 lore raw

Re: [PATCH v5 31/41] arm_mpam: resctrl: Add resctrl_arch_rmid_read() and resctrl_arch_reset_rmid()

Hi Ben,

Quoted 67 lines · Ben Horgan

Hi Zeng,

Quoted 45 lines · Zeng Heng

Hi Ben,

Quoted 22 lines · Ben Horgan

From: James Morse <[email protected]>

resctrl uses resctrl_arch_rmid_read() to read counters. CDP emulation means
the counter may need reading in three different ways. The same goes for reset.

The helpers behind the resctrl_arch_ functions will be re-used for the ABMC
equivalent functions.

Add the rounding helper for checking monitor values while we're here.

---

[...]

Quoted 7 lines
(quoted diff) +2 -0
+
+static int read_mon_cdp_safe(struct mpam_resctrl_mon *mon, struct

mpam_component *mon_comp,
+                 enum mpam_device_features mon_type, +                 int mon_idx, u32 closid, u32 rmid, u64 *val) +{
+    if (cdp_enabled) {

While reviewing the resctrl limbo handling code, I noticed a issue in __check_limbo() that could lead to premature RMID release when CDP is enabled.

In __check_limbo(), RMIDs in limbo state undergo L3 occupancy checks before being released. This check is performed via resctrl_arch_rmid_read(), on arm64 MPAM, which relies on the cdp_enabled state to determine to check which PARTID.

Quoted 6 lines

The concern arises in the following scenario: Filesystem is mounted with CDP enabled. During normal operation, some RMIDs enter limbo. On umount, cdp_enabled is reset to false. __check_limbo() may then run and perform L3 checks with cdp_enabled = false. This could cause RMIDs to be incorrectly released from limbo while still effectively busy after remount.

I think a stale limbo list cause more problems than that. If you mount with cdp disabled, cause some rmids to be dirty, unmount and then remount with cdp enabled then you may have some of the entries in upper half marked as busy but when the limbo code checks them it ends up using an out of range partid and may trigger an mpam error interrupt.

To avoid a stale list we could disable the limbo checking at unmount and at remount remake the bitmap. This would involve some resctrl changes which I will have a further look into. For now, to avoid the dependency without a lot of patch churn in this series I think we can hide the cdp enablement behind CONFIG_EXPERT. Does that sound ok to you?

Quoted 4 lines

Thanks,

Ben

Confirmed. Toggling between non-CDP and CDP mount modes leads to out-of-range PARTID hardware errors and memory access violations. This can cause MPAM to halt by provoking mpam_broken_work.

I agreed properly fixing this will require resctrl modifications to handle the limbo state across mount cycles. Hiding CDP behind CONFIG_EXPERT is acceptable as a short-term mitigation to prevent users from hitting this bug accidentally.

Best regards,
Zeng Heng

author maintainer
#53 lore raw

PATCH v5 32/41 arm_mpam: resctrl: Update the rmid reallocation limit

In reply to Ben Horgan

From: James Morse <[email protected]>

resctrl's limbo code needs to be told when the data left in a cache is small enough for the partid+pmg value to be re-allocated.

x86 uses the cache size divided by the number of rmid users the cache may have. Do the same, but for the smallest cache, and with the number of partid-and-pmg users.

---
Changes since v2:
Move waiting for cache info into it's own patch

Changes since v3:
Move check class is csu higher (just kept to document intent) continue -> break

to squash update rmid limits
use raw_smp_processor_id()

---
 drivers/resctrl/mpam_resctrl.c | 39 ++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
drivers/resctrl/mpam_resctrl.c +39 -0
index 99b6ad89f1ab..d4fdad875d95 100644
@@ -495,6 +495,42 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_l3_mon_domain *d
 	reset_mon_cdp_safe(mon, mon_comp, USE_PRE_ALLOCATED, closid, rmid);
 }
 
+/*
+ * The rmid realloc threshold should be for the smallest cache exposed to
+ * resctrl.
+ */
+static int update_rmid_limits(struct mpam_class *class)
+{
+	u32 num_unique_pmg = resctrl_arch_system_num_rmid_idx();
+	struct mpam_props *cprops = &class->props;
+	struct cacheinfo *ci;
+
+	lockdep_assert_cpus_held();
+
+	if (!mpam_has_feature(mpam_feat_msmon_csu, cprops))
+		return 0;
+
+	/*
+	 * Assume cache levels are the same size for all CPUs...
+	 * The check just requires any online CPU and it can't go offline as we
+	 * hold the cpu lock.
+	 */
+	ci = get_cpu_cacheinfo_level(raw_smp_processor_id(), class->level);
+	if (!ci || ci->size == 0) {
+		pr_debug("Could not read cache size for class %u\n",
+			 class->level);
+		return -EINVAL;
+	}
+
+	if (!resctrl_rmid_realloc_limit ||
+	    ci->size < resctrl_rmid_realloc_limit) {
+		resctrl_rmid_realloc_limit = ci->size;
+		resctrl_rmid_realloc_threshold = ci->size / num_unique_pmg;
+	}
+
+	return 0;
+}
+
 static bool cache_has_usable_cpor(struct mpam_class *class)
 {
 	struct mpam_props *cprops = &class->props;
@@ -1000,6 +1036,9 @@ static void mpam_resctrl_pick_counters(void)
 			/* CSU counters only make sense on a cache. */
 			switch (class->type) {
 			case MPAM_CLASS_CACHE:
+				if (update_rmid_limits(class))
+					break;
+
 				counter_update_class(QOS_L3_OCCUP_EVENT_ID, class);
 				break;
 			default:
Signature · 1 line
2.43.0
author maintainer
#54 lore raw

PATCH v5 33/41 arm_mpam: resctrl: Add empty definitions for assorted resctrl functions

In reply to Ben Horgan

From: James Morse <[email protected]>

A few resctrl features and hooks need to be provided, but aren't needed or supported on MPAM platforms.

resctrl has individual hooks to separately enable and disable the closid/partid and rmid/pmg context switching code. For MPAM this is all the same thing, as the value in struct task_struct is used to cache the value that should be written to hardware. arm64's context switching code is enabled once MPAM is usable, but doesn't touch the hardware unless the value has changed.

For now event configuration is not supported, and can be turned off by returning 'false' from resctrl_arch_is_evt_configurable().

The new io_alloc feature is not supported either, always return false from the enable helper to indicate and fail the enable.

Add this, and empty definitions for the other hooks.

---
Changes since v3:
Add resctrl_arch_pre_mount() {}
resctrl_arch_reset_rmid_all() signature update
add stubs for abmc
keep empty definitions together

---
 drivers/resctrl/mpam_resctrl.c | 60 ++++++++++++++++++++++++++++++++++
 include/linux/arm_mpam.h       |  9 +++++
 2 files changed, 69 insertions(+)
drivers/resctrl/mpam_resctrl.c +60 -0
index d4fdad875d95..490e49ab730c 100644
@@ -99,6 +99,66 @@ bool resctrl_arch_mon_capable(void)
 	return l3->mon_capable;
 }
 
+bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt)
+{
+	return false;
+}
+
+void resctrl_arch_mon_event_config_read(void *info)
+{
+}
+
+void resctrl_arch_mon_event_config_write(void *info)
+{
+}
+
+void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_l3_mon_domain *d)
+{
+}
+
+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)
+{
+}
+
+void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
+			      enum resctrl_event_id evtid, u32 rmid, u32 closid,
+			      u32 cntr_id, bool assign)
+{
+}
+
+int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domain *d,
+			   u32 unused, u32 rmid, int cntr_id,
+			   enum resctrl_event_id eventid, u64 *val)
+{
+	return -EOPNOTSUPP;
+}
+
+bool resctrl_arch_mbm_cntr_assign_enabled(struct rdt_resource *r)
+{
+	return false;
+}
+
+int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable)
+{
+	return -EINVAL;
+}
+
+int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable)
+{
+	return -EOPNOTSUPP;
+}
+
+bool resctrl_arch_get_io_alloc_enabled(struct rdt_resource *r)
+{
+	return false;
+}
+
+void resctrl_arch_pre_mount(void)
+{
+}
+
 bool resctrl_arch_get_cdp_enabled(enum resctrl_res_level rid)
 {
 	return mpam_resctrl_controls[rid].cdp_enabled;
include/linux/arm_mpam.h +9 -0
index 86d5e326d2bd..f92a36187a52 100644
@@ -67,6 +67,15 @@ struct rdt_resource;
 void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r, enum resctrl_event_id evtid);
 void resctrl_arch_mon_ctx_free(struct rdt_resource *r, enum resctrl_event_id evtid, void *ctx);
 
+/*
+ * The CPU configuration for MPAM is cheap to write, and is only written if it
+ * has changed. No need for fine grained enables.
+ */
+static inline void resctrl_arch_enable_mon(void) { }
+static inline void resctrl_arch_disable_mon(void) { }
+static inline void resctrl_arch_enable_alloc(void) { }
+static inline void resctrl_arch_disable_alloc(void) { }
+
 static inline unsigned int resctrl_arch_round_mon_val(unsigned int val)
 {
 	return val;
Signature · 1 line
2.43.0
author maintainer
#55 lore raw

PATCH v5 34/41 arm64: mpam: Select ARCH_HAS_CPU_RESCTRL

In reply to Ben Horgan

From: James Morse <[email protected]>

Enough MPAM support is present to enable ARCH_HAS_CPU_RESCTRL. Let it rip^Wlink!

ARCH_HAS_CPU_RESCTRL indicates resctrl can be enabled. It is enabled by the arch code simply because it has 'arch' in its name.

This removes ARM_CPU_RESCTRL as a mimic of X86_CPU_RESCTRL. While here, move the ACPI dependency to the driver's Kconfig file.

---
 arch/arm64/Kconfig               | 2 +-
 arch/arm64/include/asm/resctrl.h | 2 ++
 drivers/resctrl/Kconfig          | 7 +++++++
 drivers/resctrl/Makefile         | 2 +-
 4 files changed, 11 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm64/include/asm/resctrl.h
arch/arm64/Kconfig +1 -1
index 3170c67464fb..41a5b4ef86b4 100644
@@ -2017,7 +2017,7 @@ config ARM64_TLB_RANGE
 config ARM64_MPAM
 	bool "Enable support for MPAM"
 	select ARM64_MPAM_DRIVER
-	select ACPI_MPAM if ACPI
+	select ARCH_HAS_CPU_RESCTRL
 	help
 	  Memory System Resource Partitioning and Monitoring (MPAM) is an
 	  optional extension to the Arm architecture that allows each
arch/arm64/include/asm/resctrl.h new file +2 -0
new file mode 100644
index 000000000000..b506e95cf6e3
@@ -0,0 +1,2 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#include <linux/arm_mpam.h>
drivers/resctrl/Kconfig +7 -0
index c34e059c6e41..672abea3b03c 100644
@@ -1,6 +1,7 @@
 menuconfig ARM64_MPAM_DRIVER
 	bool "MPAM driver"
 	depends on ARM64 && ARM64_MPAM
+	select ACPI_MPAM if ACPI
 	help
 	  Memory System Resource Partitioning and Monitoring (MPAM) driver for
 	  System IP, e.g. caches and memory controllers.
@@ -22,3 +23,9 @@ config MPAM_KUNIT_TEST
 	  If unsure, say N.
 
 endif
+
+config ARM64_MPAM_RESCTRL_FS
+	bool
+	default y if ARM64_MPAM_DRIVER && RESCTRL_FS
+	select RESCTRL_RMID_DEPENDS_ON_CLOSID
+	select RESCTRL_ASSIGN_FIXED
drivers/resctrl/Makefile +1 -1
index 40beaf999582..4f6d0e81f9b8 100644
@@ -1,5 +1,5 @@
 obj-$(CONFIG_ARM64_MPAM_DRIVER)			+= mpam.o
 mpam-y						+= mpam_devices.o
-mpam-$(CONFIG_ARM_CPU_RESCTRL)			+= mpam_resctrl.o
+mpam-$(CONFIG_ARM64_MPAM_RESCTRL_FS)		+= mpam_resctrl.o
 
 ccflags-$(CONFIG_ARM64_MPAM_DRIVER_DEBUG)	+= -DDEBUG
Signature · 1 line
2.43.0
author maintainer
#56 lore raw

PATCH v5 35/41 arm_mpam: resctrl: Call resctrl_init() on platforms that can support resctrl

In reply to Ben Horgan

From: James Morse <[email protected]>

Now that MPAM links against resctrl, call resctrl_init() to register the filesystem and setup resctrl's structures.

---
Changes since v2:
Use for_each_mpam...
error path tidying

Changes since v3:
Don't consider abmc in teardown

---
 drivers/resctrl/mpam_devices.c  | 32 ++++++++++++--
 drivers/resctrl/mpam_internal.h |  4 ++
 drivers/resctrl/mpam_resctrl.c  | 76 ++++++++++++++++++++++++++++++++-
 3 files changed, 107 insertions(+), 5 deletions(-)
drivers/resctrl/mpam_devices.c +28 -4
index 90d69091e0b9..528936ececd9 100644
@@ -73,6 +73,14 @@ static DECLARE_WORK(mpam_broken_work, &mpam_disable);
 /* When mpam is disabled, the printed reason to aid debugging */
 static char *mpam_disable_reason;
 
+/*
+ * Whether resctrl has been setup. Used by cpuhp in preference to
+ * mpam_is_enabled(). The disable call after an error interrupt makes
+ * mpam_is_enabled() false before the cpuhp callbacks are made.
+ * Reads/writes should hold mpam_cpuhp_state_lock, (or be cpuhp callbacks).
+ */
+static bool mpam_resctrl_enabled;
+
 /*
  * An MSC is a physical container for controls and monitors, each identified by
  * their RIS index. These share a base-address, interrupts and some MMIO
@@ -1635,7 +1643,7 @@ static int mpam_cpu_online(unsigned int cpu)
 			mpam_reprogram_msc(msc);
 	}
 
-	if (mpam_is_enabled())
+	if (mpam_resctrl_enabled)
 		return mpam_resctrl_online_cpu(cpu);
 
 	return 0;
@@ -1681,7 +1689,7 @@ static int mpam_cpu_offline(unsigned int cpu)
 {
 	struct mpam_msc *msc;
 
-	if (mpam_is_enabled())
+	if (mpam_resctrl_enabled)
 		mpam_resctrl_offline_cpu(cpu);
 
 	guard(srcu)(&mpam_srcu);
@@ -2542,6 +2550,7 @@ static void mpam_enable_once(void)
 	}
 
 	static_branch_enable(&mpam_enabled);
+	mpam_resctrl_enabled = true;
 	mpam_register_cpuhp_callbacks(mpam_cpu_online, mpam_cpu_offline,
 				      "mpam:online");
 
@@ -2601,24 +2610,39 @@ static void mpam_reset_class(struct mpam_class *class)
 void mpam_disable(struct work_struct *ignored)
 {
 	int idx;
+	bool do_resctrl_exit;
 	struct mpam_class *class;
 	struct mpam_msc *msc, *tmp;
 
+	if (mpam_is_enabled())
+		static_branch_disable(&mpam_enabled);
+
 	mutex_lock(&mpam_cpuhp_state_lock);
 	if (mpam_cpuhp_state) {
 		cpuhp_remove_state(mpam_cpuhp_state);
 		mpam_cpuhp_state = 0;
 	}
+
+	/*
+	 * Removing the cpuhp state called mpam_cpu_offline() and told resctrl
+	 * all the CPUs are offline.
+	 */
+	do_resctrl_exit = mpam_resctrl_enabled;
+	mpam_resctrl_enabled = false;
 	mutex_unlock(&mpam_cpuhp_state_lock);
 
-	static_branch_disable(&mpam_enabled);
+	if (do_resctrl_exit)
+		mpam_resctrl_exit();
 
 	mpam_unregister_irqs();
 
 	idx = srcu_read_lock(&mpam_srcu);
 	list_for_each_entry_srcu(class, &mpam_classes, classes_list,
-				 srcu_read_lock_held(&mpam_srcu))
+				 srcu_read_lock_held(&mpam_srcu)) {
 		mpam_reset_class(class);
+		if (do_resctrl_exit)
+			mpam_resctrl_teardown_class(class);
+	}
 	srcu_read_unlock(&mpam_srcu, idx);
 
 	mutex_lock(&mpam_list_lock);
drivers/resctrl/mpam_internal.h +4 -0
index 5fac8fa115ff..a79c7670f7ae 100644
@@ -436,12 +436,16 @@ 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_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_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 +75 -1

124 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#57 lore raw

PATCH v5 36/41 arm_mpam: Add quirk framework

In reply to Ben Horgan

From: Shanker Donthineni <[email protected]>

The MPAM specification includes the MPAMF_IIDR, which serves to uniquely identify the MSC implementation through a combination of implementer details, product ID, variant, and revision. Certain hardware issues/errata can be resolved using software workarounds.

Introduce a quirk framework to allow workarounds to be enabled based on the MPAMF_IIDR value.

---
Changes by James:
Stash the IIDR so this doesn't need an IPI, enable quirks only once, move the description to the callback so it can be pr_once()d, add an enum of workarounds for popular errata. Add macros for making lists of product/revision/vendor half readable

Changes since rfc:
remove trailing commas in last element of enums
Make mpam_enable_quirks() in charge of mpam_set_quirk() even if there is an enable.

Changes since v3:
Brackets in macro

---
 drivers/resctrl/mpam_devices.c  | 32 ++++++++++++++++++++++++++++++++
 drivers/resctrl/mpam_internal.h | 25 +++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
drivers/resctrl/mpam_devices.c +32 -0
index 528936ececd9..382dc5c9b885 100644
@@ -630,6 +630,30 @@ static struct mpam_msc_ris *mpam_get_or_create_ris(struct mpam_msc *msc,
 	return ERR_PTR(-ENOENT);
 }
 
+static const struct mpam_quirk mpam_quirks[] = {
+	{ NULL } /* Sentinel */
+};
+
+static void mpam_enable_quirks(struct mpam_msc *msc)
+{
+	const struct mpam_quirk *quirk;
+
+	for (quirk = &mpam_quirks[0]; quirk->iidr_mask; quirk++) {
+		int err = 0;
+
+		if (quirk->iidr != (msc->iidr & quirk->iidr_mask))
+			continue;
+
+		if (quirk->init)
+			err = quirk->init(msc, quirk);
+
+		if (err)
+			continue;
+
+		mpam_set_quirk(quirk->workaround, msc);
+	}
+}
+
 /*
  * IHI009A.a has this nugget: "If a monitor does not support automatic behaviour
  * of NRDY, software can use this bit for any purpose" - so hardware might not
@@ -864,8 +888,11 @@ static int mpam_msc_hw_probe(struct mpam_msc *msc)
 	/* Grab an IDR value to find out how many RIS there are */
 	mutex_lock(&msc->part_sel_lock);
 	idr = mpam_msc_read_idr(msc);
+	msc->iidr = mpam_read_partsel_reg(msc, IIDR);
 	mutex_unlock(&msc->part_sel_lock);
 
+	mpam_enable_quirks(msc);
+
 	msc->ris_max = FIELD_GET(MPAMF_IDR_RIS_MAX, idr);
 
 	/* Use these values so partid/pmg always starts with a valid value */
@@ -1988,6 +2015,7 @@ static bool mpam_has_cmax_wd_feature(struct mpam_props *props)
  * resulting safe value must be compatible with both. When merging values in
  * the tree, all the aliasing resources must be handled first.
  * On mismatch, parent is modified.
+ * Quirks on an MSC will apply to all MSC in that class.
  */
 static void __props_mismatch(struct mpam_props *parent,
 			     struct mpam_props *child, bool alias)
@@ -2107,6 +2135,7 @@ static void __props_mismatch(struct mpam_props *parent,
  * nobble the class feature, as we can't configure all the resources.
  * e.g. The L3 cache is composed of two resources with 13 and 17 portion
  * bitmaps respectively.
+ * Quirks on an MSC will apply to all MSC in that class.
  */
 static void
 __class_props_mismatch(struct mpam_class *class, struct mpam_vmsc *vmsc)
@@ -2120,6 +2149,9 @@ __class_props_mismatch(struct mpam_class *class, struct mpam_vmsc *vmsc)
 	dev_dbg(dev, "Merging features for class:0x%lx &= vmsc:0x%lx\n",
 		(long)cprops->features, (long)vprops->features);
 
+	/* Merge quirks */
+	class->quirks |= vmsc->msc->quirks;
+
 	/* Take the safe value for any common features */
 	__props_mismatch(cprops, vprops, false);
 }
drivers/resctrl/mpam_internal.h +25 -0
index a79c7670f7ae..60e445e94ee6 100644
@@ -85,6 +85,8 @@ struct mpam_msc {
 	u8			pmg_max;
 	unsigned long		ris_idxs;
 	u32			ris_max;
+	u32			iidr;
+	u16			quirks;
 
 	/*
 	 * error_irq_lock is taken when registering/unregistering the error
@@ -216,6 +218,28 @@ struct mpam_props {
 #define mpam_set_feature(_feat, x)	__set_bit(_feat, (x)->features)
 #define mpam_clear_feature(_feat, x)	__clear_bit(_feat, (x)->features)
 
+/* Workaround bits for msc->quirks */
+enum mpam_device_quirks {
+	MPAM_QUIRK_LAST
+};
+
+#define mpam_has_quirk(_quirk, x)	((1 << (_quirk) & (x)->quirks))
+#define mpam_set_quirk(_quirk, x)	((x)->quirks |= (1 << (_quirk)))
+
+struct mpam_quirk {
+	int (*init)(struct mpam_msc *msc, const struct mpam_quirk *quirk);
+
+	u32 iidr;
+	u32 iidr_mask;
+
+	enum mpam_device_quirks workaround;
+};
+
+#define MPAM_IIDR_MATCH_ONE	(FIELD_PREP_CONST(MPAMF_IIDR_PRODUCTID,   0xfff) | \
+				 FIELD_PREP_CONST(MPAMF_IIDR_VARIANT,     0xf)	 | \
+				 FIELD_PREP_CONST(MPAMF_IIDR_REVISION,    0xf)	 | \
+				 FIELD_PREP_CONST(MPAMF_IIDR_IMPLEMENTER, 0xfff))
+
 /* The values for MSMON_CFG_MBWU_FLT.RWBW */
 enum mon_filter_options {
 	COUNT_BOTH	= 0,
@@ -259,6 +283,7 @@ struct mpam_class {
 
 	struct mpam_props	props;
 	u32			nrdy_usec;
+	u16			quirks;
 	u8			level;
 	enum mpam_class_types	type;
 
Signature · 1 line
2.43.0
author maintainer
#58 lore raw

PATCH v5 37/41 arm_mpam: Add workaround for T241-MPAM-1

In reply to Ben Horgan

From: Shanker Donthineni <[email protected]>

The MPAM bandwidth partitioning controls will not be correctly configured, and hardware will retain default configuration register values, meaning generally that bandwidth will remain unprovisioned.

To address the issue, follow the below steps after updating the MBW_MIN and/or MBW_MAX registers.

- Perform 64b reads from all 12 bridge MPAM shadow registers at offsets (0x360048 + slice*0x10000 + partid*8). These registers are read-only.
- Continue iterating until all 12 shadow register values match in a loop. pr_warn_once if the values fail to match within the loop count 1000.
- Perform 64b writes with the value 0x0 to the two spare registers at offsets 0x1b0000 and 0x1c0000.

In the hardware, writes to the MPAMCFG_MBW_MAX MPAMCFG_MBW_MIN registers are transformed into broadcast writes to the 12 shadow registers. The final two writes to the spare registers cause a final rank of downstream micro-architectural MPAM registers to be updated from the shadow copies. The intervening loop to read the 12 shadow registers helps avoid a race condition where writes to the spare registers occur before all shadow registers have been updated.

---

Changes from James:
Merged the min/max update into a single mpam_quirk_post_config_change() helper. Stashed the t241_id in the msc instead of carrying the physical address around. Test the msc quirk bit instead of a static key.

Changes since rfc:
MPAM_IIDR_NVIDIA_T421 -> MPAM_IIDR_NVIDIA_T241
return err from init
Be specific about the errata in the init name,
mpam_enable_quirk_nvidia_t241 -> mpam_enable_quirk_nvidia_t241_1

Changes since v3:
parentheses

---
 Documentation/arch/arm64/silicon-errata.rst |  2 +
 drivers/resctrl/mpam_devices.c              | 88 +++++++++++++++++++++
 drivers/resctrl/mpam_internal.h             |  9 +++
 3 files changed, 99 insertions(+)
Documentation/arch/arm64/silicon-errata.rst +2 -0
index 4c300caad901..a65620f98e3a 100644
@@ -247,6 +247,8 @@ stable kernels.
 +----------------+-----------------+-----------------+-----------------------------+
 | NVIDIA         | T241 GICv3/4.x  | T241-FABRIC-4   | N/A                         |
 +----------------+-----------------+-----------------+-----------------------------+
+| NVIDIA         | T241 MPAM       | T241-MPAM-1     | N/A                         |
++----------------+-----------------+-----------------+-----------------------------+
 +----------------+-----------------+-----------------+-----------------------------+
 | Freescale/NXP  | LS2080A/LS1043A | A-008585        | FSL_ERRATUM_A008585         |
 +----------------+-----------------+-----------------+-----------------------------+
drivers/resctrl/mpam_devices.c +88 -0

113 lines not on this page · raw message

drivers/resctrl/mpam_internal.h +9 -0
index 60e445e94ee6..508cc03d0453 100644
@@ -130,6 +130,9 @@ struct mpam_msc {
 	void __iomem		*mapped_hwpage;
 	size_t			mapped_hwpage_sz;
 
+	/* Values only used on some platforms for quirks */
+	u32			t241_id;
+
 	struct mpam_garbage	garbage;
 };
 
@@ -220,6 +223,7 @@ struct mpam_props {
 
 /* Workaround bits for msc->quirks */
 enum mpam_device_quirks {
+	T241_SCRUB_SHADOW_REGS,
 	MPAM_QUIRK_LAST
 };
 
@@ -240,6 +244,11 @@ struct mpam_quirk {
 				 FIELD_PREP_CONST(MPAMF_IIDR_REVISION,    0xf)	 | \
 				 FIELD_PREP_CONST(MPAMF_IIDR_IMPLEMENTER, 0xfff))
 
+#define MPAM_IIDR_NVIDIA_T241	(FIELD_PREP_CONST(MPAMF_IIDR_PRODUCTID,   0x241) | \
+				 FIELD_PREP_CONST(MPAMF_IIDR_VARIANT,     0)	 | \
+				 FIELD_PREP_CONST(MPAMF_IIDR_REVISION,    0)	 | \
+				 FIELD_PREP_CONST(MPAMF_IIDR_IMPLEMENTER, 0x36b))
+
 /* The values for MSMON_CFG_MBWU_FLT.RWBW */
 enum mon_filter_options {
 	COUNT_BOTH	= 0,
Signature · 1 line
2.43.0
author maintainer
#59 lore raw

PATCH v5 38/41 arm_mpam: Add workaround for T241-MPAM-4

In reply to Ben Horgan

From: Shanker Donthineni <[email protected]>

In the T241 implementation of memory-bandwidth partitioning, in the absence of contention for bandwidth, the minimum bandwidth setting can affect the amount of achieved bandwidth. Specifically, the achieved bandwidth in the absence of contention can settle to any value between the values of MPAMCFG_MBW_MIN and MPAMCFG_MBW_MAX. Also, if MPAMCFG_MBW_MIN is set zero (below 0.78125%), once a core enters a throttled state, it will never leave that state.

The first issue is not a concern if the MPAM software allows to program MPAMCFG_MBW_MIN through the sysfs interface. This patch ensures program MBW_MIN=1 (0.78125%) whenever MPAMCFG_MBW_MIN=0 is programmed.

In the scenario where the resctrl doesn't support the MBW_MIN interface via sysfs, to achieve bandwidth closer to MBW_MAX in the absence of contention, software should configure a relatively narrow gap between MBW_MIN and MBW_MAX. The recommendation is to use a 5% gap to mitigate the problem.

Clear the feature MBW_MIN feature from the class to ensure we don't accidentally change behaviour when resctrl adds support for a MBW_MIN interface.

---
[ morse: Added as second quirk, adapted to use the new intermediate values in mpam_extend_config() ]

Changes since rfc:
MPAM_IIDR_NVIDIA_T421 -> MPAM_IIDR_NVIDIA_T241
Handling when reset_mbw_min is set

Changes since v3:
Move the 5% gap policy back here
Clear mbw_min feature in class

---
 Documentation/arch/arm64/silicon-errata.rst |  2 +
 drivers/resctrl/mpam_devices.c              | 50 +++++++++++++++++++--
 drivers/resctrl/mpam_internal.h             |  1 +
 3 files changed, 50 insertions(+), 3 deletions(-)
Documentation/arch/arm64/silicon-errata.rst +2 -0
index a65620f98e3a..a4b246655e37 100644
@@ -249,6 +249,8 @@ stable kernels.
 +----------------+-----------------+-----------------+-----------------------------+
 | NVIDIA         | T241 MPAM       | T241-MPAM-1     | N/A                         |
 +----------------+-----------------+-----------------+-----------------------------+
+| NVIDIA         | T241 MPAM       | T241-MPAM-4     | N/A                         |
++----------------+-----------------+-----------------+-----------------------------+
 +----------------+-----------------+-----------------+-----------------------------+
 | Freescale/NXP  | LS2080A/LS1043A | A-008585        | FSL_ERRATUM_A008585         |
 +----------------+-----------------+-----------------+-----------------------------+
drivers/resctrl/mpam_devices.c +47 -3

74 lines not on this page · raw message

drivers/resctrl/mpam_internal.h +1 -0
index 508cc03d0453..9f92fd49a61c 100644
@@ -224,6 +224,7 @@ struct mpam_props {
 /* Workaround bits for msc->quirks */
 enum mpam_device_quirks {
 	T241_SCRUB_SHADOW_REGS,
+	T241_FORCE_MBW_MIN_TO_ONE,
 	MPAM_QUIRK_LAST
 };
 
Signature · 1 line
2.43.0
reviewer Reviewed-by on v5 38/41
#60 lore raw

Re: [PATCH v5 38/41] arm_mpam: Add workaround for T241-MPAM-4

Hi, Ben,

Quoted 23 lines · Ben Horgan

From: Shanker Donthineni <[email protected]>

In the T241 implementation of memory-bandwidth partitioning, in the absence of contention for bandwidth, the minimum bandwidth setting can affect the amount of achieved bandwidth. Specifically, the achieved bandwidth in the absence of contention can settle to any value between the values of MPAMCFG_MBW_MIN and MPAMCFG_MBW_MAX. Also, if MPAMCFG_MBW_MIN is set zero (below 0.78125%), once a core enters a throttled state, it will never leave that state.

The first issue is not a concern if the MPAM software allows to program MPAMCFG_MBW_MIN through the sysfs interface. This patch ensures program MBW_MIN=1 (0.78125%) whenever MPAMCFG_MBW_MIN=0 is programmed.

In the scenario where the resctrl doesn't support the MBW_MIN interface via sysfs, to achieve bandwidth closer to MBW_MAX in the absence of contention, software should configure a relatively narrow gap between MBW_MIN and MBW_MAX. The recommendation is to use a 5% gap to mitigate the problem.

Clear the feature MBW_MIN feature from the class to ensure we don't accidentally change behaviour when resctrl adds support for a MBW_MIN interface.

Quoted 6 lines

This patch itself is good.

Please check the following comments.

Quoted 57 lines

---
[ morse: Added as second quirk, adapted to use the new intermediate values in mpam_extend_config() ]

Changes since rfc:
MPAM_IIDR_NVIDIA_T421 -> MPAM_IIDR_NVIDIA_T241
Handling when reset_mbw_min is set

Changes since v3:
Move the 5% gap policy back here
Clear mbw_min feature in class

---
  Documentation/arch/arm64/silicon-errata.rst |  2 +
  drivers/resctrl/mpam_devices.c              | 50 +++++++++++++++++++--
  drivers/resctrl/mpam_internal.h             |  1 +
  3 files changed, 50 insertions(+), 3 deletions(-)
Documentation/arch/arm64/silicon-errata.rst +2 -0
index a65620f98e3a..a4b246655e37 100644
@@ -249,6 +249,8 @@ stable kernels.
  +----------------+-----------------+-----------------+-----------------------------+
  | NVIDIA         | T241 MPAM       | T241-MPAM-1     | N/A                         |
  +----------------+-----------------+-----------------+-----------------------------+
+| NVIDIA         | T241 MPAM       | T241-MPAM-4     | N/A                         |
++----------------+-----------------+-----------------+-----------------------------+
  +----------------+-----------------+-----------------+-----------------------------+
  | Freescale/NXP  | LS2080A/LS1043A | A-008585        | FSL_ERRATUM_A008585         |
  +----------------+-----------------+-----------------+-----------------------------+
drivers/resctrl/mpam_devices.c +12 -0
index 08cb080592d9..8f44e9dee207 100644
@@ -679,6 +679,12 @@ static const struct mpam_quirk mpam_quirks[] = {
  	.iidr_mask  = MPAM_IIDR_MATCH_ONE,
  	.workaround = T241_SCRUB_SHADOW_REGS,
  	},
+	{
+	/* NVIDIA t241 erratum T241-MPAM-4 */
+	.iidr       = MPAM_IIDR_NVIDIA_T241,
+	.iidr_mask  = MPAM_IIDR_MATCH_ONE,
+	.workaround = T241_FORCE_MBW_MIN_TO_ONE,
+	},
  	{ NULL } /* Sentinel */
  };
 
@@ -1464,6 +1470,31 @@ static void mpam_quirk_post_config_change(struct mpam_msc_ris *ris, u16 partid,
  		mpam_apply_t241_erratum(ris, partid);
  }
 
+static u16 mpam_wa_t241_force_mbw_min_to_one(struct mpam_props *props)
+{
+	u16 max_hw_value, min_hw_granule, res0_bits;
+
+	res0_bits = 16 - props->bwa_wd;
+	max_hw_value = ((1 << props->bwa_wd) - 1) << res0_bits;

drivers/resctrl/mpam_devices.c static void mpam_quirk_post_config_change(struct mpam_msc_ris *ris, u16 partid, · line 1488

Quoted 10 lines
drivers/resctrl/mpam_devices.c +10 -0
+	min_hw_granule = ~max_hw_value;
+
+	return min_hw_granule + 1;
+}
+
+static u16 mpam_wa_t241_calc_min_from_max(struct mpam_config *cfg)
+{
+	u16 val = 0;
+
+	if (mpam_has_feature(mpam_feat_mbw_max, cfg)) {

But the problem is mpam_feat_mbw_max feature is NOT set in cfg.

drivers/resctrl/mpam_devices.c static void mpam_quirk_post_config_change(struct mpam_msc_ris *ris, u16 partid, · line 1495

Quoted 7 lines
drivers/resctrl/mpam_devices.c +7 -0
+		u16 delta = ((5 * MPAMCFG_MBW_MAX_MAX) / 100) - 1;
+
+		if (cfg->mbw_max > delta)
+			val = cfg->mbw_max - delta;
+	}
+
+	return val;

So 0 is always returned.

The workaround will set mbw_min as 1% which is too small and will cause performance degradation, e.g. about 20% degradation on some benchmarks.

This patch itself doesn't have any issue.

The issue is the mbw_max feature bit in cfg is not set. This is a legacy issue, not introduced by this patch set.

Here is a fix patch for the issue:
https://lore.kernel.org/lkml/[email protected]/T/#u

If the fix patch is good, could you please add it into the next version of this series?

Thanks.

-Fenghua

author maintainer
#61 lore raw

Re: [PATCH v5 38/41] arm_mpam: Add workaround for T241-MPAM-4

Hi Fenghua,

Quoted 133 lines · Fenghua Yu

Hi, Ben,

Quoted 27 lines · Ben Horgan

From: Shanker Donthineni <[email protected]>

In the T241 implementation of memory-bandwidth partitioning, in the absence
of contention for bandwidth, the minimum bandwidth setting can affect the amount of achieved bandwidth. Specifically, the achieved bandwidth in the absence of contention can settle to any value between the values of MPAMCFG_MBW_MIN and MPAMCFG_MBW_MAX.  Also, if MPAMCFG_MBW_MIN is set zero (below 0.78125%), once a core enters a throttled state, it will never
leave that state.

The first issue is not a concern if the MPAM software allows to program MPAMCFG_MBW_MIN through the sysfs interface. This patch ensures program MBW_MIN=1 (0.78125%) whenever MPAMCFG_MBW_MIN=0 is programmed.

In the scenario where the resctrl doesn't support the MBW_MIN interface via
sysfs, to achieve bandwidth closer to MBW_MAX in the absence of contention,
software should configure a relatively narrow gap between MBW_MIN and MBW_MAX. The recommendation is to use a 5% gap to mitigate the problem.

Clear the feature MBW_MIN feature from the class to ensure we don't accidentally change behaviour when resctrl adds support for a MBW_MIN interface.

Quoted 6 lines

This patch itself is good.

Please check the following comments.

Quoted 67 lines

---
[ morse: Added as second quirk, adapted to use the new intermediate values
in mpam_extend_config() ]

Changes since rfc:
MPAM_IIDR_NVIDIA_T421 -> MPAM_IIDR_NVIDIA_T241
Handling when reset_mbw_min is set

Changes since v3:
Move the 5% gap policy back here
Clear mbw_min feature in class
---
  Documentation/arch/arm64/silicon-errata.rst |  2 + drivers/resctrl/mpam_devices.c              | 50 +++++++++++++++++++-- drivers/resctrl/mpam_internal.h             |  1 +

  3 files changed, 50 insertions(+), 3 deletions(-)
(quoted diff) renamed from Documentation/arch/arm64/silicon-errata.rst +0 -0

Documentation/arch/arm64/silicon-errata.rst
index a65620f98e3a..a4b246655e37 100644

Documentation/arch/arm64/silicon-errata.rst +0 -0
@@ -249,6 +249,8 @@ stable kernels.
  +----------------+-----------------+-----------------
+-----------------------------+
  | NVIDIA         | T241 MPAM       | T241-MPAM-1     | N/
A                         |
  +----------------+-----------------+-----------------
+-----------------------------+
+| NVIDIA         | T241 MPAM       | T241-MPAM-4     | N/
A                         |
++----------------+-----------------+-----------------
+-----------------------------+
  +----------------+-----------------+-----------------
+-----------------------------+
  | Freescale/NXP  | LS2080A/LS1043A | A-008585        |
FSL_ERRATUM_A008585         |
  +----------------+-----------------+-----------------
+-----------------------------+
drivers/resctrl/ renamed from drivers/resctrl/mpam_devices.c +0 -0

mpam_devices.c
index 08cb080592d9..8f44e9dee207 100644

drivers/resctrl/mpam_devices.c +6 -0
@@ -679,6 +679,12 @@ static const struct mpam_quirk mpam_quirks[] = {
       .iidr_mask  = MPAM_IIDR_MATCH_ONE,
       .workaround = T241_SCRUB_SHADOW_REGS,
       },
+    {
+    /* NVIDIA t241 erratum T241-MPAM-4 */
+    .iidr       = MPAM_IIDR_NVIDIA_T241,
+    .iidr_mask  = MPAM_IIDR_MATCH_ONE,
+    .workaround = T241_FORCE_MBW_MIN_TO_ONE,
+    },

      { NULL } /* Sentinel */
  };
  @@ -1464,6 +1470,31 @@ static void mpam_quirk_post_config_change(struct mpam_msc_ris *ris, u16 partid, mpam_apply_t241_erratum(ris, partid);
  }
  +static u16 mpam_wa_t241_force_mbw_min_to_one(struct mpam_props *props)

drivers/resctrl/mpam_devices.c +5 -0
+{
+    u16 max_hw_value, min_hw_granule, res0_bits;
+
+    res0_bits = 16 - props->bwa_wd;
+    max_hw_value = ((1 << props->bwa_wd) - 1) << res0_bits;

drivers/resctrl/mpam_devices.c

Quoted 10 lines
drivers/resctrl/mpam_devices.c +10 -0
+    min_hw_granule = ~max_hw_value;
+
+    return min_hw_granule + 1;
+}
+
+static u16 mpam_wa_t241_calc_min_from_max(struct mpam_config *cfg)
+{
+    u16 val = 0;
+
+    if (mpam_has_feature(mpam_feat_mbw_max, cfg)) {

But the problem is mpam_feat_mbw_max feature is NOT set in cfg.

drivers/resctrl/mpam_devices.c

Quoted 7 lines

+        u16 delta = ((5 * MPAMCFG_MBW_MAX_MAX) / 100) - 1;

drivers/resctrl/mpam_devices.c +6 -0
+
+        if (cfg->mbw_max > delta)
+            val = cfg->mbw_max - delta;
+    }
+
+    return val;

So 0 is always returned.

Quoted 6 lines

The workaround will set mbw_min as 1% which is too small and will cause performance degradation, e.g. about 20% degradation on some benchmarks.

This patch itself doesn't have any issue.

The issue is the mbw_max feature bit in cfg is not set.

This is intended behaviour as the reset is done independently from the value set in the config. The value is there so that resctrl can display the expected values.

Quoted 4 lines

This is a legacy issue, not introduced by this patch set.

Quoted 1 line

Here is a fix patch for the issue:

https://lore.kernel.org/lkml/20260301171829.1357886-1-
[email protected]/T/#u

I've commented on that patch. I think it's best to fix it in the context of the erratum.

Does the below solve your performance problems?

drivers/resctrl/mpam_devices.c +12 -9
index 236f78ab9163..60d3d3e2193f 100644
@@ -1515,16 +1515,20 @@ static u16 mpam_wa_t241_force_mbw_min_to_one(struct mpam_props *props)
        return min_hw_granule + 1;
 }
 
-static u16 mpam_wa_t241_calc_min_from_max(struct mpam_config *cfg)
+static u16 mpam_wa_t241_calc_min_from_max(struct mpam_props *props,
+                                         struct mpam_config *cfg)
 {
        u16 val = 0;
+       u16 max;
+       u16 delta = ((5 * MPAMCFG_MBW_MAX_MAX) / 100) - 1;
 
-       if (mpam_has_feature(mpam_feat_mbw_max, cfg)) {
-               u16 delta = ((5 * MPAMCFG_MBW_MAX_MAX) / 100) - 1;
+       if (mpam_has_feature(mpam_feat_mbw_max, cfg))
+               max = cfg->mbw_max;
+       else
+               max = GENMASK(15, 16 - cprops->bwa_wd);
 
-               if (cfg->mbw_max > delta)
-                       val = cfg->mbw_max - delta;
-       }
+       if (max > delta)
+               val = max - delta;
 
        return val;
 }
@@ -1577,9 +1581,8 @@ static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid,
                if (mpam_has_quirk(T241_FORCE_MBW_MIN_TO_ONE, msc)) {
                        u16 min = mpam_wa_t241_force_mbw_min_to_one(rprops);
 
-                       val = mpam_wa_t241_calc_min_from_max(cfg);
-                       if (val < min)
-                               val = min;
+                       val = mpam_wa_t241_calc_min_from_max(rprops, cfg);
+                       val = max(val, min);
                }
 
                mpam_write_partsel_reg(msc, MBW_MIN, val);
Quoted 7 lines

If the fix patch is good, could you please add it into the next version of this series?

Thanks.

-Fenghua

Thanks,

Ben

reviewer
#62 lore raw

Re: [PATCH v5 38/41] arm_mpam: Add workaround for T241-MPAM-4

Hi, Ben,

Quoted 173 lines · Ben Horgan

Hi Fenghua,

Quoted 133 lines · Fenghua Yu

Hi, Ben,

Quoted 27 lines · Ben Horgan

From: Shanker Donthineni <[email protected]>

In the T241 implementation of memory-bandwidth partitioning, in the absence
of contention for bandwidth, the minimum bandwidth setting can affect the amount of achieved bandwidth. Specifically, the achieved bandwidth in the absence of contention can settle to any value between the values of MPAMCFG_MBW_MIN and MPAMCFG_MBW_MAX.  Also, if MPAMCFG_MBW_MIN is set zero (below 0.78125%), once a core enters a throttled state, it will never
leave that state.

The first issue is not a concern if the MPAM software allows to program MPAMCFG_MBW_MIN through the sysfs interface. This patch ensures program MBW_MIN=1 (0.78125%) whenever MPAMCFG_MBW_MIN=0 is programmed.

In the scenario where the resctrl doesn't support the MBW_MIN interface via
sysfs, to achieve bandwidth closer to MBW_MAX in the absence of contention,
software should configure a relatively narrow gap between MBW_MIN and MBW_MAX. The recommendation is to use a 5% gap to mitigate the problem.

Clear the feature MBW_MIN feature from the class to ensure we don't accidentally change behaviour when resctrl adds support for a MBW_MIN interface.

Quoted 6 lines

This patch itself is good.

Please check the following comments.

Quoted 67 lines

---
[ morse: Added as second quirk, adapted to use the new intermediate values
in mpam_extend_config() ]

Changes since rfc:
MPAM_IIDR_NVIDIA_T421 -> MPAM_IIDR_NVIDIA_T241
Handling when reset_mbw_min is set

Changes since v3:
Move the 5% gap policy back here
Clear mbw_min feature in class

---
   Documentation/arch/arm64/silicon-errata.rst |  2 +
   drivers/resctrl/mpam_devices.c              | 50 +++++++++++++++++++--
   drivers/resctrl/mpam_internal.h             |  1 +
   3 files changed, 50 insertions(+), 3 deletions(-)
(quoted diff) renamed from Documentation/arch/arm64/silicon-errata.rst +0 -0

Documentation/arch/arm64/silicon-errata.rst
index a65620f98e3a..a4b246655e37 100644

Documentation/arch/arm64/silicon-errata.rst +1 -0
@@ -249,6 +249,8 @@ stable kernels.
   +----------------+-----------------+-----------------
+-----------------------------+
   | NVIDIA         | T241 MPAM       | T241-MPAM-1     | N/

A                         |

   +----------------+-----------------+-----------------
+-----------------------------+
+| NVIDIA         | T241 MPAM       | T241-MPAM-4     | N/
A                         |
++----------------+-----------------+-----------------
+-----------------------------+
   +----------------+-----------------+-----------------
+-----------------------------+
   | Freescale/NXP  | LS2080A/LS1043A | A-008585        |
FSL_ERRATUM_A008585         |
   +----------------+-----------------+-----------------
+-----------------------------+
drivers/resctrl/ renamed from drivers/resctrl/mpam_devices.c +0 -0

mpam_devices.c
index 08cb080592d9..8f44e9dee207 100644

drivers/resctrl/mpam_devices.c +6 -0
@@ -679,6 +679,12 @@ static const struct mpam_quirk mpam_quirks[] = {
       .iidr_mask  = MPAM_IIDR_MATCH_ONE,
       .workaround = T241_SCRUB_SHADOW_REGS,
       },
+    {
+    /* NVIDIA t241 erratum T241-MPAM-4 */
+    .iidr       = MPAM_IIDR_NVIDIA_T241,
+    .iidr_mask  = MPAM_IIDR_MATCH_ONE,
+    .workaround = T241_FORCE_MBW_MIN_TO_ONE,
+    },
       { NULL } /* Sentinel */
   };
   @@ -1464,6 +1470,31 @@ static void

mpam_quirk_post_config_change(struct mpam_msc_ris *ris, u16 partid,
          mpam_apply_t241_erratum(ris, partid);
  }
  +static u16 mpam_wa_t241_force_mbw_min_to_one(struct mpam_props *props)

drivers/resctrl/mpam_devices.c +5 -0
+{
+    u16 max_hw_value, min_hw_granule, res0_bits;
+
+    res0_bits = 16 - props->bwa_wd;
+    max_hw_value = ((1 << props->bwa_wd) - 1) << res0_bits;

drivers/resctrl/mpam_devices.c

Quoted 10 lines
drivers/resctrl/mpam_devices.c +10 -0
+    min_hw_granule = ~max_hw_value;
+
+    return min_hw_granule + 1;
+}
+
+static u16 mpam_wa_t241_calc_min_from_max(struct mpam_config *cfg)
+{
+    u16 val = 0;
+
+    if (mpam_has_feature(mpam_feat_mbw_max, cfg)) {

But the problem is mpam_feat_mbw_max feature is NOT set in cfg.

drivers/resctrl/mpam_devices.c

Quoted 7 lines

+        u16 delta = ((5 * MPAMCFG_MBW_MAX_MAX) / 100) - 1;

drivers/resctrl/mpam_devices.c +6 -0
+
+        if (cfg->mbw_max > delta)
+            val = cfg->mbw_max - delta;
+    }
+
+    return val;

So 0 is always returned.

Quoted 6 lines

The workaround will set mbw_min as 1% which is too small and will cause performance degradation, e.g. about 20% degradation on some benchmarks.

This patch itself doesn't have any issue.

The issue is the mbw_max feature bit in cfg is not set.

This is intended behaviour as the reset is done independently from the value set in the config. The value is there so that resctrl can display the expected values.

Quoted 4 lines

This is a legacy issue, not introduced by this patch set.

Quoted 1 line

Here is a fix patch for the issue:

https://lore.kernel.org/lkml/20260301171829.1357886-1-
[email protected]/T/#u

I've commented on that patch. I think it's best to fix it in the context of the erratum.

Does the below solve your performance problems?

drivers/resctrl/mpam_devices.c +4 -1
index 236f78ab9163..60d3d3e2193f 100644
@@ -1515,16 +1515,20 @@ static u16 mpam_wa_t241_force_mbw_min_to_one(struct mpam_props *props)
         return min_hw_granule + 1;
  }
 
-static u16 mpam_wa_t241_calc_min_from_max(struct mpam_config *cfg)
+static u16 mpam_wa_t241_calc_min_from_max(struct mpam_props *props,
+                                         struct mpam_config *cfg)
  {
         u16 val = 0;
+       u16 max;
+       u16 delta = ((5 * MPAMCFG_MBW_MAX_MAX) / 100) - 1;
 

drivers/resctrl/mpam_devices.c static u16 mpam_wa_t241_force_mbw_min_to_one(struct mpam_props *props) · line 1527

Quoted 10 lines
drivers/resctrl/mpam_devices.c +4 -5
-       if (mpam_has_feature(mpam_feat_mbw_max, cfg)) {
-               u16 delta = ((5 * MPAMCFG_MBW_MAX_MAX) / 100) - 1;
+       if (mpam_has_feature(mpam_feat_mbw_max, cfg))
+               max = cfg->mbw_max;
+       else
+               max = GENMASK(15, 16 - cprops->bwa_wd);
 
-               if (cfg->mbw_max > delta)
-                       val = cfg->mbw_max - delta;
-       }

Could you please add some comments on this piece of code? It's worth to comment on why there are different values on cfg and props.

Quoted 8 lines
drivers/resctrl/mpam_devices.c +2 -0
+       if (max > delta)
+               val = max - delta;
 
         return val;
  }
@@ -1577,9 +1581,8 @@ static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid,
                 if (mpam_has_quirk(T241_FORCE_MBW_MIN_TO_ONE, msc)) {

drivers/resctrl/mpam_devices.c static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid, · line 1588

Quoted 10 lines
drivers/resctrl/mpam_devices.c +2 -3
                         u16 min = mpam_wa_t241_force_mbw_min_to_one(rprops);
 
-                       val = mpam_wa_t241_calc_min_from_max(cfg);
-                       if (val < min)
-                               val = min;
+                       val = mpam_wa_t241_calc_min_from_max(rprops, cfg);
+                       val = max(val, min);
                 }
 
                 mpam_write_partsel_reg(msc, MBW_MIN, val);

Otherwise, this change looks good to me.

Thanks.

-Fenghua

author maintainer
#63 lore raw

Re: [PATCH v5 38/41] arm_mpam: Add workaround for T241-MPAM-4

Hi Fenghua,

Quoted 184 lines · Fenghua Yu

Hi, Ben,

Quoted 181 lines · Ben Horgan

Hi Fenghua,

Quoted 137 lines · Fenghua Yu

Hi, Ben,

Quoted 29 lines · Ben Horgan

From: Shanker Donthineni <[email protected]>

In the T241 implementation of memory-bandwidth partitioning, in the absence
of contention for bandwidth, the minimum bandwidth setting can affect the
amount of achieved bandwidth. Specifically, the achieved bandwidth in the
absence of contention can settle to any value between the values of MPAMCFG_MBW_MIN and MPAMCFG_MBW_MAX.  Also, if MPAMCFG_MBW_MIN is set zero (below 0.78125%), once a core enters a throttled state, it will never
leave that state.

The first issue is not a concern if the MPAM software allows to program MPAMCFG_MBW_MIN through the sysfs interface. This patch ensures program MBW_MIN=1 (0.78125%) whenever MPAMCFG_MBW_MIN=0 is programmed.

In the scenario where the resctrl doesn't support the MBW_MIN interface via
sysfs, to achieve bandwidth closer to MBW_MAX in the absence of contention,
software should configure a relatively narrow gap between MBW_MIN and MBW_MAX. The recommendation is to use a 5% gap to mitigate the problem.

Clear the feature MBW_MIN feature from the class to ensure we don't accidentally change behaviour when resctrl adds support for a MBW_MIN interface.

Quoted 6 lines

This patch itself is good.

Please check the following comments.

Quoted 69 lines

---
[ morse: Added as second quirk, adapted to use the new intermediate values
in mpam_extend_config() ]

Changes since rfc:
MPAM_IIDR_NVIDIA_T421 -> MPAM_IIDR_NVIDIA_T241
Handling when reset_mbw_min is set

Changes since v3:
Move the 5% gap policy back here
Clear mbw_min feature in class
---
   Documentation/arch/arm64/silicon-errata.rst |  2 + drivers/resctrl/mpam_devices.c              | 50 ++++++++++++++++
+++--
   drivers/resctrl/mpam_internal.h             |  1 +

   3 files changed, 50 insertions(+), 3 deletions(-)
(quoted diff) renamed from Documentation/arch/arm64/silicon-errata.rst +0 -0

Documentation/arch/arm64/silicon-errata.rst
index a65620f98e3a..a4b246655e37 100644

Documentation/arch/arm64/silicon-errata.rst +0 -0
@@ -249,6 +249,8 @@ stable kernels.
   +----------------+-----------------+-----------------
+-----------------------------+
   | NVIDIA         | T241 MPAM       | T241-MPAM-1     | N/
A                         |
   +----------------+-----------------+-----------------
+-----------------------------+
+| NVIDIA         | T241 MPAM       | T241-MPAM-4     | N/
A                         |
++----------------+-----------------+-----------------
+-----------------------------+
   +----------------+-----------------+-----------------
+-----------------------------+
   | Freescale/NXP  | LS2080A/LS1043A | A-008585        |
FSL_ERRATUM_A008585         |
   +----------------+-----------------+-----------------
+-----------------------------+
drivers/resctrl/ renamed from drivers/resctrl/mpam_devices.c +0 -0

mpam_devices.c
index 08cb080592d9..8f44e9dee207 100644

drivers/resctrl/mpam_devices.c +6 -0
@@ -679,6 +679,12 @@ static const struct mpam_quirk mpam_quirks[] = {
        .iidr_mask  = MPAM_IIDR_MATCH_ONE,
        .workaround = T241_SCRUB_SHADOW_REGS,
        },
+    {
+    /* NVIDIA t241 erratum T241-MPAM-4 */
+    .iidr       = MPAM_IIDR_NVIDIA_T241,
+    .iidr_mask  = MPAM_IIDR_MATCH_ONE,
+    .workaround = T241_FORCE_MBW_MIN_TO_ONE,
+    },

       { NULL } /* Sentinel */
   };
   @@ -1464,6 +1470,31 @@ static void mpam_quirk_post_config_change(struct mpam_msc_ris *ris, u16 partid, mpam_apply_t241_erratum(ris, partid);
   }
   +static u16 mpam_wa_t241_force_mbw_min_to_one(struct mpam_props *props)

drivers/resctrl/mpam_devices.c +5 -0
+{
+    u16 max_hw_value, min_hw_granule, res0_bits;
+
+    res0_bits = 16 - props->bwa_wd;
+    max_hw_value = ((1 << props->bwa_wd) - 1) << res0_bits;

drivers/resctrl/mpam_devices.c

Quoted 10 lines
drivers/resctrl/mpam_devices.c +10 -0
+    min_hw_granule = ~max_hw_value;
+
+    return min_hw_granule + 1;
+}
+
+static u16 mpam_wa_t241_calc_min_from_max(struct mpam_config *cfg)
+{
+    u16 val = 0;
+
+    if (mpam_has_feature(mpam_feat_mbw_max, cfg)) {

But the problem is mpam_feat_mbw_max feature is NOT set in cfg.

drivers/resctrl/mpam_devices.c

Quoted 7 lines

+        u16 delta = ((5 * MPAMCFG_MBW_MAX_MAX) / 100) - 1;

drivers/resctrl/mpam_devices.c +6 -0
+
+        if (cfg->mbw_max > delta)
+            val = cfg->mbw_max - delta;
+    }
+
+    return val;

So 0 is always returned.

Quoted 6 lines

The workaround will set mbw_min as 1% which is too small and will cause performance degradation, e.g. about 20% degradation on some benchmarks.

This patch itself doesn't have any issue.

The issue is the mbw_max feature bit in cfg is not set.

This is intended behaviour as the reset is done independently from the value set in the config. The value is there so that resctrl can display the expected values.

Quoted 4 lines

This is a legacy issue, not introduced by this patch set.

Quoted 1 line

Here is a fix patch for the issue:

https://lore.kernel.org/lkml/20260301171829.1357886-1-
[email protected]/T/#u

I've commented on that patch. I think it's best to fix it in the context of the erratum.

Does the below solve your performance problems?

drivers/resctrl/ renamed from drivers/resctrl/mpam_devices.c +0 -0

mpam_devices.c
index 236f78ab9163..60d3d3e2193f 100644

drivers/resctrl/mpam_devices.c +6 -1
@@ -1515,16 +1515,20 @@ static u16
 mpam_wa_t241_force_mbw_min_to_one(struct mpam_props *props)
          return min_hw_granule + 1;
   }
   -static u16 mpam_wa_t241_calc_min_from_max(struct mpam_config *cfg)
+static u16 mpam_wa_t241_calc_min_from_max(struct mpam_props *props,
+                                         struct mpam_config *cfg)
   {
          u16 val = 0;
+       u16 max;
+       u16 delta = ((5 * MPAMCFG_MBW_MAX_MAX) / 100) - 1;
   -       if (mpam_has_feature(mpam_feat_mbw_max, cfg)) {
-               u16 delta = ((5 * MPAMCFG_MBW_MAX_MAX) / 100) - 1;
+       if (mpam_has_feature(mpam_feat_mbw_max, cfg))
+               max = cfg->mbw_max;
Quoted 8 lines

drivers/resctrl/mpam_devices.c static u16 mpam_wa_t241_force_mbw_min_to_one(struct mpam_props *props) · line 1527

Quoted 5 lines
drivers/resctrl/mpam_devices.c +2 -2
+       else
+               max = GENMASK(15, 16 - cprops->bwa_wd);
   -               if (cfg->mbw_max > delta)
-                       val = cfg->mbw_max - delta;
-       }

Could you please add some comments on this piece of code? It's worth to comment on why there are different values on cfg and props.

Sure, how about this?

	} else {
		/* Resetting so use the ris specific default. */
		max = GENMASK(15, 16 - props->bwa_wd);
	}
Quoted 12 lines
Quoted 12 lines
drivers/resctrl/mpam_devices.c +2 -0
+       if (max > delta)
+               val = max - delta;
            return val;
   }
@@ -1577,9 +1581,8 @@ static void mpam_reprogram_ris_partid(struct
 mpam_msc_ris *ris, u16 partid,
                  if (mpam_has_quirk(T241_FORCE_MBW_MIN_TO_ONE, msc)) {

                         u16 min = mpam_wa_t241_force_mbw_min_to_one(rprops);
  -                       val = mpam_wa_t241_calc_min_from_max(cfg); -                       if (val < min)
-                               val = min;

Quoted 8 lines
Quoted 6 lines

+                       val = mpam_wa_t241_calc_min_from_max(rprops, cfg);
+                       val = max(val, min);
                 }
                   mpam_write_partsel_reg(msc, MBW_MIN, val);

Otherwise, this change looks good to me.

Did you get a chance to confirm if it behaves as expected on your harware?

Quoted 4 lines

Thanks.

-Fenghua

Thanks,

Ben

author maintainer
#64 lore raw

PATCH v5 39/41 arm_mpam: Add workaround for T241-MPAM-6

In reply to Ben Horgan

From: Shanker Donthineni <[email protected]>

The registers MSMON_MBWU_L and MSMON_MBWU return the number of requests rather than the number of bytes transferred.

Bandwidth resource monitoring is performed at the last level cache, where each request arrive in 64Byte granularity. The current implementation returns the number of transactions received at the last level cache but does not provide the value in bytes. Scaling by 64 gives an accurate byte count to match the MPAM specification for the MSMON_MBWU and MSMON_MBWU_L registers. This patch fixes the issue by reporting the actual number of bytes instead of the number of transactions from __ris_msmon_read().

---
Changes since rfc:
MPAM_IIDR_NVIDIA_T421 -> MPAM_IIDR_NVIDIA_T241
Don't apply workaround to MSMON_MBWU_LWD

---
 Documentation/arch/arm64/silicon-errata.rst |  2 ++
 drivers/resctrl/mpam_devices.c              | 26 +++++++++++++++++++--
 drivers/resctrl/mpam_internal.h             |  1 +
 3 files changed, 27 insertions(+), 2 deletions(-)
Documentation/arch/arm64/silicon-errata.rst +2 -0
index a4b246655e37..1aa3326bb320 100644
@@ -251,6 +251,8 @@ stable kernels.
 +----------------+-----------------+-----------------+-----------------------------+
 | NVIDIA         | T241 MPAM       | T241-MPAM-4     | N/A                         |
 +----------------+-----------------+-----------------+-----------------------------+
+| NVIDIA         | T241 MPAM       | T241-MPAM-6     | N/A                         |
++----------------+-----------------+-----------------+-----------------------------+
 +----------------+-----------------+-----------------+-----------------------------+
 | Freescale/NXP  | LS2080A/LS1043A | A-008585        | FSL_ERRATUM_A008585         |
 +----------------+-----------------+-----------------+-----------------------------+
drivers/resctrl/mpam_devices.c +24 -2
index 8f44e9dee207..48a233875a9a 100644
@@ -685,6 +685,12 @@ static const struct mpam_quirk mpam_quirks[] = {
 	.iidr_mask  = MPAM_IIDR_MATCH_ONE,
 	.workaround = T241_FORCE_MBW_MIN_TO_ONE,
 	},
+	{
+	/* NVIDIA t241 erratum T241-MPAM-6 */
+	.iidr       = MPAM_IIDR_NVIDIA_T241,
+	.iidr_mask  = MPAM_IIDR_MATCH_ONE,
+	.workaround = T241_MBW_COUNTER_SCALE_64,
+	},
 	{ NULL } /* Sentinel */
 };
 
@@ -1146,7 +1152,7 @@ static void write_msmon_ctl_flt_vals(struct mon_read *m, u32 ctl_val,
 	}
 }
 
-static u64 mpam_msmon_overflow_val(enum mpam_device_features type)
+static u64 __mpam_msmon_overflow_val(enum mpam_device_features type)
 {
 	/* TODO: implement scaling counters */
 	switch (type) {
@@ -1161,6 +1167,18 @@ static u64 mpam_msmon_overflow_val(enum mpam_device_features type)
 	}
 }
 
+static u64 mpam_msmon_overflow_val(enum mpam_device_features type,
+				   struct mpam_msc *msc)
+{
+	u64 overflow_val = __mpam_msmon_overflow_val(type);
+
+	if (mpam_has_quirk(T241_MBW_COUNTER_SCALE_64, msc) &&
+	    type != mpam_feat_msmon_mbwu_63counter)
+		overflow_val *= 64;
+
+	return overflow_val;
+}
+
 static void __ris_msmon_read(void *arg)
 {
 	u64 now;
@@ -1251,13 +1269,17 @@ static void __ris_msmon_read(void *arg)
 			now = FIELD_GET(MSMON___VALUE, now);
 		}
 
+		if (mpam_has_quirk(T241_MBW_COUNTER_SCALE_64, msc) &&
+		    m->type != mpam_feat_msmon_mbwu_63counter)
+			now *= 64;
+
 		if (nrdy)
 			break;
 
 		mbwu_state = &ris->mbwu_state[ctx->mon];
 
 		if (overflow)
-			mbwu_state->correction += mpam_msmon_overflow_val(m->type);
+			mbwu_state->correction += mpam_msmon_overflow_val(m->type, msc);
 
 		/*
 		 * Include bandwidth consumed before the last hardware reset and
drivers/resctrl/mpam_internal.h +1 -0
index 9f92fd49a61c..1443a1dd996e 100644
@@ -225,6 +225,7 @@ struct mpam_props {
 enum mpam_device_quirks {
 	T241_SCRUB_SHADOW_REGS,
 	T241_FORCE_MBW_MIN_TO_ONE,
+	T241_MBW_COUNTER_SCALE_64,
 	MPAM_QUIRK_LAST
 };
 
Signature · 1 line
2.43.0
author maintainer
#65 lore raw

PATCH v5 40/41 arm_mpam: Quirk CMN-650's CSU NRDY behaviour

In reply to Ben Horgan

From: James Morse <[email protected]>

CMN-650 is afflicted with an erratum where the CSU NRDY bit never clears. This tells us the monitor never finishes scanning the cache. The erratum document says to wait the maximum time, then ignore the field.

Add a flag to indicate whether this is the final attempt to read the counter, and when this quirk is applied, ignore the NRDY field.

This means accesses to this counter will always retry, even if the counter was previously programmed to the same values.

The counter value is not expected to be stable, it drifts up and down with each allocation and eviction. The CSU register provides the value for a point in time.

---
Changes since v3:
parentheses in macro

---
 Documentation/arch/arm64/silicon-errata.rst |  3 +++
 drivers/resctrl/mpam_devices.c              | 12 ++++++++++++
 drivers/resctrl/mpam_internal.h             |  6 ++++++
 3 files changed, 21 insertions(+)
Documentation/arch/arm64/silicon-errata.rst +3 -0
index 1aa3326bb320..65ed6ea33751 100644
@@ -214,6 +214,9 @@ stable kernels.
 +----------------+-----------------+-----------------+-----------------------------+
 | ARM            | SI L1           | #4311569        | ARM64_ERRATUM_4311569       |
 +----------------+-----------------+-----------------+-----------------------------+
+| ARM            | CMN-650         | #3642720        | N/A                         |
++----------------+-----------------+-----------------+-----------------------------+
++----------------+-----------------+-----------------+-----------------------------+
 | Broadcom       | Brahma-B53      | N/A             | ARM64_ERRATUM_845719        |
 +----------------+-----------------+-----------------+-----------------------------+
 | Broadcom       | Brahma-B53      | N/A             | ARM64_ERRATUM_843419        |
drivers/resctrl/mpam_devices.c +12 -0
index 48a233875a9a..9182c8fcf003 100644
@@ -691,6 +691,12 @@ static const struct mpam_quirk mpam_quirks[] = {
 	.iidr_mask  = MPAM_IIDR_MATCH_ONE,
 	.workaround = T241_MBW_COUNTER_SCALE_64,
 	},
+	{
+	/* ARM CMN-650 CSU erratum 3642720 */
+	.iidr       = MPAM_IIDR_ARM_CMN_650,
+	.iidr_mask  = MPAM_IIDR_MATCH_ONE,
+	.workaround = IGNORE_CSU_NRDY,
+	},
 	{ NULL } /* Sentinel */
 };
 
@@ -1003,6 +1009,7 @@ struct mon_read {
 	enum mpam_device_features	type;
 	u64				*val;
 	int				err;
+	bool				waited_timeout;
 };
 
 static bool mpam_ris_has_mbwu_long_counter(struct mpam_msc_ris *ris)
@@ -1249,6 +1256,10 @@ static void __ris_msmon_read(void *arg)
 		if (mpam_has_feature(mpam_feat_msmon_csu_hw_nrdy, rprops))
 			nrdy = now & MSMON___NRDY;
 		now = FIELD_GET(MSMON___VALUE, now);
+
+		if (mpam_has_quirk(IGNORE_CSU_NRDY, msc) && m->waited_timeout)
+			nrdy = false;
+
 		break;
 	case mpam_feat_msmon_mbwu_31counter:
 	case mpam_feat_msmon_mbwu_44counter:
@@ -1386,6 +1397,7 @@ int mpam_msmon_read(struct mpam_component *comp, struct mon_cfg *ctx,
 			.ctx = ctx,
 			.type = type,
 			.val = val,
+			.waited_timeout = true,
 		};
 		*val = 0;
 
drivers/resctrl/mpam_internal.h +6 -0
index 1443a1dd996e..195ab821cc52 100644
@@ -226,6 +226,7 @@ enum mpam_device_quirks {
 	T241_SCRUB_SHADOW_REGS,
 	T241_FORCE_MBW_MIN_TO_ONE,
 	T241_MBW_COUNTER_SCALE_64,
+	IGNORE_CSU_NRDY,
 	MPAM_QUIRK_LAST
 };
 
@@ -251,6 +252,11 @@ struct mpam_quirk {
 				 FIELD_PREP_CONST(MPAMF_IIDR_REVISION,    0)	 | \
 				 FIELD_PREP_CONST(MPAMF_IIDR_IMPLEMENTER, 0x36b))
 
+#define MPAM_IIDR_ARM_CMN_650	(FIELD_PREP_CONST(MPAMF_IIDR_PRODUCTID,   0)	 | \
+				 FIELD_PREP_CONST(MPAMF_IIDR_VARIANT,     0)	 | \
+				 FIELD_PREP_CONST(MPAMF_IIDR_REVISION,    0)	 | \
+				 FIELD_PREP_CONST(MPAMF_IIDR_IMPLEMENTER, 0x43b))
+
 /* The values for MSMON_CFG_MBWU_FLT.RWBW */
 enum mon_filter_options {
 	COUNT_BOTH	= 0,
Signature · 1 line
2.43.0
author maintainer
#66 lore raw

PATCH v5 41/41 arm64: mpam: Add initial MPAM documentation

In reply to Ben Horgan

MPAM (Memory Partitioning and Monitoring) is now exposed to user-space via resctrl. Add some documentation so the user knows what features to expect.

---
Changes by Ben:
Some tidying, update for current heuristics

Changes from v4:
Fix unusual indentation

---
 Documentation/arch/arm64/index.rst |  1 +
 Documentation/arch/arm64/mpam.rst  | 94 ++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+)
 create mode 100644 Documentation/arch/arm64/mpam.rst
Documentation/arch/arm64/index.rst +1 -0
index af52edc8c0ac..98052b4ef4a1 100644
@@ -23,6 +23,7 @@ ARM64 Architecture
     memory
     memory-tagging-extension
     mops
+    mpam
     perf
     pointer-authentication
     ptdump
Documentation/arch/arm64/mpam.rst new file +94 -0

94 lines not on this page · raw message

Signature · 1 line
2.43.0
Reviewed-by on v5 41/41
#67 lore raw

Re: [PATCH v5 41/41] arm64: mpam: Add initial MPAM documentation

Quoted 7 lines · On Tue, 24 Feb 2026 17:57:20 +0000 Ben Horgan <[email protected]> wrote:

MPAM (Memory Partitioning and Monitoring) is now exposed to user-space via resctrl. Add some documentation so the user knows what features to expect.

LGTM

author maintainer
#68 lore raw
In reply to Ben Horgan
Quoted 7 lines · Ben Horgan

The main change in this version of the mpam missing pieces series is to update the cdp emulation to match the resctrl interface. L2 and L3 resources can now enable cdp separately. Cdp can't be hidden correctly for memory bandwidth allocation, as max per partid can't be emulated with more partids, and so we hide this completely when cdp is enabled. There is a little restructuring and a few smaller changes.

Quoted 5 lines

Changelogs in patches

It would be great to get this series merged this cycle. For that we'll need more testing and reviewing. Thanks!

There is a small build conflict with resctrl abmc precursors, [1]. The last patch of that series applies on top of this series and if the abmc precursors go first that patch should go with this series to fix the build. Alternatively, if it's obvious ahead of time it can be squashed into pathc 33 with the other empty resctrl arch hooks.

[1]
https://lore.kernel.org/lkml/[email protected]/

Thanks,

Ben

maintainer
#69 lore raw
Quoted 14 lines · Ben Horgan
Quoted 7 lines · Ben Horgan

The main change in this version of the mpam missing pieces series is to update the cdp emulation to match the resctrl interface. L2 and L3 resources can now enable cdp separately. Cdp can't be hidden correctly for memory bandwidth allocation, as max per partid can't be emulated with more partids, and so we hide this completely when cdp is enabled. There is a little restructuring and a few smaller changes.

Quoted 5 lines

Changelogs in patches

It would be great to get this series merged this cycle. For that we'll need more testing and reviewing. Thanks!

Quoted 8 lines

There is a small build conflict with resctrl abmc precursors, [1]. The last patch of that series applies on top of this series and if the abmc precursors go first that patch should go with this series to fix the build. Alternatively, if it's obvious ahead of time it can be squashed into pathc 33 with the other empty resctrl arch hooks.

[1]
https://lore.kernel.org/lkml/[email protected]/

Typically we resolve these by having the first three patches in the above series on a stable branch (could be tip as it touches x86) and we can base the 41 patches here on top, together with the last one from the abmc series.

Alternatively, happy to take them all via the arm64 tree as long as Reinette/Tony are ok with this and ack the abmc patches.

Signature · 1 line
Catalin
#70 lore raw
In reply to Ben Horgan

Hi Ben,

Quoted 32 lines · Ben Horgan

The main change in this version of the mpam missing pieces series is to update the cdp emulation to match the resctrl interface. L2 and L3 resources can now enable cdp separately. Cdp can't be hidden correctly for memory bandwidth allocation, as max per partid can't be emulated with more partids, and so we hide this completely when cdp is enabled. There is a little restructuring and a few smaller changes.

Changelogs in patches

It would be great to get this series merged this cycle. For that we'll need more testing and reviewing. Thanks!

Quoted 1 line

From James' cover letter:

This is the missing piece to make MPAM usable resctrl in user-space. This has shed its debugfs code and the read/write 'event configuration' for the monitors to make the series smaller.

This adds the arch code and KVM support first. I anticipate the whole thing going via arm64, but if goes via tip instead, the an immutable branch with those patches should be easy to do.

Generally the resctrl glue code works by picking what MPAM features it can expose from the MPAM drive, then configuring the structs that back the resctrl helpers. If your platform is sufficiently Xeon shaped, you should be able to get L2/L3 CPOR bitmaps exposed via resctrl. CSU counters work if they are on/after the L3. MBWU counters are considerably more hairy, and depend on hueristics around the topology, and a bunch of stuff trying to emulate ABMC.
If it didn't pick what you wanted it to, please share the debug messages produced when enabling dynamic debug and booting with:
| dyndbg="file mpam_resctrl.c +pl"

Quoted 8 lines

I've not found a platform that can test all the behaviours around the monitors, so this is where I'd expect the most bugs.

The MPAM spec that describes all the system and MMIO registers can be found here:
https://developer.arm.com/documentation/ddi0598/db/?lang=en
(Ignored the 'RETIRED' warning - that is just arm moving the documentation around.
This document has the best overview)

I have completed retesting based on glue v5. The latest boot logs are provided below:

# dmesg | grep -i mpam
[    0.000000] ACPI: MPAM 0x000000007FF34018 003024 (v01 HISI   HIP12 00000000 HISI 20151124)
[    0.000000] Kernel command line: BOOT_IMAGE=/vmlinuz-7.0.0-rc1-g4288ec146462 root=UUID=e0c69d2c-35e2-4ed0-9b5b-338fe4e689e8 ro cgroup_disable=files apparmor=0 crashkernel=1024M,high smmu.bypassdev=0x1000:0x17 smmu.bypassdev=0x1000:0x15 arm64.nopauth console=ttyAMA0,115200 net.ifnames=0 modprobe.blacklist=hibmc_drm,ipmi_ssif,ipmi_devintf,ipmi_si selinux=0 arm64.mpam nokaslr "dyndbg=file mpam_resctrl.c +p"
[    0.000000] Unknown kernel command line parameters "apparmor=0 selinux=0 dyndbg=file mpam_resctrl.c +p", will be passed to user space.
[   17.707273] mpam_msc mpam_msc.254: Merging features for vmsc:0xffff08009b3aaba0 |= ris:0xffff0800a1d52c98
[   17.707277] mpam_msc mpam_msc.252: Merging features for vmsc:0xffff08009b3aac20 |= ris:0xffff0800a1d53098
[   17.707279] mpam_msc mpam_msc.250: Merging features for vmsc:0xffff08009b3aaca0 |= ris:0xffff0800a1d53498
[   17.707280] mpam_msc mpam_msc.248: Merging features for vmsc:0xffff08009b3aad20 |= ris:0xffff0800a1d53898
[   17.707281] mpam_msc mpam_msc.246: Merging features for vmsc:0xffff08009b3aada0 |= ris:0xffff0800a1d53c98
[   17.707282] mpam_msc mpam_msc.244: Merging features for vmsc:0xffff08009b3aae20 |= ris:0xffff0800a1d3d098
[   17.707283] mpam_msc mpam_msc.242: Merging features for vmsc:0xffff08009b3aaea0 |= ris:0xffff0800a1d3d498
[   17.707284] mpam_msc mpam_msc.240: Merging features for vmsc:0xffff08009b3aaf20 |= ris:0xffff0800a1d3d898
[   17.707285] mpam_msc mpam_msc.238: Merging features for vmsc:0xffff08009b3aafa0 |= ris:0xffff0800a1d3dc98
[   17.707286] mpam_msc mpam_msc.236: Merging features for vmsc:0xffff08009b3ab020 |= ris:0xffff0800a1d3e098
[   17.707287] mpam_msc mpam_msc.234: Merging features for vmsc:0xffff08009b3ab0a0 |= ris:0xffff0800a1d3e498
[   17.707287] mpam_msc mpam_msc.232: Merging features for vmsc:0xffff08009b3ab120 |= ris:0xffff0800a1d3e898
[   17.707288] mpam_msc mpam_msc.230: Merging features for vmsc:0xffff08009b3ab1a0 |= ris:0xffff0800a1d3ec98
[   17.707289] mpam_msc mpam_msc.228: Merging features for vmsc:0xffff08009b3ab220 |= ris:0xffff0800a1d3f098
[   17.707290] mpam_msc mpam_msc.226: Merging features for vmsc:0xffff08009b3ab2a0 |= ris:0xffff0800a1d3f498
[   17.707291] mpam_msc mpam_msc.224: Merging features for vmsc:0xffff08009b3ab320 |= ris:0xffff0800a1d3f898
[   17.707292] mpam_msc mpam_msc.222: Merging features for vmsc:0xffff08009b3ab3a0 |= ris:0xffff0800a1d3fc98
[   17.707293] mpam_msc mpam_msc.220: Merging features for vmsc:0xffff08009b3ab420 |= ris:0xffff0800a1d50098
[   17.707294] mpam_msc mpam_msc.218: Merging features for vmsc:0xffff08009b3ab4a0 |= ris:0xffff0800a1d50498
[   17.707294] mpam_msc mpam_msc.216: Merging features for vmsc:0xffff08009b3ab520 |= ris:0xffff0800a1d39898
[   17.707295] mpam_msc mpam_msc.214: Merging features for vmsc:0xffff08009b3ab5a0 |= ris:0xffff0800a1d39c98
[   17.707296] mpam_msc mpam_msc.212: Merging features for vmsc:0xffff08009b3ab620 |= ris:0xffff0800a1d3a098
[   17.707297] mpam_msc mpam_msc.210: Merging features for vmsc:0xffff08009b3ab6a0 |= ris:0xffff0800a1d3a498
[   17.707298] mpam_msc mpam_msc.208: Merging features for vmsc:0xffff08009b3ab720 |= ris:0xffff0800a1d3a898
[   17.707299] mpam_msc mpam_msc.206: Merging features for vmsc:0xffff08009b3ab7a0 |= ris:0xffff0800a1d3ac98
[   17.707300] mpam_msc mpam_msc.204: Merging features for vmsc:0xffff08009b3ab820 |= ris:0xffff0800a1d3b098
[   17.707301] mpam_msc mpam_msc.202: Merging features for vmsc:0xffff08009b3ab8a0 |= ris:0xffff0800a1d3b498
[   17.707302] mpam_msc mpam_msc.200: Merging features for vmsc:0xffff08009b3ab920 |= ris:0xffff0800a1d3b898
[   17.707303] mpam_msc mpam_msc.198: Merging features for vmsc:0xffff08009b3ab9a0 |= ris:0xffff0800a1d3bc98
[   17.707304] mpam_msc mpam_msc.196: Merging features for vmsc:0xffff08009b3aba20 |= ris:0xffff0800a1d3c098
[   17.707305] mpam_msc mpam_msc.194: Merging features for vmsc:0xffff08009b3abaa0 |= ris:0xffff0800a1d3c498
[   17.707305] mpam_msc mpam_msc.192: Merging features for vmsc:0xffff08009b3abb20 |= ris:0xffff0800a1d3c898
[   17.707306] mpam_msc mpam_msc.190: Merging features for vmsc:0xffff08009b3abba0 |= ris:0xffff0800a1d3cc98
[   17.707307] mpam_msc mpam_msc.188: Merging features for vmsc:0xffff08009b3abc20 |= ris:0xffff0800a1d2e098
[   17.707308] mpam_msc mpam_msc.186: Merging features for vmsc:0xffff08009b3abca0 |= ris:0xffff0800a1d2e498
[   17.707309] mpam_msc mpam_msc.184: Merging features for vmsc:0xffff08009b3abd20 |= ris:0xffff0800a1d2e898
[   17.707310] mpam_msc mpam_msc.182: Merging features for vmsc:0xffff08009b3abda0 |= ris:0xffff0800a1d2ec98
[   17.707311] mpam_msc mpam_msc.180: Merging features for vmsc:0xffff08009b3abe20 |= ris:0xffff0800a1d2f098
[   17.707312] mpam_msc mpam_msc.178: Merging features for vmsc:0xffff08009b3abea0 |= ris:0xffff0800a1d2f498
[   17.707313] mpam_msc mpam_msc.176: Merging features for vmsc:0xffff08009b3abf20 |= ris:0xffff0800a1d2f898
[   17.707314] mpam_msc mpam_msc.174: Merging features for vmsc:0xffff08009b3abfa0 |= ris:0xffff0800a1d2fc98
[   17.707315] mpam_msc mpam_msc.172: Merging features for vmsc:0xffff08009b318420 |= ris:0xffff0800a1d38098
[   17.707316] mpam_msc mpam_msc.170: Merging features for vmsc:0xffff08009b3184a0 |= ris:0xffff0800a1d38498
[   17.707317] mpam_msc mpam_msc.168: Merging features for vmsc:0xffff08009b318520 |= ris:0xffff0800a1d38898
[   17.707318] mpam_msc mpam_msc.166: Merging features for vmsc:0xffff08009b3185a0 |= ris:0xffff0800a1d38c98
[   17.707318] mpam_msc mpam_msc.164: Merging features for vmsc:0xffff08009b318620 |= ris:0xffff0800a1d39098
[   17.707319] mpam_msc mpam_msc.162: Merging features for vmsc:0xffff08009b3186a0 |= ris:0xffff0800a1d39498
[   17.707320] mpam_msc mpam_msc.160: Merging features for vmsc:0xffff08009b318720 |= ris:0xffff0800a1d2a898
[   17.707321] mpam_msc mpam_msc.158: Merging features for vmsc:0xffff08009b3187a0 |= ris:0xffff0800a1d2ac98
[   17.707322] mpam_msc mpam_msc.156: Merging features for vmsc:0xffff08009b318820 |= ris:0xffff0800a1d2b098
[   17.707323] mpam_msc mpam_msc.154: Merging features for vmsc:0xffff08009b3188a0 |= ris:0xffff0800a1d2b498
[   17.707324] mpam_msc mpam_msc.152: Merging features for vmsc:0xffff08009b318920 |= ris:0xffff0800a1d2b898
[   17.707325] mpam_msc mpam_msc.150: Merging features for vmsc:0xffff08009b3189a0 |= ris:0xffff0800a1d2bc98
[   17.707326] mpam_msc mpam_msc.148: Merging features for vmsc:0xffff08009b318a20 |= ris:0xffff0800a1d2c098
[   17.707327] mpam_msc mpam_msc.146: Merging features for vmsc:0xffff08009b318aa0 |= ris:0xffff0800a1d2c498
[   17.707327] mpam_msc mpam_msc.144: Merging features for vmsc:0xffff08009b318b20 |= ris:0xffff0800a1d2c898
[   17.707328] mpam_msc mpam_msc.142: Merging features for vmsc:0xffff08009b318ba0 |= ris:0xffff0800a1d2cc98
[   17.707329] mpam_msc mpam_msc.140: Merging features for vmsc:0xffff08009b318c20 |= ris:0xffff0800a1d2d098
[   17.707330] mpam_msc mpam_msc.138: Merging features for vmsc:0xffff08009b318ca0 |= ris:0xffff0800a1d2d498
[   17.707331] mpam_msc mpam_msc.136: Merging features for vmsc:0xffff08009b318d20 |= ris:0xffff0800a1d2d898
[   17.707332] mpam_msc mpam_msc.134: Merging features for vmsc:0xffff08009b318da0 |= ris:0xffff0800a1d2dc98
[   17.707332] mpam_msc mpam_msc.132: Merging features for vmsc:0xffff08009b318e20 |= ris:0xffff0800a1cd7098
[   17.707333] mpam_msc mpam_msc.130: Merging features for vmsc:0xffff08009b318ea0 |= ris:0xffff0800a1cd7498
[   17.707334] mpam_msc mpam_msc.128: Merging features for vmsc:0xffff08009b318f20 |= ris:0xffff0800a1cd7898
[   17.707335] mpam_msc mpam_msc.126: Merging features for vmsc:0xffff08009b318fa0 |= ris:0xffff0800a1cd7c98
[   17.707336] mpam_msc mpam_msc.124: Merging features for vmsc:0xffff08009b319020 |= ris:0xffff0800a1d28098
[   17.707337] mpam_msc mpam_msc.122: Merging features for vmsc:0xffff08009b3190a0 |= ris:0xffff0800a1d28498
[   17.707338] mpam_msc mpam_msc.120: Merging features for vmsc:0xffff08009b319120 |= ris:0xffff0800a1d28898
[   17.707339] mpam_msc mpam_msc.118: Merging features for vmsc:0xffff08009b319220 |= ris:0xffff0800a1d28c98
[   17.707340] mpam_msc mpam_msc.116: Merging features for vmsc:0xffff08009b3192a0 |= ris:0xffff0800a1d29098
[   17.707340] mpam_msc mpam_msc.114: Merging features for vmsc:0xffff08009b319320 |= ris:0xffff0800a1d29498
[   17.707341] mpam_msc mpam_msc.112: Merging features for vmsc:0xffff08009b3193a0 |= ris:0xffff0800a1d29898
[   17.707342] mpam_msc mpam_msc.110: Merging features for vmsc:0xffff08009b319420 |= ris:0xffff0800a1d29c98
[   17.707343] mpam_msc mpam_msc.108: Merging features for vmsc:0xffff08009b3194a0 |= ris:0xffff0800a1d2a098
[   17.707344] mpam_msc mpam_msc.106: Merging features for vmsc:0xffff08009b319520 |= ris:0xffff0800a1d2a498
[   17.707345] mpam_msc mpam_msc.104: Merging features for vmsc:0xffff08009b3195a0 |= ris:0xffff0800a1cd3898
[   17.707346] mpam_msc mpam_msc.102: Merging features for vmsc:0xffff08009b319620 |= ris:0xffff0800a1cd3c98
[   17.707346] mpam_msc mpam_msc.100: Merging features for vmsc:0xffff08009b3196a0 |= ris:0xffff0800a1cd4098
[   17.707347] mpam_msc mpam_msc.98: Merging features for vmsc:0xffff08009b319720 |= ris:0xffff0800a1cd4498
[   17.707348] mpam_msc mpam_msc.96: Merging features for vmsc:0xffff08009b3197a0 |= ris:0xffff0800a1cd4898
[   17.707349] mpam_msc mpam_msc.94: Merging features for vmsc:0xffff08009b319820 |= ris:0xffff0800a1cd4c98
[   17.707350] mpam_msc mpam_msc.92: Merging features for vmsc:0xffff08009b3198a0 |= ris:0xffff0800a1cd5098
[   17.707351] mpam_msc mpam_msc.90: Merging features for vmsc:0xffff08009b319920 |= ris:0xffff0800a1cd5498
[   17.707352] mpam_msc mpam_msc.88: Merging features for vmsc:0xffff08009b3199a0 |= ris:0xffff0800a1cd5898
[   17.707353] mpam_msc mpam_msc.86: Merging features for vmsc:0xffff08009b319a20 |= ris:0xffff0800a1cd5c98
[   17.707354] mpam_msc mpam_msc.84: Merging features for vmsc:0xffff08009b319aa0 |= ris:0xffff0800a1cd6098
[   17.707354] mpam_msc mpam_msc.82: Merging features for vmsc:0xffff08009b319b20 |= ris:0xffff0800a1cd6498
[   17.707355] mpam_msc mpam_msc.80: Merging features for vmsc:0xffff08009b319ba0 |= ris:0xffff0800a1cd6898
[   17.707356] mpam_msc mpam_msc.78: Merging features for vmsc:0xffff08009b319c20 |= ris:0xffff0800a1cd6c98
[   17.707357] mpam_msc mpam_msc.76: Merging features for vmsc:0xffff08009b319ca0 |= ris:0xffff0800a1cd0098
[   17.707358] mpam_msc mpam_msc.74: Merging features for vmsc:0xffff08009b319d20 |= ris:0xffff0800a1cd0498
[   17.707359] mpam_msc mpam_msc.72: Merging features for vmsc:0xffff08009b319da0 |= ris:0xffff0800a1cd0898
[   17.707359] mpam_msc mpam_msc.70: Merging features for vmsc:0xffff08009b319e20 |= ris:0xffff0800a1cd0c98
[   17.707361] mpam_msc mpam_msc.68: Merging features for vmsc:0xffff08009b319ea0 |= ris:0xffff0800a1cd1098
[   17.707361] mpam_msc mpam_msc.66: Merging features for vmsc:0xffff08009b319f20 |= ris:0xffff0800a1cd1498
[   17.707362] mpam_msc mpam_msc.64: Merging features for vmsc:0xffff08009b319fa0 |= ris:0xffff0800a1cd1898
[   17.707363] mpam_msc mpam_msc.254: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3aaba0
[   17.707364] mpam_msc mpam_msc.252: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3aac20
[   17.707365] mpam_msc mpam_msc.250: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3aaca0
[   17.707366] mpam_msc mpam_msc.248: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3aad20
[   17.707367] mpam_msc mpam_msc.246: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3aada0
[   17.707367] mpam_msc mpam_msc.244: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3aae20
[   17.707368] mpam_msc mpam_msc.242: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3aaea0
[   17.707369] mpam_msc mpam_msc.240: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3aaf20
[   17.707370] mpam_msc mpam_msc.238: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3aafa0
[   17.707370] mpam_msc mpam_msc.236: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab020
[   17.707371] mpam_msc mpam_msc.234: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab0a0
[   17.707372] mpam_msc mpam_msc.232: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab120
[   17.707373] mpam_msc mpam_msc.230: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab1a0
[   17.707373] mpam_msc mpam_msc.228: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab220
[   17.707374] mpam_msc mpam_msc.226: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab2a0
[   17.707375] mpam_msc mpam_msc.224: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab320
[   17.707376] mpam_msc mpam_msc.222: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab3a0
[   17.707376] mpam_msc mpam_msc.220: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab420
[   17.707377] mpam_msc mpam_msc.218: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab4a0
[   17.707378] mpam_msc mpam_msc.216: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab520
[   17.707379] mpam_msc mpam_msc.214: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab5a0
[   17.707379] mpam_msc mpam_msc.212: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab620
[   17.707380] mpam_msc mpam_msc.210: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab6a0
[   17.707381] mpam_msc mpam_msc.208: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab720
[   17.707382] mpam_msc mpam_msc.206: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab7a0
[   17.707384] mpam_msc mpam_msc.204: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab820
[   17.707385] mpam_msc mpam_msc.202: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab8a0
[   17.707385] mpam_msc mpam_msc.200: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab920
[   17.707386] mpam_msc mpam_msc.198: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3ab9a0
[   17.707387] mpam_msc mpam_msc.196: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3aba20
[   17.707388] mpam_msc mpam_msc.194: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3abaa0
[   17.707388] mpam_msc mpam_msc.192: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3abb20
[   17.707389] mpam_msc mpam_msc.190: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3abba0
[   17.707390] mpam_msc mpam_msc.188: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3abc20
[   17.707391] mpam_msc mpam_msc.186: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3abca0
[   17.707391] mpam_msc mpam_msc.184: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3abd20
[   17.707392] mpam_msc mpam_msc.182: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3abda0
[   17.707393] mpam_msc mpam_msc.180: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3abe20
[   17.707394] mpam_msc mpam_msc.178: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3abea0
[   17.707394] mpam_msc mpam_msc.176: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3abf20
[   17.707395] mpam_msc mpam_msc.174: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3abfa0
[   17.707396] mpam_msc mpam_msc.172: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318420
[   17.707397] mpam_msc mpam_msc.170: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3184a0
[   17.707398] mpam_msc mpam_msc.168: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318520
[   17.707398] mpam_msc mpam_msc.166: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3185a0
[   17.707399] mpam_msc mpam_msc.164: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318620
[   17.707400] mpam_msc mpam_msc.162: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3186a0
[   17.707401] mpam_msc mpam_msc.160: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318720
[   17.707401] mpam_msc mpam_msc.158: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3187a0
[   17.707402] mpam_msc mpam_msc.156: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318820
[   17.707403] mpam_msc mpam_msc.154: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3188a0
[   17.707404] mpam_msc mpam_msc.152: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318920
[   17.707404] mpam_msc mpam_msc.150: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3189a0
[   17.707405] mpam_msc mpam_msc.148: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318a20
[   17.707406] mpam_msc mpam_msc.146: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318aa0
[   17.707407] mpam_msc mpam_msc.144: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318b20
[   17.707407] mpam_msc mpam_msc.142: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318ba0
[   17.707408] mpam_msc mpam_msc.140: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318c20
[   17.707409] mpam_msc mpam_msc.138: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318ca0
[   17.707410] mpam_msc mpam_msc.136: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318d20
[   17.707410] mpam_msc mpam_msc.134: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318da0
[   17.707411] mpam_msc mpam_msc.132: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318e20
[   17.707412] mpam_msc mpam_msc.130: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318ea0
[   17.707412] mpam_msc mpam_msc.128: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318f20
[   17.707413] mpam_msc mpam_msc.126: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b318fa0
[   17.707414] mpam_msc mpam_msc.124: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319020
[   17.707415] mpam_msc mpam_msc.122: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3190a0
[   17.707416] mpam_msc mpam_msc.120: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319120
[   17.707416] mpam_msc mpam_msc.118: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319220
[   17.707417] mpam_msc mpam_msc.116: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3192a0
[   17.707418] mpam_msc mpam_msc.114: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319320
[   17.707418] mpam_msc mpam_msc.112: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3193a0
[   17.707419] mpam_msc mpam_msc.110: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319420
[   17.707420] mpam_msc mpam_msc.108: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3194a0
[   17.707421] mpam_msc mpam_msc.106: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319520
[   17.707422] mpam_msc mpam_msc.104: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3195a0
[   17.707422] mpam_msc mpam_msc.102: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319620
[   17.707423] mpam_msc mpam_msc.100: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3196a0
[   17.707424] mpam_msc mpam_msc.98: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319720
[   17.707424] mpam_msc mpam_msc.96: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3197a0
[   17.707425] mpam_msc mpam_msc.94: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319820
[   17.707426] mpam_msc mpam_msc.92: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3198a0
[   17.707427] mpam_msc mpam_msc.90: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319920
[   17.707427] mpam_msc mpam_msc.88: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b3199a0
[   17.707428] mpam_msc mpam_msc.86: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319a20
[   17.707429] mpam_msc mpam_msc.84: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319aa0
[   17.707430] mpam_msc mpam_msc.82: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319b20
[   17.707430] mpam_msc mpam_msc.80: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319ba0
[   17.707431] mpam_msc mpam_msc.78: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319c20
[   17.707432] mpam_msc mpam_msc.76: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319ca0
[   17.707433] mpam_msc mpam_msc.74: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319d20
[   17.707433] mpam_msc mpam_msc.72: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319da0
[   17.707434] mpam_msc mpam_msc.70: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319e20
[   17.707435] mpam_msc mpam_msc.68: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319ea0
[   17.707436] mpam_msc mpam_msc.66: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319f20
[   17.707436] mpam_msc mpam_msc.64: Merging features for class:0xffff08009b233e50 &= vmsc:0xffff08009b319fa0
[   17.707437] mpam_msc mpam_msc.62: Merging features for vmsc:0xffff08009b3aa020 |= ris:0xffff0800a1cd1c98
[   17.707438] mpam_msc mpam_msc.60: Merging features for vmsc:0xffff08009b3aa0a0 |= ris:0xffff0800a1cd2098
[   17.707439] mpam_msc mpam_msc.58: Merging features for vmsc:0xffff08009b3aa120 |= ris:0xffff0800a1cd2498
[   17.707440] mpam_msc mpam_msc.56: Merging features for vmsc:0xffff08009b3aa1a0 |= ris:0xffff0800a1cd2898
[   17.707441] mpam_msc mpam_msc.54: Merging features for vmsc:0xffff08009aeb6620 |= ris:0xffff0800a1cd2c98
[   17.707442] mpam_msc mpam_msc.52: Merging features for vmsc:0xffff08009aeb66a0 |= ris:0xffff0800a1cd3098
[   17.707443] mpam_msc mpam_msc.50: Merging features for vmsc:0xffff08009aeb6720 |= ris:0xffff0800a1cd3498
[   17.707444] mpam_msc mpam_msc.48: Merging features for vmsc:0xffff08009aeb67a0 |= ris:0xffff0800a1bb4898
[   17.707444] mpam_msc mpam_msc.46: Merging features for vmsc:0xffff08009aeb6820 |= ris:0xffff0800a1bb4c98
[   17.707445] mpam_msc mpam_msc.44: Merging features for vmsc:0xffff08009aeb68a0 |= ris:0xffff0800a1bb5098
[   17.707446] mpam_msc mpam_msc.42: Merging features for vmsc:0xffff08009aeb6920 |= ris:0xffff0800a1bb5498
[   17.707447] mpam_msc mpam_msc.40: Merging features for vmsc:0xffff08009aeb69a0 |= ris:0xffff0800a1bb5898
[   17.707448] mpam_msc mpam_msc.38: Merging features for vmsc:0xffff08009aeb6a20 |= ris:0xffff0800a1bb5c98
[   17.707449] mpam_msc mpam_msc.36: Merging features for vmsc:0xffff08009aeb6aa0 |= ris:0xffff0800a1bb6098
[   17.707449] mpam_msc mpam_msc.34: Merging features for vmsc:0xffff08009aeb6b20 |= ris:0xffff0800a1bb6498
[   17.707450] mpam_msc mpam_msc.32: Merging features for vmsc:0xffff08009aeb6ba0 |= ris:0xffff0800a1bb6898
[   17.707451] mpam_msc mpam_msc.30: Merging features for vmsc:0xffff08009aeb6c20 |= ris:0xffff0800a1bb6c98
[   17.707452] mpam_msc mpam_msc.28: Merging features for vmsc:0xffff08009aeb6ca0 |= ris:0xffff0800a1bb7098
[   17.707453] mpam_msc mpam_msc.26: Merging features for vmsc:0xffff08009aeb6d20 |= ris:0xffff0800a1bb7498
[   17.707454] mpam_msc mpam_msc.24: Merging features for vmsc:0xffff08009aeb6da0 |= ris:0xffff0800a1bb7898
[   17.707454] mpam_msc mpam_msc.22: Merging features for vmsc:0xffff08009aeb6e20 |= ris:0xffff0800a1bb7c98
[   17.707455] mpam_msc mpam_msc.20: Merging features for vmsc:0xffff08009aeb6ea0 |= ris:0xffff0800a1bb1098
[   17.707456] mpam_msc mpam_msc.18: Merging features for vmsc:0xffff08009aeb6f20 |= ris:0xffff0800a1bb1498
[   17.707457] mpam_msc mpam_msc.16: Merging features for vmsc:0xffff08009aeb6fa0 |= ris:0xffff0800a1bb1898
[   17.707457] mpam_msc mpam_msc.62: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009b3aa020
[   17.707458] mpam_msc mpam_msc.60: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009b3aa0a0
[   17.707459] mpam_msc mpam_msc.58: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009b3aa120
[   17.707460] mpam_msc mpam_msc.56: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009b3aa1a0
[   17.707461] mpam_msc mpam_msc.54: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb6620
[   17.707461] mpam_msc mpam_msc.52: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb66a0
[   17.707462] mpam_msc mpam_msc.50: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb6720
[   17.707463] mpam_msc mpam_msc.48: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb67a0
[   17.707463] mpam_msc mpam_msc.46: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb6820
[   17.707464] mpam_msc mpam_msc.44: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb68a0
[   17.707465] mpam_msc mpam_msc.42: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb6920
[   17.707466] mpam_msc mpam_msc.40: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb69a0
[   17.707466] mpam_msc mpam_msc.38: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb6a20
[   17.707467] mpam_msc mpam_msc.36: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb6aa0
[   17.707468] mpam_msc mpam_msc.34: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb6b20
[   17.707469] mpam_msc mpam_msc.32: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb6ba0
[   17.707469] mpam_msc mpam_msc.30: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb6c20
[   17.707470] mpam_msc mpam_msc.28: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb6ca0
[   17.707471] mpam_msc mpam_msc.26: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb6d20
[   17.707472] mpam_msc mpam_msc.24: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb6da0
[   17.707472] mpam_msc mpam_msc.22: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb6e20
[   17.707473] mpam_msc mpam_msc.20: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb6ea0
[   17.707474] mpam_msc mpam_msc.18: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb6f20
[   17.707475] mpam_msc mpam_msc.16: Merging features for class:0xffff08009b230050 &= vmsc:0xffff08009aeb6fa0
[   17.707475] mpam_msc mpam_msc.14: Merging features for vmsc:0xffff08009aeb7020 |= ris:0xffff0800a1bb1c98
[   17.707476] mpam_msc mpam_msc.12: Merging features for vmsc:0xffff08009aeb70a0 |= ris:0xffff0800a1bb2098
[   17.707477] mpam_msc mpam_msc.10: Merging features for vmsc:0xffff08009aeb7120 |= ris:0xffff0800a1bb2498
[   17.707478] mpam_msc mpam_msc.8: Merging features for vmsc:0xffff08009aeb71a0 |= ris:0xffff0800a1bb2898
[   17.707479] mpam_msc mpam_msc.6: Merging features for vmsc:0xffff08009aeb7220 |= ris:0xffff0800a1bb2c98
[   17.707480] mpam_msc mpam_msc.4: Merging features for vmsc:0xffff08009aeb72a0 |= ris:0xffff0800a1bb3098
[   17.707480] mpam_msc mpam_msc.2: Merging features for vmsc:0xffff08009aeb7320 |= ris:0xffff0800a1bb3498
[   17.707481] mpam_msc mpam_msc.0: Merging features for vmsc:0xffff08009aeb73a0 |= ris:0xffff0800a1bb3898
[   17.707482] mpam_msc mpam_msc.14: Merging features for class:0xffff08009b231150 &= vmsc:0xffff08009aeb7020
[   17.707483] mpam_msc mpam_msc.12: Merging features for class:0xffff08009b231150 &= vmsc:0xffff08009aeb70a0
[   17.707483] mpam_msc mpam_msc.10: Merging features for class:0xffff08009b231150 &= vmsc:0xffff08009aeb7120
[   17.707484] mpam_msc mpam_msc.8: Merging features for class:0xffff08009b231150 &= vmsc:0xffff08009aeb71a0
[   17.707485] mpam_msc mpam_msc.6: Merging features for class:0xffff08009b231150 &= vmsc:0xffff08009aeb7220
[   17.707485] mpam_msc mpam_msc.4: Merging features for class:0xffff08009b231150 &= vmsc:0xffff08009aeb72a0
[   17.707486] mpam_msc mpam_msc.2: Merging features for class:0xffff08009b231150 &= vmsc:0xffff08009aeb7320
[   17.707487] mpam_msc mpam_msc.0: Merging features for class:0xffff08009b231150 &= vmsc:0xffff08009aeb73a0
[   22.876035] mpam:mpam_resctrl_pick_caches: class 255 is not a cache
[   22.876039] mpam:mpam_resctrl_pick_mba: class 2 is a cache but not the L3
[   22.876040] mpam:mpam_resctrl_pick_mba: class 3 has no bandwidth control
[   22.878500] mpam:topology_matches_l3: class 255 component 0 has Mismatched CPU mask with L3 equivalent
[   22.878503] mpam:mpam_resctrl_pick_mba: class 255 topology doesn't match L3
[   22.878505] mpam:mpam_resctrl_pick_counters: class 2 is a cache but not the L3
[   22.878505] mpam:mpam_resctrl_pick_counters: class 3 has usable CSU
[   22.878506] mpam:counter_update_class: Updating event 1 to use class 3
[   22.878508] mpam:class_has_usable_mbwu: monitors usable in free-running mode
[   22.880995] mpam:topology_matches_l3: class 255 component 0 has Mismatched CPU mask with L3 equivalent
[   22.900111] WARNING: drivers/resctrl/mpam_resctrl.c:1495 at mpam_resctrl_domain_insert+0x74/0x80, CPU#2: cpuhp/2/25
[   29.755844] pc : mpam_resctrl_domain_insert+0x74/0x80
[   29.760886] lr : mpam_resctrl_domain_insert+0x34/0x80
[   29.842897]  mpam_resctrl_domain_insert+0x74/0x80 (P)
[   29.847938]  mpam_resctrl_online_cpu+0x2b4/0x428
[   29.852544]  mpam_cpu_online+0x274/0x298
[   29.941348] MPAM enabled with 32 PARTIDs and 4 PMGs
[   29.977840]     dyndbg=file mpam_resctrl.c +p

With the exception of the issue previously raised in patch 26, all other aspects meet expectations. Please apply my reviewed-by tag to this patch series once the patch 26 issue is addressed as mentioned.

+ Reviewed-by: Zeng Heng <[email protected]>

Thanks,
Zeng Heng

Tested-by on the v5 series
#71 lore raw
In reply to Ben Horgan

Hi Ben,

Quoted 41 lines · Ben Horgan

The main change in this version of the mpam missing pieces series is to update the cdp emulation to match the resctrl interface. L2 and L3 resources can now enable cdp separately. Cdp can't be hidden correctly for memory bandwidth allocation, as max per partid can't be emulated with more partids, and so we hide this completely when cdp is enabled. There is a little restructuring and a few smaller changes.

Changelogs in patches

It would be great to get this series merged this cycle. For that we'll need more testing and reviewing. Thanks!

From James' cover letter:

This is the missing piece to make MPAM usable resctrl in user-space. This has shed its debugfs code and the read/write 'event configuration' for the monitors to make the series smaller.

This adds the arch code and KVM support first. I anticipate the whole thing going via arm64, but if goes via tip instead, the an immutable branch with those patches should be easy to do.

Generally the resctrl glue code works by picking what MPAM features it can expose from the MPAM drive, then configuring the structs that back the resctrl helpers. If your platform is sufficiently Xeon shaped, you should be able to get L2/L3 CPOR bitmaps exposed via resctrl. CSU counters work if they are on/after the L3. MBWU counters are considerably more hairy, and depend on hueristics around the topology, and a bunch of stuff trying to emulate ABMC.
If it didn't pick what you wanted it to, please share the debug messages produced when enabling dynamic debug and booting with:
| dyndbg="file mpam_resctrl.c +pl"

I've not found a platform that can test all the behaviours around the monitors, so this is where I'd expect the most bugs.

The MPAM spec that describes all the system and MMIO registers can be found here:
https://developer.arm.com/documentation/ddi0598/db/?lang=en
(Ignored the 'RETIRED' warning - that is just arm moving the documentation around.
This document has the best overview)

Quoted 4 lines

Based on v7.0-rc1

The series can be retrieved from:
https://gitlab.arm.com/linux-arm/linux-bh.git mpam_resctrl_glue_v5

I booted with the series applied on an MPAM capable platform. The driver is able to probe the L2 attached MSCs.

In terms of features, bit-mapped based cache portion partitioning works as expected. The platform also supports additional controls (cache capacity and priority partitioning) and monitors (memory bandwidth and cache storage). The ones supported in MPAM driver probe OK but don't seem to be exposed. E.g.,

mpam:mpam_resctrl_pick_counters: class 2 is a cache but not the L3

It looks like some of it is due to an impedance mismatch with resctrl expectations but hopefully we can get to it with the basics in-place.

Feel free to add

Thanks,
Punit

author maintainer
#72 lore raw

Hi Punit,

Quoted 59 lines · Punit Agrawal

Hi Ben,

Quoted 41 lines · Ben Horgan

The main change in this version of the mpam missing pieces series is to update the cdp emulation to match the resctrl interface. L2 and L3 resources can now enable cdp separately. Cdp can't be hidden correctly for memory bandwidth allocation, as max per partid can't be emulated with more partids, and so we hide this completely when cdp is enabled. There is a little restructuring and a few smaller changes.

Changelogs in patches

It would be great to get this series merged this cycle. For that we'll need more testing and reviewing. Thanks!

From James' cover letter:

This is the missing piece to make MPAM usable resctrl in user-space. This has shed its debugfs code and the read/write 'event configuration' for the monitors to make the series smaller.

This adds the arch code and KVM support first. I anticipate the whole thing going via arm64, but if goes via tip instead, the an immutable branch with those patches should be easy to do.

Generally the resctrl glue code works by picking what MPAM features it can expose from the MPAM drive, then configuring the structs that back the resctrl helpers. If your platform is sufficiently Xeon shaped, you should be able to get L2/L3 CPOR bitmaps exposed via resctrl. CSU counters work if they are on/after the L3. MBWU counters are considerably more hairy, and depend on hueristics around the topology, and a bunch of stuff trying to emulate ABMC.
If it didn't pick what you wanted it to, please share the debug messages produced when enabling dynamic debug and booting with:
| dyndbg="file mpam_resctrl.c +pl"

I've not found a platform that can test all the behaviours around the monitors, so this is where I'd expect the most bugs.

The MPAM spec that describes all the system and MMIO registers can be found here:
https://developer.arm.com/documentation/ddi0598/db/?lang=en
(Ignored the 'RETIRED' warning - that is just arm moving the documentation around.
This document has the best overview)

Quoted 4 lines

Based on v7.0-rc1

The series can be retrieved from:
https://gitlab.arm.com/linux-arm/linux-bh.git mpam_resctrl_glue_v5

I booted with the series applied on an MPAM capable platform. The driver is able to probe the L2 attached MSCs.

In terms of features, bit-mapped based cache portion partitioning works as expected. The platform also supports additional controls (cache capacity and priority partitioning) and monitors (memory bandwidth and cache storage). The ones supported in MPAM driver probe OK but don't seem to be exposed. E.g.,

Quoted 4 lines

mpam:mpam_resctrl_pick_counters: class 2 is a cache but not the L3

It looks like some of it is due to an impedance mismatch with resctrl

Yes, what you describe is expected behaviour. There is no support yet for cache capacity (CMAX) or bandwidth priority partitioning and monitors are only exposed on the L3.

Quoted 1 line

expectations but hopefully we can get to it with the basics in-place.

I hope so. The CMAX and the bandwidth priority partitioning should be easy to add once there is a generic way of adding new schema. There is a plan/discussion here [1] and I don't expect adding monitoring on L2 to be hard.

[1] https://lore.kernel.org/lkml/aPtfMFfLV1l%[email protected]/

Quoted 4 lines

Feel free to add

Thanks for testing!

Quoted 4 lines

Thanks,
Punit

Thanks,

Ben