Skip to contentSkip to conversation

platform/x86/amd/hsmp: Add CONFIG_ACPI dependency

PATCH In review Suma Hegde 3 participants 8 messages Jan 30, 2024 – Feb 20, 2024 x86 platform drivers

lore
Share & tools
lore

Suma Hegde

author
#0 lore raw

PATCH v2 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.

---
Changes since v1:
Correct the email id for Naveen Krishna Chatradhi and change it as Reviewed-by.

 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 v2 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.

---
Changes since v1:
Correct the email id for Naveen Krishna Chatradhi.

 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 v2] platform/x86/amd/hsmp: Remove NULL dereferencing code

Hi Suma,

Quoted 35 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.

---
Changes since v1:
Correct the email id for Naveen Krishna Chatradhi.

 drivers/platform/x86/amd/hsmp.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/platform/x86/amd/hsmp.c +3 -0
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;

drivers/platform/x86/amd/hsmp.c static ssize_t hsmp_metric_tbl_read(struct file *filp, struct kobject *kobj, · line 580

Quoted 10 lines
drivers/platform/x86/amd/hsmp.c +0 -5
 	}
 
-	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;
 

sock gets initialized like this:

        struct hsmp_socket *sock = bin_attr->private;

and bin_attr->private is setup before registering the file and thus it will never be NULL.

So the correct fix would be to simply drop the check rather then to move it.

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

Quoted 10 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;
 
 	return false;

This bit looks fine but this really belongs in a separate patch as it has nothing to do with "Remove NULL dereferencing code"

Regards,

Hans

#3 lore raw

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

Hi Hans,

Quoted 53 lines · Hans de Goede

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Hi Suma,

Quoted 35 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.

---
Changes since v1:
Correct the email id for Naveen Krishna Chatradhi.

  drivers/platform/x86/amd/hsmp.c | 11 ++++-------
  1 file changed, 4 insertions(+), 7 deletions(-)
drivers/platform/x86/amd/hsmp.c +3 -0
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;

drivers/platform/x86/amd/hsmp.c static ssize_t hsmp_metric_tbl_read(struct file *filp, struct kobject *kobj, · line 580

Quoted 10 lines
drivers/platform/x86/amd/hsmp.c +0 -5
       }
 
-     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;
 

sock gets initialized like this:

Quoted 7 lines
         struct hsmp_socket *sock = bin_attr->private;

and bin_attr->private is setup before registering the file and thus it will never be NULL.

So the correct fix would be to simply drop the check rather then to move it.

Thank you for your review comment, I will send a patch to address this change.

Quoted 9 lines
Quoted 9 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;
 
Quoted 3 lines

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

Quoted 1 line
drivers/platform/x86/amd/hsmp.c +0 -0
       return false;

This bit looks fine but this really belongs in a separate patch as it has nothing to do with "Remove NULL dereferencing code"

Ilpo has already merged it into relevant patch(platform/x86/amd/hsmp: Non-ACPI support for AMD F1A_M00~0Fh) and the change is available in review-ilpo branch.

Quoted 3 lines

Regards,

Hans

Thanks and Regards,

Suma

Quoted 1 line
#4 lore raw
In reply to Suma Hegde

Hi,

Quoted 7 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.

Thank you for your patch, I've applied this patch to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.

I will include this patch in my next fixes pull-req to Linus for the current kernel development cycle.

Regards,

Hans

Quoted 21 lines

---
Changes since v1:
Correct the email id for Naveen Krishna Chatradhi and change it as Reviewed-by.

 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.
#5 lore raw

Hi Hans,

Quoted 20 lines · Hans de Goede

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Hi,

Quoted 7 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.

Thank you for your patch, I've applied this patch to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.

Quoted 6 lines

I will include this patch in my next fixes pull-req to Linus for the current kernel development cycle.

Regards,

Hans

This change was merged by Ilpo in review-ilpo branch into commit: platform/x86/amd/hsmp: Add support for ACPI based probing.

Quoted 23 lines
Quoted 23 lines

---
Changes since v1:
Correct the email id for Naveen Krishna Chatradhi and change it as Reviewed-by.

  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.
maintainer
#6 lore raw
Quoted 30 lines · Suma
Quoted 13 lines · Hans de Goede
Quoted 8 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.

Closes:
https://lore.kernel.org/oe-kbuild-all/[email protected]/

Thank you for your patch, I've applied this patch to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Quoted 5 lines

Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.

I will include this patch in my next fixes pull-req to Linus for the current kernel development cycle.

This change was merged by Ilpo in review-ilpo branch into commit:
platform/x86/amd/hsmp: Add support for ACPI based probing.

Quoted 7 lines
Quoted 7 lines
drivers/platform/x86/amd/Kconfig +0 -0
index 54753213cc61..f88682d36447 100644
@@ -8,7 +8,7 @@ source "drivers/platform/x86/amd/pmc/Kconfig"
 
Quoted 4 lines
Quoted 4 lines

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

Quoted 4 lines
drivers/platform/x86/amd/Kconfig +1 -1
  config AMD_HSMP
       tristate "AMD HSMP Driver"
-     depends on AMD_NB && X86_64
+     depends on AMD_NB && X86_64 && ACPI

Yes, it only belongs to for-next.

The change that triggered the build fail is (it is only in for-next):

commit ba8dcff0e9c4f8fa6a46315126fb837acb0f98fc

Author: Suma Hegde <[email protected]>
Date:   Sat Jan 6 02:25:28 2024 +0000

platform/x86/amd/hsmp: Add support for ACPI based probing

Signature · 1 line
 i.
#7 lore raw

Hi,

Quoted 31 lines · Ilpo Järvinen
Quoted 30 lines · Suma
Quoted 13 lines · Hans de Goede
Quoted 8 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.

Closes:
https://lore.kernel.org/oe-kbuild-all/[email protected]/

Thank you for your patch, I've applied this patch to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Quoted 5 lines

Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.

I will include this patch in my next fixes pull-req to Linus for the current kernel development cycle.

This change was merged by Ilpo in review-ilpo branch into commit:
platform/x86/amd/hsmp: Add support for ACPI based probing.

Quoted 7 lines
Quoted 7 lines
drivers/platform/x86/amd/Kconfig +0 -0
index 54753213cc61..f88682d36447 100644
@@ -8,7 +8,7 @@ source "drivers/platform/x86/amd/pmc/Kconfig"
 
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

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

Quoted 4 lines
drivers/platform/x86/amd/Kconfig +1 -1
  config AMD_HSMP
       tristate "AMD HSMP Driver"
-     depends on AMD_NB && X86_64
+     depends on AMD_NB && X86_64 && ACPI

Yes, it only belongs to for-next.

The change that triggered the build fail is (it is only in for-next):

Ah, my bad, thank you both for catching this.

I have dropped this from my review-hans branch now.

Regards,

Hans