From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=50338 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OHuI0-0006LA-PE for qemu-devel@nongnu.org; Fri, 28 May 2010 03:47:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OHuHz-0007Fr-Jh for qemu-devel@nongnu.org; Fri, 28 May 2010 03:47:32 -0400 Received: from fmmailgate03.web.de ([217.72.192.234]:49823) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OHuHz-0007Fg-4n for qemu-devel@nongnu.org; Fri, 28 May 2010 03:47:31 -0400 Message-ID: <4BFF750D.70309@web.de> Date: Fri, 28 May 2010 09:47:25 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <4BFE8F13.2000009@cs.vu.nl> <4BFEBF9E.90600@web.de> <4BFECCC3.2000806@cs.vu.nl> <4BFEF010.50300@web.de> <20100528073346.GC3266@amd.com> In-Reply-To: <20100528073346.GC3266@amd.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig4D90E4334C59D61758C4C86F" Sender: jan.kiszka@web.de Subject: [Qemu-devel] Re: SVM emulation: EVENTINJ marked valid when a pagefault happens while issuing a software interrupt List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Roedel, Joerg" Cc: Gleb Natapov , "qemu-devel@nongnu.org" , Erik van der Kouwe This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig4D90E4334C59D61758C4C86F Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Roedel, Joerg wrote: > On Thu, May 27, 2010 at 06:20:00PM -0400, Jan Kiszka wrote: >> Erik van der Kouwe wrote: >>> Problem is: I'm compiling in Linux and testing in MINIX. Testing on t= he >>> real hardware would require a reboot everytime. Moreover, it might sc= rew >>> up my system if I make bad mistakes (the MINIX filesystem is easily >>> corrupted). >> Use Linux+KVM as host OS, it can also run VMMs as guests (aka nested >> SVM). And you could even debug those guests just like when you would r= un >> QEMU in emulation mode. In contrast to SVM emulation, nesting is fairl= y >> stable AFAIK. And it is faster. >=20 > At least it is more stable than any other nested-svm implementation I > know of ;-) > There are issues with kvmclock when you run kvm-on-kvm and you should > not expect windows-based hypervisors to run without problems. Beside > that, for running kvm-on-kvm and xen-on-kvm it is indeed fairly > stable :-) >=20 >>> Linux source tree (2.6.31-ubuntu), arch/x86/kvm/svm.c, end of functio= n >>> nested_svm_vmrun. Here event_inj and event_inj_err are copied from a >>> different VMCB, effectively clearing the value set by the CPU. Maybe >>> this isn't were I should have been looking though? >=20 > The interesting part is in nested_svm_vmexit. There you have this piece= > of code: >=20 > /* > * If we emulate a VMRUN/#VMEXIT in the same host #vmexit cycle= we have > * to make sure that we do not lose injected events. So check e= vent_inj > * here and copy it to exit_int_info if it is valid. > * Exit_int_info and event_inj can't be both valid because the = case > * below only happens on a VMRUN instruction intercept which ha= s > * no valid exit_int_info set. > */ > if (vmcb->control.event_inj & SVM_EVTINJ_VALID) { > struct vmcb_control_area *nc =3D &nested_vmcb->control;= >=20 > nc->exit_int_info =3D vmcb->control.event_inj; > nc->exit_int_info_err =3D vmcb->control.event_inj_err; > } >=20 > and a few lines later: >=20 > nested_vmcb->control.event_inj =3D 0; > nested_vmcb->control.event_inj_err =3D 0; >=20 > ... which takes care of this situation. The vmcb.eventinf field is _def= ined_ to > be zero on a #vmexit. (Hmm, must have missed that line in the spec.) In that case something like diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c index dcbdfe7..caabdb4 100644 --- a/target-i386/op_helper.c +++ b/target-i386/op_helper.c @@ -1263,13 +1263,6 @@ void do_interrupt(int intno, int is_int, int error= _code, #endif do_interrupt_real(intno, is_int, error_code, next_eip); } - -#if !defined(CONFIG_USER_ONLY) - if (env->hflags & HF_SVMI_MASK) { - uint32_t event_inj =3D ldl_phys(env->vm_vmcb + offsetof(struct vmcb= , control.event_inj)); - stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj), e= vent_inj & ~SVM_EVTINJ_VALID); - } -#endif } =20 /* This should come from sysemu.h - if we could include it here... */ @@ -5388,6 +5381,7 @@ void helper_vmexit(uint32_t exit_code, uint64_t exi= t_info_1) ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event= _inj))); stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_int_info_= err), ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event= _inj_err))); + stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj), 0)= ; =20 env->hflags2 &=3D ~HF2_GIF_MASK; /* FIXME: Resets the current ASID register to zero (host ASID). */ should resolve the QEMU issue, right? Jan --------------enig4D90E4334C59D61758C4C86F Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iEYEARECAAYFAkv/dRAACgkQitSsb3rl5xRVXACgioOi2Mx4XGshpsQ7iPO5zmf9 TOcAn1IHhbPxHx9d/ISfviTDpgAWkVLA =pA5K -----END PGP SIGNATURE----- --------------enig4D90E4334C59D61758C4C86F--