Skip to content

Commit 0fea7aa

Browse files
committed
KVM: x86: Explicitly track feature flags that require vendor enabling
Add another CPUID feature macro, VENDOR_F(), and use it to track features that KVM supports, but that need additional vendor support and so are conditionally enabled in vendor code. Currently, VENDOR_F() is mostly just documentation, but tracking all KVM-supported features will allow for asserting, at build time, take), that all features that are set, cleared, *or* checked by KVM are known to kvm_set_cpu_caps(). To fudge around a macro collision on 32-bit kernels, #undef DS to be able to get at X86_FEATURE_DS. No functional change intended. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 9b2776c commit 0fea7aa

File tree

1 file changed

+43
-16
lines changed

1 file changed

+43
-16
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -779,12 +779,25 @@ do { \
779779
feature_bit(name); \
780780
})
781781

782+
/*
783+
* Vendor Features - For features that KVM supports, but are added in later
784+
* because they require additional vendor enabling.
785+
*/
786+
#define VENDOR_F(name) \
787+
({ \
788+
KVM_VALIDATE_CPU_CAP_USAGE(name); \
789+
0; \
790+
})
791+
782792
/*
783793
* Undefine the MSR bit macro to avoid token concatenation issues when
784794
* processing X86_FEATURE_SPEC_CTRL_SSBD.
785795
*/
786796
#undef SPEC_CTRL_SSBD
787797

798+
/* DS is defined by ptrace-abi.h on 32-bit builds. */
799+
#undef DS
800+
788801
void kvm_set_cpu_caps(void)
789802
{
790803
memset(kvm_cpu_caps, 0, sizeof(kvm_cpu_caps));
@@ -795,13 +808,14 @@ void kvm_set_cpu_caps(void)
795808
kvm_cpu_cap_init(CPUID_1_ECX,
796809
F(XMM3) |
797810
F(PCLMULQDQ) |
798-
0 /* DTES64 */ |
811+
VENDOR_F(DTES64) |
799812
/*
800813
* NOTE: MONITOR (and MWAIT) are emulated as NOP, but *not*
801814
* advertised to guests via CPUID!
802815
*/
803816
0 /* MONITOR */ |
804-
0 /* DS-CPL, VMX, SMX, EST */ |
817+
VENDOR_F(VMX) |
818+
0 /* DS-CPL, SMX, EST */ |
805819
0 /* TM2 */ |
806820
F(SSSE3) |
807821
0 /* CNXT-ID */ |
@@ -848,7 +862,9 @@ void kvm_set_cpu_caps(void)
848862
F(PSE36) |
849863
0 /* PSN */ |
850864
F(CLFLUSH) |
851-
0 /* Reserved, DS, ACPI */ |
865+
0 /* Reserved */ |
866+
VENDOR_F(DS) |
867+
0 /* ACPI */ |
852868
F(MMX) |
853869
F(FXSR) |
854870
F(XMM) |
@@ -871,7 +887,7 @@ void kvm_set_cpu_caps(void)
871887
F(INVPCID) |
872888
F(RTM) |
873889
F(ZERO_FCS_FDS) |
874-
0 /*MPX*/ |
890+
VENDOR_F(MPX) |
875891
F(AVX512F) |
876892
F(AVX512DQ) |
877893
F(RDSEED) |
@@ -880,7 +896,7 @@ void kvm_set_cpu_caps(void)
880896
F(AVX512IFMA) |
881897
F(CLFLUSHOPT) |
882898
F(CLWB) |
883-
0 /*INTEL_PT*/ |
899+
VENDOR_F(INTEL_PT) |
884900
F(AVX512PF) |
885901
F(AVX512ER) |
886902
F(AVX512CD) |
@@ -905,7 +921,7 @@ void kvm_set_cpu_caps(void)
905921
F(CLDEMOTE) |
906922
F(MOVDIRI) |
907923
F(MOVDIR64B) |
908-
0 /*WAITPKG*/ |
924+
VENDOR_F(WAITPKG) |
909925
F(SGX_LC) |
910926
F(BUS_LOCK_DETECT)
911927
);
@@ -1001,7 +1017,7 @@ void kvm_set_cpu_caps(void)
10011017
kvm_cpu_cap_init(CPUID_8000_0001_ECX,
10021018
F(LAHF_LM) |
10031019
F(CMP_LEGACY) |
1004-
0 /*SVM*/ |
1020+
VENDOR_F(SVM) |
10051021
0 /* ExtApicSpace */ |
10061022
F(CR8_LEGACY) |
10071023
F(ABM) |
@@ -1015,7 +1031,7 @@ void kvm_set_cpu_caps(void)
10151031
F(FMA4) |
10161032
F(TBM) |
10171033
F(TOPOEXT) |
1018-
0 /* PERFCTR_CORE */
1034+
VENDOR_F(PERFCTR_CORE)
10191035
);
10201036

10211037
kvm_cpu_cap_init(CPUID_8000_0001_EDX,
@@ -1101,17 +1117,27 @@ void kvm_set_cpu_caps(void)
11011117
!boot_cpu_has(X86_FEATURE_AMD_SSBD))
11021118
kvm_cpu_cap_set(X86_FEATURE_VIRT_SSBD);
11031119

1104-
/*
1105-
* Hide all SVM features by default, SVM will set the cap bits for
1106-
* features it emulates and/or exposes for L1.
1107-
*/
1108-
kvm_cpu_cap_init(CPUID_8000_000A_EDX, 0);
1120+
/* All SVM features required additional vendor module enabling. */
1121+
kvm_cpu_cap_init(CPUID_8000_000A_EDX,
1122+
VENDOR_F(NPT) |
1123+
VENDOR_F(VMCBCLEAN) |
1124+
VENDOR_F(FLUSHBYASID) |
1125+
VENDOR_F(NRIPS) |
1126+
VENDOR_F(TSCRATEMSR) |
1127+
VENDOR_F(V_VMSAVE_VMLOAD) |
1128+
VENDOR_F(LBRV) |
1129+
VENDOR_F(PAUSEFILTER) |
1130+
VENDOR_F(PFTHRESHOLD) |
1131+
VENDOR_F(VGIF) |
1132+
VENDOR_F(VNMI) |
1133+
VENDOR_F(SVME_ADDR_CHK)
1134+
);
11091135

11101136
kvm_cpu_cap_init(CPUID_8000_001F_EAX,
1111-
0 /* SME */ |
1112-
0 /* SEV */ |
1137+
VENDOR_F(SME) |
1138+
VENDOR_F(SEV) |
11131139
0 /* VM_PAGE_FLUSH */ |
1114-
0 /* SEV_ES */ |
1140+
VENDOR_F(SEV_ES) |
11151141
F(SME_COHERENT)
11161142
);
11171143

@@ -1183,6 +1209,7 @@ EXPORT_SYMBOL_GPL(kvm_set_cpu_caps);
11831209
#undef SYNTHESIZED_F
11841210
#undef PASSTHROUGH_F
11851211
#undef ALIASED_1_EDX_F
1212+
#undef VENDOR_F
11861213

11871214
struct kvm_cpuid_array {
11881215
struct kvm_cpuid_entry2 *entries;

0 commit comments

Comments
 (0)