From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gleb Natapov Subject: Re: [patch 1/2] KVM: x86: handle double and triple faults for every exception Date: Thu, 12 Nov 2009 14:26:59 +0200 Message-ID: <20091112122659.GC7392@redhat.com> References: <20091111192947.348198723@localhost.localdomain> <20091111193837.115825934@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, jan.kiszka@siemens.com, joerg.roedel@amd.com, Jan Kiszka To: Marcelo Tosatti Return-path: Received: from mx1.redhat.com ([209.132.183.28]:1026 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751173AbZKLM07 (ORCPT ); Thu, 12 Nov 2009 07:26:59 -0500 Content-Disposition: inline In-Reply-To: <20091111193837.115825934@localhost.localdomain> Sender: kvm-owner@vger.kernel.org List-ID: On Wed, Nov 11, 2009 at 05:29:48PM -0200, Marcelo Tosatti wrote: > From: Joerg Roedel > > 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 > CC: Jan Kiszka > > 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.