Commit ac9d1b75 authored by Sean Christopherson's avatar Sean Christopherson
Browse files

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/20241128013424.4096668-57-seanjc@google.com


Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
parent 0fea7aa2
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -789,6 +789,16 @@ do { \
	0;							\
})

/*
 * Runtime Features - For features that KVM dynamically sets/clears at runtime,
 * e.g. when CR4 changes, but which are never advertised to userspace.
 */
#define RUNTIME_F(name)						\
({								\
	KVM_VALIDATE_CPU_CAP_USAGE(name);			\
	0;							\
})

/*
 * Undefine the MSR bit macro to avoid token concatenation issues when
 * processing X86_FEATURE_SPEC_CTRL_SSBD.
@@ -811,9 +821,11 @@ void kvm_set_cpu_caps(void)
		VENDOR_F(DTES64) |
		/*
		 * NOTE: MONITOR (and MWAIT) are emulated as NOP, but *not*
		 * advertised to guests via CPUID!
		 * advertised to guests via CPUID!  MWAIT is also technically a
		 * runtime flag thanks to IA32_MISC_ENABLES; mark it as such so
		 * that KVM is aware that it's a known, unadvertised flag.
		 */
		0 /* MONITOR */ |
		RUNTIME_F(MWAIT) |
		VENDOR_F(VMX) |
		0 /* DS-CPL, SMX, EST */ |
		0 /* TM2 */ |
@@ -834,7 +846,7 @@ void kvm_set_cpu_caps(void)
		EMULATED_F(TSC_DEADLINE_TIMER) |
		F(AES) |
		F(XSAVE) |
		0 /* OSXSAVE */ |
		RUNTIME_F(OSXSAVE) |
		F(AVX) |
		F(F16C) |
		F(RDRAND) |
@@ -908,7 +920,7 @@ void kvm_set_cpu_caps(void)
		F(AVX512VBMI) |
		PASSTHROUGH_F(LA57) |
		F(PKU) |
		0 /*OSPKE*/ |
		RUNTIME_F(OSPKE) |
		F(RDPID) |
		F(AVX512_VPOPCNTDQ) |
		F(UMIP) |
@@ -1210,6 +1222,7 @@ EXPORT_SYMBOL_GPL(kvm_set_cpu_caps);
#undef PASSTHROUGH_F
#undef ALIASED_1_EDX_F
#undef VENDOR_F
#undef RUNTIME_F

struct kvm_cpuid_array {
	struct kvm_cpuid_entry2 *entries;