From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joerg Roedel Subject: Re: [PATCH] x86: handle double and triple faults for every exception Date: Wed, 30 Apr 2008 11:48:43 +0200 Message-ID: <20080430094843.GB6567@amd.com> References: <1209481325-14892-1-git-send-email-joerg.roedel@amd.com> <48183198.1050508@siemens.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm-devel@lists.sourceforge.net, Avi Kivity To: Jan Kiszka Return-path: Content-Disposition: inline In-Reply-To: <48183198.1050508@siemens.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces@lists.sourceforge.net Errors-To: kvm-devel-bounces@lists.sourceforge.net List-Id: kvm.vger.kernel.org On Wed, Apr 30, 2008 at 10:45:12AM +0200, Jan Kiszka wrote: > Joerg Roedel wrote: > > 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 > > --- > > arch/x86/kvm/x86.c | 31 +++++++++++++++++-------------- > > 1 files changed, 17 insertions(+), 14 deletions(-) > > > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > index 578a0c1..c05aa32 100644 > > --- a/arch/x86/kvm/x86.c > > +++ b/arch/x86/kvm/x86.c > > @@ -144,9 +144,21 @@ void kvm_set_apic_base(struct kvm_vcpu *vcpu, u64 data) > > } > > 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); > > +} > > + > > 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; > > @@ -157,25 +169,16 @@ void kvm_inject_page_fault(struct kvm_vcpu *vcpu, unsigned long addr, > > u32 error_code) > > { > > ++vcpu->stat.pf_guest; > > - if (vcpu->arch.exception.pending) { > > - if (vcpu->arch.exception.nr == PF_VECTOR) { > > - printk(KERN_DEBUG "kvm: inject_page_fault:" > > - " double fault 0x%lx\n", addr); > > - vcpu->arch.exception.nr = DF_VECTOR; > > - vcpu->arch.exception.error_code = 0; > > - } else if (vcpu->arch.exception.nr == DF_VECTOR) { > > - /* triple fault -> shutdown */ > > - set_bit(KVM_REQ_TRIPLE_FAULT, &vcpu->requests); > > - } > > - return; > > - } > > vcpu->arch.cr2 = addr; > > kvm_queue_exception_e(vcpu, PF_VECTOR, error_code); > > } > > > > 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; > > And here is an add-on patch to fix reset-on-triple-fault: > > > Clear the pending original exception when raising a triple fault. This > allows to re-use the vcpu instance, e.g. after a reset which is > typically issued as reaction on the triple fault. > > Signed-off-by: Jan Kiszka > > --- > arch/x86/kvm/x86.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > Index: b/arch/x86/kvm/x86.c > =================================================================== > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -149,8 +149,10 @@ static void handle_multiple_faults(struc > if (vcpu->arch.exception.nr != DF_VECTOR) { > vcpu->arch.exception.nr = DF_VECTOR; > vcpu->arch.exception.error_code = 0; > - } else > + } else { > set_bit(KVM_REQ_TRIPLE_FAULT, &vcpu->requests); > + vcpu->arch.exception.pending = false; > + } > } > > void kvm_queue_exception(struct kvm_vcpu *vcpu, unsigned nr) Ah, indeed. Thanks. -- | AMD Saxony Limited Liability Company & Co. KG Operating | Wilschdorfer Landstr. 101, 01109 Dresden, Germany System | Register Court Dresden: HRA 4896 Research | General Partner authorized to represent: Center | AMD Saxony LLC (Wilmington, Delaware, US) | General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone