x86: Check SSBD and STIBP only on Intel CPUs

Message ID CAMe9rOqaQyWdRaDw8jxCTzLSuS0J0-0fTOk5tEsfaGfCKVU1mA@mail.gmail.com
State New
Headers show
Series
  • x86: Check SSBD and STIBP only on Intel CPUs
Related show

Commit Message

DJ Delorie via Libc-alpha Jan. 30, 2021, 1:59 p.m.
On Sat, Jan 30, 2021 at 2:26 AM Winfried Magerl
<winfried.magerl@t-online.de> wrote:
>

> Hello,

>

> On Sat, Jan 30, 2021 at 09:34:56AM +0100, Winfried Magerl wrote:

> > Hello,

> >

> > I got a suspicious error when building current upcoming glibc-2.33:

> >

> > FAIL: elf/tst-cpu-features-cpuinfo

> >

> > The relavant details from elf/tst-cpu-features-cpuinfo.out

> > (likely invariant_tsc can be ignored):

> >

> > Checking HAS_CPU_FEATURE (INVARIANT_TSC):

> >   HAS_CPU_FEATURE (INVARIANT_TSC): 1

> >   cpuinfo (invariant_tsc): 0

> >  *** missing in /proc/cpuinfo ***

> > Checking HAS_CPU_FEATURE (SSBD):

> >   HAS_CPU_FEATURE (SSBD): 0

> >   cpuinfo (ssbd): 1

> >  *** failure ***

> > Checking HAS_CPU_FEATURE (STIBP):

> >   HAS_CPU_FEATURE (STIBP): 0

> >   cpuinfo (stibp): 1

> >  *** failure ***

> > 2 differences between /proc/cpuinfo and glibc code.

> >

> > The details of the build-system:

> >       cpu:            AMD Ryzen 9 3900X 12-Core Processor

> >       os:             openSUSE Tumbleweed 20210128

> >       gcc:            gcc-10-3.1.x86_64

> >       binutils:       binutils-2.35.1-1.1

>

> the missing kernel-version:

>         openSUSE:       kernel-default-5.10.9-1.2.x86_64

>

> also tested with vanilla-kernels with identical result:

>         linux-5.9.16

>         linux-5.11-rc5

>

> > Maybe this helps to track down the problem. From a quick look it's

> > likely uncritical because the feature is simply missing (as opposed

> > to a missdetected non-existing feature).


Try this.

-- 
H.J.

Comments

Winfried Magerl Jan. 30, 2021, 4:26 p.m. | #1
Hello,

On Sat, Jan 30, 2021 at 05:59:55AM -0800, H.J. Lu via Libc-alpha wrote:
> On Sat, Jan 30, 2021 at 2:26 AM Winfried Magerl

> <winfried.magerl@t-online.de> wrote:

> >

> > Hello,

> >

> > On Sat, Jan 30, 2021 at 09:34:56AM +0100, Winfried Magerl wrote:

> > > Hello,

> > >

> > > I got a suspicious error when building current upcoming glibc-2.33:

> > >

> > > FAIL: elf/tst-cpu-features-cpuinfo

> > >

> > > The relavant details from elf/tst-cpu-features-cpuinfo.out

> > > (likely invariant_tsc can be ignored):

> > >

> > > Checking HAS_CPU_FEATURE (INVARIANT_TSC):

> > >   HAS_CPU_FEATURE (INVARIANT_TSC): 1

> > >   cpuinfo (invariant_tsc): 0

> > >  *** missing in /proc/cpuinfo ***

> > > Checking HAS_CPU_FEATURE (SSBD):

> > >   HAS_CPU_FEATURE (SSBD): 0

> > >   cpuinfo (ssbd): 1

> > >  *** failure ***

> > > Checking HAS_CPU_FEATURE (STIBP):

> > >   HAS_CPU_FEATURE (STIBP): 0

> > >   cpuinfo (stibp): 1

> > >  *** failure ***

> > > 2 differences between /proc/cpuinfo and glibc code.

> > >

> > > The details of the build-system:

> > >       cpu:            AMD Ryzen 9 3900X 12-Core Processor

> > >       os:             openSUSE Tumbleweed 20210128

> > >       gcc:            gcc-10-3.1.x86_64

> > >       binutils:       binutils-2.35.1-1.1

> >

> > the missing kernel-version:

> >         openSUSE:       kernel-default-5.10.9-1.2.x86_64

> >

> > also tested with vanilla-kernels with identical result:

> >         linux-5.9.16

> >         linux-5.11-rc5

> >

> > > Maybe this helps to track down the problem. From a quick look it's

> > > likely uncritical because the feature is simply missing (as opposed

> > > to a missdetected non-existing feature).

> 

> Try this.


Thank you!

I can confirm that the patch results in a successfull run of the test.

The expected result when the check for ssbd and stibp is done for
intel-cpus only.

regards

	winfried

Patch

From 132ba6e1daf5463975467cf3af5ec0f0602d96e9 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Sat, 30 Jan 2021 05:44:40 -0800
Subject: [PATCH] x86: Check SSBD and STIBP only on Intel CPUs

Since /proc/cpuinfo reports different SSBD and STIBP on AMD CPUs, check
SSBD and STIBP only on Intel CPUs.  Also /proc/cpuinfo doesn't report
IBRS_IBPB.
---
 sysdeps/x86/tst-cpu-features-cpuinfo.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/sysdeps/x86/tst-cpu-features-cpuinfo.c b/sysdeps/x86/tst-cpu-features-cpuinfo.c
index 3c2fa7d9b6..ebe7337ab8 100644
--- a/sysdeps/x86/tst-cpu-features-cpuinfo.c
+++ b/sysdeps/x86/tst-cpu-features-cpuinfo.c
@@ -16,7 +16,7 @@ 
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <sys/platform/x86.h>
+#include <cpu-features.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -99,6 +99,7 @@  static int
 do_test (int argc, char **argv)
 {
   int fails = 0;
+  const struct cpu_features *cpu_features = __get_cpu_features ();
 
   get_cpuinfo ();
   fails += CHECK_PROC (acpi, ACPI);
@@ -159,7 +160,10 @@  do_test (int argc, char **argv)
   fails += CHECK_PROC (hle, HLE);
   fails += CHECK_PROC (ht, HTT);
   fails += CHECK_PROC (hybrid, HYBRID);
-  fails += CHECK_PROC (ibrs, IBRS_IBPB);
+#if 0
+  /* NB: /proc/cpuinfo doesn't report this feature.  */
+  fails += CHECK_PROC (ibrs_ibpb, IBRS_IBPB);
+#endif
   fails += CHECK_PROC (ibt, IBT);
   fails += CHECK_PROC (invariant_tsc, INVARIANT_TSC);
   fails += CHECK_PROC (invpcid, INVPCID);
@@ -220,7 +224,9 @@  do_test (int argc, char **argv)
   fails += CHECK_PROC (smep, SMEP);
   fails += CHECK_PROC (smx, SMX);
   fails += CHECK_PROC (ss, SS);
-  fails += CHECK_PROC (ssbd, SSBD);
+  /* NB: /proc/cpuinfo reports different SSBD on AMD CPUs.  */
+  if (cpu_features->basic.kind == arch_kind_intel)
+    fails += CHECK_PROC (ssbd, SSBD);
   fails += CHECK_PROC (sse, SSE);
   fails += CHECK_PROC (sse2, SSE2);
   fails += CHECK_PROC (pni, SSE3);
@@ -228,7 +234,9 @@  do_test (int argc, char **argv)
   fails += CHECK_PROC (sse4_2, SSE4_2);
   fails += CHECK_PROC (sse4a, SSE4A);
   fails += CHECK_PROC (ssse3, SSSE3);
-  fails += CHECK_PROC (stibp, STIBP);
+  /* NB: /proc/cpuinfo reports different STIBP on AMD CPUs.  */
+  if (cpu_features->basic.kind == arch_kind_intel)
+    fails += CHECK_PROC (stibp, STIBP);
   fails += CHECK_PROC (svm, SVM);
 #ifdef __x86_64__
   /* NB: SYSCALL_SYSRET is 64-bit only.  */
-- 
2.29.2