Message ID | 1474515259-3197-1-git-send-email-wanpeng.li@hotmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 22/09/2016 05:34, Wanpeng Li wrote: > - if (vmx->rmode.vm86_active) { > - if (kvm_inject_realmode_interrupt(vcpu, NMI_VECTOR, 0) != EMULATE_DONE) > - kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); > - return; > + ++vcpu->stat.nmi_injections; > + vmx->nmi_known_unmasked = false; > + if (vmx->rmode.vm86_active) { > + if (kvm_inject_realmode_interrupt(vcpu, NMI_VECTOR, 0) != EMULATE_DONE) > + kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); > + return; > + } > } > vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, > INTR_TYPE_NMI_INTR | INTR_INFO_VALID_MASK | NMI_VECTOR); Hi, the patch is mostly okay but the "if (vmx->rmode.vm86_active)" part should be done also if the VCPU is in guest mode. See vmx_queue_exception for a similar example. I would like to know which processors lack virtual NMI support. I'd rather rip that code out... Thanks, Paolo -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
2016-09-22 17:37 GMT+08:00 Paolo Bonzini <pbonzini@redhat.com>: > > > On 22/09/2016 05:34, Wanpeng Li wrote: >> - if (vmx->rmode.vm86_active) { >> - if (kvm_inject_realmode_interrupt(vcpu, NMI_VECTOR, 0) != EMULATE_DONE) >> - kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); >> - return; >> + ++vcpu->stat.nmi_injections; >> + vmx->nmi_known_unmasked = false; >> + if (vmx->rmode.vm86_active) { >> + if (kvm_inject_realmode_interrupt(vcpu, NMI_VECTOR, 0) != EMULATE_DONE) >> + kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); >> + return; >> + } >> } >> vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, >> INTR_TYPE_NMI_INTR | INTR_INFO_VALID_MASK | NMI_VECTOR); > > Hi, > > the patch is mostly okay but the "if (vmx->rmode.vm86_active)" part > should be done also if the VCPU is in guest mode. See > vmx_queue_exception for a similar example. Thanks for pointing out. :) > > I would like to know which processors lack virtual NMI support. I'd > rather rip that code out... At least the Sandy Bridge server on my hand supports Virtual NMIs, I don't have machine older than this. Regards, Wanpeng Li -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 2016-09-22 11:45, Wanpeng Li wrote: > 2016-09-22 17:37 GMT+08:00 Paolo Bonzini <pbonzini@redhat.com>: >> >> >> On 22/09/2016 05:34, Wanpeng Li wrote: >>> - if (vmx->rmode.vm86_active) { >>> - if (kvm_inject_realmode_interrupt(vcpu, NMI_VECTOR, 0) != EMULATE_DONE) >>> - kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); >>> - return; >>> + ++vcpu->stat.nmi_injections; >>> + vmx->nmi_known_unmasked = false; >>> + if (vmx->rmode.vm86_active) { >>> + if (kvm_inject_realmode_interrupt(vcpu, NMI_VECTOR, 0) != EMULATE_DONE) >>> + kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); >>> + return; >>> + } >>> } >>> vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, >>> INTR_TYPE_NMI_INTR | INTR_INFO_VALID_MASK | NMI_VECTOR); >> >> Hi, >> >> the patch is mostly okay but the "if (vmx->rmode.vm86_active)" part >> should be done also if the VCPU is in guest mode. See >> vmx_queue_exception for a similar example. > > Thanks for pointing out. :) > >> >> I would like to know which processors lack virtual NMI support. I'd >> rather rip that code out... > > At least the Sandy Bridge server on my hand supports Virtual NMIs, I > don't have machine older than this. IIRC, my last-but-one notebook was lacking vNMI, and that was a Core 2 Duo. Maybe there are embedded product out there relying on this emulation, but I don't have any evidence. Jan
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 813658d..c883d73 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -5309,28 +5309,27 @@ static void vmx_inject_nmi(struct kvm_vcpu *vcpu) { struct vcpu_vmx *vmx = to_vmx(vcpu); - if (is_guest_mode(vcpu)) - return; - - if (!cpu_has_virtual_nmis()) { - /* - * Tracking the NMI-blocked state in software is built upon - * finding the next open IRQ window. This, in turn, depends on - * well-behaving guests: They have to keep IRQs disabled at - * least as long as the NMI handler runs. Otherwise we may - * cause NMI nesting, maybe breaking the guest. But as this is - * highly unlikely, we can live with the residual risk. - */ - vmx->soft_vnmi_blocked = 1; - vmx->vnmi_blocked_time = 0; - } + if (!is_guest_mode(vcpu)) { + if (!cpu_has_virtual_nmis()) { + /* + * Tracking the NMI-blocked state in software is built upon + * finding the next open IRQ window. This, in turn, depends on + * well-behaving guests: They have to keep IRQs disabled at + * least as long as the NMI handler runs. Otherwise we may + * cause NMI nesting, maybe breaking the guest. But as this is + * highly unlikely, we can live with the residual risk. + */ + vmx->soft_vnmi_blocked = 1; + vmx->vnmi_blocked_time = 0; + } - ++vcpu->stat.nmi_injections; - vmx->nmi_known_unmasked = false; - if (vmx->rmode.vm86_active) { - if (kvm_inject_realmode_interrupt(vcpu, NMI_VECTOR, 0) != EMULATE_DONE) - kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); - return; + ++vcpu->stat.nmi_injections; + vmx->nmi_known_unmasked = false; + if (vmx->rmode.vm86_active) { + if (kvm_inject_realmode_interrupt(vcpu, NMI_VECTOR, 0) != EMULATE_DONE) + kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); + return; + } } vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, INTR_TYPE_NMI_INTR | INTR_INFO_VALID_MASK | NMI_VECTOR);