[PATCH 12 22/25 UPDATED] platform/x86/intel/pmt: Inform resctrl when MMIO maps are being removed

From: Tony Luck

Date: Fri Sep 18 2026 - 12:45:17 EST


Before destroying devices, tell resctrl that the virtual addresses
supplied by an earlier call to intel_pmt_get_regions_by_feature()
are about to be invalidated and should not be used again.

Signed-off-by: Tony Luck <tony.luck@xxxxxxxxx>
---
v12.1:
Add new aet_mmio_lock.
---
arch/x86/kernel/cpu/resctrl/intel_aet.c | 9 ++++---
drivers/platform/x86/intel/pmt/telemetry.c | 29 ++++++++++++++++++++++
2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/resctrl/intel_aet.c
index 1fd25fd9cd96..dafd69b8249a 100644
--- a/arch/x86/kernel/cpu/resctrl/intel_aet.c
+++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c
@@ -298,10 +298,13 @@ static enum pmt_feature_id lookup_pfid(const char *pfname)
/*
* Protects pmt_module, get_feature, put_feature against races between module
* load/unload of the pmt_telemetry module and mount/unmount of the resctrl
- * file system. Also protects pmt_in_use telemetry_region::addr.
+ * file system. Also protects pmt_in_use.
*/
static DEFINE_MUTEX(aet_register_lock);

+/* Protects telemetry_region::addr. */
+static DEFINE_MUTEX(aet_mmio_lock);
+
static struct module *pmt_module;
static struct pmt_feature_group *(*get_feature)(enum pmt_feature_id id);
static void (*put_feature)(struct pmt_feature_group *p);
@@ -374,7 +377,7 @@ void intel_aet_invalidate(u8 package_id)
{
struct event_group **peg;

- guard(mutex)(&aet_register_lock);
+ guard(mutex)(&aet_mmio_lock);

for_each_event_group(peg) {
struct event_group *e = *peg;
@@ -452,7 +455,7 @@ int intel_aet_read_event(int domid, u32 rmid, void *arch_priv, u64 *val)
void *pevt0;
u32 idx;

- guard(mutex)(&aet_register_lock);
+ guard(mutex)(&aet_mmio_lock);

pevt0 = pevt - pevt->idx;
e = container_of(pevt0, struct event_group, evts);
diff --git a/drivers/platform/x86/intel/pmt/telemetry.c b/drivers/platform/x86/intel/pmt/telemetry.c
index bf0c9295feb3..f11b25ece4f9 100644
--- a/drivers/platform/x86/intel/pmt/telemetry.c
+++ b/drivers/platform/x86/intel/pmt/telemetry.c
@@ -366,12 +366,41 @@ pmt_telem_find_and_register_endpoint(struct device *dev, u32 guid, u16 pos)
}
EXPORT_SYMBOL_NS_GPL(pmt_telem_find_and_register_endpoint, "INTEL_PMT_TELEMETRY");

+static int pmt_telem_get_package_id(struct pmt_telem_priv *priv)
+{
+ int i;
+
+ for (i = 0; i < priv->num_entries; i++) {
+ struct intel_pmt_entry *entry = &priv->entry[i];
+ struct pci_dev *pdev = to_pci_dev(entry->ep->dev);
+ struct oobmsm_plat_info *plat_info;
+
+ plat_info = intel_vsec_get_mapping(pdev);
+ if (!IS_ERR(plat_info))
+ return plat_info->package_id;
+ }
+
+ return -ENODEV;
+}
+
static void pmt_telem_remove(struct auxiliary_device *auxdev)
{
struct pmt_telem_priv *priv = auxiliary_get_drvdata(auxdev);
+ int package_id;
int i;

mutex_lock(&ep_lock);
+ package_id = pmt_telem_get_package_id(priv);
+ /*
+ * Tell resctrl/AET that virtual mappings for MMIO space in a CPU
+ * package are about to be torn down.
+ */
+ if (package_id < 0) {
+ dev_dbg(&auxdev->dev, "Unable to determine package ID for removed device\n");
+ } else {
+ intel_aet_invalidate(package_id);
+ }
+
for (i = 0; i < priv->num_entries; i++) {
struct intel_pmt_entry *entry = &priv->entry[i];

--
2.55.0