[2/2] KVM: VMX: check for existence of secondary exec controls before accessing
diff mbox series

Message ID 20181001212534.20073-3-sean.j.christopherson@intel.com
State New
Headers show
Series
  • KVM: VMX: clean up virtual APIC control handling
Related show

Commit Message

Sean Christopherson Oct. 1, 2018, 9:25 p.m. UTC
Return early from vmx_set_virtual_apic_mode() if the processor doesn't
support VIRTUALIZE_APIC_ACCESSES or VIRTUALIZE_X2APIC_MODE, both of
which reside in SECONDARY_VM_EXEC_CONTROL.  This eliminates warnings
due to VMWRITEs to SECONDARY_VM_EXEC_CONTROL (VMCS field 401e) failing
on processors without secondary exec controls.

Remove the similar check for TPR shadowing as it is incorported in the
cpu_has_vmx_flexpriority() check and the APIC-related code in
vmx_update_msr_bitmap() is further gated by VIRTUALIZE_X2APIC_MODE.

Reported-by: Gerhard Wiesinger <redhat@wiesinger.com>
Fixes: 8d860bbeedef ("kvm: vmx: Basic APIC virtualization controls have three settings")
Cc: Jim Mattson <jmattson@google.com>
Cc: stable@vger.kernel.org
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/kvm/vmx.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Jim Mattson Oct. 1, 2018, 9:48 p.m. UTC | #1
On Mon, Oct 1, 2018 at 2:25 PM, Sean Christopherson
<sean.j.christopherson@intel.com> wrote:
> Return early from vmx_set_virtual_apic_mode() if the processor doesn't
> support VIRTUALIZE_APIC_ACCESSES or VIRTUALIZE_X2APIC_MODE, both of
> which reside in SECONDARY_VM_EXEC_CONTROL.  This eliminates warnings
> due to VMWRITEs to SECONDARY_VM_EXEC_CONTROL (VMCS field 401e) failing
> on processors without secondary exec controls.
>
> Remove the similar check for TPR shadowing as it is incorported in the
> cpu_has_vmx_flexpriority() check and the APIC-related code in
> vmx_update_msr_bitmap() is further gated by VIRTUALIZE_X2APIC_MODE.
>
> Reported-by: Gerhard Wiesinger <redhat@wiesinger.com>
> Fixes: 8d860bbeedef ("kvm: vmx: Basic APIC virtualization controls have three settings")
> Cc: Jim Mattson <jmattson@google.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>

In the context of part 1...

Reviewed-by: Jim Mattson <jmattson@google.com>

Patch
diff mbox series

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index e1b8ea9a2bc4..a3c864abf58d 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -10203,15 +10203,16 @@  static void vmx_set_virtual_apic_mode(struct kvm_vcpu *vcpu)
 	if (!lapic_in_kernel(vcpu))
 		return;
 
+	if (!cpu_has_vmx_flexpriority() &&
+	    !cpu_has_vmx_virtualize_x2apic_mode())
+		return;
+
 	/* Postpone execution until vmcs01 is the current VMCS. */
 	if (is_guest_mode(vcpu)) {
 		to_vmx(vcpu)->nested.change_vmcs01_virtual_apic_mode = true;
 		return;
 	}
 
-	if (!cpu_need_tpr_shadow(vcpu))
-		return;
-
 	sec_exec_control = vmcs_read32(SECONDARY_VM_EXEC_CONTROL);
 	sec_exec_control &= ~(SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES |
 			      SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE);