[PATCH v2 1/2] kvm: nVMX: NMI-window exiting should wake L2 from HLT

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



According to the SDM, "NMI-window exiting" VM-exits wake a logical
processor from the same inactive states as would an NMI. Specifically,
they wake a logical processor from the shutdown state and from the
states entered using the HLT and MWAIT instructions.

Fixes: 6dfacadd5858 ("KVM: nVMX: Add support for activity state HLT")
Signed-off-by: Jim Mattson <jmattson@xxxxxxxxxx>
Reviewed-by: Peter Shier <pshier@xxxxxxxxxx>
---
 arch/x86/kvm/vmx.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index d78fe0abf9ac..358e96f0c21d 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -13489,6 +13489,15 @@ static int nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,
 	return 1;
 }
 
+static bool nested_vmx_nmi_window_exit(struct vmcs12 *vmcs12)
+{
+	return (vmcs12->cpu_based_vm_exec_control &
+		CPU_BASED_VIRTUAL_NMI_PENDING) &&
+		vmcs12->guest_activity_state != GUEST_ACTIVITY_WAIT_SIPI &&
+		!(vmcs12->guest_interruptibility_info &
+		  (GUEST_INTR_STATE_NMI | GUEST_INTR_STATE_MOV_SS));
+}
+
 /*
  * nested_vmx_run() handles a nested entry, i.e., a VMLAUNCH or VMRESUME on L1
  * for running an L2 nested guest.
@@ -13580,11 +13589,13 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)
 	nested_cache_shadow_vmcs12(vcpu, vmcs12);
 
 	/*
-	 * If we're entering a halted L2 vcpu and the L2 vcpu won't be woken
-	 * by event injection, halt vcpu.
+	 * If we're entering a halted L2 vcpu and the L2 vcpu won't be
+	 * awakened by event injection or by an NMI-window VM-exit,
+	 * halt the vcpu.
 	 */
 	if ((vmcs12->guest_activity_state == GUEST_ACTIVITY_HLT) &&
-	    !(vmcs12->vm_entry_intr_info_field & INTR_INFO_VALID_MASK)) {
+	    !(vmcs12->vm_entry_intr_info_field & INTR_INFO_VALID_MASK) &&
+	    !nested_vmx_nmi_window_exit(vmcs12)) {
 		vmx->nested.nested_run_pending = 0;
 		return kvm_vcpu_halt(vcpu);
 	}
-- 
2.20.0.rc0.387.gc7a69e6b6c-goog




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux