KVM: VMX: Rewrite vmx_complete_interrupt()'s twisted maze of if() statements

...with a more straightforward switch().

Also fix a bug when NMI could be dropped on exit. Although this should
never happen in practice, since NMIs can only be injected, never triggered
internally by the guest like exceptions.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
This commit is contained in:
Gleb Natapov 2009-03-30 16:03:13 +03:00 committed by Avi Kivity
parent 7b4a25cb29
commit 37b96e9880
1 changed files with 25 additions and 18 deletions

View File

@ -3277,7 +3277,6 @@ static void vmx_complete_interrupts(struct vcpu_vmx *vmx)
u8 vector; u8 vector;
int type; int type;
bool idtv_info_valid; bool idtv_info_valid;
u32 error;
idtv_info_valid = idt_vectoring_info & VECTORING_INFO_VALID_MASK; idtv_info_valid = idt_vectoring_info & VECTORING_INFO_VALID_MASK;
exit_intr_info = vmcs_read32(VM_EXIT_INTR_INFO); exit_intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
@ -3302,34 +3301,42 @@ static void vmx_complete_interrupts(struct vcpu_vmx *vmx)
vmx->vnmi_blocked_time += vmx->vnmi_blocked_time +=
ktime_to_ns(ktime_sub(ktime_get(), vmx->entry_time)); ktime_to_ns(ktime_sub(ktime_get(), vmx->entry_time));
vmx->vcpu.arch.nmi_injected = false;
kvm_clear_exception_queue(&vmx->vcpu);
kvm_clear_interrupt_queue(&vmx->vcpu);
if (!idtv_info_valid)
return;
vector = idt_vectoring_info & VECTORING_INFO_VECTOR_MASK; vector = idt_vectoring_info & VECTORING_INFO_VECTOR_MASK;
type = idt_vectoring_info & VECTORING_INFO_TYPE_MASK; type = idt_vectoring_info & VECTORING_INFO_TYPE_MASK;
if (vmx->vcpu.arch.nmi_injected) {
switch(type) {
case INTR_TYPE_NMI_INTR:
vmx->vcpu.arch.nmi_injected = true;
/* /*
* SDM 3: 27.7.1.2 (September 2008) * SDM 3: 27.7.1.2 (September 2008)
* Clear bit "block by NMI" before VM entry if a NMI delivery * Clear bit "block by NMI" before VM entry if a NMI
* faulted. * delivery faulted.
*/ */
if (idtv_info_valid && type == INTR_TYPE_NMI_INTR) vmcs_clear_bits(GUEST_INTERRUPTIBILITY_INFO,
vmcs_clear_bits(GUEST_INTERRUPTIBILITY_INFO, GUEST_INTR_STATE_NMI);
GUEST_INTR_STATE_NMI); break;
else case INTR_TYPE_HARD_EXCEPTION:
vmx->vcpu.arch.nmi_injected = false; case INTR_TYPE_SOFT_EXCEPTION:
}
kvm_clear_exception_queue(&vmx->vcpu);
if (idtv_info_valid && (type == INTR_TYPE_HARD_EXCEPTION ||
type == INTR_TYPE_SOFT_EXCEPTION)) {
if (idt_vectoring_info & VECTORING_INFO_DELIVER_CODE_MASK) { if (idt_vectoring_info & VECTORING_INFO_DELIVER_CODE_MASK) {
error = vmcs_read32(IDT_VECTORING_ERROR_CODE); u32 err = vmcs_read32(IDT_VECTORING_ERROR_CODE);
kvm_queue_exception_e(&vmx->vcpu, vector, error); kvm_queue_exception_e(&vmx->vcpu, vector, err);
} else } else
kvm_queue_exception(&vmx->vcpu, vector); kvm_queue_exception(&vmx->vcpu, vector);
vmx->idt_vectoring_info = 0; vmx->idt_vectoring_info = 0;
} break;
kvm_clear_interrupt_queue(&vmx->vcpu); case INTR_TYPE_EXT_INTR:
if (idtv_info_valid && type == INTR_TYPE_EXT_INTR) {
kvm_queue_interrupt(&vmx->vcpu, vector); kvm_queue_interrupt(&vmx->vcpu, vector);
vmx->idt_vectoring_info = 0; vmx->idt_vectoring_info = 0;
break;
default:
break;
} }
} }