* [PATCH 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps
@ 2026-10-08 9:29 Suma Hegde
2026-10-08 9:29 ` [PATCH 01/11] platform/x86/amd/hsmp: Fix sock_ind bounds check in is_bin_visible Suma Hegde
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: Suma Hegde @ 2026-10-08 9:29 UTC (permalink / raw)
To: platform-driver-x86
Cc: ilpo.jarvinen, hdegoede, muthusamy.ramalingam,
NaveenKrishna.Chatradhi, Suma Hegde, Muthusamy Ramalingam
From: Suma Hegde <Suma.Hegde@amd.com>
This series introduces per-socket read/write enabled-message bitmaps so
the HSMP driver rejects unsupported messages before they reach the SMU.
Prep patches fix sock_ind bounds checking, move proto_ver onto
hsmp_socket, and reorder helpers for the validation path. Later patches
populate the bitmaps statically and via HSMP_GET_ENABLED_HSMP_CMDS
(6th Gen AMD EPYC Server and future platforms), and update sysfs/hwmon
file modes from the bitmaps.
Client platforms skip bitmap init, populate, and validation until
dedicated client tables exist; shared smu_fw_version and
protocol_version sysfs attributes remain visible there.
Patch summary:
01/11 platform/x86/amd/hsmp: Fix sock_ind bounds check in is_bin_visible
02/11 platform/x86/amd/hsmp: Move proto_ver to hsmp_socket structure
03/11 platform/x86/amd/hsmp: Null-check drvdata in hsmp_is_sock_attr_visible()
04/11 platform/x86/amd/hsmp: Move is_get_msg() before validate_message()
05/11 platform/x86/amd/hsmp: Use local sock pointer in init_acpi()
06/11 platform/x86/amd/hsmp: Move the sock_ind bound check before validate_message()
07/11 platform/x86/amd/hsmp: Add per-platform bitmap to validate HSMP messages
08/11 platform/x86/amd/hsmp: Populate the bitmaps dynamically on 6th Gen AMD EPYC Server
09/11 platform/x86/amd/hsmp: Populate the bitmaps dynamically for future platforms
10/11 platform/x86/amd/hsmp: Relocate to_hsmp_sys_attr() macro
11/11 platform/x86/amd/hsmp: Update sysfs and hwmon file modes based on platform capabilities
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Suma Hegde (11):
platform/x86/amd/hsmp: Fix sock_ind bounds check in is_bin_visible
platform/x86/amd/hsmp: Move proto_ver to hsmp_socket structure
platform/x86/amd/hsmp: Null-check drvdata in
hsmp_is_sock_attr_visible()
platform/x86/amd/hsmp: Move is_get_msg() before validate_message()
platform/x86/amd/hsmp: Use local sock pointer in init_acpi()
platform/x86/amd/hsmp: Move the sock_ind bound check before
validate_message()
platform/x86/amd/hsmp: Add per-platform bitmap to validate HSMP
messages
platform/x86/amd/hsmp: Populate the bitmaps dynamically on 6th Gen AMD
EPYC Server
platform/x86/amd/hsmp: Populate the bitmaps dynamically for future
platforms
platform/x86/amd/hsmp: Relocate to_hsmp_sys_attr() macro
platform/x86/amd/hsmp: Update sysfs and hwmon file modes based on
platform capabilities
drivers/platform/x86/amd/hsmp/acpi.c | 92 ++++++++++--
drivers/platform/x86/amd/hsmp/hsmp.c | 203 ++++++++++++++++++++++++--
drivers/platform/x86/amd/hsmp/hsmp.h | 29 +++-
drivers/platform/x86/amd/hsmp/hwmon.c | 24 ++-
drivers/platform/x86/amd/hsmp/plat.c | 26 +++-
5 files changed, 339 insertions(+), 35 deletions(-)
This is rebased on below patchset:
https://lore.kernel.org/platform-driver-x86/20260924154947.1706669-1-muralidhara.mk@amd.com/T/#t
[PATCH v7 0/4] platform/x86/amd/hsmp: Family 1Ah client support by Muralidhar M K
--
2.34.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 01/11] platform/x86/amd/hsmp: Fix sock_ind bounds check in is_bin_visible
2026-10-08 9:29 [PATCH 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
@ 2026-10-08 9:29 ` Suma Hegde
2026-10-08 9:29 ` [PATCH 02/11] platform/x86/amd/hsmp: Move proto_ver to hsmp_socket structure Suma Hegde
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-10-08 9:29 UTC (permalink / raw)
To: platform-driver-x86
Cc: ilpo.jarvinen, hdegoede, muthusamy.ramalingam,
NaveenKrishna.Chatradhi, Suma Hegde, Muthusamy Ramalingam
From: Suma Hegde <Suma.Hegde@amd.com>
The bounds check in hsmp_is_sock_attr_visible() only ran when id == 0.
SYSFS_GROUP_INVISIBLE is only valid for the group-visibility call
(id == 0), but sock_ind must still be validated for every attribute
so a later bin attribute cannot use an out-of-range socket index.
Always bounds-check sock_ind first; return SYSFS_GROUP_INVISIBLE for
id == 0 and 0 otherwise.
Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---
drivers/platform/x86/amd/hsmp/plat.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/amd/hsmp/plat.c
index e9b2b809c0f52..af8aee1fb22ba 100644
--- a/drivers/platform/x86/amd/hsmp/plat.c
+++ b/drivers/platform/x86/amd/hsmp/plat.c
@@ -71,8 +71,13 @@ static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
sock_ind = (uintptr_t)battr->private;
- if (id == 0 && sock_ind >= hsmp_pdev->num_sockets)
- return SYSFS_GROUP_INVISIBLE;
+ /*
+ * Always bounds-check sock_ind. SYSFS_GROUP_INVISIBLE is only
+ * meaningful for id == 0 (group visibility); for later attributes
+ * just hide the file.
+ */
+ if (sock_ind >= hsmp_pdev->num_sockets)
+ return id == 0 ? SYSFS_GROUP_INVISIBLE : 0;
if (hsmp_pdev->proto_ver == HSMP_PROTO_VER6)
return battr->attr.mode;
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 02/11] platform/x86/amd/hsmp: Move proto_ver to hsmp_socket structure
2026-10-08 9:29 [PATCH 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
2026-10-08 9:29 ` [PATCH 01/11] platform/x86/amd/hsmp: Fix sock_ind bounds check in is_bin_visible Suma Hegde
@ 2026-10-08 9:29 ` Suma Hegde
2026-10-08 9:29 ` [PATCH 03/11] platform/x86/amd/hsmp: Null-check drvdata in hsmp_is_sock_attr_visible() Suma Hegde
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-10-08 9:29 UTC (permalink / raw)
To: platform-driver-x86
Cc: ilpo.jarvinen, hdegoede, muthusamy.ramalingam,
NaveenKrishna.Chatradhi, Suma Hegde, Dhruv Gupta,
Muthusamy Ramalingam
From: Suma Hegde <Suma.Hegde@amd.com>
Move proto_ver from hsmp_plat_device to hsmp_socket, as the protocol
version is fetched per socket. Update all users to read the per-socket
proto_ver.
Signed-off-by: Dhruv Gupta <dhruv.gupta@amd.com>
Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---
drivers/platform/x86/amd/hsmp/acpi.c | 14 +++++++++-----
drivers/platform/x86/amd/hsmp/hsmp.c | 2 +-
drivers/platform/x86/amd/hsmp/hsmp.h | 2 +-
drivers/platform/x86/amd/hsmp/plat.c | 4 ++--
4 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index d775ea8ba6035..088c44ea1782e 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -286,7 +286,7 @@ static ssize_t hsmp_metric_tbl_acpi_read(struct file *filp, struct kobject *kobj
* Surface the unsupported case here as -EOPNOTSUPP rather than
* silently truncating the snapshot.
*/
- if (hsmp_pdev->proto_ver != HSMP_PROTO_VER6)
+ if (sock->proto_ver != HSMP_PROTO_VER6)
return -EOPNOTSUPP;
return hsmp_metric_tbl_read(sock, buf, count);
@@ -303,7 +303,10 @@ static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
* The client set has its own telemetry table, read only through
* HSMP_IOCTL_GET_TELEMETRY_DATA; never show this file there.
*/
- if (!is_client_platform() && hsmp_pdev->proto_ver >= HSMP_PROTO_VER6)
+ struct device *dev = kobj_to_dev(kobj);
+ struct hsmp_socket *sock = dev_get_drvdata(dev);
+
+ if (!is_client_platform() && sock->proto_ver >= HSMP_PROTO_VER6)
return battr->attr.mode;
return 0;
@@ -572,8 +575,10 @@ static int init_acpi(struct device *dev)
return ret;
}
- if ((is_client_platform() && hsmp_pdev->proto_ver >= RYZEN_MASTER_PROTO_VER1) ||
- (!is_client_platform() && hsmp_pdev->proto_ver >= HSMP_PROTO_VER6)) {
+ if ((is_client_platform() &&
+ hsmp_pdev->sock[sock_ind].proto_ver >= RYZEN_MASTER_PROTO_VER1) ||
+ (!is_client_platform() &&
+ hsmp_pdev->sock[sock_ind].proto_ver >= HSMP_PROTO_VER6)) {
ret = hsmp_get_tbl_dram_base(sock_ind);
if (ret)
dev_info(dev, "Failed to init metric table\n");
@@ -685,7 +690,6 @@ static void hsmp_acpi_sock_release(struct kref *kref)
kfree(hsmp_pdev->sock);
hsmp_pdev->sock = NULL;
hsmp_pdev->num_sockets = 0;
- hsmp_pdev->proto_ver = 0;
}
/**
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
index ecfd2f92a531c..607e77350410e 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp/hsmp.c
@@ -815,7 +815,7 @@ int hsmp_cache_proto_ver(u16 sock_ind)
ret = hsmp_send_message_locked(&msg);
if (!ret)
- hsmp_pdev.proto_ver = msg.args[0];
+ hsmp_pdev.sock[sock_ind].proto_ver = msg.args[0];
return ret;
}
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.h b/drivers/platform/x86/amd/hsmp/hsmp.h
index 62ba795dc8c56..6c850c91a51b1 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.h
+++ b/drivers/platform/x86/amd/hsmp/hsmp.h
@@ -76,13 +76,13 @@ struct hsmp_socket {
char name[HSMP_ATTR_GRP_NAME_SIZE];
struct device *dev;
u16 sock_ind;
+ u32 proto_ver;
int (*amd_hsmp_rdwr)(struct hsmp_socket *sock, u32 off, u32 *val, bool rw);
};
struct hsmp_plat_device {
struct miscdevice mdev;
struct hsmp_socket *sock;
- u32 proto_ver;
u16 num_sockets;
};
diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/amd/hsmp/plat.c
index af8aee1fb22ba..40c98d9c66d4f 100644
--- a/drivers/platform/x86/amd/hsmp/plat.c
+++ b/drivers/platform/x86/amd/hsmp/plat.c
@@ -79,7 +79,7 @@ static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
if (sock_ind >= hsmp_pdev->num_sockets)
return id == 0 ? SYSFS_GROUP_INVISIBLE : 0;
- if (hsmp_pdev->proto_ver == HSMP_PROTO_VER6)
+ if (hsmp_pdev->sock[sock_ind].proto_ver == HSMP_PROTO_VER6)
return battr->attr.mode;
return 0;
@@ -193,7 +193,7 @@ static int init_platform_device(struct device *dev)
return ret;
}
- if (hsmp_pdev->proto_ver == HSMP_PROTO_VER6) {
+ if (sock->proto_ver == HSMP_PROTO_VER6) {
ret = hsmp_get_tbl_dram_base(i);
if (ret)
dev_info(dev, "Failed to init metric table\n");
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 03/11] platform/x86/amd/hsmp: Null-check drvdata in hsmp_is_sock_attr_visible()
2026-10-08 9:29 [PATCH 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
2026-10-08 9:29 ` [PATCH 01/11] platform/x86/amd/hsmp: Fix sock_ind bounds check in is_bin_visible Suma Hegde
2026-10-08 9:29 ` [PATCH 02/11] platform/x86/amd/hsmp: Move proto_ver to hsmp_socket structure Suma Hegde
@ 2026-10-08 9:29 ` Suma Hegde
2026-10-08 9:29 ` [PATCH 04/11] platform/x86/amd/hsmp: Move is_get_msg() before validate_message() Suma Hegde
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-10-08 9:29 UTC (permalink / raw)
To: platform-driver-x86
Cc: ilpo.jarvinen, hdegoede, muthusamy.ramalingam,
NaveenKrishna.Chatradhi, Suma Hegde, Muthusamy Ramalingam
From: Suma Hegde <Suma.Hegde@amd.com>
dev_get_drvdata() can return NULL if probe failed before setting the
socket pointer. Check for that before reading sock->proto_ver so the
sysfs visibility callback cannot NULL-dereference.
Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---
drivers/platform/x86/amd/hsmp/acpi.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index 088c44ea1782e..0e412c23c69c8 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -306,6 +306,9 @@ static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
struct device *dev = kobj_to_dev(kobj);
struct hsmp_socket *sock = dev_get_drvdata(dev);
+ if (!sock)
+ return 0;
+
if (!is_client_platform() && sock->proto_ver >= HSMP_PROTO_VER6)
return battr->attr.mode;
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 04/11] platform/x86/amd/hsmp: Move is_get_msg() before validate_message()
2026-10-08 9:29 [PATCH 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
` (2 preceding siblings ...)
2026-10-08 9:29 ` [PATCH 03/11] platform/x86/amd/hsmp: Null-check drvdata in hsmp_is_sock_attr_visible() Suma Hegde
@ 2026-10-08 9:29 ` Suma Hegde
2026-10-08 9:29 ` [PATCH 05/11] platform/x86/amd/hsmp: Use local sock pointer in init_acpi() Suma Hegde
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-10-08 9:29 UTC (permalink / raw)
To: platform-driver-x86
Cc: ilpo.jarvinen, hdegoede, muthusamy.ramalingam,
NaveenKrishna.Chatradhi, Suma Hegde, Muthusamy Ramalingam
From: Suma Hegde <Suma.Hegde@amd.com>
An upcoming patch invokes is_get_msg() inside validate_message().
Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---
drivers/platform/x86/amd/hsmp/hsmp.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
index 607e77350410e..788a49404875a 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp/hsmp.c
@@ -270,6 +270,17 @@ static int __hsmp_send_message(struct hsmp_socket *sock, struct hsmp_message *ms
return ret;
}
+static bool is_get_msg(const struct hsmp_msg_desc *desc, struct hsmp_message *msg)
+{
+ if (desc->type == HSMP_GET)
+ return true;
+
+ if (desc->type == HSMP_SET_GET && (msg->args[0] & CHECK_GET_BIT))
+ return true;
+
+ return false;
+}
+
static int validate_message(struct hsmp_message *msg)
{
const struct hsmp_plat_desc *plat_desc = hsmp_desc();
@@ -442,17 +453,6 @@ int hsmp_test(u16 sock_ind, u32 value)
}
EXPORT_SYMBOL_NS_GPL(hsmp_test, "AMD_HSMP");
-static bool is_get_msg(const struct hsmp_msg_desc *desc, struct hsmp_message *msg)
-{
- if (desc->type == HSMP_GET)
- return true;
-
- if (desc->type == HSMP_SET_GET && (msg->args[0] & CHECK_GET_BIT))
- return true;
-
- return false;
-}
-
static long hsmp_ioctl_msg(struct file *fp, unsigned long arg)
{
int __user *arguser = (int __user *)arg;
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 05/11] platform/x86/amd/hsmp: Use local sock pointer in init_acpi()
2026-10-08 9:29 [PATCH 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
` (3 preceding siblings ...)
2026-10-08 9:29 ` [PATCH 04/11] platform/x86/amd/hsmp: Move is_get_msg() before validate_message() Suma Hegde
@ 2026-10-08 9:29 ` Suma Hegde
2026-10-08 9:29 ` [PATCH 06/11] platform/x86/amd/hsmp: Move the sock_ind bound check before validate_message() Suma Hegde
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-10-08 9:29 UTC (permalink / raw)
To: platform-driver-x86
Cc: ilpo.jarvinen, hdegoede, muthusamy.ramalingam,
NaveenKrishna.Chatradhi, Suma Hegde, Muthusamy Ramalingam
From: Suma Hegde <Suma.Hegde@amd.com>
Introduce a local struct hsmp_socket *sock pointer in init_acpi() to avoid
repeated use of &hsmp_pdev->sock[sock_ind]. The subsequent patch adds more
users of this pointer beyond dev_set_drvdata().
Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---
drivers/platform/x86/amd/hsmp/acpi.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index 0e412c23c69c8..b6f54e8b91663 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -546,6 +546,7 @@ static ssize_t hsmp_freq_limit_source_show(struct device *dev, struct device_att
*/
static int init_acpi(struct device *dev)
{
+ struct hsmp_socket *sock;
u16 sock_ind;
int ret;
@@ -563,6 +564,8 @@ static int init_acpi(struct device *dev)
return ret;
}
+ sock = &hsmp_pdev->sock[sock_ind];
+
/* Test the hsmp interface */
ret = hsmp_test(sock_ind, 0xDEADBEEF);
if (ret) {
@@ -579,9 +582,9 @@ static int init_acpi(struct device *dev)
}
if ((is_client_platform() &&
- hsmp_pdev->sock[sock_ind].proto_ver >= RYZEN_MASTER_PROTO_VER1) ||
+ sock->proto_ver >= RYZEN_MASTER_PROTO_VER1) ||
(!is_client_platform() &&
- hsmp_pdev->sock[sock_ind].proto_ver >= HSMP_PROTO_VER6)) {
+ sock->proto_ver >= HSMP_PROTO_VER6)) {
ret = hsmp_get_tbl_dram_base(sock_ind);
if (ret)
dev_info(dev, "Failed to init metric table\n");
@@ -597,7 +600,7 @@ static int init_acpi(struct device *dev)
dev_info(dev, "Failed to register HSMP sensors with hwmon\n");
}
- dev_set_drvdata(dev, &hsmp_pdev->sock[sock_ind]);
+ dev_set_drvdata(dev, sock);
return 0;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 06/11] platform/x86/amd/hsmp: Move the sock_ind bound check before validate_message()
2026-10-08 9:29 [PATCH 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
` (4 preceding siblings ...)
2026-10-08 9:29 ` [PATCH 05/11] platform/x86/amd/hsmp: Use local sock pointer in init_acpi() Suma Hegde
@ 2026-10-08 9:29 ` Suma Hegde
2026-10-08 9:29 ` [PATCH 07/11] platform/x86/amd/hsmp: Add per-platform bitmap to validate HSMP messages Suma Hegde
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-10-08 9:29 UTC (permalink / raw)
To: platform-driver-x86
Cc: ilpo.jarvinen, hdegoede, muthusamy.ramalingam,
NaveenKrishna.Chatradhi, Suma Hegde, Muthusamy Ramalingam
From: Suma Hegde <Suma.Hegde@amd.com>
Move the socket index bound check and the hsmp_pdev.sock NULL check
before validate_message() in hsmp_send_message_locked(). This ensures
the socket index and socket array are validated before any use,
preventing potential out-of-bounds access if validate_message() were
to dereference them.
The subsequent patch uses sock_ind inside validate_message().
Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---
drivers/platform/x86/amd/hsmp/hsmp.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
index 788a49404875a..8dc1fc75bd9ba 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp/hsmp.c
@@ -344,13 +344,14 @@ static int hsmp_send_message_locked(struct hsmp_message *msg)
if (!msg)
return -EINVAL;
- ret = validate_message(msg);
- if (ret)
- return ret;
if (!hsmp_pdev.sock || msg->sock_ind >= hsmp_pdev.num_sockets)
return -ENODEV;
+ ret = validate_message(msg);
+ if (ret)
+ return ret;
+
/*
* Sanitize sock_ind after the bounds check. A mispredicted branch can
* still let the CPU speculatively use msg->sock_ind as an index into
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 07/11] platform/x86/amd/hsmp: Add per-platform bitmap to validate HSMP messages
2026-10-08 9:29 [PATCH 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
` (5 preceding siblings ...)
2026-10-08 9:29 ` [PATCH 06/11] platform/x86/amd/hsmp: Move the sock_ind bound check before validate_message() Suma Hegde
@ 2026-10-08 9:29 ` Suma Hegde
2026-10-08 9:29 ` [PATCH 08/11] platform/x86/amd/hsmp: Populate the bitmaps dynamically on 6th Gen AMD EPYC Server Suma Hegde
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-10-08 9:29 UTC (permalink / raw)
To: platform-driver-x86
Cc: ilpo.jarvinen, hdegoede, muthusamy.ramalingam,
NaveenKrishna.Chatradhi, Suma Hegde, Dhruv Gupta,
Muthusamy Ramalingam
From: Suma Hegde <Suma.Hegde@amd.com>
The HSMP driver previously allowed sending any message defined in
amd_hsmp.h, including ones not supported on the running platform.
Add read and write bitmaps per socket to store which HSMP messages
are enabled on the platform. Add validation in validate_message()
to reject unsupported messages before they reach the SMU.
Key changes:
- Introduce enabled_read_msg_ids and enabled_write_msg_ids bitmaps in
struct hsmp_socket.
- Add is_read_msg_enabled() and is_write_msg_enabled() helpers in
hsmp.h.
- Use is_get_msg() to distinguish read and write HSMP messages.
- Mark HSMP_TEST, HSMP_GET_PROTO_VER, and HSMP_GET_SMU_VER as always
enabled during bitmap initialization, as these cannot be masked by
BIOS.
- Skip bitmap init, populate, and validation on client platforms; the
client message set has no per-platform bitmaps yet.
Co-developed-by: Dhruv Gupta <dhruv.gupta@amd.com>
Signed-off-by: Dhruv Gupta <dhruv.gupta@amd.com>
Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---
drivers/platform/x86/amd/hsmp/acpi.c | 13 ++++
drivers/platform/x86/amd/hsmp/hsmp.c | 94 ++++++++++++++++++++++++++++
drivers/platform/x86/amd/hsmp/hsmp.h | 27 ++++++++
drivers/platform/x86/amd/hsmp/plat.c | 13 ++++
4 files changed, 147 insertions(+)
diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index b6f54e8b91663..0d3b324fe2244 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -566,6 +566,11 @@ static int init_acpi(struct device *dev)
sock = &hsmp_pdev->sock[sock_ind];
+ if (!is_client_platform()) {
+ init_read_enabled_msg_bitmap(sock);
+ init_write_enabled_msg_bitmap(sock);
+ }
+
/* Test the hsmp interface */
ret = hsmp_test(sock_ind, 0xDEADBEEF);
if (ret) {
@@ -581,6 +586,14 @@ static int init_acpi(struct device *dev)
return ret;
}
+ if (!is_client_platform()) {
+ ret = hsmp_populate_msg_bitmaps(sock_ind);
+ if (ret) {
+ dev_err(dev, "Failed to get enabled HSMP messages on this platform\n");
+ return ret;
+ }
+ }
+
if ((is_client_platform() &&
sock->proto_ver >= RYZEN_MASTER_PROTO_VER1) ||
(!is_client_platform() &&
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
index 8dc1fc75bd9ba..89528632c9532 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp/hsmp.c
@@ -11,6 +11,7 @@
#include <linux/acpi.h>
#include <linux/array_size.h>
+#include <linux/bitmap.h>
#include <linux/build_bug.h>
#include <linux/cleanup.h>
#include <linux/compiler.h>
@@ -285,6 +286,8 @@ static int validate_message(struct hsmp_message *msg)
{
const struct hsmp_plat_desc *plat_desc = hsmp_desc();
const struct hsmp_msg_desc *desc;
+ struct hsmp_socket *sock;
+ unsigned int sock_ind;
if (!plat_desc->msg_desc) {
/*
@@ -294,6 +297,9 @@ static int validate_message(struct hsmp_message *msg)
* supports in each direction and leave msg_id correctness,
* such as an unsupported or out-of-range value, to the SMU
* status code __hsmp_send_message() already translates.
+ *
+ * Client platforms also have no per-platform enabled-message
+ * bitmaps yet, so skip that check here.
*/
if (msg->num_args > HSMP_CLIENT_MAX_MSG_LEN ||
msg->response_sz > HSMP_CLIENT_MAX_MSG_LEN)
@@ -307,6 +313,17 @@ static int validate_message(struct hsmp_message *msg)
if (!desc)
return -ENOMSG;
+ sock_ind = array_index_nospec(msg->sock_ind, hsmp_pdev.num_sockets);
+ sock = &hsmp_pdev.sock[sock_ind];
+
+ if (is_get_msg(desc, msg)) {
+ if (!is_read_msg_enabled(sock, msg->msg_id))
+ return -ENOMSG;
+ } else {
+ if (!is_write_msg_enabled(sock, msg->msg_id))
+ return -ENOMSG;
+ }
+
/*
* num_args passed by user should match the num_args specified in
* message description table.
@@ -822,6 +839,83 @@ int hsmp_cache_proto_ver(u16 sock_ind)
}
EXPORT_SYMBOL_NS_GPL(hsmp_cache_proto_ver, "AMD_HSMP");
+/*
+ * Predefine read and write enabled message bitmaps for use on platforms where
+ * HSMP_GET_ENABLED_HSMP_CMDS (37h) is not available.
+ */
+static const u32 read_bitmap_f19h_m00h_0fh[] = {0x001b8cde, 0x00000000, 0x00000000};
+static const u32 write_bitmap_f19h_m00h_0fh[] = {0x00047320, 0x00000000, 0x00000000};
+
+static const u32 read_bitmap_zen4_variants[] = {0x7fdb8cde, 0x00000000, 0x00000000};
+static const u32 write_bitmap_zen4_variants[] = {0x80047320, 0x00000007, 0x00000000};
+
+static const u32 read_bitmap_f19h_m80h_9fh[] = {0x7e0b8cde, 0x00000038, 0x00000000};
+static const u32 write_bitmap_f19h_m80h_9fh[] = {0x00040320, 0x00000000, 0x00000000};
+
+static const u32 read_bitmap_f1ah_m00h_1fh[] = {0x7fdb8cde, 0x00070182, 0x00000000};
+static const u32 write_bitmap_f1ah_m00h_1fh[] = {0x80047320, 0x000001c6, 0x00000000};
+/*
+ * Family 0x1A model 0x50-0x5f, family 0x1A model 0xC0-0xCF,
+ * family 0x1A model 0x90-0x9B and family 0x1A model 0xA0-0xAB
+ * belong to 6th Gen AMD EPYC Server family.
+ */
+static const u32 read_bitmap_zen6_variants[] = {0x7fdbbcde, 0x05ff07fe, 0x00000000};
+static const u32 write_bitmap_zen6_variants[] = {0x00047320, 0x070007c6, 0x00000000};
+
+#define set_read_enabled_msg_bitmap(sock, src) \
+ bitmap_from_arr32((sock)->enabled_read_msg_ids, (src), HSMP_MAX_MSGS)
+#define set_write_enabled_msg_bitmap(sock, src) \
+ bitmap_from_arr32((sock)->enabled_write_msg_ids, (src), HSMP_MAX_MSGS)
+
+int hsmp_populate_msg_bitmaps(u16 sock_ind)
+{
+ struct hsmp_socket *sock = &hsmp_pdev.sock[sock_ind];
+
+ switch (boot_cpu_data.x86) {
+ case 0x19:
+ switch (boot_cpu_data.x86_model) {
+ case 0x00 ... 0x0F:
+ set_read_enabled_msg_bitmap(sock, read_bitmap_f19h_m00h_0fh);
+ set_write_enabled_msg_bitmap(sock, write_bitmap_f19h_m00h_0fh);
+ return 0;
+ case 0x10 ... 0x1F:
+ case 0xA0 ... 0xAF:
+ set_read_enabled_msg_bitmap(sock, read_bitmap_zen4_variants);
+ set_write_enabled_msg_bitmap(sock, write_bitmap_zen4_variants);
+ return 0;
+ case 0x80 ... 0x9F:
+ set_read_enabled_msg_bitmap(sock, read_bitmap_f19h_m80h_9fh);
+ set_write_enabled_msg_bitmap(sock, write_bitmap_f19h_m80h_9fh);
+ return 0;
+ }
+ break;
+ case 0x1A:
+ switch (boot_cpu_data.x86_model) {
+ case 0x00 ... 0x1F:
+ set_read_enabled_msg_bitmap(sock, read_bitmap_f1ah_m00h_1fh);
+ set_write_enabled_msg_bitmap(sock, write_bitmap_f1ah_m00h_1fh);
+ return 0;
+ case 0x50 ... 0x5F:
+ case 0x90 ... 0x9B:
+ case 0xA0 ... 0xAB:
+ case 0xC0 ... 0xCF:
+ set_read_enabled_msg_bitmap(sock, read_bitmap_zen6_variants);
+ set_write_enabled_msg_bitmap(sock, write_bitmap_zen6_variants);
+ /*
+ * PC6 control (msg 0x29) is not supported from
+ * protocol 0x70002 onwards on these models.
+ */
+ if (sock->proto_ver >= 0x70002) {
+ clear_bit(HSMP_PC6_ENABLE, sock->enabled_read_msg_ids);
+ clear_bit(HSMP_PC6_ENABLE, sock->enabled_write_msg_ids);
+ }
+ return 0;
+ }
+ }
+ return -ENODEV;
+}
+EXPORT_SYMBOL_NS_GPL(hsmp_populate_msg_bitmaps, "AMD_HSMP");
+
static const struct file_operations hsmp_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = hsmp_ioctl,
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.h b/drivers/platform/x86/amd/hsmp/hsmp.h
index 6c850c91a51b1..e67bbdd2b9bee 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.h
+++ b/drivers/platform/x86/amd/hsmp/hsmp.h
@@ -13,6 +13,8 @@
#include <asm/amd/hsmp.h>
#include <linux/acpi.h>
+#include <linux/bitmap.h>
+#include <linux/bitops.h>
#include <linux/compiler_types.h>
#include <linux/device.h>
#include <linux/hwmon.h>
@@ -26,6 +28,8 @@
#include <linux/sysfs.h>
#include <linux/types.h>
+#define HSMP_MAX_MSGS 96
+
#define HSMP_METRICS_TABLE_NAME "metrics_bin"
#define HSMP_ATTR_GRP_NAME_SIZE 10
@@ -77,6 +81,8 @@ struct hsmp_socket {
struct device *dev;
u16 sock_ind;
u32 proto_ver;
+ DECLARE_BITMAP(enabled_read_msg_ids, HSMP_MAX_MSGS);
+ DECLARE_BITMAP(enabled_write_msg_ids, HSMP_MAX_MSGS);
int (*amd_hsmp_rdwr)(struct hsmp_socket *sock, u32 off, u32 *val, bool rw);
};
@@ -86,7 +92,28 @@ struct hsmp_plat_device {
u16 num_sockets;
};
+/* HSMP_TEST, HSMP_GET_PROTO_VER, HSMP_GET_SMU_VER are always enabled in
+ * all the platforms and can't be masked by BIOS. Set those bits in the
+ * bitmap during bitmap initialization.
+ */
+#define init_read_enabled_msg_bitmap(sock) \
+ do { \
+ bitmap_zero((sock)->enabled_read_msg_ids, HSMP_MAX_MSGS); \
+ bitmap_set((sock)->enabled_read_msg_ids, HSMP_TEST, 1); \
+ bitmap_set((sock)->enabled_read_msg_ids, HSMP_GET_PROTO_VER, 1);\
+ bitmap_set((sock)->enabled_read_msg_ids, HSMP_GET_SMU_VER, 1); \
+ } while (0)
+
+#define init_write_enabled_msg_bitmap(sock) \
+ bitmap_zero((sock)->enabled_write_msg_ids, HSMP_MAX_MSGS)
+
+#define is_read_msg_enabled(sock, msg_id) \
+ test_bit((msg_id), (sock)->enabled_read_msg_ids)
+#define is_write_msg_enabled(sock, msg_id) \
+ test_bit((msg_id), (sock)->enabled_write_msg_ids)
+
int hsmp_cache_proto_ver(u16 sock_ind);
+int hsmp_populate_msg_bitmaps(u16 sock_ind);
int hsmp_test(u16 sock_ind, u32 value);
long hsmp_ioctl(struct file *fp, unsigned int cmd, unsigned long arg);
void hsmp_misc_deregister(void);
diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/amd/hsmp/plat.c
index 40c98d9c66d4f..310a776125961 100644
--- a/drivers/platform/x86/amd/hsmp/plat.c
+++ b/drivers/platform/x86/amd/hsmp/plat.c
@@ -178,6 +178,11 @@ static int init_platform_device(struct device *dev)
sock->mbinfo.msg_arg_off = SMN_HSMP_MSG_DATA;
sema_init(&sock->hsmp_sem, 1);
+ if (!is_client_platform()) {
+ init_read_enabled_msg_bitmap(sock);
+ init_write_enabled_msg_bitmap(sock);
+ }
+
/* Test the hsmp interface on each socket */
ret = hsmp_test(i, 0xDEADBEEF);
if (ret) {
@@ -193,6 +198,14 @@ static int init_platform_device(struct device *dev)
return ret;
}
+ if (!is_client_platform()) {
+ ret = hsmp_populate_msg_bitmaps(i);
+ if (ret) {
+ dev_err(dev, "Failed to get enabled HSMP messages on this platform\n");
+ return ret;
+ }
+ }
+
if (sock->proto_ver == HSMP_PROTO_VER6) {
ret = hsmp_get_tbl_dram_base(i);
if (ret)
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 08/11] platform/x86/amd/hsmp: Populate the bitmaps dynamically on 6th Gen AMD EPYC Server
2026-10-08 9:29 [PATCH 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
` (6 preceding siblings ...)
2026-10-08 9:29 ` [PATCH 07/11] platform/x86/amd/hsmp: Add per-platform bitmap to validate HSMP messages Suma Hegde
@ 2026-10-08 9:29 ` Suma Hegde
2026-10-08 9:29 ` [PATCH 09/11] platform/x86/amd/hsmp: Populate the bitmaps dynamically for future platforms Suma Hegde
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-10-08 9:29 UTC (permalink / raw)
To: platform-driver-x86
Cc: ilpo.jarvinen, hdegoede, muthusamy.ramalingam,
NaveenKrishna.Chatradhi, Suma Hegde, Muthusamy Ramalingam
From: Suma Hegde <Suma.Hegde@amd.com>
HSMP_GET_ENABLED_HSMP_CMDS(0x37) returns the read/get and write/set
messages supported on the running platform, and correctly reflects
BIOS-masked messages in its bitmap.
6th Gen AMD EPYC Server and any future platforms support this
HSMP_GET_ENABLED_HSMP_CMDS message. On 6th Gen AMD EPYC Server, SMU
sends only BIOS masked message info. Hence add a work around.
Use hsmp_send_message_locked() when fetching the bitmaps during probe,
as the caller already holds hsmp_sock_rwsem for write.
Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---
drivers/platform/x86/amd/hsmp/hsmp.c | 64 ++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
index 89528632c9532..bb1f98def3fb6 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp/hsmp.c
@@ -867,6 +867,69 @@ static const u32 write_bitmap_zen6_variants[] = {0x00047320, 0x070007c6, 0x00000
#define set_write_enabled_msg_bitmap(sock, src) \
bitmap_from_arr32((sock)->enabled_write_msg_ids, (src), HSMP_MAX_MSGS)
+#define HSMP_GET_ENABLED_CMD_READ_MASK 1
+#define HSMP_GET_ENABLED_CMD_WRITE_MASK 0
+
+static int hsmp_fetch_read_enabled_msgs(u16 sock_ind, unsigned long *read_msg_bmap)
+{
+ struct hsmp_message msg = {};
+ int ret;
+
+ msg.msg_id = HSMP_GET_ENABLED_HSMP_CMDS;
+ msg.num_args = hsmp_msg_desc_table[HSMP_GET_ENABLED_HSMP_CMDS].num_args;
+ msg.response_sz = hsmp_msg_desc_table[HSMP_GET_ENABLED_HSMP_CMDS].response_sz;
+ msg.args[0] = HSMP_GET_ENABLED_CMD_READ_MASK;
+ msg.sock_ind = sock_ind;
+ ret = hsmp_send_message_locked(&msg);
+ if (!ret)
+ bitmap_from_arr32(read_msg_bmap, msg.args, HSMP_MAX_MSGS);
+
+ return ret;
+}
+
+static int hsmp_fetch_write_enabled_msgs(u16 sock_ind, unsigned long *write_msg_bmap)
+{
+ struct hsmp_message msg = {};
+ int ret;
+
+ msg.msg_id = HSMP_GET_ENABLED_HSMP_CMDS;
+ msg.num_args = hsmp_msg_desc_table[HSMP_GET_ENABLED_HSMP_CMDS].num_args;
+ msg.response_sz = hsmp_msg_desc_table[HSMP_GET_ENABLED_HSMP_CMDS].response_sz;
+ msg.args[0] = HSMP_GET_ENABLED_CMD_WRITE_MASK;
+ msg.sock_ind = sock_ind;
+ ret = hsmp_send_message_locked(&msg);
+ if (!ret)
+ bitmap_from_arr32(write_msg_bmap, msg.args, HSMP_MAX_MSGS);
+
+ return ret;
+}
+
+static void hsmp_dynamic_bitmap_zen6(u16 sock_ind)
+{
+ struct hsmp_socket *sock = &hsmp_pdev.sock[sock_ind];
+ DECLARE_BITMAP(read_msgs_bmap, HSMP_MAX_MSGS);
+ DECLARE_BITMAP(write_msgs_bmap, HSMP_MAX_MSGS);
+
+ bitmap_zero(read_msgs_bmap, HSMP_MAX_MSGS);
+ bitmap_zero(write_msgs_bmap, HSMP_MAX_MSGS);
+ /*
+ * On 6th Gen AMD EPYC Server variants, the SMU firmware only reports
+ * which features are disabled by BIOS — all other bits are set to 1.
+ * Combine the static bitmap with the SMU-returned bitmap using
+ * bitwise AND to produce the correct feature mask.
+ */
+ if (!hsmp_fetch_read_enabled_msgs(sock_ind, read_msgs_bmap)) {
+ bitmap_and(read_msgs_bmap, read_msgs_bmap,
+ sock->enabled_read_msg_ids, HSMP_MAX_MSGS);
+ bitmap_copy(sock->enabled_read_msg_ids, read_msgs_bmap, HSMP_MAX_MSGS);
+ }
+ if (!hsmp_fetch_write_enabled_msgs(sock_ind, write_msgs_bmap)) {
+ bitmap_and(write_msgs_bmap, write_msgs_bmap,
+ sock->enabled_write_msg_ids, HSMP_MAX_MSGS);
+ bitmap_copy(sock->enabled_write_msg_ids, write_msgs_bmap, HSMP_MAX_MSGS);
+ }
+}
+
int hsmp_populate_msg_bitmaps(u16 sock_ind)
{
struct hsmp_socket *sock = &hsmp_pdev.sock[sock_ind];
@@ -909,6 +972,7 @@ int hsmp_populate_msg_bitmaps(u16 sock_ind)
clear_bit(HSMP_PC6_ENABLE, sock->enabled_read_msg_ids);
clear_bit(HSMP_PC6_ENABLE, sock->enabled_write_msg_ids);
}
+ hsmp_dynamic_bitmap_zen6(sock_ind);
return 0;
}
}
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 09/11] platform/x86/amd/hsmp: Populate the bitmaps dynamically for future platforms
2026-10-08 9:29 [PATCH 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
` (7 preceding siblings ...)
2026-10-08 9:29 ` [PATCH 08/11] platform/x86/amd/hsmp: Populate the bitmaps dynamically on 6th Gen AMD EPYC Server Suma Hegde
@ 2026-10-08 9:29 ` Suma Hegde
2026-10-08 9:29 ` [PATCH 10/11] platform/x86/amd/hsmp: Relocate to_hsmp_sys_attr() macro Suma Hegde
2026-10-08 9:29 ` [PATCH 11/11] platform/x86/amd/hsmp: Update sysfs and hwmon file modes based on platform capabilities Suma Hegde
10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-10-08 9:29 UTC (permalink / raw)
To: platform-driver-x86
Cc: ilpo.jarvinen, hdegoede, muthusamy.ramalingam,
NaveenKrishna.Chatradhi, Suma Hegde, Muthusamy Ramalingam
From: Suma Hegde <Suma.Hegde@amd.com>
Future AMD server platforms are expected to support the
HSMP_GET_ENABLED_HSMP_CMDS (0x37) message for reporting
which HSMP messages are available. This also handles
detection of BIOS-enabled and BIOS-disabled messages.
Instead of returning -ENODEV when no static bitmap
matches the running CPU family/model, fall back to
dynamically querying the enabled read and write message
bitmaps via 0x37.
Add hsmp_set_default_msg_bitmap() which temporarily enables the
HSMP_GET_ENABLED_HSMP_CMDS bit so that validate_message() allows
the query, then fetches the read and write bitmaps from the
firmware.
Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---
drivers/platform/x86/amd/hsmp/hsmp.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
index bb1f98def3fb6..1b34336aa8979 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp/hsmp.c
@@ -904,6 +904,20 @@ static int hsmp_fetch_write_enabled_msgs(u16 sock_ind, unsigned long *write_msg_
return ret;
}
+static int hsmp_set_default_msg_bitmap(u16 sock_ind)
+{
+ struct hsmp_socket *sock = &hsmp_pdev.sock[sock_ind];
+ int ret;
+
+ /* Set HSMP_GET_ENABLED_HSMP_CMDS bit to ensure validate_message() doesn't fail */
+ bitmap_set(sock->enabled_read_msg_ids, HSMP_GET_ENABLED_HSMP_CMDS, 1);
+
+ ret = hsmp_fetch_read_enabled_msgs(sock_ind, sock->enabled_read_msg_ids);
+ if (ret)
+ return ret;
+ return hsmp_fetch_write_enabled_msgs(sock_ind, sock->enabled_write_msg_ids);
+}
+
static void hsmp_dynamic_bitmap_zen6(u16 sock_ind)
{
struct hsmp_socket *sock = &hsmp_pdev.sock[sock_ind];
@@ -976,7 +990,7 @@ int hsmp_populate_msg_bitmaps(u16 sock_ind)
return 0;
}
}
- return -ENODEV;
+ return hsmp_set_default_msg_bitmap(sock_ind);
}
EXPORT_SYMBOL_NS_GPL(hsmp_populate_msg_bitmaps, "AMD_HSMP");
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 10/11] platform/x86/amd/hsmp: Relocate to_hsmp_sys_attr() macro
2026-10-08 9:29 [PATCH 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
` (8 preceding siblings ...)
2026-10-08 9:29 ` [PATCH 09/11] platform/x86/amd/hsmp: Populate the bitmaps dynamically for future platforms Suma Hegde
@ 2026-10-08 9:29 ` Suma Hegde
2026-10-08 9:29 ` [PATCH 11/11] platform/x86/amd/hsmp: Update sysfs and hwmon file modes based on platform capabilities Suma Hegde
10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-10-08 9:29 UTC (permalink / raw)
To: platform-driver-x86
Cc: ilpo.jarvinen, hdegoede, muthusamy.ramalingam,
NaveenKrishna.Chatradhi, Suma Hegde, Muthusamy Ramalingam
From: Suma Hegde <Suma.Hegde@amd.com>
Move the to_hsmp_sys_attr() macro definition above
hsmp_is_sock_attr_visible() so it is available before its first use
in a subsequent patch that adds bitmap based visibility checks.
Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---
drivers/platform/x86/amd/hsmp/acpi.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index 0d3b324fe2244..3ea35d8936f8d 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -292,6 +292,8 @@ static ssize_t hsmp_metric_tbl_acpi_read(struct file *filp, struct kobject *kobj
return hsmp_metric_tbl_read(sock, buf, count);
}
+#define to_hsmp_sys_attr(_attr) container_of(_attr, struct hsmp_sys_attr, dattr)
+
static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
const struct bin_attribute *battr, int id)
{
@@ -334,8 +336,6 @@ static umode_t hsmp_is_sock_dev_attr_visible(struct kobject *kobj,
return attr->mode;
}
-#define to_hsmp_sys_attr(_attr) container_of(_attr, struct hsmp_sys_attr, dattr)
-
static ssize_t hsmp_msg_resp32_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 11/11] platform/x86/amd/hsmp: Update sysfs and hwmon file modes based on platform capabilities
2026-10-08 9:29 [PATCH 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
` (9 preceding siblings ...)
2026-10-08 9:29 ` [PATCH 10/11] platform/x86/amd/hsmp: Relocate to_hsmp_sys_attr() macro Suma Hegde
@ 2026-10-08 9:29 ` Suma Hegde
10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-10-08 9:29 UTC (permalink / raw)
To: platform-driver-x86
Cc: ilpo.jarvinen, hdegoede, muthusamy.ramalingam,
NaveenKrishna.Chatradhi, Suma Hegde, Muthusamy Ramalingam
From: Suma Hegde <Suma.Hegde@amd.com>
HSMP messages can be read-only, write-only, or read-write. The set of
supported operations varies across AMD platforms. Older platforms may
only support write, while newer ones support both read and write.
Currently, sysfs and hwmon files are created with a fixed mode based on
what the latest platform supports, regardless of what the running
platform actually provides.
Update the sysfs visibility callback hsmp_is_sock_dev_attr_visible()
to check the per-socket read/write enabled message bitmaps and return
only the permission bits corresponding to operations supported on the
running platform. For files that are both readable and writable, each
direction is checked independently so the mode reflects actual support.
Apply the same logic to the hwmon visibility callback
hsmp_hwmon_is_visble(). Check the enabled bitmaps and
return the updated mode for each power attribute.
On client platforms, keep fixed modes for the shared smu_fw_version and
protocol_version attributes and hide the rest; client platforms have no
enabled-message bitmaps yet.
Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---
drivers/platform/x86/amd/hsmp/acpi.c | 53 +++++++++++++++++++++++++--
drivers/platform/x86/amd/hsmp/hwmon.c | 24 ++++++++++--
2 files changed, 70 insertions(+), 7 deletions(-)
diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index 3ea35d8936f8d..1cb19e7ac843e 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -16,6 +16,7 @@
#include <linux/bits.h>
#include <linux/bitfield.h>
#include <linux/cleanup.h>
+#include <linux/container_of.h>
#include <linux/device.h>
#include <linux/dev_printk.h>
#include <linux/ioport.h>
@@ -324,16 +325,60 @@ static struct hsmp_sys_attr hattr_protocol_version;
static umode_t hsmp_is_sock_dev_attr_visible(struct kobject *kobj,
struct attribute *attr, int id)
{
+ struct device_attribute *dattr = container_of(attr, struct device_attribute, attr);
+ struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(dattr);
+ struct device *dev = kobj_to_dev(kobj);
+ umode_t mode = attr->mode;
+ umode_t mode_updated = 0;
+ struct hsmp_socket *sock;
+ bool readable, writable;
+
/*
* smu_fw_version and protocol_version map to the same data in both
* message tables. Every other attribute here uses server-only
- * message IDs that resolve to unrelated client commands.
+ * message IDs that resolve to unrelated client commands. Client
+ * platforms have no enabled-message bitmaps yet, so keep the fixed
+ * modes for the shared attributes and hide the rest.
*/
- if (is_client_platform() && attr != &hattr_smu_fw_version.dattr.attr &&
- attr != &hattr_protocol_version.dattr.attr)
+ if (is_client_platform()) {
+ if (attr == &hattr_smu_fw_version.dattr.attr ||
+ attr == &hattr_protocol_version.dattr.attr)
+ return mode;
return 0;
+ }
- return attr->mode;
+ sock = dev_get_drvdata(dev);
+ if (!sock)
+ return 0;
+
+ readable = !!(mode & 0444);
+ writable = !!(mode & 0200);
+
+ /*
+ * File is both readable and writeable. Some platforms support only set/write operation.
+ * Some platforms support only get/read operation. Update the file mode accordingly.
+ */
+ if (readable && writable) {
+ if (is_read_msg_enabled(sock, hattr->msg_id))
+ mode_updated |= mode & 0444;
+ if (is_write_msg_enabled(sock, hattr->msg_id))
+ mode_updated |= 0200;
+ return mode_updated;
+ }
+
+ /* Read-only attribute */
+ if (readable) {
+ if (is_read_msg_enabled(sock, hattr->msg_id))
+ return mode;
+ }
+
+ /* Write-only attribute */
+ if (writable) {
+ if (is_write_msg_enabled(sock, hattr->msg_id))
+ return mode;
+ }
+
+ return 0;
}
static ssize_t hsmp_msg_resp32_show(struct device *dev, struct device_attribute *attr,
diff --git a/drivers/platform/x86/amd/hsmp/hwmon.c b/drivers/platform/x86/amd/hsmp/hwmon.c
index c8314eee06f4f..b0da511f03774 100644
--- a/drivers/platform/x86/amd/hsmp/hwmon.c
+++ b/drivers/platform/x86/amd/hsmp/hwmon.c
@@ -80,16 +80,34 @@ static umode_t hsmp_hwmon_is_visble(const void *data,
enum hwmon_sensor_types type,
u32 attr, int channel)
{
+ struct hsmp_plat_device *pdev = get_hsmp_pdev();
+ u16 sock_ind = (uintptr_t)data;
+ struct hsmp_socket *sock;
+ umode_t mode_updated = 0;
+
+ if (!pdev || !pdev->sock || sock_ind >= pdev->num_sockets)
+ return 0;
+
+ sock = &pdev->sock[sock_ind];
+
if (type != hwmon_power)
return 0;
switch (attr) {
case hwmon_power_input:
- return 0444;
+ if (is_read_msg_enabled(sock, HSMP_GET_SOCKET_POWER))
+ mode_updated |= 0444;
+ return mode_updated;
case hwmon_power_cap:
- return 0644;
+ if (is_read_msg_enabled(sock, HSMP_GET_SOCKET_POWER_LIMIT))
+ mode_updated |= 0444;
+ if (is_write_msg_enabled(sock, HSMP_SET_SOCKET_POWER_LIMIT))
+ mode_updated |= 0200;
+ return mode_updated;
case hwmon_power_cap_max:
- return 0444;
+ if (is_read_msg_enabled(sock, HSMP_GET_SOCKET_POWER_LIMIT_MAX))
+ mode_updated |= 0444;
+ return mode_updated;
default:
return 0;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-10-08 9:30 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-08 9:29 [PATCH 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
2026-10-08 9:29 ` [PATCH 01/11] platform/x86/amd/hsmp: Fix sock_ind bounds check in is_bin_visible Suma Hegde
2026-10-08 9:29 ` [PATCH 02/11] platform/x86/amd/hsmp: Move proto_ver to hsmp_socket structure Suma Hegde
2026-10-08 9:29 ` [PATCH 03/11] platform/x86/amd/hsmp: Null-check drvdata in hsmp_is_sock_attr_visible() Suma Hegde
2026-10-08 9:29 ` [PATCH 04/11] platform/x86/amd/hsmp: Move is_get_msg() before validate_message() Suma Hegde
2026-10-08 9:29 ` [PATCH 05/11] platform/x86/amd/hsmp: Use local sock pointer in init_acpi() Suma Hegde
2026-10-08 9:29 ` [PATCH 06/11] platform/x86/amd/hsmp: Move the sock_ind bound check before validate_message() Suma Hegde
2026-10-08 9:29 ` [PATCH 07/11] platform/x86/amd/hsmp: Add per-platform bitmap to validate HSMP messages Suma Hegde
2026-10-08 9:29 ` [PATCH 08/11] platform/x86/amd/hsmp: Populate the bitmaps dynamically on 6th Gen AMD EPYC Server Suma Hegde
2026-10-08 9:29 ` [PATCH 09/11] platform/x86/amd/hsmp: Populate the bitmaps dynamically for future platforms Suma Hegde
2026-10-08 9:29 ` [PATCH 10/11] platform/x86/amd/hsmp: Relocate to_hsmp_sys_attr() macro Suma Hegde
2026-10-08 9:29 ` [PATCH 11/11] platform/x86/amd/hsmp: Update sysfs and hwmon file modes based on platform capabilities Suma Hegde
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.