[PATCH v2] x86: Check SSBD and STIBP only on Intel CPUs
H.J. Lu
hjl.tools@gmail.com
Tue Feb 2 14:57:33 GMT 2021
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 --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. */
--
2.29.2
More information about the Libc-alpha
mailing list