diff mbox

[Xenial,SRU] KVM: PPC: Book3S PR: Fix illegal opcode emulation

Message ID 1483992469-25577-1-git-send-email-tim.gardner@canonical.com
State New
Headers show

Commit Message

Tim Gardner Jan. 9, 2017, 8:07 p.m. UTC
From: Thomas Huth <thuth@redhat.com>

BugLink: http://bugs.launchpad.net/bugs/1634129

If kvmppc_handle_exit_pr() calls kvmppc_emulate_instruction() to emulate
one instruction (in the BOOK3S_INTERRUPT_H_EMUL_ASSIST case), it calls
kvmppc_core_queue_program() afterwards if kvmppc_emulate_instruction()
returned EMULATE_FAIL, so the guest gets an program interrupt for the
illegal opcode.
However, the kvmppc_emulate_instruction() also tried to inject a
program exception for this already, so the program interrupt gets
injected twice and the return address in srr0 gets destroyed.
All other callers of kvmppc_emulate_instruction() are also injecting
a program interrupt, and since the callers have the right knowledge
about the srr1 flags that should be used, it is the function
kvmppc_emulate_instruction() that should _not_ inject program
interrupts, so remove the kvmppc_core_queue_program() here.

This fixes the issue discovered by Laurent Vivier with kvm-unit-tests
where the logs are filled with these messages when the test tries
to execute an illegal instruction:

     Couldn't emulate instruction 0x00000000 (op 0 xop 0)
     kvmppc_handle_exit_pr: emulation at 700 failed (00000000)

Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Alexander Graf <agraf@suse.de>
Tested-by: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
(cherry picked from commit 708e75a3ee750dce1072134e630d66c4e6eaf63c)
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
---
 arch/powerpc/kvm/emulate.c | 1 -
 1 file changed, 1 deletion(-)

Comments

Colin Ian King Jan. 9, 2017, 8:09 p.m. UTC | #1
On 09/01/17 20:07, Tim Gardner wrote:
> From: Thomas Huth <thuth@redhat.com>
> 
> BugLink: http://bugs.launchpad.net/bugs/1634129
> 
> If kvmppc_handle_exit_pr() calls kvmppc_emulate_instruction() to emulate
> one instruction (in the BOOK3S_INTERRUPT_H_EMUL_ASSIST case), it calls
> kvmppc_core_queue_program() afterwards if kvmppc_emulate_instruction()
> returned EMULATE_FAIL, so the guest gets an program interrupt for the
> illegal opcode.
> However, the kvmppc_emulate_instruction() also tried to inject a
> program exception for this already, so the program interrupt gets
> injected twice and the return address in srr0 gets destroyed.
> All other callers of kvmppc_emulate_instruction() are also injecting
> a program interrupt, and since the callers have the right knowledge
> about the srr1 flags that should be used, it is the function
> kvmppc_emulate_instruction() that should _not_ inject program
> interrupts, so remove the kvmppc_core_queue_program() here.
> 
> This fixes the issue discovered by Laurent Vivier with kvm-unit-tests
> where the logs are filled with these messages when the test tries
> to execute an illegal instruction:
> 
>      Couldn't emulate instruction 0x00000000 (op 0 xop 0)
>      kvmppc_handle_exit_pr: emulation at 700 failed (00000000)
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> Reviewed-by: Alexander Graf <agraf@suse.de>
> Tested-by: Laurent Vivier <lvivier@redhat.com>
> Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
> (cherry picked from commit 708e75a3ee750dce1072134e630d66c4e6eaf63c)
> Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
> ---
>  arch/powerpc/kvm/emulate.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
> index 5cc2e7a..b379146 100644
> --- a/arch/powerpc/kvm/emulate.c
> +++ b/arch/powerpc/kvm/emulate.c
> @@ -302,7 +302,6 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
>  			advance = 0;
>  			printk(KERN_ERR "Couldn't emulate instruction 0x%08x "
>  			       "(op %d xop %d)\n", inst, get_op(inst), get_xop(inst));
> -			kvmppc_core_queue_program(vcpu, 0);
>  		}
>  	}
>  
> 
Seems to do what it says in the description, so..

Acked-by: Colin Ian King <colin.king@canonical.com>
Stefan Bader Jan. 10, 2017, 9:27 a.m. UTC | #2

Luis Henriques Jan. 10, 2017, 5:50 p.m. UTC | #3
Applied to xenial master-next branch.

Cheers,
--
Luís
diff mbox

Patch

diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index 5cc2e7a..b379146 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -302,7 +302,6 @@  int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
 			advance = 0;
 			printk(KERN_ERR "Couldn't emulate instruction 0x%08x "
 			       "(op %d xop %d)\n", inst, get_op(inst), get_xop(inst));
-			kvmppc_core_queue_program(vcpu, 0);
 		}
 	}