[PATCH v2 7/7] platform/x86/amd/hsmp: Drop stale metric table mapping on rebind
From: Muralidhara M K
Date: Thu Jun 25 2026 - 08:37:15 EST
Now that the ACPI socket array persists across a non-final unbind, a
stale metric_tbl_addr from a previous bind can still be recorded in the
socket when hsmp_get_tbl_dram_base() runs on a later (re)probe.
Re-ioremap()ing over it leaks one metric-table mapping per unbind/rebind
cycle.
iounmap() any existing mapping before remapping. This runs during
(re)probe before the metric sysfs attribute is exposed, so no reader can
be using the old mapping.
Signed-off-by: Muralidhara M K <muralidhara.mk@xxxxxxx>
---
drivers/platform/x86/amd/hsmp/hsmp.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
index 2e836124f486..a75190ea41c4 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp/hsmp.c
@@ -498,6 +498,17 @@ int hsmp_get_tbl_dram_base(u16 sock_ind)
dev_err(sock->dev, "Invalid DRAM address for metric table\n");
return -ENOMEM;
}
+ /*
+ * The ACPI socket array now persists across a non-final unbind, so a
+ * stale mapping from a previous bind can still be recorded here. Drop
+ * it before remapping to avoid leaking one metric-table mapping per
+ * unbind/rebind cycle. This runs during (re)probe before the metric
+ * sysfs attribute is exposed, so no reader can be using it.
+ */
+ if (sock->metric_tbl_addr) {
+ iounmap(sock->metric_tbl_addr);
+ sock->metric_tbl_addr = NULL;
+ }
sock->metric_tbl_addr = ioremap(dram_addr, sizeof(struct hsmp_metric_table));
if (!sock->metric_tbl_addr) {
dev_err(sock->dev, "Failed to ioremap metric table addr\n");
--
2.43.0