V10 [PATCH] x86: Support usable check for all CPU features
H.J. Lu
hjl.tools@gmail.com
Sun Jul 12 12:36:53 GMT 2020
On Wed, Jul 8, 2020 at 9:32 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Wed, Jul 08, 2020 at 05:49:25PM +0200, Florian Weimer wrote:
> > * H. J. Lu:
> >
> > > + /* Before COMMON_CPUID_INDEX_80000001, clear the unknown usable bits
> > > + and the always zero bits. */
> > > + CPU_FEATURE_UNSET (cpu_features, INDEX_1_ECX_16);
> > > + CPU_FEATURE_UNSET (cpu_features, INDEX_1_ECX_31);
> > > + CPU_FEATURE_UNSET (cpu_features, INDEX_1_EDX_10);
> > > + CPU_FEATURE_UNSET (cpu_features, INDEX_1_EDX_20);
> > > + CPU_FEATURE_UNSET (cpu_features, INDEX_1_EDX_30);
> > > + CPU_FEATURE_UNSET (cpu_features, INDEX_7_EBX_6);
> > > + CPU_FEATURE_UNSET (cpu_features, INDEX_7_EBX_22);
> >
> > INDEX_7_EBX_13 is missing, I think.
>
> Bit 13: Deprecates FPU CS and FPU DS values if 1. I added DEPR_FPU_CS_DS.
>
> >
> > > + CPU_FEATURE_UNSET (cpu_features, INDEX_7_ECX_13);
> > > + CPU_FEATURE_UNSET (cpu_features, INDEX_7_ECX_15);
> > > + CPU_FEATURE_UNSET (cpu_features, INDEX_7_ECX_16);
> > > + CPU_FEATURE_UNSET (cpu_features, INDEX_7_ECX_23);
> > > + CPU_FEATURE_UNSET (cpu_features, INDEX_7_ECX_24);
> > > + CPU_FEATURE_UNSET (cpu_features, INDEX_7_ECX_26);
> >
> > INDEX_7_ECX_17 and four more are missing.
>
> Bits 17-21: The value of MAWAU used by the BNDLDX and BNDSTX instructions
> in 64-bit mode for MPX. Since MPX has been deprecated, I added
>
> CPU_FEATURE_UNSET (cpu_features, MPX);
>
> >
> > We do not mask unknown flags in the EAX and EDX registers, those are
> > copied unconditionally. Is this a problem?
> >
>
> EDX are checked. Did you mean EAX/EBX from INDEX_1 and EAX from INDEX_7?
> They aren't used for CPU feature detection.
>
> Here is the updated patch. OK for master?
>
> Thanks.
>
> H.J.
> --
> Support usable check for all CPU features with the following changes:
>
> 1. Change struct cpu_features to
>
> struct cpuid_features
> {
> struct cpuid_registers cpuid;
> struct cpuid_registers usable;
> };
>
> struct cpu_features
> {
> struct cpu_features_basic basic;
> struct cpuid_features features[COMMON_CPUID_INDEX_MAX];
> unsigned int preferred[PREFERRED_FEATURE_INDEX_MAX];
> ...
> };
>
> so that there is a usable bit for each cpuid bit.
> 2. After the cpuid bits have been initialized, copy the known bits to the
> usable bits. EAX/EBX from INDEX_1 and EAX from INDEX_7 aren't used for
> CPU feature detection.
> 3. Clear the usable bits which require OS support.
> 4. If the feature is supported by OS, copy its cpuid bit to its usable
> bit.
> 5. Replace HAS_CPU_FEATURE and CPU_FEATURES_CPU_P with CPU_FEATURE_USABLE
> and CPU_FEATURE_USABLE_P to check if a feature is usable.
> 6. Add DEPR_FPU_CS_DS for INDEX_7_EBX_13.
> 7. Unset MPX feature since it has been deprecated.
>
> The results are
>
> 1. If the feature is known and doesn't requre OS support, its usable bit
> is copied from the cpuid bit.
> 2. Otherwise, its usable bit is copied from the cpuid bit only if the
> feature is known to supported by OS.
> 3. CPU_FEATURE_USABLE/CPU_FEATURE_USABLE_P are used to check if the
> feature can be used.
> 4. HAS_CPU_FEATURE/CPU_FEATURE_CPU_P are used to check if CPU supports
> the feature.
I will check it:
https://sourceware.org/pipermail/libc-alpha/2020-July/116035.html
in next Monday if there are no further comments.
Thanks.
--
H.J.
More information about the Libc-alpha
mailing list