Skip to contentSkip to conversation

platform/x86/amd/hsmp: add CONFIG_ACPI dependency

PATCH Superseded Suma Hegde 2 participants 4 messages Jan 29, 2024 x86 platform drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Suma Hegde

author
#0 lore raw

PATCH 1/1 platform/x86/amd/hsmp: add CONFIG_ACPI dependency

HSMP interface is only supported on x86 based AMD EPYC line of processors. Driver uses ACPI APIs, so make it dependent on CONFIG_ACPI.

---

 drivers/platform/x86/amd/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/amd/Kconfig +1 -1
index 54753213cc61..f88682d36447 100644
@@ -8,7 +8,7 @@ source "drivers/platform/x86/amd/pmc/Kconfig"
 
 config AMD_HSMP
 	tristate "AMD HSMP Driver"
-	depends on AMD_NB && X86_64
+	depends on AMD_NB && X86_64 && ACPI
 	help
 	  The driver provides a way for user space tools to monitor and manage
 	  system management functionality on EPYC server CPUs from AMD.
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/1 platform/x86/amd/hsmp: Remove NULL dereferencing code

Do not log using dev_err() in case of !sock, which causes null pointer dereferencing.

Also remove unnecessary check "boot_cpu_data.x86_model >= 0x00", which is always true because its an unsigned type.

---

 drivers/platform/x86/amd/hsmp.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/platform/x86/amd/hsmp.c +4 -7
index 1baddf403920..1927be901108 100644
@@ -566,17 +566,15 @@ static ssize_t hsmp_metric_tbl_read(struct file *filp, struct kobject *kobj,
 	struct hsmp_message msg = { 0 };
 	int ret;
 
+	if (!sock)
+		return -EINVAL;
+
 	/* Do not support lseek(), reads entire metric table */
 	if (count < bin_attr->size) {
 		dev_err(sock->dev, "Wrong buffer size\n");
 		return -EINVAL;
 	}
 
-	if (!sock) {
-		dev_err(sock->dev, "Failed to read attribute private data\n");
-		return -EINVAL;
-	}
-
 	msg.msg_id	= HSMP_GET_METRIC_TABLE;
 	msg.sock_ind	= sock->sock_ind;
 
@@ -739,8 +737,7 @@ static int hsmp_cache_proto_ver(u16 sock_ind)
 
 static inline bool is_f1a_m0h(void)
 {
-	if (boot_cpu_data.x86 == 0x1A &&
-	    (boot_cpu_data.x86_model >= 0x00 && boot_cpu_data.x86_model <= 0x0F))
+	if (boot_cpu_data.x86 == 0x1A && boot_cpu_data.x86_model <= 0x0F)
 		return true;
 
 	return false;
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH] platform/x86/amd/hsmp: Remove NULL dereferencing code

Quoted 44 lines · Suma Hegde

Do not log using dev_err() in case of !sock, which causes null pointer dereferencing.

Also remove unnecessary check "boot_cpu_data.x86_model >= 0x00", which is always true because its an unsigned type.

---

  drivers/platform/x86/amd/hsmp.c | 11 ++++-------
  1 file changed, 4 insertions(+), 7 deletions(-)
drivers/platform/x86/amd/hsmp.c +3 -5
index 1baddf403920..1927be901108 100644
@@ -566,17 +566,15 @@ static ssize_t hsmp_metric_tbl_read(struct file *filp, struct kobject *kobj,
  	struct hsmp_message msg = { 0 };
  	int ret;
 
+	if (!sock)
+		return -EINVAL;
+
  	/* Do not support lseek(), reads entire metric table */
  	if (count < bin_attr->size) {
  		dev_err(sock->dev, "Wrong buffer size\n");
  		return -EINVAL;
  	}
 
-	if (!sock) {
-		dev_err(sock->dev, "Failed to read attribute private data\n");
-		return -EINVAL;
-	}
-
  	msg.msg_id	= HSMP_GET_METRIC_TABLE;
  	msg.sock_ind	= sock->sock_ind;
 

drivers/platform/x86/amd/hsmp.c static int hsmp_cache_proto_ver(u16 sock_ind) · line 741

Quoted 7 lines
drivers/platform/x86/amd/hsmp.c +1 -2
@@ -739,8 +737,7 @@ static int hsmp_cache_proto_ver(u16 sock_ind)
 
  static inline bool is_f1a_m0h(void)
  {
-	if (boot_cpu_data.x86 == 0x1A &&
-	    (boot_cpu_data.x86_model >= 0x00 && boot_cpu_data.x86_model <= 0x0F))
+	if (boot_cpu_data.x86 == 0x1A && boot_cpu_data.x86_model <= 0x0F)
  		return true;

Does this really need to match a specific model, or is it a Zen generation level? I wonder if you want the synthetic CPU feature flag for Zen5 for example?

Quoted 2 lines
drivers/platform/x86/amd/hsmp.c +0 -0
  	return false;
Reviewed-by on v1 1/1
#3 lore raw
In reply to Suma Hegde
Quoted 17 lines · Suma Hegde

HSMP interface is only supported on x86 based AMD EPYC line of processors. Driver uses ACPI APIs, so make it dependent on CONFIG_ACPI.

---

  drivers/platform/x86/amd/Kconfig | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/amd/Kconfig +0 -0
index 54753213cc61..f88682d36447 100644

drivers/platform/x86/amd/Kconfig source "drivers/platform/x86/amd/pmc/Kconfig" · line 14

Quoted 8 lines
drivers/platform/x86/amd/Kconfig +1 -1
@@ -8,7 +8,7 @@ source "drivers/platform/x86/amd/pmc/Kconfig"
 
  config AMD_HSMP
  	tristate "AMD HSMP Driver"
-	depends on AMD_NB && X86_64
+	depends on AMD_NB && X86_64 && ACPI
  	help
  	  The driver provides a way for user space tools to monitor and manage
  	  system management functionality on EPYC server CPUs from AMD.

This specific patch looks fine to me.

However I would like to ask for some follow up code:

This driver is missing some safety checks that it really is running on EPYC. Probing registers that don't match the same mailboxes randomly on client or embedded parts might lead to unexpected behaviors.

I've seen when someone explicitly compiled with CONFIG_AMD_HSMP=y this breaks s0i3 on at least one system.

I have two suggestions:

1) Use something like amd-pstate does in init:

static bool amd_pstate_acpi_pm_profile_server(void)

{
	switch (acpi_gbl_FADT.preferred_profile) {
	case PM_ENTERPRISE_SERVER:
	case PM_SOHO_SERVER:
	case PM_PERFORMANCE_SERVER:
		return true;
	}
	return false;
}

2) If in non-ACPI mode, require that a user use a module parameter like "amd_hsmp.force=1" to load the driver.

Furthermore I noticed that your init call has a dev_err() that will show on unsupported parts. If someone compiles this driver into the kernel and runs it on one of these parts that's pretty noisy.

I suggest you downgrade this to debug.