From: Qinyun Tan <qinyuntan@linux.alibaba.com>
To: babu.moger@amd.com
Cc: tony.luck@intel.com, reinette.chatre@intel.com,
james.morse@arm.com, Dave.Martin@arm.com, tglx@kernel.org,
bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org,
linux-kernel@vger.kernel.org, feng.tang@linux.alibaba.com,
xlpang@linux.alibaba.com,
Qinyun Tan <qinyuntan@linux.alibaba.com>
Subject: [PATCH 4/4] fs/resctrl: program PLZA on a CPU that comes online under a binding
Date: Thu, 11 Jun 2026 19:17:06 +0800 [thread overview]
Message-ID: <20260611111706.1981788-5-qinyuntan@linux.alibaba.com> (raw)
In-Reply-To: <cover.1777591496.git.babu.moger@amd.com>
The kernel-mode (PLZA) MSR (MSR_IA32_PQR_PLZA_ASSOC) is per-CPU and is
only written when a binding is configured via info/kernel_mode or when a
group's kmode_cpus mask is changed. Both paths only touch the CPUs that
are online at that moment, and the CPU hotplug online callback does not
reprogram it.
As a result, a CPU that comes online *after* a binding is in place -- a
hot-added vCPU, or a CPU that was offline at bind time -- runs with PLZA
disabled even though an empty kmode_cpu_mask ("all online CPUs") or an
explicit mask says it is in scope. Its CPL0 traffic then uses the
default PQR_ASSOC CLOSID/RMID instead of the bound kernel-mode group, so
the kernel-mode protection is silently off on that CPU while
info/kernel_mode still reports the binding as active.
Make resctrl_online_cpu() the single authoritative sync point: on every
CPU online, idempotently drive the CPU to the state it should have under
the current binding -- enable PLZA with the bound CLOSID/RMID when the
CPU is in scope, otherwise explicitly clear it so stale enable bits left
on a CPU that was offline while it was removed from the scope are cleared
too (offline CPUs are skipped by the IPI-based reprogram paths and the
MSR is not reset by a soft offline). Bail out early on platforms without
kernel-mode support so the MSR is never touched there.
offline needs no counterpart: a CPU's PLZA state is fully determined by
this online-time sync.
Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com>
Reviewed-by: Xunlei Pang <xlpang@linux.alibaba.com>
---
fs/resctrl/rdtgroup.c | 53 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index cef6ab75c2b57..35cc0083d1b2f 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -5336,11 +5336,64 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *hdr
return err;
}
+/*
+ * resctrl_kmode_online_cpu() - Sync a freshly onlined CPU to its PLZA state
+ * @cpu: The CPU that just came online.
+ *
+ * The kernel-mode (PLZA) MSR is per-CPU and is only written when a binding is
+ * configured or its kmode_cpus mask is changed; nothing reprograms it for a
+ * CPU that comes online afterwards. Make the online callback the single
+ * authoritative sync point: idempotently drive @cpu to the state it should
+ * have under the current binding. This both programs a CPU that is onlined
+ * after a binding is in place (e.g. a hot-added vCPU, or a CPU that was
+ * offline at bind time) and clears stale enable bits left on a CPU that was
+ * offline while it was removed from the scope (offline CPUs are skipped by
+ * the IPI-based reprogram paths and the MSR is not reset by a soft offline).
+ *
+ * Scope: an empty kmode_cpu_mask means "all online CPUs" (so @cpu is always
+ * included), a non-empty mask means only the CPUs explicitly listed there.
+ *
+ * Context: Caller must hold rdtgroup_mutex. Runs on @cpu during the CPU
+ * hotplug online callback, so the MSR write lands on the right CPU and no
+ * cross-CPU IPI is needed.
+ */
+static void resctrl_kmode_online_cpu(unsigned int cpu)
+{
+ struct rdtgroup *rdtgrp = resctrl_kcfg.k_rdtgrp;
+ u32 closid = 0, rmid = 0;
+ bool assign_rmid = false;
+ bool enable = false;
+
+ /* Platform without kernel-mode (PLZA) support: never touch the MSR. */
+ if (!(resctrl_kcfg.kmode & ~BIT(INHERIT_CTRL_AND_MON)))
+ return;
+
+ /* Compute this CPU's correct state under the active binding. */
+ if (resctrl_kcfg.kmode_cur != BIT(INHERIT_CTRL_AND_MON) && rdtgrp &&
+ (cpumask_empty(&rdtgrp->kmode_cpu_mask) ||
+ cpumask_test_cpu(cpu, &rdtgrp->kmode_cpu_mask))) {
+ if (rdtgrp->type == RDTMON_GROUP) {
+ closid = rdtgrp->mon.parent->closid;
+ rmid = rdtgrp->mon.rmid;
+ } else {
+ closid = rdtgrp->closid;
+ rmid = rdtgrp->mon.rmid;
+ }
+ assign_rmid = (resctrl_kcfg.kmode_cur == BIT(GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU));
+ enable = true;
+ }
+
+ /* Idempotent sync: enable when in scope, otherwise clear stale bits. */
+ resctrl_arch_configure_kmode(cpumask_of(cpu), closid, rmid, assign_rmid, enable);
+}
+
void resctrl_online_cpu(unsigned int cpu)
{
mutex_lock(&rdtgroup_mutex);
/* The CPU is set in default rdtgroup after online. */
cpumask_set_cpu(cpu, &rdtgroup_default.cpu_mask);
+ /* Restore the kernel-mode (PLZA) binding on a CPU that just came online. */
+ resctrl_kmode_online_cpu(cpu);
mutex_unlock(&rdtgroup_mutex);
}
--
2.43.7
next prev parent reply other threads:[~2026-06-11 11:17 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 23:24 [PATCH v3 00/12] [PATCH v3 00/12] x86/resctrl: Add kernel-mode (e.g., PLZA) support to the resctrl subsystem Babu Moger
2026-04-30 23:24 ` [PATCH v3 01/12] x86/resctrl: Support Privilege-Level Zero Association (PLZA) Babu Moger
2026-06-11 23:23 ` Reinette Chatre
2026-06-12 16:56 ` Moger, Babu
2026-06-12 17:00 ` Moger, Babu
2026-06-17 0:00 ` Reinette Chatre
2026-06-17 16:28 ` Babu Moger
2026-04-30 23:24 ` [PATCH v3 02/12] x86/resctrl: Add data structures and definitions for PLZA configuration Babu Moger
2026-06-11 23:40 ` Reinette Chatre
2026-06-12 15:40 ` Luck, Tony
2026-06-12 17:46 ` Moger, Babu
2026-06-12 17:32 ` Moger, Babu
2026-06-12 17:49 ` Moger, Babu
2026-04-30 23:24 ` [PATCH v3 03/12] fs/resctrl: Add kernel mode (kmode) data structures and arch hook Babu Moger
2026-06-16 23:30 ` Reinette Chatre
2026-06-17 19:36 ` Babu Moger
2026-04-30 23:24 ` [PATCH v3 04/12] x86,fs/resctrl: Program PLZA through kmode arch hooks Babu Moger
2026-05-19 20:59 ` Luck, Tony
2026-05-20 17:49 ` Babu Moger
2026-05-20 22:16 ` Luck, Tony
2026-05-20 23:09 ` Moger, Babu
2026-06-05 10:06 ` Qinyun Tan
2026-06-08 18:17 ` Babu Moger
2026-06-11 11:44 ` Peter Newman
2026-06-11 14:46 ` Babu Moger
2026-06-16 23:33 ` Reinette Chatre
2026-06-17 23:15 ` Moger, Babu
2026-04-30 23:24 ` [PATCH v3 05/12] x86/resctrl: Initialize supported kernel modes for PLZA Babu Moger
2026-06-16 23:35 ` Reinette Chatre
2026-06-18 16:20 ` Babu Moger
2026-04-30 23:24 ` [PATCH v3 06/12] fs/resctrl: Initialize the global kernel-mode policy at subsystem init Babu Moger
2026-06-16 23:36 ` Reinette Chatre
2026-06-18 17:14 ` Babu Moger
2026-06-22 16:21 ` Reinette Chatre
2026-06-22 16:38 ` Babu Moger
2026-04-30 23:24 ` [PATCH v3 07/12] fs/resctrl: Add info/kernel_mode for kernel-mode policy introspection Babu Moger
2026-06-16 23:38 ` Reinette Chatre
2026-06-18 19:16 ` Babu Moger
2026-04-30 23:24 ` [PATCH v3 08/12] fs/resctrl: Make info/kernel_mode writable and identify the bound group Babu Moger
2026-06-16 23:42 ` Reinette Chatre
2026-06-19 1:29 ` Babu Moger
2026-06-22 16:47 ` Reinette Chatre
2026-06-22 19:03 ` Babu Moger
2026-04-30 23:24 ` [PATCH v3 09/12] fs/resctrl: Reset kernel-mode binding when its rdtgroup goes away Babu Moger
2026-06-16 23:42 ` Reinette Chatre
2026-06-19 20:22 ` Babu Moger
2026-04-30 23:24 ` [PATCH v3 10/12] fs/resctrl: Expose kmode_cpus / kmode_cpus_list per rdtgroup Babu Moger
2026-04-30 23:24 ` [PATCH v3 11/12] resctrl: Hide kmode_cpus[_list] on groups not bound to kernel-mode Babu Moger
2026-04-30 23:24 ` [PATCH v3 12/12] fs/resctrl: Allow user space to write kmode_cpus / kmode_cpus_list Babu Moger
2026-06-08 9:23 ` [PATCH v3 00/12] x86/resctrl: Add kernel-mode (e.g., PLZA) support to the resctrl subsystem Qinyun Tan
2026-06-09 14:10 ` Babu Moger
2026-06-10 1:40 ` qinyuntan
2026-06-11 11:17 ` [PATCH 0/4] x86,fs/resctrl: kernel-mode (PLZA) fixes found during review Qinyun Tan
2026-06-11 21:02 ` Babu Moger
2026-06-11 11:17 ` [PATCH 1/4] resctrl: Add kmode arch stubs for ARM MPAM and hide kernel_mode on non-PLZA platforms Qinyun Tan
2026-06-11 11:33 ` [PATCH v2 1/4] resctrl: Add kmode arch stubs for ARM MPAM Qinyun Tan
2026-06-11 11:17 ` [PATCH 2/4] resctrl: Fix PLZA RMID_EN to be mode-based and relax RDTMON_GROUP constraint for assign_mon Qinyun Tan
2026-06-11 11:17 ` [PATCH 3/4] fs/resctrl: make a failed kernel-mode switch a no-op Qinyun Tan
2026-06-11 11:17 ` Qinyun Tan [this message]
2026-06-11 21:53 ` [PATCH v3 00/12] [PATCH v3 00/12] x86/resctrl: Add kernel-mode (e.g., PLZA) support to the resctrl subsystem Reinette Chatre
2026-06-12 15:37 ` Moger, Babu
2026-06-17 4:34 ` Reinette Chatre
2026-06-17 15:56 ` Babu Moger
2026-06-17 17:33 ` Reinette Chatre
2026-06-17 19:55 ` Babu Moger
2026-06-26 15:55 ` Luck, Tony
2026-06-29 13:20 ` Moger, Babu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260611111706.1981788-5-qinyuntan@linux.alibaba.com \
--to=qinyuntan@linux.alibaba.com \
--cc=Dave.Martin@arm.com \
--cc=babu.moger@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=feng.tang@linux.alibaba.com \
--cc=james.morse@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=reinette.chatre@intel.com \
--cc=tglx@kernel.org \
--cc=tony.luck@intel.com \
--cc=x86@kernel.org \
--cc=xlpang@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®