KVM: VMX: Use proper accessor to read guest CR4 in handle_desc()
authorSean Christopherson <seanjc@google.com>
Thu, 13 Apr 2023 23:19:14 +0000 (16:19 -0700)
committerSean Christopherson <seanjc@google.com>
Fri, 26 May 2023 20:50:42 +0000 (13:50 -0700)
commit023cfa6fc200fc179dbf8e1857cc7140fa1466f9
tree9aeda27d691ceca8324877e259185ffc35455150
parent3243b93c16d90c2d63cf30655276ffdf5bb65bf7
KVM: VMX: Use proper accessor to read guest CR4 in handle_desc()

Use kvm_is_cr4_bit_set() to read guest CR4.UMIP when sanity checking that
a descriptor table VM-Exit occurs if and only if guest.CR4.UMIP=1.  UMIP
can't be guest-owned, i.e. using kvm_read_cr4_bits() to decache guest-
owned bits isn't strictly necessary, but eliminating raw reads of
vcpu->arch.cr4 is desirable as it makes it easy to visually audit KVM for
correctness.

Opportunistically add a compile-time assertion that UMIP isn't guest-owned
as letting the guest own UMIP isn't compatible with emulation (or any CR4
bit that is emulated by KVM).

Opportunistically change the WARN_ON() to a ONCE variant.  When the WARN
fires, it fires _a lot_, and spamming the kernel logs ends up doing more
harm than whatever led to KVM's unnecessary emulation.

Reported-by: Robert Hoo <robert.hu@intel.com>
Link: https://lore.kernel.org/all/20230310125718.1442088-4-robert.hu@intel.com
Link: https://lore.kernel.org/r/20230413231914.1482782-3-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/vmx/vmx.c