From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mohammed Gamal Subject: Re: [PATCHv3] VMX: Enhance invalid guest state emulation Date: Tue, 1 Sep 2009 15:32:29 +0200 Message-ID: <52d4a3890909010632wd1b6d9fxb2b5f5042e151b4f@mail.gmail.com> References: <1251802098-23819-1-git-send-email-m.gamal005@gmail.com> <20090901114806.GA18778@amt.cnet> <52d4a3890909010514n20ceef87i4767e277c550a581@mail.gmail.com> <20090901121804.GA19145@amt.cnet> <52d4a3890909010608h1f406b42j98d403493859d6b6@mail.gmail.com> <20090901132938.GA19864@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: avi@redhat.com, kvm@vger.kernel.org To: Marcelo Tosatti Return-path: Received: from mail-bw0-f219.google.com ([209.85.218.219]:34548 "EHLO mail-bw0-f219.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754497AbZIANc2 convert rfc822-to-8bit (ORCPT ); Tue, 1 Sep 2009 09:32:28 -0400 Received: by bwz19 with SMTP id 19so3526627bwz.37 for ; Tue, 01 Sep 2009 06:32:29 -0700 (PDT) In-Reply-To: <20090901132938.GA19864@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: On Tue, Sep 1, 2009 at 3:29 PM, Marcelo Tosatti wr= ote: > On Tue, Sep 01, 2009 at 03:08:55PM +0200, Mohammed Gamal wrote: >> On Tue, Sep 1, 2009 at 2:18 PM, Marcelo Tosatti= wrote: >> > On Tue, Sep 01, 2009 at 02:14:17PM +0200, Mohammed Gamal wrote: >> >> On Tue, Sep 1, 2009 at 1:48 PM, Marcelo Tosatti wrote: >> >> > On Tue, Sep 01, 2009 at 12:48:18PM +0200, Mohammed Gamal wrote: >> >> >> - Change returned handle_invalid_guest_state() to return relev= ant exit codes >> >> >> - Move triggering the emulation from vmx_vcpu_run() to vmx_han= dle_exit() >> >> >> - Return to userspace instead of repeatedly trying to emulate = instructions that have already failed >> >> >> >> >> >> Signed-off-by: Mohammed Gamal >> >> > >> >> > Mohammed, >> >> > >> >> > The handle_invalid_guest_state loop is potentially problematic.= It would >> >> > be more appropriate to use the __vcpu_run loop. >> >> > >> >> > Can't you set vmx->emulation_required depending on the result >> >> > of one call to emulate_instruction and get rid of the while >> >> > (!guest_state_valid(vcpu)) loop? >> >> > >> >> >> >> Invalid state emulation is VMX-specfic, while the __vcpu_run loop= is >> >> independent of the virtualization extension (defined in x86.c), n= o? >> >> AMD SVM can comforably run hosts in big-real mode and thus it doe= sn't >> >> have the notion of a guest going to an invalid state because of m= ode >> >> switching, so I don't think it'd be a good idea to move emulation= into >> >> a generic layer. Please correct me if I am wrong >> > >> > Right. But all i am asking is to emulate one instruction at a >> > time in handle_invalid_guest_state, instead of looping until >> > guest_state_valid(vcpu). >> > >> > So you get rid of schedule(), the check for signal_pending, etc. >> >> But we'll still need to enter the guest when it's in a valid state, = so >> we need to move that loop somewhere, > > Sure, just set vmx->emulation_required =3D guest_state_valid(vcpu). W= hen > the state is good, the entry handler will vmentry. > >> and now that we still have a loop >> we'll also still need to do the pending signals and scheduling check= s, >> no? > > Point is you can use the __vcpu_run loop. > > In the latest patch you do: > > + =A0 =A0 =A0 /* Don't enter VMX if guest state is invalid, let the e= xit handler > + =A0 =A0 =A0 =A0 =A0start emulation until we arrive back to a valid = state */ > + =A0 =A0 =A0 if (vmx->emulation_required && emulate_invalid_guest_st= ate) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return; > > And then emulate in the exit handler. > >> I'd appreciate any suggestions you have to alleviate this. > > I fail to see why you need an internal loop if you can use the extern= al > (__vcpu_run) one. Because it's not just used by VMX. So I don't think it'd be wise to use it for something that's VMX-specific.