]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: x86: Explicitly track feature flags that are enabled at runtime
authorSean Christopherson <seanjc@google.com>
Thu, 28 Nov 2024 01:34:23 +0000 (17:34 -0800)
committerSean Christopherson <seanjc@google.com>
Wed, 18 Dec 2024 22:20:22 +0000 (14:20 -0800)
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: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/cpuid.c

index 79a569bdb121e7f644819d8f58cee963deaea49a..f35f99b27d02d9497997d8aa0af896613f585a53 100644 (file)
@@ -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;