KVM: x86: Clear PV_UNHALT for !HLT-exiting only when userspace sets CPUID
authorSean Christopherson <seanjc@google.com>
Thu, 28 Nov 2024 01:33:59 +0000 (17:33 -0800)
committerSean Christopherson <seanjc@google.com>
Wed, 18 Dec 2024 22:19:55 +0000 (14:19 -0800)
commit63d8c702c2d41d070c84d97069a71ade808f8054
treee3a04acbce29baaf8428524910e49ee416dc37b1
parent8c01290bda1ab957c0b6d4640bdb351985a26123
KVM: x86: Clear PV_UNHALT for !HLT-exiting only when userspace sets CPUID

Now that KVM disallows disabling HLT-exiting after vCPUs have been created,
i.e. now that it's impossible for kvm_hlt_in_guest() to change while vCPUs
are running, apply KVM's PV_UNHALT quirk only when userspace is setting
guest CPUID.

Opportunistically rename the helper to make it clear that KVM's behavior
is a quirk that should never have been added.  KVM's documentation
explicitly states that userspace should not advertise PV_UNHALT if
HLT-exiting is disabled, but for unknown reasons, commit caa057a2cad6
("KVM: X86: Provide a capability to disable HLT intercepts") didn't stop
at documenting the requirement and also massaged the incoming guest CPUID.

Unfortunately, it's quite likely that userspace has come to rely on KVM's
behavior, i.e. the code can't simply be deleted.  The only reason KVM
doesn't have an "official" quirk is that there is no known use case where
disabling the quirk would make sense, i.e. letting userspace disable the
quirk would further increase KVM's burden without any benefit.

Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Link: https://lore.kernel.org/r/20241128013424.4096668-33-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/cpuid.c