[PATCH v3 4/7] platform/x86/amd/hsmp: Source metric-table size from firmware
From: Muralidhara M K
Date: Sun May 17 2026 - 11:14:15 EST
The driver currently hard-codes the metric-table region size to
sizeof(struct hsmp_metric_table) when it ioremaps the DRAM region
returned by HSMP_GET_METRIC_TABLE_DRAM_ADDR and when it validates
buffer sizes in hsmp_metric_tbl_read(). That layout is fixed for
HSMP protocol version 6, but Family 1Ah Model 50h-5Fh uses the larger
struct hsmp_metric_table_zen6 (~13 KB), and future processors are
expected to grow the table further.
Pick up the table size from firmware instead:
- Bump the hsmp_msg_desc_table[] entry for
HSMP_GET_METRIC_TABLE_DRAM_ADDR from response_sz = 2 to 3 so
msg.args[2] is read back. SMU on Family 1Ah Model 50h and
later populates args[2] with the DRAM region size in bytes;
older firmware leaves it as 0.
- Add size_t hsmp_table_size to struct hsmp_plat_device, holding
the metric-table size discovered at probe time.
- In hsmp_get_tbl_dram_base(), set hsmp_pdev.hsmp_table_size to
msg.args[2] when firmware reports a non-zero value, and fall
back to sizeof(struct hsmp_metric_table) otherwise. Use the
same value for the devm_ioremap() of the DRAM region so the
full firmware-reported window is mapped.
- In hsmp_metric_tbl_read(), validate the caller-supplied buffer
size against hsmp_pdev.hsmp_table_size instead of the
hard-coded sizeof(struct hsmp_metric_table).
Behaviour is unchanged on existing protocol-version-6 hardware:
firmware returns 0 in args[2], the driver falls back to
sizeof(struct hsmp_metric_table), and both the ioremap and the
size check produce the same result as before.
The ioctl interface added later in this series uses
hsmp_pdev.hsmp_table_size to size its kernel buffer, validate the
userspace request, and copy out the full firmware-reported region
for protocol-version-7 (and future) layouts that exceed the
standard sysfs PAGE_SIZE read cap.
Co-developed-by: Muthusamy Ramalingam <muthusamy.ramalingam@xxxxxxx>
Signed-off-by: Muthusamy Ramalingam <muthusamy.ramalingam@xxxxxxx>
Signed-off-by: Muralidhara M K <muralidhara.mk@xxxxxxx>
---
Changes:
v1->v2: New
v2->v3: None
arch/x86/include/uapi/asm/amd_hsmp.h | 5 +++--
drivers/platform/x86/amd/hsmp/hsmp.c | 11 ++++++++---
drivers/platform/x86/amd/hsmp/hsmp.h | 1 +
3 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/arch/x86/include/uapi/asm/amd_hsmp.h b/arch/x86/include/uapi/asm/amd_hsmp.h
index da3e3bbfa33e..b86bbc929395 100644
--- a/arch/x86/include/uapi/asm/amd_hsmp.h
+++ b/arch/x86/include/uapi/asm/amd_hsmp.h
@@ -342,11 +342,12 @@ static const struct hsmp_msg_desc hsmp_msg_desc_table[]
{0, 0, HSMP_GET},
/*
- * HSMP_GET_METRIC_TABLE_DRAM_ADDR, num_args = 0, response_sz = 2
+ * HSMP_GET_METRIC_TABLE_DRAM_ADDR, num_args = 0, response_sz = 3
* output: args[0] = lower 32 bits of the address
* output: args[1] = upper 32 bits of the address
+ * output: args[2] = DRAM region size in bytes
*/
- {0, 2, HSMP_GET},
+ {0, 3, HSMP_GET},
/*
* HSMP_SET_XGMI_PSTATE_RANGE, num_args = 1, response_sz = 0/1
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
index 9bad58fef304..cf9392f99298 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp/hsmp.c
@@ -356,8 +356,7 @@ ssize_t hsmp_metric_tbl_read(struct hsmp_socket *sock, char *buf, size_t size)
return -ENOMEM;
}
- /* Do not support lseek(), also don't allow more than the size of metric table */
- if (size != sizeof(struct hsmp_metric_table)) {
+ if (size != hsmp_pdev.hsmp_table_size) {
dev_err(sock->dev, "Wrong buffer size\n");
return -EINVAL;
}
@@ -398,8 +397,14 @@ int hsmp_get_tbl_dram_base(u16 sock_ind)
dev_err(sock->dev, "Invalid DRAM address for metric table\n");
return -ENOMEM;
}
+ /* SMU returns table size from Family 1Ah Model 50h and forward */
+ if (msg.args[2])
+ hsmp_pdev.hsmp_table_size = msg.args[2];
+ else
+ hsmp_pdev.hsmp_table_size = sizeof(struct hsmp_metric_table);
+
sock->metric_tbl_addr = devm_ioremap(sock->dev, dram_addr,
- sizeof(struct hsmp_metric_table));
+ hsmp_pdev.hsmp_table_size);
if (!sock->metric_tbl_addr) {
dev_err(sock->dev, "Failed to ioremap metric table addr\n");
return -ENOMEM;
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.h b/drivers/platform/x86/amd/hsmp/hsmp.h
index b153527e0a0d..e7f051475728 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.h
+++ b/drivers/platform/x86/amd/hsmp/hsmp.h
@@ -55,6 +55,7 @@ struct hsmp_plat_device {
u32 proto_ver;
u16 num_sockets;
bool is_probed;
+ size_t hsmp_table_size;
};
int hsmp_cache_proto_ver(u16 sock_ind);
--
2.34.1