Patchwork [1/1] UBUNTU: SAUCE: kvm: fix push of wrong eip when doing softint

login
register
mail settings
Submitter Andy Whitcroft
Date April 13, 2011, 3:28 p.m.
Message ID <1302708500-17516-2-git-send-email-apw@canonical.com>
Download mbox | patch
Permalink /patch/91056/
State New
Headers show

Comments

Andy Whitcroft - April 13, 2011, 3:28 p.m.
From: Serge E. Hallyn <serge.hallyn@canonical.com>

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.

[apw@canonical.com: merged eip update as per Jan's recommendation.]
BugLink: http://bugs.launchpad.net/bugs/747090
Signed-off-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Andy Whitcroft <apw@canonical.com>
---
 arch/x86/kvm/vmx.c |   12 +++++++++---
 arch/x86/kvm/x86.c |    5 +++--
 arch/x86/kvm/x86.h |    2 +-
 3 files changed, 13 insertions(+), 6 deletions(-)
Tim Gardner - April 13, 2011, 3:39 p.m.
On 04/13/2011 08:28 AM, Andy Whitcroft wrote:
> From: Serge E. Hallyn<serge.hallyn@canonical.com>
>
> 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.
>
> [apw@canonical.com: merged eip update as per Jan's recommendation.]
> BugLink: http://bugs.launchpad.net/bugs/747090
> Signed-off-by: Serge E. Hallyn<serge.hallyn@ubuntu.com>
> Signed-off-by: Andy Whitcroft<apw@canonical.com>
> ---
>   arch/x86/kvm/vmx.c |   12 +++++++++---
>   arch/x86/kvm/x86.c |    5 +++--
>   arch/x86/kvm/x86.h |    2 +-
>   3 files changed, 13 insertions(+), 6 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..980317a 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;
> @@ -4302,7 +4302,8 @@ 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 = vcpu->arch.emulate_ctxt.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);
>

ouch! Looks right to me, especially given the test results.

Acked-by: Tim Gardner <tim.gardner@canonical.com>
Stefan Bader - April 13, 2011, 4:14 p.m.
On 04/13/2011 05:28 PM, Andy Whitcroft wrote:
> From: Serge E. Hallyn <serge.hallyn@canonical.com>
> 
> 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.
> 
> [apw@canonical.com: merged eip update as per Jan's recommendation.]
> BugLink: http://bugs.launchpad.net/bugs/747090
> Signed-off-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
> Signed-off-by: Andy Whitcroft <apw@canonical.com>
> ---
>  arch/x86/kvm/vmx.c |   12 +++++++++---
>  arch/x86/kvm/x86.c |    5 +++--
>  arch/x86/kvm/x86.h |    2 +-
>  3 files changed, 13 insertions(+), 6 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..980317a 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;
> @@ -4302,7 +4302,8 @@ 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 = vcpu->arch.emulate_ctxt.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);
>  
Looks like it does what it intends to do. And should be simplish to verify.

Acked-by: Stefan Bader <stefan.bader@canonical.com>

Patch

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..980317a 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;
@@ -4302,7 +4302,8 @@  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 = vcpu->arch.emulate_ctxt.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);