Re: [PATCH v3 04/12] x86,fs/resctrl: Program PLZA through kmode arch hooks

From: Moger, Babu

Date: Wed Jun 17 2026 - 19:15:37 EST


Hi Reinette,

On 6/16/2026 6:33 PM, Reinette Chatre wrote:
Hi Babu,

On 4/30/26 4:24 PM, Babu Moger wrote:
AMD Privilege Level Zero Association (PLZA) exposes kernel CLOSID/RMID
association through MSR_IA32_PQR_PLZA_ASSOC. Generic resctrl already
tracks supported and effective kernel-mode policy in struct
resctrl_kmode_cfg, but the architecture layer needs a callable entry point
that can push those values into per-CPU hardware on a chosen CPU mask.

Declare resctrl_arch_configure_kmode() in linux/resctrl.h with kernel-doc.
Implement it on x86: add an SMP callback that writes
MSR_IA32_PQR_PLZA_ASSOC on each targeted CPU, and use on_each_cpu_mask()
for the broadcast.

Above is clear from the patch. Please start with focus on why this patch is
needed.


The hook is unused in this patch; later patches in the series wire it into

Similar to previous work: write changelog in imperative tone and do not
refer to patches in series but instead let each patch stand on its own.

Will rewrite the changelog.


generic resctrl when an effective kernel-mode policy is selected or a CPU
mask changes.

Signed-off-by: Babu Moger <babu.moger@xxxxxxx>
---


---
arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 35 +++++++++++++++++++++++
include/linux/resctrl.h | 10 +++++++
2 files changed, 45 insertions(+)

diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
index b20e705606b8..68f1cf503904 100644
--- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
+++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
@@ -131,3 +131,38 @@ int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable)
return 0;
}
+
+/*
+ * SMP call-function callback: each CPU writes its own MSR_IA32_PQR_PLZA_ASSOC
+ * (AMD PLZA). Invoked via on_each_cpu_mask() with wait=1 so the on-stack
+ * union pointed at by @arg is safe.
+ */
+static void resctrl_kmode_set_one_amd(void *arg)
+{
+ union msr_pqr_plza_assoc *plza = arg;
+
+ wrmsrl(MSR_IA32_PQR_PLZA_ASSOC, plza->full);

fyi ...
commit 2232959db26d ("x86/msr: Switch wrmsrl() users to wrmsrq()")
commit b5884070f9da ("x86/msr: Remove wrmsrl()")


Yes. Saw that. Will change it to wrmsrq.

+}
+
+/**
+ * resctrl_arch_configure_kmode() - x86/AMD: program PLZA MSR on a CPU subset
+ * @cpu_mask: CPUs to receive the update (see on_each_cpu_mask() for online subset).

Why is the caveat added? Will resctrl ever provide offline CPUs in the mask?

No. Offline CPUs will not be provided. I am not sure why I added that caveat. Probably came from AI review. Will remove.


+ * @closid: CLOSID field written into the MSR with CLOSID_EN set.
+ * @rmid: RMID field written into the MSR with RMID_EN set.
+ * @enable: Value for the PLZA_EN split field.

Please describe the meaning of the fields instead the mechanics of the code
that are obvious.

ok.


+ *
+ * Context: Do not call with IRQs off or from IRQ context except as allowed for
+ * on_each_cpu_mask(); see kernel/smp.c.

Why is this context caveat needed?

Again, Probably came from AI review. Does not look relevant. Will remove.


+ */
+void resctrl_arch_configure_kmode(cpumask_var_t cpu_mask, u32 closid, u32 rmid, bool enable)

Please replace "cpumask_var_t cpu_mask" with "const struct cpumask *cpu_mask".

Sure.


+{
+ union msr_pqr_plza_assoc plza = { 0 };
+
+ plza.split.rmid = rmid;
+ plza.split.rmid_en = 1;
+ plza.split.closid = closid;
+ plza.split.closid_en = 1;
+ plza.split.plza_en = enable;
+
+ on_each_cpu_mask(cpu_mask, resctrl_kmode_set_one_amd, &plza, 1);
+}

function self has been discussed already

diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index ce28418df00f..570918e57e24 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -712,6 +712,16 @@ bool resctrl_arch_get_io_alloc_enabled(struct rdt_resource *r);
*/
void resctrl_arch_get_kmode_support(struct resctrl_kmode_cfg *kcfg);
+/**
+ * resctrl_arch_configure_kmode() - Program MSR_IA32_PQR_PLZA_ASSOC on CPUs in @cpu_mask
+ * @cpu_mask: Target CPUs; on_each_cpu_mask() applies the callback on the online subset.
+ * @closid: CLOSID written to the MSR with CLOSID_EN set.
+ * @rmid: RMID written to the MSR with RMID_EN set.
+ * @enable: PLZA_EN field value for this update.

This is a resctrl fs API - please replace all the AMD architecture specific implementation details
with what the parameters actually mean/represent.

Sure. Will rewrite it.

Thanks

Babu