]> www.infradead.org Git - users/jedix/linux-maple.git/commit
KVM: x86: Query X86_FEATURE_MWAIT iff userspace owns the CPUID feature bit
authorSean Christopherson <seanjc@google.com>
Wed, 11 Dec 2024 01:33:01 +0000 (17:33 -0800)
committerSean Christopherson <seanjc@google.com>
Wed, 12 Feb 2025 18:16:32 +0000 (10:16 -0800)
commita487f6797c881460024ab45f2fea562bc377f02a
tree0e98067c3d48b01df3cb3a3f6806e48f9731b9a5
parent7e9f735e7ac4b95207e108ec67d04a9c4cb9cced
KVM: x86: Query X86_FEATURE_MWAIT iff userspace owns the CPUID feature bit

Rework MONITOR/MWAIT emulation to query X86_FEATURE_MWAIT if and only if
the MISC_ENABLE_NO_MWAIT quirk is enabled, in which case MWAIT is not a
dynamic, KVM-controlled CPUID feature.  KVM's funky ABI for that quirk is
to emulate MONITOR/MWAIT as nops if userspace sets MWAIT in guest CPUID.

For the case where KVM owns the MWAIT feature bit, check MISC_ENABLES
itself, i.e. check the actual control, not its reflection in guest CPUID.

Avoiding consumption of dynamic CPUID features will allow KVM to defer
runtime CPUID updates until kvm_emulate_cpuid(), i.e. until the updates
become visible to the guest.  Alternatively, KVM could play other games
with runtime CPUID updates, e.g. by precisely specifying which feature
bits to update, but doing so adds non-trivial complexity and doesn't solve
the underlying issue of unnecessary updates causing meaningful overhead
for nested virtualization roundtrips.

Link: https://lore.kernel.org/r/20241211013302.1347853-5-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/x86.c