From patchwork Tue Apr 12 22:39:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Serge E. Hallyn" X-Patchwork-Id: 702271 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3CMdpJ5001885 for ; Tue, 12 Apr 2011 22:39:51 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752691Ab1DLWjr (ORCPT ); Tue, 12 Apr 2011 18:39:47 -0400 Received: from hrndva-omtalb.mail.rr.com ([71.74.56.123]:44509 "EHLO hrndva-omtalb.mail.rr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750901Ab1DLWjr (ORCPT ); Tue, 12 Apr 2011 18:39:47 -0400 X-Authority-Analysis: v=1.1 cv=aqMe+0lCtaYvy4h0jyaoPGyq+DPF+P6rPG2xbekoY9Q= c=1 sm=0 a=wom5GMh1gUkA:10 a=Rj1_iGo3bfgA:10 a=kj9zAlcOel0A:10 a=eAWTIsOZi86Vnn5xZOjC/w==:17 a=hBqU3vQJAAAA:8 a=DfNHnWVPAAAA:8 a=fxJcL_dCAAAA:8 a=8PHqUPwwEFgc6QYRyYYA:9 a=HG0vQ9kPelv7G4YL_7UA:7 a=CjuIK1q_8ugA:10 a=4gZ4WExUoD4A:10 a=5KVauyKsRKMA:10 a=lBRciGGoxdUA:10 a=2eKvNQJKnqYA:10 a=eAWTIsOZi86Vnn5xZOjC/w==:117 X-Cloudmark-Score: 0 X-Originating-IP: 70.123.154.172 Received: from [70.123.154.172] ([70.123.154.172:54638] helo=sergelap) by hrndva-oedge01.mail.rr.com (envelope-from ) (ecelerity 2.2.3.46 r()) with ESMTP id FA/B3-20102-1B4D4AD4; Tue, 12 Apr 2011 22:39:45 +0000 Received: by sergelap (Postfix, from userid 1000) id 539A511BBFC8; Tue, 12 Apr 2011 17:39:40 -0500 (CDT) Date: Tue, 12 Apr 2011 17:39:40 -0500 From: "Serge E. Hallyn" To: Jan Kiszka Cc: Avi Kivity , KVM mailing list Subject: Re: buggy emulate_int_real Message-ID: <20110412223940.GA3485@hallyn.com> 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> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20110412212543.GA906@hallyn.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 12 Apr 2011 22:39:51 +0000 (UTC) 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. With the obvious fixes, that turns into the below, which seems to be working for me: 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 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. 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(-) 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, } if (vmx->rmode.vm86_active) { - if (kvm_inject_realmode_interrupt(vcpu, nr) != EMULATE_DONE) + int inc_eip = 0; + if (kvm_exception_is_soft(nr)) + inc_eip = vcpu->arch.event_exit_inst_len; + if (kvm_inject_realmode_interrupt(vcpu, nr, inc_eip) != EMULATE_DONE) kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); return; } @@ -2871,7 +2874,10 @@ static void vmx_inject_irq(struct kvm_vcpu *vcpu) ++vcpu->stat.irq_injections; if (vmx->rmode.vm86_active) { - if (kvm_inject_realmode_interrupt(vcpu, irq) != EMULATE_DONE) + int inc_eip = 0; + if (vcpu->arch.interrupt.soft) + inc_eip = vcpu->arch.event_exit_inst_len; + if (kvm_inject_realmode_interrupt(vcpu, irq, inc_eip) != EMULATE_DONE) kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); return; } @@ -2905,7 +2911,7 @@ static void vmx_inject_nmi(struct kvm_vcpu *vcpu) ++vcpu->stat.nmi_injections; if (vmx->rmode.vm86_active) { - if (kvm_inject_realmode_interrupt(vcpu, NMI_VECTOR) != EMULATE_DONE) + if (kvm_inject_realmode_interrupt(vcpu, NMI_VECTOR, 0) != 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 *vcpu) memcpy(c->regs, vcpu->arch.regs, sizeof c->regs); } -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 = &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 = 2; vcpu->arch.emulate_ctxt.decode.ad_bytes = 2; vcpu->arch.emulate_ctxt.decode.eip = vcpu->arch.emulate_ctxt.eip; + vcpu->arch.emulate_ctxt.decode.eip += inc_eip; ret = emulate_int_real(&vcpu->arch.emulate_ctxt, &emulate_ops, irq); if (ret != 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) 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); void kvm_write_tsc(struct kvm_vcpu *vcpu, u64 data);