public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org, jan.kiszka@siemens.com, joerg.roedel@amd.com
Subject: Re: [patch 0/2] Handle multiple exceptions (fixes Win2003 reboot by triple fault)
Date: Thu, 12 Nov 2009 20:03:09 +0200	[thread overview]
Message-ID: <20091112180309.GA20150@redhat.com> (raw)
In-Reply-To: <20091112160709.GB26525@amt.cnet>

On Thu, Nov 12, 2009 at 02:07:09PM -0200, Marcelo Tosatti wrote:
> On Thu, Nov 12, 2009 at 02:21:24PM +0200, Gleb Natapov wrote:
> > On Wed, Nov 11, 2009 at 05:29:47PM -0200, Marcelo Tosatti wrote:
> > > I suppose a complete fix would be to follow the "Conditions for
> > > Generating a Double Fault" with support for handling exceptions
> > > serially.
> > > 
> > > But this works for me.
> > > 
> > I prefer proper solution. Like one attached (this is combination of ths
> > patch by Eddie Dong and my fix):
> > 
> > Move Double-Fault generation logic out of page fault
> > exception generating function to cover more generic case.
> > 
> > Signed-off-by: Eddie Dong <eddie.dong@intel.com>
> > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> 
> Nice.
> 
> Tested-by: Marcelo Tosatti <mtosatti@redhat.com>
> 
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index 76c8375..88c4490 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -248,12 +248,61 @@ 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;
> > +}
> > +
> > +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) {
> > +	queue:
> > +		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;
> > +	if (prev_nr == DF_VECTOR) {
> > +		/* triple fault -> shutdown */
> > +		set_bit(KVM_REQ_TRIPLE_FAULT, &vcpu->requests);
> > +		return;
> > +	}
> > +	class1 = exception_class(prev_nr);
> > +	class2 = exception_class(nr);
> > +	if ((class1 == EXCPT_CONTRIBUTORY && class2 == EXCPT_CONTRIBUTORY)
> > +		|| (class1 == EXCPT_PF && class2 != EXCPT_BENIGN)) {
> > +		/* generate double fault per SDM Table 5-5 */
> > +		vcpu->arch.exception.pending = true;
> > +		vcpu->arch.exception.has_error_code = true;
> > +		vcpu->arch.exception.nr = DF_VECTOR;
> > +		vcpu->arch.exception.error_code = 0;
> 
> > +	} else
> > +		/* replace previous exception with a new one in a hope
> > +		   that instruction re-execution will regenerate lost
> > +		   exception */
> 
> Out of curiosity, why not an exception queue? 
> 
It seems unnecessary. Lost exception will be regenerated after
instruction that caused it will be re-executed.

> > +		goto queue;
> 
> This goto seems unnecessary.
It is very important. It replaces previous exception with the new one.
This allows CPU to proceed in situation where exception injection causes
another exception serially. Think about #DE that causes #PF (because
stack is not mapped for instance). If we'll drop #PF and re-inject #DE it
will generate #PF once again. If we'll drop #DE and inject #PF then #PF
handler with hopefully fix #PF condition and #DE will be regenerated
when devision will be retried.

--
			Gleb.

      reply	other threads:[~2009-11-12 18:03 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-11 19:29 [patch 0/2] Handle multiple exceptions (fixes Win2003 reboot by triple fault) Marcelo Tosatti
2009-11-11 19:29 ` [patch 1/2] KVM: x86: handle double and triple faults for every exception Marcelo Tosatti
2009-11-11 20:07   ` Jan Kiszka
2009-11-11 20:41     ` Marcelo Tosatti
2009-11-11 21:02       ` Jan Kiszka
2009-11-11 21:40         ` Marcelo Tosatti
2009-11-15 12:30           ` Avi Kivity
2009-11-12 12:26   ` Gleb Natapov
2009-11-15 12:41     ` Avi Kivity
2009-11-15 12:51       ` Gleb Natapov
2009-11-15 13:11         ` Avi Kivity
2009-11-15 14:29           ` Jan Kiszka
2009-11-15 14:34             ` Avi Kivity
2009-11-15 14:36               ` Jan Kiszka
2009-11-11 19:29 ` [patch 2/2] KVM: x86: raise TSS exception for NULL CS and SS segments Marcelo Tosatti
2009-11-12 12:21 ` [patch 0/2] Handle multiple exceptions (fixes Win2003 reboot by triple fault) Gleb Natapov
2009-11-12 12:41   ` Jan Kiszka
2009-11-12 13:05     ` Gleb Natapov
2009-11-15 12:54       ` Avi Kivity
2009-11-19 15:54         ` Gleb Natapov
2009-11-20 15:55           ` Ryan Harper
2009-11-23 16:52           ` Marcelo Tosatti
2009-11-25  9:55           ` Avi Kivity
2009-11-25 13:03           ` Marcelo Tosatti
2009-11-12 16:07   ` Marcelo Tosatti
2009-11-12 18:03     ` Gleb Natapov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091112180309.GA20150@redhat.com \
    --to=gleb@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=joerg.roedel@amd.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox