diff mbox series

elf: Fix tst-cpu-features-cpuinfo on some ADM systems (BZ #28090)

Message ID 20210715115804.4192826-1-adhemerval.zanella@linaro.org
State New
Headers show
Series elf: Fix tst-cpu-features-cpuinfo on some ADM systems (BZ #28090) | expand

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Adhemerval Zanella July 15, 2021, 11:58 a.m. UTC
The SSBD feature is implemented in 2 different ways on AMD processors:
newer systems (Zen3) provides AMD_SSBD (function 8000_0008, EBX[24]),
while older system provides AMD_VIRT_SSBD (function 8000_0008, EBX[25]).
However for AMD_VIRT_SSBD, kernel shows both 'ssdb' and 'virt_ssdb' on
/proc/cpuinfo; while for AMD_SSBD only 'ssdb' is provided.

This now check is AMD_SSBD is set to check for 'ssbd', otherwise check
if AMD_VIRT_SSDB is set to check for 'virt_ssdb'.

Checked on x86_64-linux-gnu on a Ryzen 9 5900x.
---
 sysdeps/x86/bits/platform/x86.h        |  1 +
 sysdeps/x86/include/cpu-features.h     |  3 +++
 sysdeps/x86/tst-cpu-features-cpuinfo.c | 13 ++++++++++++-
 3 files changed, 16 insertions(+), 1 deletion(-)

Comments

H.J. Lu July 15, 2021, 12:39 p.m. UTC | #1
On Thu, Jul 15, 2021 at 5:00 AM Adhemerval Zanella via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> The SSBD feature is implemented in 2 different ways on AMD processors:
> newer systems (Zen3) provides AMD_SSBD (function 8000_0008, EBX[24]),
> while older system provides AMD_VIRT_SSBD (function 8000_0008, EBX[25]).
> However for AMD_VIRT_SSBD, kernel shows both 'ssdb' and 'virt_ssdb' on
> /proc/cpuinfo; while for AMD_SSBD only 'ssdb' is provided.
>
> This now check is AMD_SSBD is set to check for 'ssbd', otherwise check
> if AMD_VIRT_SSDB is set to check for 'virt_ssdb'.
>
> Checked on x86_64-linux-gnu on a Ryzen 9 5900x.
> ---
>  sysdeps/x86/bits/platform/x86.h        |  1 +
>  sysdeps/x86/include/cpu-features.h     |  3 +++
>  sysdeps/x86/tst-cpu-features-cpuinfo.c | 13 ++++++++++++-
>  3 files changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/sysdeps/x86/bits/platform/x86.h b/sysdeps/x86/bits/platform/x86.h
> index 5509b1ad87..2b257606b2 100644
> --- a/sysdeps/x86/bits/platform/x86.h
> +++ b/sysdeps/x86/bits/platform/x86.h
> @@ -282,6 +282,7 @@ enum
>    x86_cpu_AMD_IBRS             = x86_cpu_index_80000008_ebx + 14,
>    x86_cpu_AMD_STIBP            = x86_cpu_index_80000008_ebx + 15,
>    x86_cpu_AMD_SSBD             = x86_cpu_index_80000008_ebx + 24,
> +  x86_cpu_AMD_VIRT_SSBD                = x86_cpu_index_80000008_ebx + 25,
>
>    x86_cpu_index_7_ecx_1_eax
>      = (CPUID_INDEX_7_ECX_1 * 8 * 4 * sizeof (unsigned int)
> diff --git a/sysdeps/x86/include/cpu-features.h b/sysdeps/x86/include/cpu-features.h
> index 59e01df543..a3f11baa7a 100644
> --- a/sysdeps/x86/include/cpu-features.h
> +++ b/sysdeps/x86/include/cpu-features.h
> @@ -293,6 +293,7 @@ enum
>  #define bit_cpu_AMD_IBRS       (1u << 14)
>  #define bit_cpu_AMD_STIBP      (1u << 15)
>  #define bit_cpu_AMD_SSBD       (1u << 24)
> +#define bit_cpu_AMD_VIRT_SSBD  (1u << 25)
>
>  /* CPUID_INDEX_7_ECX_1.  */
>
> @@ -527,6 +528,7 @@ enum
>  #define index_cpu_AMD_IBRS     CPUID_INDEX_80000008
>  #define index_cpu_AMD_STIBP    CPUID_INDEX_80000008
>  #define index_cpu_AMD_SSBD     CPUID_INDEX_80000008
> +#define index_cpu_AMD_VIRT_SSBD        CPUID_INDEX_80000008
>
>  /* CPUID_INDEX_7_ECX_1.  */
>
> @@ -761,6 +763,7 @@ enum
>  #define reg_AMD_IBRS           ebx
>  #define reg_AMD_STIBP          ebx
>  #define reg_AMD_SSBD           ebx
> +#define reg_AMD_VIRT_SSBD      ebx
>
>  /* CPUID_INDEX_7_ECX_1.  */
>
> diff --git a/sysdeps/x86/tst-cpu-features-cpuinfo.c b/sysdeps/x86/tst-cpu-features-cpuinfo.c
> index f457e8677b..9d4ae65e26 100644
> --- a/sysdeps/x86/tst-cpu-features-cpuinfo.c
> +++ b/sysdeps/x86/tst-cpu-features-cpuinfo.c
> @@ -236,7 +236,18 @@ do_test (int argc, char **argv)
>    if (cpu_features->basic.kind == arch_kind_intel)
>      fails += CHECK_PROC (ssbd, SSBD);
>    else if (cpu_features->basic.kind == arch_kind_amd)
> -    fails += CHECK_PROC (ssbd, AMD_SSBD);
> +    {
> +      /* This feature is implemented in 2 different ways on AMD processors:
> +        newer systems provides AMD_SSBD (function 8000_0008, EBX[24]),
> +        while older system proviseds AMD_VIRT_SSBD (function 8000_008,
> +        EBX[25]).  However for AMD_VIRT_SSBD, kernel shows both 'ssdb'
> +        and 'virt_ssdb' on /proc/cpuinfo; while for AMD_SSBD only 'ssdb'
> +        is provided.  */
> +      if (HAS_CPU_FEATURE (AMD_SSBD))
> +       fails += CHECK_PROC (ssbd, AMD_SSBD);
> +      else if (HAS_CPU_FEATURE (AMD_VIRT_SSBD))
> +       fails += CHECK_PROC (virt_ssbd, AMD_VIRT_SSBD);
> +    }
>    fails += CHECK_PROC (sse, SSE);
>    fails += CHECK_PROC (sse2, SSE2);
>    fails += CHECK_PROC (pni, SSE3);
> --
> 2.30.2
>

Please fix the commit subject.  It should be AMD, not ADM.
Otherwise LGTM.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>

Thanks.
Adhemerval Zanella July 19, 2021, 4:42 p.m. UTC | #2
On 15/07/2021 09:39, H.J. Lu wrote:
> Please fix the commit subject.  It should be AMD, not ADM.

Ack.

> Otherwise LGTM.
> 
> Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
> 
> Thanks.
diff mbox series

Patch

diff --git a/sysdeps/x86/bits/platform/x86.h b/sysdeps/x86/bits/platform/x86.h
index 5509b1ad87..2b257606b2 100644
--- a/sysdeps/x86/bits/platform/x86.h
+++ b/sysdeps/x86/bits/platform/x86.h
@@ -282,6 +282,7 @@  enum
   x86_cpu_AMD_IBRS	        = x86_cpu_index_80000008_ebx + 14,
   x86_cpu_AMD_STIBP	        = x86_cpu_index_80000008_ebx + 15,
   x86_cpu_AMD_SSBD	        = x86_cpu_index_80000008_ebx + 24,
+  x86_cpu_AMD_VIRT_SSBD	        = x86_cpu_index_80000008_ebx + 25,
 
   x86_cpu_index_7_ecx_1_eax
     = (CPUID_INDEX_7_ECX_1 * 8 * 4 * sizeof (unsigned int)
diff --git a/sysdeps/x86/include/cpu-features.h b/sysdeps/x86/include/cpu-features.h
index 59e01df543..a3f11baa7a 100644
--- a/sysdeps/x86/include/cpu-features.h
+++ b/sysdeps/x86/include/cpu-features.h
@@ -293,6 +293,7 @@  enum
 #define bit_cpu_AMD_IBRS	(1u << 14)
 #define bit_cpu_AMD_STIBP	(1u << 15)
 #define bit_cpu_AMD_SSBD	(1u << 24)
+#define bit_cpu_AMD_VIRT_SSBD	(1u << 25)
 
 /* CPUID_INDEX_7_ECX_1.  */
 
@@ -527,6 +528,7 @@  enum
 #define index_cpu_AMD_IBRS	CPUID_INDEX_80000008
 #define index_cpu_AMD_STIBP	CPUID_INDEX_80000008
 #define index_cpu_AMD_SSBD	CPUID_INDEX_80000008
+#define index_cpu_AMD_VIRT_SSBD	CPUID_INDEX_80000008
 
 /* CPUID_INDEX_7_ECX_1.  */
 
@@ -761,6 +763,7 @@  enum
 #define reg_AMD_IBRS		ebx
 #define reg_AMD_STIBP		ebx
 #define reg_AMD_SSBD		ebx
+#define reg_AMD_VIRT_SSBD	ebx
 
 /* CPUID_INDEX_7_ECX_1.  */
 
diff --git a/sysdeps/x86/tst-cpu-features-cpuinfo.c b/sysdeps/x86/tst-cpu-features-cpuinfo.c
index f457e8677b..9d4ae65e26 100644
--- a/sysdeps/x86/tst-cpu-features-cpuinfo.c
+++ b/sysdeps/x86/tst-cpu-features-cpuinfo.c
@@ -236,7 +236,18 @@  do_test (int argc, char **argv)
   if (cpu_features->basic.kind == arch_kind_intel)
     fails += CHECK_PROC (ssbd, SSBD);
   else if (cpu_features->basic.kind == arch_kind_amd)
-    fails += CHECK_PROC (ssbd, AMD_SSBD);
+    {
+      /* This feature is implemented in 2 different ways on AMD processors:
+	 newer systems provides AMD_SSBD (function 8000_0008, EBX[24]),
+	 while older system proviseds AMD_VIRT_SSBD (function 8000_008,
+	 EBX[25]).  However for AMD_VIRT_SSBD, kernel shows both 'ssdb'
+	 and 'virt_ssdb' on /proc/cpuinfo; while for AMD_SSBD only 'ssdb'
+	 is provided.  */
+      if (HAS_CPU_FEATURE (AMD_SSBD))
+	fails += CHECK_PROC (ssbd, AMD_SSBD);
+      else if (HAS_CPU_FEATURE (AMD_VIRT_SSBD))
+	fails += CHECK_PROC (virt_ssbd, AMD_VIRT_SSBD);
+    }
   fails += CHECK_PROC (sse, SSE);
   fails += CHECK_PROC (sse2, SSE2);
   fails += CHECK_PROC (pni, SSE3);