2016-03-15 20:18:53

by Laurent Vivier

[permalink] [raw]
Subject: [PATCH] kvm-pr: manage illegal instructions

While writing some instruction tests for kvm-unit-tests for powerpc,
I've found that illegal instructions are not managed correctly with kvm-pr,
while it is fine with kvm-hv.

When an illegal instruction (like ".long 0") is processed by kvm-pr,
the kernel logs are filled with:

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

While the exception handler receives an interrupt for each instruction
executed after the illegal instruction.

Signed-off-by: Laurent Vivier <[email protected]>
---
arch/powerpc/kvm/book3s_emulate.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/book3s_emulate.c b/arch/powerpc/kvm/book3s_emulate.c
index 2afdb9c..4ee969d 100644
--- a/arch/powerpc/kvm/book3s_emulate.c
+++ b/arch/powerpc/kvm/book3s_emulate.c
@@ -99,7 +99,6 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,

switch (get_op(inst)) {
case 0:
- emulated = EMULATE_FAIL;
if ((kvmppc_get_msr(vcpu) & MSR_LE) &&
(inst == swab32(inst_sc))) {
/*
@@ -112,6 +111,9 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,
kvmppc_set_gpr(vcpu, 3, EV_UNIMPLEMENTED);
kvmppc_set_pc(vcpu, kvmppc_get_pc(vcpu) + 4);
emulated = EMULATE_DONE;
+ } else {
+ kvmppc_core_queue_program(vcpu, SRR1_PROGILL);
+ emulated = EMULATE_AGAIN;
}
break;
case 19:
--
2.5.0


2016-03-22 10:11:33

by Laurent Vivier

[permalink] [raw]
Subject: Re: [PATCH] kvm-pr: manage illegal instructions

Hi,

as Paolo has merged the test into kvm-unit-tests, this patch (and
original bug) can be now tested with it.

git://git.kernel.org/pub/scm/virt/kvm/kvm-unit-tests.git

at least:

be9b007 powerpc: add test to check invalid instruction trap

Run this with KVM-PR and check your dmesg:

qemu-system-ppc64 -machine pseries,accel=kvm \
-bios powerpc/boot_rom.bin \
-display none -serial stdio \
-kernel powerpc/emulator.elf -smp 1

Laurent

On 15/03/2016 21:18, Laurent Vivier wrote:
> While writing some instruction tests for kvm-unit-tests for powerpc,
> I've found that illegal instructions are not managed correctly with kvm-pr,
> while it is fine with kvm-hv.
>
> When an illegal instruction (like ".long 0") is processed by kvm-pr,
> the kernel logs are filled with:
>
> Couldn't emulate instruction 0x00000000 (op 0 xop 0)
> kvmppc_handle_exit_pr: emulation at 700 failed (00000000)
>
> While the exception handler receives an interrupt for each instruction
> executed after the illegal instruction.
>
> Signed-off-by: Laurent Vivier <[email protected]>
> ---
> arch/powerpc/kvm/book3s_emulate.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/kvm/book3s_emulate.c b/arch/powerpc/kvm/book3s_emulate.c
> index 2afdb9c..4ee969d 100644
> --- a/arch/powerpc/kvm/book3s_emulate.c
> +++ b/arch/powerpc/kvm/book3s_emulate.c
> @@ -99,7 +99,6 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,
>
> switch (get_op(inst)) {
> case 0:
> - emulated = EMULATE_FAIL;
> if ((kvmppc_get_msr(vcpu) & MSR_LE) &&
> (inst == swab32(inst_sc))) {
> /*
> @@ -112,6 +111,9 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,
> kvmppc_set_gpr(vcpu, 3, EV_UNIMPLEMENTED);
> kvmppc_set_pc(vcpu, kvmppc_get_pc(vcpu) + 4);
> emulated = EMULATE_DONE;
> + } else {
> + kvmppc_core_queue_program(vcpu, SRR1_PROGILL);
> + emulated = EMULATE_AGAIN;
> }
> break;
> case 19:
>

2016-04-07 11:32:07

by Laurent Vivier

[permalink] [raw]
Subject: Re: [PATCH] kvm-pr: manage illegal instructions

Ping?

On 15/03/2016 21:18, Laurent Vivier wrote:
> While writing some instruction tests for kvm-unit-tests for powerpc,
> I've found that illegal instructions are not managed correctly with kvm-pr,
> while it is fine with kvm-hv.
>
> When an illegal instruction (like ".long 0") is processed by kvm-pr,
> the kernel logs are filled with:
>
> Couldn't emulate instruction 0x00000000 (op 0 xop 0)
> kvmppc_handle_exit_pr: emulation at 700 failed (00000000)
>
> While the exception handler receives an interrupt for each instruction
> executed after the illegal instruction.
>
> Signed-off-by: Laurent Vivier <[email protected]>
> ---
> arch/powerpc/kvm/book3s_emulate.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/kvm/book3s_emulate.c b/arch/powerpc/kvm/book3s_emulate.c
> index 2afdb9c..4ee969d 100644
> --- a/arch/powerpc/kvm/book3s_emulate.c
> +++ b/arch/powerpc/kvm/book3s_emulate.c
> @@ -99,7 +99,6 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,
>
> switch (get_op(inst)) {
> case 0:
> - emulated = EMULATE_FAIL;
> if ((kvmppc_get_msr(vcpu) & MSR_LE) &&
> (inst == swab32(inst_sc))) {
> /*
> @@ -112,6 +111,9 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,
> kvmppc_set_gpr(vcpu, 3, EV_UNIMPLEMENTED);
> kvmppc_set_pc(vcpu, kvmppc_get_pc(vcpu) + 4);
> emulated = EMULATE_DONE;
> + } else {
> + kvmppc_core_queue_program(vcpu, SRR1_PROGILL);
> + emulated = EMULATE_AGAIN;
> }
> break;
> case 19:
>

2016-04-21 09:25:18

by Thomas Huth

[permalink] [raw]
Subject: Re: [PATCH] kvm-pr: manage illegal instructions

On 15.03.2016 21:18, Laurent Vivier wrote:
> While writing some instruction tests for kvm-unit-tests for powerpc,
> I've found that illegal instructions are not managed correctly with kvm-pr,
> while it is fine with kvm-hv.
>
> When an illegal instruction (like ".long 0") is processed by kvm-pr,
> the kernel logs are filled with:
>
> Couldn't emulate instruction 0x00000000 (op 0 xop 0)
> kvmppc_handle_exit_pr: emulation at 700 failed (00000000)
>
> While the exception handler receives an interrupt for each instruction
> executed after the illegal instruction.
>
> Signed-off-by: Laurent Vivier <[email protected]>
> ---
> arch/powerpc/kvm/book3s_emulate.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/kvm/book3s_emulate.c b/arch/powerpc/kvm/book3s_emulate.c
> index 2afdb9c..4ee969d 100644
> --- a/arch/powerpc/kvm/book3s_emulate.c
> +++ b/arch/powerpc/kvm/book3s_emulate.c
> @@ -99,7 +99,6 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,
>
> switch (get_op(inst)) {
> case 0:
> - emulated = EMULATE_FAIL;
> if ((kvmppc_get_msr(vcpu) & MSR_LE) &&
> (inst == swab32(inst_sc))) {
> /*
> @@ -112,6 +111,9 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,
> kvmppc_set_gpr(vcpu, 3, EV_UNIMPLEMENTED);
> kvmppc_set_pc(vcpu, kvmppc_get_pc(vcpu) + 4);
> emulated = EMULATE_DONE;
> + } else {
> + kvmppc_core_queue_program(vcpu, SRR1_PROGILL);
> + emulated = EMULATE_AGAIN;
> }
> break;
> case 19:
>

Tested-by: Thomas Huth <[email protected]>