platform/x86/amd/hsmp: Per-platform enabled-message bitmaps
Subsystems (2)
cover platform/x86/amd/hsmp: Per-platform enabled-message bitmaps
From: Suma Hegde <[email protected]>
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
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/[email protected]/T/#t
[PATCH v7 0/4] platform/x86/amd/hsmp: Family 1Ah client support by Muralidhar M K
Signature · 1 line
2.34.1
PATCH 1/11 platform/x86/amd/hsmp: Fix sock_ind bounds check in is_bin_visible
From: Suma Hegde <[email protected]>
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.
--- drivers/platform/x86/amd/hsmp/plat.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/platform/x86/amd/hsmp/plat.c +7 -2
@@ -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;
Signature · 1 line
2.34.1
PATCH 2/11 platform/x86/amd/hsmp: Move proto_ver to hsmp_socket structure
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
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.
--- 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(-)
drivers/platform/x86/amd/hsmp/acpi.c +9 -5
@@ -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 ; }/**
drivers/platform/x86/amd/hsmp/hsmp.c +1 -1
@@ -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; }
drivers/platform/x86/amd/hsmp/hsmp.h +1 -1
@@ -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; };
drivers/platform/x86/amd/hsmp/plat.c +2 -2
@@ -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" );
Signature · 1 line
2.34.1
PATCH 3/11 platform/x86/amd/hsmp: Null-check drvdata in hsmp_is_sock_attr_visible()
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
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.
--- drivers/platform/x86/amd/hsmp/acpi.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/platform/x86/amd/hsmp/acpi.c +3 -0
@@ -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;
Signature · 1 line
2.34.1
Ilpo Järvinen
maintainerRe: [PATCH 03/11] platform/x86/amd/hsmp: Null-check drvdata in hsmp_is_sock_attr_visible()
Quoted 18 lines · Suma Hegde
From: Suma Hegde <[email protected]>
dev_get_drvdata()can return NULL if probe failed before setting the socket pointer. Check for that before readingsock->proto_verso the sysfs visibility callback cannot NULL-dereference.Co-developed-by Muthusamy Ramalingam <[email protected]>Signed-off-by Muthusamy Ramalingam <[email protected]>Signed-off-by Suma Hegde <[email protected]>--- drivers/platform/x86/amd/hsmp/acpi.c | 3 +++ 1 file changed, 3 insertions(+)drivers/platform/x86/amd/hsmp/acpi.c +0
-0
drivers/platform/x86/amd/hsmp/acpi.c static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj, · line 309
Quoted 4 lines
drivers/platform/x86/amd/hsmp/acpi.c +1
-0@@ -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)
Please put call and it's error handling next to each other, effectively that means moving sock assignment out of the local variable block.
Quoted 6 lines
drivers/platform/x86/amd/hsmp/acpi.c +2
-0+return 0 ; +if (!is_client_platform () && sock->proto_ver >=HSMP_PROTO_VER6 )return battr->attr.mode;
Signature · 1 line
i.
PATCH 4/11 platform/x86/amd/hsmp: Move is_get_msg() before validate_message()
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
An upcoming patch invokes is_get_msg() inside validate_message().
--- drivers/platform/x86/amd/hsmp/hsmp.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/platform/x86/amd/hsmp/hsmp.c +11 -11
@@ -270,6 +270,17 @@ static int __hsmp_send_message(struct hsmp_socket *sock, struct hsmp_message *msreturn 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;
Signature · 1 line
2.34.1
PATCH 5/11 platform/x86/amd/hsmp: Use local sock pointer in init_acpi()
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
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().
--- drivers/platform/x86/amd/hsmp/acpi.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/platform/x86/amd/hsmp/acpi.c +6 -3
@@ -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 ; }
Signature · 1 line
2.34.1
PATCH 6/11 platform/x86/amd/hsmp: Move the sock_ind bound check before validate_message()
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
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().
--- drivers/platform/x86/amd/hsmp/hsmp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/platform/x86/amd/hsmp/hsmp.c +4 -3
@@ -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
Signature · 1 line
2.34.1
PATCH 7/11 platform/x86/amd/hsmp: Add per-platform bitmap to validate HSMP messages
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
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.
--- 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(+)
drivers/platform/x86/amd/hsmp/acpi.c +13 -0
@@ -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() &&
drivers/platform/x86/amd/hsmp/hsmp.c +94 -0
124 lines not on this page · raw message
drivers/platform/x86/amd/hsmp/hsmp.h +27 -0
@@ -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 );
drivers/platform/x86/amd/hsmp/plat.c +13 -0
@@ -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)
Signature · 1 line
2.34.1
Ilpo Järvinen
maintainerRe: [PATCH 07/11] platform/x86/amd/hsmp: Add per-platform bitmap to validate HSMP messages
Quoted 86 lines · Suma Hegde
From: Suma Hegde <[email protected]>
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:
- Introduceenabled_read_msg_idsandenabled_write_msg_idsbitmaps in structhsmp_socket.
- Addis_read_msg_enabled()andis_write_msg_enabled()helpers inhsmp.h.
- Useis_get_msg()to distinguish read and write HSMP messages.
- MarkHSMP_TEST,HSMP_GET_PROTO_VER, andHSMP_GET_SMU_VERas 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 <[email protected]>Signed-off-by Dhruv Gupta <[email protected]>Co-developed-by Muthusamy Ramalingam <[email protected]>Signed-off-by Muthusamy Ramalingam <[email protected]>Signed-off-by Suma Hegde <[email protected]>--- 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(+)drivers/platform/x86/amd/hsmp/acpi.c +13
-0@@ -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() &&drivers/platform/x86/amd/hsmp/hsmp.c +3
-0@@ -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) {/*
drivers/platform/x86/amd/hsmp/hsmp.c static int validate_message(struct hsmp_message *msg) · line 302
Quoted 6 lines
drivers/platform/x86/amd/hsmp/hsmp.c +3
-0@@ -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.
I'm unsure how to read this. This validation seems to be on driver side so why cannot it be validated for client?
Quoted 22 lines
drivers/platform/x86/amd/hsmp/hsmp.c +11
-0*/ 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.
drivers/platform/x86/amd/hsmp/hsmp.c int hsmp_cache_proto_ver(u16 sock_ind) · line 846
Quoted 8 lines
drivers/platform/x86/amd/hsmp/hsmp.c +5
-0@@ -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 };
These are just a combination of BIT(msg_id), right? If yes, these should be constructed from the named defines by OR'ing them together instead of using those obscure literals.
drivers/platform/x86/amd/hsmp/hsmp.c int hsmp_cache_proto_ver(u16 sock_ind) · line 856
Quoted 10 lines
drivers/platform/x86/amd/hsmp/hsmp.c +10
-0+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 };
What's the general plan with these? Do we have to keep adding to them when more platforms appear?
Quoted 157 lines
drivers/platform/x86/amd/hsmp/hsmp.c +62
-0+/* +* 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,drivers/platform/x86/amd/hsmp/hsmp.h +27
-0@@ -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 );drivers/platform/x86/amd/hsmp/plat.c +13
-0@@ -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)
Signature · 1 line
i.
Ilpo Järvinen
maintainerRe: [PATCH 07/11] platform/x86/amd/hsmp: Add per-platform bitmap to validate HSMP messages
Quoted 133 lines · Ilpo Järvinen
Quoted 86 lines · Suma Hegde
From: Suma Hegde <[email protected]>
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:
- Introduceenabled_read_msg_idsandenabled_write_msg_idsbitmaps in structhsmp_socket.
- Addis_read_msg_enabled()andis_write_msg_enabled()helpers inhsmp.h.
- Useis_get_msg()to distinguish read and write HSMP messages.
- MarkHSMP_TEST,HSMP_GET_PROTO_VER, andHSMP_GET_SMU_VERas 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 <[email protected]>Signed-off-by Dhruv Gupta <[email protected]>Co-developed-by Muthusamy Ramalingam <[email protected]>Signed-off-by Muthusamy Ramalingam <[email protected]>Signed-off-by Suma Hegde <[email protected]>--- 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(+)drivers/platform/x86/amd/hsmp/acpi.c +13
-0@@ -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() &&drivers/platform/x86/amd/hsmp/hsmp.c +3
-0@@ -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) {/* drivers/platform/x86/amd/hsmp/hsmp.c static int validate_message(struct hsmp_message *msg) · line 302
Quoted 6 lines
drivers/platform/x86/amd/hsmp/hsmp.c +3
-0@@ -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. I'm unsure how to read this. This validation seems to be on driver side so why cannot it be validated for client?
Quoted 22 lines
drivers/platform/x86/amd/hsmp/hsmp.c +11
-0*/ 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. drivers/platform/x86/amd/hsmp/hsmp.c int hsmp_cache_proto_ver(u16 sock_ind) · line 846
Quoted 8 lines
drivers/platform/x86/amd/hsmp/hsmp.c +5
-0@@ -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 };These are just a combination of
BIT(msg_id), right? If yes, these should be constructed from the named defines by OR'ing them together instead of using those obscure literals.
Quoted 13 lines
drivers/platform/x86/amd/hsmp/hsmp.c int hsmp_cache_proto_ver(u16 sock_ind) · line 856
Quoted 10 lines
drivers/platform/x86/amd/hsmp/hsmp.c +10
-0+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 };What's the general plan with these? Do we have to keep adding to them when more platforms appear?
Nevermind the question, I see the answer in patch 9.
Could you please add a note about the future platforms having automatic way to acquire this into changelog of this patch as well.
--
i.
Quoted 159 lines
Quoted 157 lines
drivers/platform/x86/amd/hsmp/hsmp.c +62
-0+/* +* 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,drivers/platform/x86/amd/hsmp/hsmp.h +27
-0@@ -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 );drivers/platform/x86/amd/hsmp/plat.c +13
-0@@ -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)
PATCH 8/11 platform/x86/amd/hsmp: Populate the bitmaps dynamically on 6th Gen AMD EPYC Server
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
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.
--- drivers/platform/x86/amd/hsmp/hsmp.c | 64 ++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)
drivers/platform/x86/amd/hsmp/hsmp.c +64 -0
@@ -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 ; } }
Signature · 1 line
2.34.1
PATCH 9/11 platform/x86/amd/hsmp: Populate the bitmaps dynamically for future platforms
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
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.
--- drivers/platform/x86/amd/hsmp/hsmp.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/platform/x86/amd/hsmp/hsmp.c +15 -1
@@ -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" );
Signature · 1 line
2.34.1
PATCH 10/11 platform/x86/amd/hsmp: Relocate to_hsmp_sys_attr() macro
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
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.
--- drivers/platform/x86/amd/hsmp/acpi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/amd/hsmp/acpi.c +2 -2
@@ -292,6 +292,8 @@ static ssize_t hsmp_metric_tbl_acpi_read(struct file *filp, struct kobject *kobjreturn 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) {
Signature · 1 line
2.34.1
PATCH 11/11 platform/x86/amd/hsmp: Update sysfs and hwmon file modes based on platform capabilities
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
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.
--- drivers/platform/x86/amd/hsmp/acpi.c | 53 +++++++++++++++++++++++++-- drivers/platform/x86/amd/hsmp/hwmon.c | 24 ++++++++++-- 2 files changed, 70 insertions(+), 7 deletions(-)
drivers/platform/x86/amd/hsmp/acpi.c +49 -4
@@ -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,
drivers/platform/x86/amd/hsmp/hwmon.c +21 -3
@@ -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 ; }
Signature · 1 line
2.34.1