x86: Add PTWRITE feature detection [BZ #27346]

1. Add CPUID_INDEX_14_ECX_0 for CPUID leaf 0x14 to detect PTWRITE feature
in EBX of CPUID leaf 0x14 with ECX == 0.
2. Add PTWRITE detection to CPU feature tests.
3. Add 2 static CPU feature tests.
This commit is contained in:
H.J. Lu 2021-02-04 10:39:34 -08:00
parent c3479fb793
commit 5ab25c8875
10 changed files with 47 additions and 5 deletions

View File

@ -487,6 +487,9 @@ extended state management using XSAVE/XRSTOR.
@item
@code{PSN} -- Processor Serial Number.
@item
@code{PTWRITE} -- PTWRITE instruction.
@item
@code{RDPID} -- RDPID instruction.

View File

@ -8,8 +8,11 @@ sysdep-dl-routines += dl-get-cpu-features
sysdep_headers += sys/platform/x86.h
tests += tst-get-cpu-features tst-get-cpu-features-static \
tst-cpu-features-cpuinfo tst-cpu-features-supports
tests-static += tst-get-cpu-features-static
tst-cpu-features-cpuinfo tst-cpu-features-cpuinfo-static \
tst-cpu-features-supports tst-cpu-features-supports-static
tests-static += tst-get-cpu-features-static \
tst-cpu-features-cpuinfo-static \
tst-cpu-features-supports-static
ifeq (yes,$(have-ifunc))
tests += \
tst-ifunc-isa-1 \

View File

@ -29,7 +29,8 @@ enum
CPUID_INDEX_80000007,
CPUID_INDEX_80000008,
CPUID_INDEX_7_ECX_1,
CPUID_INDEX_19
CPUID_INDEX_19,
CPUID_INDEX_14_ECX_0
};
struct cpuid_feature
@ -295,5 +296,11 @@ enum
+ cpuid_register_index_ebx * 8 * sizeof (unsigned int)),
x86_cpu_AESKLE = x86_cpu_index_19_ebx,
x86_cpu_WIDE_KL = x86_cpu_index_19_ebx + 2
x86_cpu_WIDE_KL = x86_cpu_index_19_ebx + 2,
x86_cpu_index_14_ecx_0_ebx
= (CPUID_INDEX_14_ECX_0 * 8 * 4 * sizeof (unsigned int)
+ cpuid_register_index_ebx * 8 * sizeof (unsigned int)),
x86_cpu_PTWRITE = x86_cpu_index_14_ecx_0_ebx + 4
};

View File

@ -97,6 +97,7 @@ update_usable (struct cpu_features *cpu_features)
CPU_FEATURE_SET_USABLE (cpu_features, FZLRM);
CPU_FEATURE_SET_USABLE (cpu_features, FSRS);
CPU_FEATURE_SET_USABLE (cpu_features, FSRCS);
CPU_FEATURE_SET_USABLE (cpu_features, PTWRITE);
/* Can we call xgetbv? */
if (CPU_FEATURES_CPU_P (cpu_features, OSXSAVE))
@ -359,6 +360,13 @@ get_common_indices (struct cpu_features *cpu_features,
cpu_features->features[CPUID_INDEX_D_ECX_1].cpuid.ecx,
cpu_features->features[CPUID_INDEX_D_ECX_1].cpuid.edx);
if (cpu_features->basic.max_cpuid >= 0x14)
__cpuid_count (0x14, 0,
cpu_features->features[CPUID_INDEX_14_ECX_0].cpuid.eax,
cpu_features->features[CPUID_INDEX_14_ECX_0].cpuid.ebx,
cpu_features->features[CPUID_INDEX_14_ECX_0].cpuid.ecx,
cpu_features->features[CPUID_INDEX_14_ECX_0].cpuid.edx);
if (cpu_features->basic.max_cpuid >= 0x19)
__cpuid_count (0x19, 0,
cpu_features->features[CPUID_INDEX_19].cpuid.eax,

View File

@ -29,7 +29,7 @@
enum
{
CPUID_INDEX_MAX = CPUID_INDEX_19 + 1
CPUID_INDEX_MAX = CPUID_INDEX_14_ECX_0 + 1
};
enum
@ -307,6 +307,11 @@ enum
#define bit_cpu_AESKLE (1u << 0)
#define bit_cpu_WIDE_KL (1u << 2)
/* CPUID_INDEX_14_ECX_0. */
/* EBX. */
#define bit_cpu_PTWRITE (1u << 4)
/* CPUID_INDEX_1. */
/* ECX. */
@ -532,6 +537,11 @@ enum
#define index_cpu_AESKLE CPUID_INDEX_19
#define index_cpu_WIDE_KL CPUID_INDEX_19
/* CPUID_INDEX_14_ECX_0. */
/* EBX. */
#define index_cpu_PTWRITE CPUID_INDEX_14_ECX_0
/* CPUID_INDEX_1. */
/* ECX. */
@ -757,6 +767,11 @@ enum
#define reg_AESKLE ebx
#define reg_WIDE_KL ebx
/* CPUID_INDEX_14_ECX_0. */
/* EBX. */
#define reg_PTWRITE ebx
/* PREFERRED_FEATURE_INDEX_1. */
#define bit_arch_I586 (1u << 0)
#define bit_arch_I686 (1u << 1)

View File

@ -0,0 +1 @@
#include "tst-cpu-features-cpuinfo.c"

View File

@ -199,6 +199,7 @@ do_test (int argc, char **argv)
fails += CHECK_PROC (popcnt, POPCNT);
fails += CHECK_PROC (3dnowprefetch, PREFETCHW);
fails += CHECK_PROC (prefetchwt1, PREFETCHWT1);
fails += CHECK_PROC (ptwrite, PTWRITE);
fails += CHECK_PROC (pse, PSE);
fails += CHECK_PROC (pse36, PSE_36);
fails += CHECK_PROC (psn, PSN);

View File

@ -0,0 +1 @@
#include "tst-cpu-features-supports.c"

View File

@ -149,6 +149,7 @@ do_test (int argc, char **argv)
fails += CHECK_SUPPORTS (popcnt, POPCNT);
#if __GNUC_PREREQ (11, 0)
fails += CHECK_SUPPORTS (prefetchwt1, PREFETCHWT1);
fails += CHECK_SUPPORTS (ptwrite, PTWRITE);
fails += CHECK_SUPPORTS (rdpid, RDPID);
fails += CHECK_SUPPORTS (rdrnd, RDRAND);
fails += CHECK_SUPPORTS (rdseed, RDSEED);

View File

@ -203,6 +203,7 @@ do_test (void)
CHECK_CPU_FEATURE (LAM);
CHECK_CPU_FEATURE (AESKLE);
CHECK_CPU_FEATURE (WIDE_KL);
CHECK_CPU_FEATURE (PTWRITE);
printf ("Usable CPU features:\n");
CHECK_CPU_FEATURE_USABLE (SSE3);
@ -364,6 +365,7 @@ do_test (void)
CHECK_CPU_FEATURE_USABLE (FSRCS);
CHECK_CPU_FEATURE_USABLE (AESKLE);
CHECK_CPU_FEATURE_USABLE (WIDE_KL);
CHECK_CPU_FEATURE_USABLE (PTWRITE);
return 0;
}