Awkwardly, some new feature bits mean "Feature $X no longer works". Store these inverted in a featureset.
This permits safe zero-extending of a smaller featureset as part of a comparison, and safe reasoning (subset?, superset?, compatible? etc.) without specific knowldge of meaning of each bit. Signed-off-by: Andrew Cooper <andrew.coop...@citrix.com> --- CC: Jan Beulich <jbeul...@suse.com> --- xen/arch/x86/Makefile | 1 + xen/arch/x86/cpu/common.c | 3 +++ xen/arch/x86/cpu/cpu.h | 2 ++ xen/arch/x86/cpuid/Makefile | 1 + xen/arch/x86/cpuid/cpuid-private.h | 27 +++++++++++++++++++++++++++ xen/arch/x86/cpuid/cpuid.c | 16 ++++++++++++++++ xen/include/asm-x86/cpufeature.h | 2 +- xen/include/public/arch-x86/featureset.h | 7 ++++++- 8 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 xen/arch/x86/cpuid/Makefile create mode 100644 xen/arch/x86/cpuid/cpuid-private.h create mode 100644 xen/arch/x86/cpuid/cpuid.c diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile index 5f24951..122cbe9 100644 --- a/xen/arch/x86/Makefile +++ b/xen/arch/x86/Makefile @@ -1,5 +1,6 @@ subdir-y += acpi subdir-y += cpu +subdir-y += cpuid subdir-y += genapic subdir-y += hvm subdir-y += mm diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c index 87bd912..3496b13 100644 --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -323,6 +323,9 @@ void __cpuinit identify_cpu(struct cpuinfo_x86 *c) * The vendor-specific functions might have changed features. Now * we do "generic changes." */ + for (i = 0; i < XEN_NR_FEATURESET_ENTRIES; ++i) { + c->x86_capability[i] ^= inverted_features[i]; + } for (i = 0 ; i < NCAPINTS ; ++i) c->x86_capability[i] &= ~cleared_caps[i]; diff --git a/xen/arch/x86/cpu/cpu.h b/xen/arch/x86/cpu/cpu.h index 1877e7d..ca4048b 100644 --- a/xen/arch/x86/cpu/cpu.h +++ b/xen/arch/x86/cpu/cpu.h @@ -1,3 +1,5 @@ +#include "../cpuid/cpuid-private.h" + /* attempt to consolidate cpu attributes */ struct cpu_dev { char * c_vendor; diff --git a/xen/arch/x86/cpuid/Makefile b/xen/arch/x86/cpuid/Makefile new file mode 100644 index 0000000..3fb2e0b --- /dev/null +++ b/xen/arch/x86/cpuid/Makefile @@ -0,0 +1 @@ +obj-y += cpuid.o diff --git a/xen/arch/x86/cpuid/cpuid-private.h b/xen/arch/x86/cpuid/cpuid-private.h new file mode 100644 index 0000000..c8b47b3 --- /dev/null +++ b/xen/arch/x86/cpuid/cpuid-private.h @@ -0,0 +1,27 @@ +#ifdef __XEN__ + +#include <asm/cpufeature.h> + +#include <xen/lib.h> + +#else + +# error TODO for userspace + +#endif + +/* + * Bitmap of "anti" features which have their representation inverted when + * stored as a featureset. + */ +extern const uint32_t inverted_features[XEN_NR_FEATURESET_ENTRIES]; + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/cpuid/cpuid.c b/xen/arch/x86/cpuid/cpuid.c new file mode 100644 index 0000000..1578725 --- /dev/null +++ b/xen/arch/x86/cpuid/cpuid.c @@ -0,0 +1,16 @@ +#include "cpuid-private.h" + +const uint32_t inverted_features[XEN_NR_FEATURESET_ENTRIES] = +{ + [cpufeat_word(X86_FEATURE_FPU_SEL)] = cpufeat_mask(X86_FEATURE_FPU_SEL), +}; + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-x86/cpufeature.h b/xen/include/asm-x86/cpufeature.h index 87724a0..547ed7d 100644 --- a/xen/include/asm-x86/cpufeature.h +++ b/xen/include/asm-x86/cpufeature.h @@ -81,7 +81,7 @@ #define cpu_has_smep boot_cpu_has(X86_FEATURE_SMEP) #define cpu_has_smap boot_cpu_has(X86_FEATURE_SMAP) -#define cpu_has_fpu_sel (!boot_cpu_has(X86_FEATURE_NO_FPU_SEL)) +#define cpu_has_fpu_sel boot_cpu_has(X86_FEATURE_FPU_SEL) #define cpu_has_ffxsr ((boot_cpu_data.x86_vendor == X86_VENDOR_AMD) \ && boot_cpu_has(X86_FEATURE_FFXSR)) diff --git a/xen/include/public/arch-x86/featureset.h b/xen/include/public/arch-x86/featureset.h index 97e5c61..19abb98 100644 --- a/xen/include/public/arch-x86/featureset.h +++ b/xen/include/public/arch-x86/featureset.h @@ -35,6 +35,11 @@ * contain any synthesied values. New words may be added to the end of * featureset. * + * "Anti" features have their representation inverted. This permits safe + * zero-extending of a smaller featureset as part of a comparison, and safe + * reasoning (subset?, superset?, compatible? etc.) without specific knowldge + * of meaning of each bit. + * * All featureset words currently originate from leaves specified for the * CPUID instruction, but this is not preclude other sources of information. */ @@ -173,7 +178,7 @@ #define X86_FEATURE_INVPCID ( 5*32+10) /* Invalidate Process Context ID */ #define X86_FEATURE_RTM ( 5*32+11) /* Restricted Transactional Memory */ #define X86_FEATURE_CMT ( 5*32+12) /* Cache Monitoring Technology */ -#define X86_FEATURE_NO_FPU_SEL ( 5*32+13) /* FPU CS/DS stored as zero */ +#define X86_FEATURE_FPU_SEL ( 5*32+13) /* ! FPU CS/DS stored as zero */ #define X86_FEATURE_MPX ( 5*32+14) /* Memory Protection Extensions */ #define X86_FEATURE_CAT ( 5*32+15) /* Cache Allocation Technology */ #define X86_FEATURE_RDSEED ( 5*32+18) /* RDSEED instruction */ -- 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel