From: "Serge E. Hallyn" <serge@hallyn.com>
To: Jan Kiszka <jan.kiszka@web.de>
Cc: Avi Kivity <avi@redhat.com>, KVM mailing list <kvm@vger.kernel.org>
Subject: Re: buggy emulate_int_real
Date: Tue, 12 Apr 2011 16:25:43 -0500 [thread overview]
Message-ID: <20110412212543.GA906@hallyn.com> (raw)
In-Reply-To: <4DA4BB40.2010201@web.de>
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.
>From a3c4d5b67eb6d91ef772bc0e04adcd7d9711275f Mon Sep 17 00:00:00 2001
From: Serge E. Hallyn <serge.hallyn@canonical.com>
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 <serge.hallyn@ubuntu.com>
---
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..6761464 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);
--
1.7.0.4
next prev parent reply other threads:[~2011-04-12 21:25 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-08 21:09 buggy emulate_int_real Serge E. Hallyn
2011-04-10 8:30 ` Avi Kivity
2011-04-12 7:53 ` Serge E. Hallyn
2011-04-12 8:02 ` Avi Kivity
2011-04-12 13:57 ` Serge E. Hallyn
2011-04-12 14:14 ` Avi Kivity
2011-04-12 14:12 ` Serge E. Hallyn
2011-04-12 14:16 ` Avi Kivity
2011-04-12 15:42 ` Jan Kiszka
2011-04-12 18:31 ` Serge E. Hallyn
2011-04-12 20:51 ` Jan Kiszka
2011-04-12 21:25 ` Serge E. Hallyn [this message]
2011-04-12 22:39 ` Serge E. Hallyn
2011-04-12 23:31 ` Jan Kiszka
2011-04-13 13:24 ` Serge E. Hallyn
2011-04-13 13:29 ` Avi Kivity
2011-04-13 13:52 ` Serge E. Hallyn
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=20110412212543.GA906@hallyn.com \
--to=serge@hallyn.com \
--cc=avi@redhat.com \
--cc=jan.kiszka@web.de \
--cc=kvm@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.