diff mbox series

[v2] x86: Check SSBD and STIBP only on Intel CPUs

Message ID 20210202145733.545020-1-hjl.tools@gmail.com
State Under Review
Delegated to: Carlos O'Donell
Headers show
Series [v2] x86: Check SSBD and STIBP only on Intel CPUs | expand

Commit Message

H.J. Lu Feb. 2, 2021, 2:57 p.m. UTC
1. Since /proc/cpuinfo reports different SSBD and STIBP on AMD CPUs,
check SSBD and STIBP only on Intel CPUs.
2. Since init_speculation_control() in Linux kernel maps SPEC_CTRL (aka
IBRS_IBPB) to IBRS and IBPB, skip IBRS_IBPB.
3. Remove "#if 0" on OSXSAVE with a comment.
---
 sysdeps/x86/tst-cpu-features-cpuinfo.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/sysdeps/x86/tst-cpu-features-cpuinfo.c b/sysdeps/x86/tst-cpu-features-cpuinfo.c
index 3c2fa7d9b6..95cefb5738 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,8 @@  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);
+  /* NB: Skip IBRS_IBPB since init_speculation_control() in Linux kernel
+     maps SPEC_CTRL (aka IBRS_IBPB) to IBRS and IBPB.  */
   fails += CHECK_PROC (ibt, IBT);
   fails += CHECK_PROC (invariant_tsc, INVARIANT_TSC);
   fails += CHECK_PROC (invpcid, INVPCID);
@@ -181,10 +183,7 @@  do_test (int argc, char **argv)
   fails += CHECK_PROC (mtrr, MTRR);
   fails += CHECK_PROC (nx, NX);
   fails += CHECK_PROC (ospke, OSPKE);
-#if 0
-  /* NB: /proc/cpuinfo doesn't report this feature.  */
-  fails += CHECK_PROC (osxsave, OSXSAVE);
-#endif
+  /* NB: Skip OSXSAVE since /proc/cpuinfo doesn't report this feature.  */
   fails += CHECK_PROC (pae, PAE);
   fails += CHECK_PROC (pdpe1gb, PAGE1GB);
   fails += CHECK_PROC (pat, PAT);
@@ -220,7 +219,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 +229,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.  */