Skip to content

Commit ac9d1b7

Browse files
committed
KVM: x86: Explicitly track feature flags that are enabled at runtime
Add one last (hopefully) CPUID feature macro, RUNTIME_F(), and use it to track features that KVM supports, but that are only set at runtime (in response to other state), and aren't advertised to userspace via KVM_GET_SUPPORTED_CPUID. Currently, RUNTIME_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(). No functional change intended. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 0fea7aa commit ac9d1b7

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,16 @@ do { \
789789
0; \
790790
})
791791

792+
/*
793+
* Runtime Features - For features that KVM dynamically sets/clears at runtime,
794+
* e.g. when CR4 changes, but which are never advertised to userspace.
795+
*/
796+
#define RUNTIME_F(name) \
797+
({ \
798+
KVM_VALIDATE_CPU_CAP_USAGE(name); \
799+
0; \
800+
})
801+
792802
/*
793803
* Undefine the MSR bit macro to avoid token concatenation issues when
794804
* processing X86_FEATURE_SPEC_CTRL_SSBD.
@@ -811,9 +821,11 @@ void kvm_set_cpu_caps(void)
811821
VENDOR_F(DTES64) |
812822
/*
813823
* NOTE: MONITOR (and MWAIT) are emulated as NOP, but *not*
814-
* advertised to guests via CPUID!
824+
* advertised to guests via CPUID! MWAIT is also technically a
825+
* runtime flag thanks to IA32_MISC_ENABLES; mark it as such so
826+
* that KVM is aware that it's a known, unadvertised flag.
815827
*/
816-
0 /* MONITOR */ |
828+
RUNTIME_F(MWAIT) |
817829
VENDOR_F(VMX) |
818830
0 /* DS-CPL, SMX, EST */ |
819831
0 /* TM2 */ |
@@ -834,7 +846,7 @@ void kvm_set_cpu_caps(void)
834846
EMULATED_F(TSC_DEADLINE_TIMER) |
835847
F(AES) |
836848
F(XSAVE) |
837-
0 /* OSXSAVE */ |
849+
RUNTIME_F(OSXSAVE) |
838850
F(AVX) |
839851
F(F16C) |
840852
F(RDRAND) |
@@ -908,7 +920,7 @@ void kvm_set_cpu_caps(void)
908920
F(AVX512VBMI) |
909921
PASSTHROUGH_F(LA57) |
910922
F(PKU) |
911-
0 /*OSPKE*/ |
923+
RUNTIME_F(OSPKE) |
912924
F(RDPID) |
913925
F(AVX512_VPOPCNTDQ) |
914926
F(UMIP) |
@@ -1210,6 +1222,7 @@ EXPORT_SYMBOL_GPL(kvm_set_cpu_caps);
12101222
#undef PASSTHROUGH_F
12111223
#undef ALIASED_1_EDX_F
12121224
#undef VENDOR_F
1225+
#undef RUNTIME_F
12131226

12141227
struct kvm_cpuid_array {
12151228
struct kvm_cpuid_entry2 *entries;

0 commit comments

Comments
 (0)