From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: Re: buggy emulate_int_real Date: Wed, 13 Apr 2011 01:31:42 +0200 Message-ID: <4DA4E0DE.7070903@web.de> References: <20110408210900.GA26787@hallyn.com> <4DA16AA1.7010108@redhat.com> <20110412075319.GA28696@hallyn.com> <4DA406F8.4090701@redhat.com> <20110412141226.GA6766@hallyn.com> <4DA45ED0.90601@redhat.com> <4DA472E5.9060807@siemens.com> <20110412183158.GA29423@hallyn.com> <4DA4BB40.2010201@web.de> <20110412212543.GA906@hallyn.com> <20110412223940.GA3485@hallyn.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig26543D45D7A22B354D99463D" Cc: Avi Kivity , KVM mailing list To: "Serge E. Hallyn" Return-path: Received: from fmmailgate02.web.de ([217.72.192.227]:57565 "EHLO fmmailgate02.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756225Ab1DLXbo (ORCPT ); Tue, 12 Apr 2011 19:31:44 -0400 In-Reply-To: <20110412223940.GA3485@hallyn.com> Sender: kvm-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig26543D45D7A22B354D99463D Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 2011-04-13 00:39, Serge E. Hallyn wrote: > Quoting Serge E. Hallyn (serge@hallyn.com): >> Quoting Jan Kiszka (jan.kiszka@web.de): >>> From a brief refresh-reading, I would say >>> >>> if (interrupt.soft || kvm_exception_is_soft(nr)) >>> increment_eip_by_inst_len >>> >>> but only for those interrupts/exceptions which were raised by the >>> triggering instructions, _not_ for exceptions raise while processing >>> them (e.g. a page fault while accessing the IDT). >>> >>> Jan >> >> Ok, thanks guys. I'm currently trying a compile of the following. >=20 > With the obvious fixes, that turns into the below, which seems to be > working for me: >=20 > From 555696f355ec2db9f4919f5e363355a2671b15a5 Mon Sep 17 00:00:00 2001 > From: Serge E. Hallyn > Date: Tue, 12 Apr 2011 22:18:40 +0100 > Subject: [PATCH 1/1] kvm: fix push of wrong eip when doing softint >=20 > When doing a soft int, we need to bump eip before pushing it to > the stack. Otherwise we'll do the int a second time. >=20 > Signed-off-by: Serge E. Hallyn > --- > arch/x86/kvm/vmx.c | 12 +++++++++--- > arch/x86/kvm/x86.c | 3 ++- > arch/x86/kvm/x86.h | 2 +- > 3 files changed, 12 insertions(+), 5 deletions(-) >=20 > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index bf89ec2..3aad96c 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -1053,7 +1053,10 @@ static void vmx_queue_exception(struct kvm_vcpu = *vcpu, unsigned nr, > } > =20 > if (vmx->rmode.vm86_active) { > - if (kvm_inject_realmode_interrupt(vcpu, nr) !=3D EMULATE_DONE) > + int inc_eip =3D 0; > + if (kvm_exception_is_soft(nr)) > + inc_eip =3D vcpu->arch.event_exit_inst_len; > + if (kvm_inject_realmode_interrupt(vcpu, nr, inc_eip) !=3D EMULATE_DO= NE) > kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); > return; > } > @@ -2871,7 +2874,10 @@ static void vmx_inject_irq(struct kvm_vcpu *vcpu= ) > =20 > ++vcpu->stat.irq_injections; > if (vmx->rmode.vm86_active) { > - if (kvm_inject_realmode_interrupt(vcpu, irq) !=3D EMULATE_DONE) > + int inc_eip =3D 0; > + if (vcpu->arch.interrupt.soft) > + inc_eip =3D vcpu->arch.event_exit_inst_len; > + if (kvm_inject_realmode_interrupt(vcpu, irq, inc_eip) !=3D EMULATE_D= ONE) > kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); > return; > } > @@ -2905,7 +2911,7 @@ static void vmx_inject_nmi(struct kvm_vcpu *vcpu)= > =20 > ++vcpu->stat.nmi_injections; > if (vmx->rmode.vm86_active) { > - if (kvm_inject_realmode_interrupt(vcpu, NMI_VECTOR) !=3D EMULATE_DON= E) > + if (kvm_inject_realmode_interrupt(vcpu, NMI_VECTOR, 0) !=3D EMULATE_= DONE) > kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); > return; > } > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index bcc0efc..8911622 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -4293,7 +4293,7 @@ static void init_emulate_ctxt(struct kvm_vcpu *vc= pu) > memcpy(c->regs, vcpu->arch.regs, sizeof c->regs); > } > =20 > -int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq) > +int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int = inc_eip) > { > struct decode_cache *c =3D &vcpu->arch.emulate_ctxt.decode; > int ret; > @@ -4303,6 +4303,7 @@ int kvm_inject_realmode_interrupt(struct kvm_vcpu= *vcpu, int irq) > vcpu->arch.emulate_ctxt.decode.op_bytes =3D 2; > vcpu->arch.emulate_ctxt.decode.ad_bytes =3D 2; > vcpu->arch.emulate_ctxt.decode.eip =3D vcpu->arch.emulate_ctxt.eip; > + vcpu->arch.emulate_ctxt.decode.eip +=3D inc_eip; I would fold this into the previous line. > ret =3D emulate_int_real(&vcpu->arch.emulate_ctxt, &emulate_ops, irq)= ; > =20 > if (ret !=3D X86EMUL_CONTINUE) > diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h > index c600da8..e407ed3 100644 > --- a/arch/x86/kvm/x86.h > +++ b/arch/x86/kvm/x86.h > @@ -77,7 +77,7 @@ static inline u32 bit(int bitno) > =20 > void kvm_before_handle_nmi(struct kvm_vcpu *vcpu); > void kvm_after_handle_nmi(struct kvm_vcpu *vcpu); > -int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq); > +int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int = inc_eip); > =20 > void kvm_write_tsc(struct kvm_vcpu *vcpu, u64 data); > =20 Looks consistent to me. Jan --------------enig26543D45D7A22B354D99463D 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.15 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iEYEARECAAYFAk2k4N4ACgkQitSsb3rl5xRf6ACeKrZOYNYbBULZPkX3WWbzuc72 NmYAnRjLRL0N/D7KTUob9MTMpKAXo1hB =ZQzb -----END PGP SIGNATURE----- --------------enig26543D45D7A22B354D99463D--