From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gleb Natapov Subject: Re: Implement generic double fault generation mechanism Date: Sun, 3 May 2009 13:53:30 +0300 Message-ID: <20090503105330.GL9795@redhat.com> References: <9832F13BD22FB94A829F798DA4A8280501A80F02A3@pdsmsx503.ccr.corp.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: "kvm@vger.kernel.org" , Avi Kivity To: "Dong, Eddie" Return-path: Received: from mx2.redhat.com ([66.187.237.31]:46913 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753686AbZECKxd (ORCPT ); Sun, 3 May 2009 06:53:33 -0400 Content-Disposition: inline In-Reply-To: <9832F13BD22FB94A829F798DA4A8280501A80F02A3@pdsmsx503.ccr.corp.intel.com> Sender: kvm-owner@vger.kernel.org List-ID: On Thu, Apr 30, 2009 at 03:24:07PM +0800, Dong, Eddie wrote: > > > Move Double-Fault generation logic out of page fault > exception generating function to cover more generic case. > > Signed-off-by: Eddie Dong > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index ab1fdac..51a8dad 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -162,12 +162,59 @@ void kvm_set_apic_base(struct kvm_vcpu *vcpu, u64 data) > } > EXPORT_SYMBOL_GPL(kvm_set_apic_base); > > +#define EXCPT_BENIGN 0 > +#define EXCPT_CONTRIBUTORY 1 > +#define EXCPT_PF 2 > + > +static int exception_class(int vector) > +{ > + if (vector == 14) > + return EXCPT_PF; > + else if (vector == 0 || (vector >= 10 && vector <= 13)) > + return EXCPT_CONTRIBUTORY; > + else > + return EXCPT_BENIGN; > +} > + This makes double fault (8) benign exception. Surely not what you want. > +static void kvm_multiple_exception(struct kvm_vcpu *vcpu, > + unsigned nr, bool has_error, u32 error_code) > +{ > + u32 prev_nr; > + int class1, class2; > + > + if (!vcpu->arch.exception.pending) { > + vcpu->arch.exception.pending = true; > + vcpu->arch.exception.has_error_code = has_error; > + vcpu->arch.exception.nr = nr; > + vcpu->arch.exception.error_code = error_code; > + return; > + } > + > + /* to check exception */ > + prev_nr = vcpu->arch.exception.nr; > + class2 = exception_class(nr); > + class1 = exception_class(prev_nr); > + if ((class1 == EXCPT_CONTRIBUTORY && class2 == EXCPT_CONTRIBUTORY) > + || (class1 == EXCPT_PF && class2 != EXCPT_BENIGN)) { > + /* generate double fault per SDM Table 5-5 */ > + printk(KERN_DEBUG "kvm: double fault 0x%x on 0x%x\n", > + prev_nr, nr); > + vcpu->arch.exception.pending = true; > + vcpu->arch.exception.has_error_code = 1; > + vcpu->arch.exception.nr = DF_VECTOR; > + vcpu->arch.exception.error_code = 0; > + if (prev_nr == DF_VECTOR) { > + /* triple fault -> shutdown */ > + set_bit(KVM_REQ_TRIPLE_FAULT, &vcpu->requests); > + } > + } else > + printk(KERN_ERR "Exception 0x%x on 0x%x happens serially\n", > + prev_nr, nr); > +} When two exceptions happens serially is is better to replace pending exception with a new one. This way the first exception (that is lost) will be regenerated when instruction will be re-executed. -- Gleb.