On Wed, Nov 11, 2009 at 05:29:48PM -0200, Marcelo Tosatti wrote: > From: Joerg Roedel <joerg.roedel@xxxxxxx> > > The current KVM x86 exception code handles double and triple faults only for > page fault exceptions. This patch extends this detection for every exception > that gets queued for the guest. > > Signed-off-by: Joerg Roedel <joerg.roedel@xxxxxxx> > CC: Jan Kiszka <jan.kiszka@xxxxxx> > > Index: kvm/arch/x86/kvm/x86.c > =================================================================== > --- kvm.orig/arch/x86/kvm/x86.c > +++ kvm/arch/x86/kvm/x86.c > @@ -170,9 +170,21 @@ void kvm_set_apic_base(struct kvm_vcpu * > } > EXPORT_SYMBOL_GPL(kvm_set_apic_base); > > +static void handle_multiple_faults(struct kvm_vcpu *vcpu) > +{ > + if (vcpu->arch.exception.nr != DF_VECTOR) { > + vcpu->arch.exception.nr = DF_VECTOR; > + vcpu->arch.exception.error_code = 0; > + } else > + set_bit(KVM_REQ_TRIPLE_FAULT, &vcpu->requests); > +} > + Making #DF from two bening exceptions is very wrong. > void kvm_queue_exception(struct kvm_vcpu *vcpu, unsigned nr) > { > - WARN_ON(vcpu->arch.exception.pending); > + if (vcpu->arch.exception.pending) { > + handle_multiple_faults(vcpu); > + return; > + } > vcpu->arch.exception.pending = true; > vcpu->arch.exception.has_error_code = false; > vcpu->arch.exception.nr = nr; > @@ -184,24 +196,6 @@ void kvm_inject_page_fault(struct kvm_vc > { > ++vcpu->stat.pf_guest; > > - if (vcpu->arch.exception.pending) { > - switch(vcpu->arch.exception.nr) { > - case DF_VECTOR: > - /* triple fault -> shutdown */ > - set_bit(KVM_REQ_TRIPLE_FAULT, &vcpu->requests); > - return; > - case PF_VECTOR: > - vcpu->arch.exception.nr = DF_VECTOR; > - vcpu->arch.exception.error_code = 0; > - return; > - default: > - /* replace previous exception with a new one in a hope > - that instruction re-execution will regenerate lost > - exception */ > - vcpu->arch.exception.pending = false; > - break; When exceptions are handled serially previous exception have to be replaced by new one. Think about #PF during #DE. #PF should be handled first before #DE can proceed. > - } > - } > vcpu->arch.cr2 = addr; > kvm_queue_exception_e(vcpu, PF_VECTOR, error_code); > } > @@ -214,7 +208,10 @@ EXPORT_SYMBOL_GPL(kvm_inject_nmi); > > void kvm_queue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code) > { > - WARN_ON(vcpu->arch.exception.pending); > + if (vcpu->arch.exception.pending) { > + handle_multiple_faults(vcpu); > + return; > + } > vcpu->arch.exception.pending = true; > vcpu->arch.exception.has_error_code = true; > vcpu->arch.exception.nr = nr; > > -- -- Gleb. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html