Re: [RESEND PATCH v4 05/15] x86,fs/resctrl: Introduce architecture hooks to program kernel-mode
From: Moger, Babu
Date: Wed Jul 08 2026 - 19:04:46 EST
On 7/7/2026 4:50 PM, Babu Moger wrote:
Kernel-mode policies defined by enum resctrl_kernel_mode must be applied to
each affected CPU whenever a policy is selected or its scope changes.
Generic resctrl therefore requires an architecture-specific interface to
program allocation and monitoring associations in hardware across a given
CPU mask.
Introduce a helper, resctrl_arch_configure_kmode(), to handle kernel-mode
programming. On x86/AMD systems, this helper programs the
MSR_IA32_PQR_PLZA_ASSOC register on all online CPUs in the specified mask
via on_each_cpu_mask(). Also provide a no-op stub for MPAM systems.
Generic resctrl does not invoke this hook yet; it will be used when user
space selects a kernel-mode policy or updates the associated CPU set.
Signed-off-by: Babu Moger <babu.moger@xxxxxxx>
---
v4: Added assign_mon parameter in resctrl_arch_configure_kmode() to program the RMID
as discussed in below.
https://lore.kernel.org/lkml/20260605100642.1103628-1-qinyuntan@xxxxxxxxxxxxxxxxx/
Changed cpumask type to "const struct cpumask *cpu_mask".
Added MPAM stub to avoid any linking issues when resctrl_arch_configure_kmode()
is called from FS layer. Thanks to Qinyun.
Re-wrote the changelog to be generic.
Updated code comments.
v3: Removed task based PLZA implementation so related changes are removed.
Removed handling of rmid_en as it is not required. The group type assigned
will be different so the monitoring part is already taken care.
Updated the change log with details.
Removed resctrl_arch_set_kmode() as arch only provides the modes supported.
It is FS which decided which mode to apply.
v2: Updated the commit message to include the sequence of steps to enable PLZA.
Added mode code comments for clarity.
Added kmode to functin names to be generic.
---
arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 36 +++++++++++++++++++++++
drivers/resctrl/mpam_resctrl.c | 5 ++++
include/linux/resctrl.h | 15 ++++++++++
3 files changed, 56 insertions(+)
diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
index b20e705606b8..025f139434f2 100644
--- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
+++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
@@ -131,3 +131,39 @@ int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable)
return 0;
}
+
+static void resctrl_kmode_set_one_amd(void *arg)
+{
+ union msr_pqr_plza_assoc *plza = arg;
+
+ wrmsrq(MSR_IA32_PQR_PLZA_ASSOC, plza->full);
+}
+
Sashiko reported:
https://sashiko.dev/#/patchset/cover.1783461016.git.babu.moger%40amd.com?part=5
--- Patch [5]: [RESEND PATCH v4 05/15] x86,fs/resctrl: Introduce architecture hooks to program kernel-mode ---
commit 97958c0d99b7e538d1f8d019e6c63712b44a6289
Author: Babu Moger <babu.moger@xxxxxxx>
x86,fs/resctrl: Introduce architecture hooks to program kernel-mode
Kernel-mode policies defined by enum resctrl_kernel_mode must be applied to
each affected CPU whenever a policy is selected or its scope changes. Generic
resctrl therefore requires an architecture-specific interface to program
allocation and monitoring associations in hardware across a given CPU mask.
This patch introduces resctrl_arch_configure_kmode() to handle this.
> diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
> --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
> +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
[ ... ]
> +static void resctrl_kmode_set_one_amd(void *arg)
> +{
> + union msr_pqr_plza_assoc *plza = arg;
> +
> + wrmsrq(MSR_IA32_PQR_PLZA_ASSOC, plza->full);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Will this truncate the upper 32 bits of the MSR on 32-bit x86 builds?
It appears that union msr_pqr_plza_assoc in
arch/x86/kernel/cpu/resctrl/internal.h uses unsigned long for both the
bitfields and the full variable. On 32-bit x86 architectures, unsigned long
is 32 bits, which means reading plza->full will truncate the 64-bit value.
When this is implicitly zero-extended to u64 and passed to wrmsrq(), the
upper 32 bits of the MSR, which contain plza_en, closid_en, and closid,
will be overwritten with zeros.
Will change the union msr_pqr_plza_assoc to use u64 instead on unsigned long. It should take care of this.
Thanks
Babu