KVM: PPC: Fix illegal opcode emulation in kvm-pr
Subsystems (3)
PATCH 1/1 KVM: PPC: Fix illegal opcode emulation in kvm-pr
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)--- arch/powerpc/kvm/emulate.c | 1 - 1 file changed, 1 deletion(-)
arch/powerpc/kvm/emulate.c +0 -1
@@ -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 ); } }
Signature · 1 line
1.8.3.1
Quoted 32 lines · Thomas Huth
If
kvmppc_handle_exit_pr()callskvmppc_emulate_instruction()to emulate one instruction (in theBOOK3S_INTERRUPT_H_EMUL_ASSISTcase), it callskvmppc_core_queue_program()afterwards ifkvmppc_emulate_instruction()returnedEMULATE_FAIL, so the guest gets an program interrupt for the illegal opcode.
However, thekvmppc_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 ofkvmppc_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 functionkvmppc_emulate_instruction()that should _not_ inject program interrupts, so remove thekvmppc_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 <[email protected]>--- arch/powerpc/kvm/emulate.c | 1 - 1 file changed, 1 deletion(-)arch/powerpc/kvm/emulate.c +0
-0
arch/powerpc/kvm/emulate.c int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) · line 307
Quoted 7 lines
arch/powerpc/kvm/emulate.c +0
-1@@ -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 ); } }
I've tested this patch with kvm-unit-tests: it solves the multiple illegal instruction exceptions, but the test fails because SRR1 is not updated correctly. It should contains the bit for "Illegal Instruction" whereas it is 0.
[But I think it's what you explain in your last email]
Thanks,
Laurent
Quoted 14 lines · Thomas Huth
If
kvmppc_handle_exit_pr()callskvmppc_emulate_instruction()to emulate one instruction (in theBOOK3S_INTERRUPT_H_EMUL_ASSISTcase), it callskvmppc_core_queue_program()afterwards ifkvmppc_emulate_instruction()returnedEMULATE_FAIL, so the guest gets an program interrupt for the illegal opcode.
However, thekvmppc_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 ofkvmppc_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 functionkvmppc_emulate_instruction()that should _not_ inject program interrupts, so remove thekvmppc_core_queue_program()here.
Quoted 8 lines
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 <[email protected]>
I'm surprised you're the first one to encounter this :).
Alex
Quoted 38 lines · Laurent Vivier
Quoted 36 lines · Thomas Huth
If
kvmppc_handle_exit_pr()callskvmppc_emulate_instruction()to emulate one instruction (in theBOOK3S_INTERRUPT_H_EMUL_ASSISTcase), it callskvmppc_core_queue_program()afterwards ifkvmppc_emulate_instruction()returnedEMULATE_FAIL, so the guest gets an program interrupt for the illegal opcode.
However, thekvmppc_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 ofkvmppc_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 functionkvmppc_emulate_instruction()that should _not_ inject program interrupts, so remove thekvmppc_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 <[email protected]>--- arch/powerpc/kvm/emulate.c | 1 - 1 file changed, 1 deletion(-)arch/powerpc/kvm/emulate.c +0
-1@@ -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 ); }
Quoted 8 lines
arch/powerpc/kvm/emulate.c int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) · line 307
Quoted 3 lines
arch/powerpc/kvm/emulate.c +0
-0}I've tested this patch with kvm-unit-tests: it solves the multiple illegal instruction exceptions, but the test fails because SRR1 is not updated correctly. It should contains the bit for "Illegal Instruction" whereas it is 0.
[But I think it's what you explain in your last email]
So if the illegal instruction flag is missing, that's probably because the host CPU didn't pass that in via SRR1. That's probably a subtle difference between EMUL_ASSIST and PROGRAM.
Please send a follow-up patch that sets the illegal instruction bit in flags on EMULATE_FAIL as well.
Alex
Quoted 40 lines · Laurent Vivier
Quoted 37 lines · Thomas Huth
If
kvmppc_handle_exit_pr()callskvmppc_emulate_instruction()to emulate one instruction (in theBOOK3S_INTERRUPT_H_EMUL_ASSISTcase), it callskvmppc_core_queue_program()afterwards ifkvmppc_emulate_instruction()returnedEMULATE_FAIL, so the guest gets an program interrupt for the illegal opcode.
However, thekvmppc_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 ofkvmppc_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 functionkvmppc_emulate_instruction()that should _not_ inject program interrupts, so remove thekvmppc_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 <[email protected]>--- arch/powerpc/kvm/emulate.c | 1 - 1 file changed, 1 deletion(-)arch/powerpc/kvm/emulate.c +0
-1@@ -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 ); } }
Quoted 8 lines
Quoted 2 lines
I've tested this patch with kvm-unit-tests: it solves the multiple illegal instruction exceptions, but the test fails because SRR1 is not updated correctly. It should contains the bit for "Illegal Instruction" whereas it is 0.
[But I think it's what you explain in your last email]
Yes, but that's a separate problem, so I did not include it in this patch here yet. (Also, I'm not sure yet how to exactly fix that other problem with SRR1)
Thomas
Quoted 49 lines · Alexander Graf
Quoted 39 lines · Laurent Vivier
Quoted 37 lines · Thomas Huth
If
kvmppc_handle_exit_pr()callskvmppc_emulate_instruction()to emulate one instruction (in theBOOK3S_INTERRUPT_H_EMUL_ASSISTcase), it callskvmppc_core_queue_program()afterwards ifkvmppc_emulate_instruction()returnedEMULATE_FAIL, so the guest gets an program interrupt for the illegal opcode.
However, thekvmppc_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 ofkvmppc_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 functionkvmppc_emulate_instruction()that should _not_ inject program interrupts, so remove thekvmppc_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 <[email protected]>--- arch/powerpc/kvm/emulate.c | 1 - 1 file changed, 1 deletion(-)arch/powerpc/kvm/emulate.c +0
-1@@ -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 );Quoted 8 lines
Quoted 3 lines
arch/powerpc/kvm/emulate.c +0
-0}}I've tested this patch with kvm-unit-tests: it solves the multiple illegal instruction exceptions, but the test fails because SRR1 is not updated correctly. It should contains the bit for "Illegal Instruction" whereas it is 0.
[But I think it's what you explain in your last email]
Quoted 3 lines
So if the illegal instruction flag is missing, that's probably because the host CPU didn't pass that in via SRR1. That's probably a subtle difference between
EMUL_ASSISTand PROGRAM.
Thanks for that hint! You're right, flags is only 0 if exit_nr is BOOK3S_INTERRUPT_H_EMUL_ASSIST. It seems to contain proper values for BOOK3S_INTERRUPT_PROGRAM, e.g. for privileged-instruction program interrupts.
Looking at the PowerISA, this also supports this theory: For emulation assist interrupts, the bits in SRR1 are 0.
So the right fix really seems to be to set flags = SRR1_PROGILL in case the function has been called with EMUL_ASSIST.
Quoted 2 lines
Please send a follow-up patch that sets the illegal instruction bit in flags on
EMULATE_FAILas well.
I think I'll best send a separate patch, since it is a separate issue.
Thomas
Laurent Vivier
Tested-byQuoted 50 lines · Thomas Huth
Quoted 40 lines · Laurent Vivier
Quoted 37 lines · Thomas Huth
If
kvmppc_handle_exit_pr()callskvmppc_emulate_instruction()to emulate one instruction (in theBOOK3S_INTERRUPT_H_EMUL_ASSISTcase), it callskvmppc_core_queue_program()afterwards ifkvmppc_emulate_instruction()returnedEMULATE_FAIL, so the guest gets an program interrupt for the illegal opcode.
However, thekvmppc_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 ofkvmppc_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 functionkvmppc_emulate_instruction()that should _not_ inject program interrupts, so remove thekvmppc_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 <[email protected]>--- arch/powerpc/kvm/emulate.c | 1 - 1 file changed, 1 deletion(-)arch/powerpc/kvm/emulate.c +0
-1@@ -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 ); } }Quoted 8 lines
Quoted 2 lines
I've tested this patch with kvm-unit-tests: it solves the multiple illegal instruction exceptions, but the test fails because SRR1 is not updated correctly. It should contains the bit for "Illegal Instruction" whereas it is 0.
[But I think it's what you explain in your last email]
Quoted 3 lines
Yes, but that's a separate problem, so I did not include it in this patch here yet. (Also, I'm not sure yet how to exactly fix that other problem with SRR1)
OK, so for this one I can say:
Laurent
Quoted 19 lines · Alexander Graf
Quoted 18 lines · Thomas Huth
If
kvmppc_handle_exit_pr()callskvmppc_emulate_instruction()to emulate one instruction (in theBOOK3S_INTERRUPT_H_EMUL_ASSISTcase), it callskvmppc_core_queue_program()afterwards ifkvmppc_emulate_instruction()returnedEMULATE_FAIL, so the guest gets an program interrupt for the illegal opcode.
However, thekvmppc_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 ofkvmppc_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 functionkvmppc_emulate_instruction()that should _not_ inject program interrupts, so remove thekvmppc_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:
Quoted 8 lines
Quoted 4 lines
Couldn't emulate instruction 0x00000000 (op 0 xop 0) kvmppc_handle_exit_pr: emulation at 700 failed (00000000)Signed-off-by Thomas Huth <[email protected]>I'm surprised you're the first one to encounter this :).
Reviewed-by Alexander Graf <[email protected]>
*ping*
Paul, could you maybe pick up this patch?
Thanks,
Thomas
Quoted 25 lines · Thomas Huth
Quoted 24 lines · Alexander Graf
Quoted 22 lines · Thomas Huth
If
kvmppc_handle_exit_pr()callskvmppc_emulate_instruction()to emulate one instruction (in theBOOK3S_INTERRUPT_H_EMUL_ASSISTcase), it callskvmppc_core_queue_program()afterwards ifkvmppc_emulate_instruction()returnedEMULATE_FAIL, so the guest gets an program interrupt for the illegal opcode.
However, thekvmppc_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 ofkvmppc_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 functionkvmppc_emulate_instruction()that should _not_ inject program interrupts, so remove thekvmppc_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 <[email protected]>
Quoted 7 lines
Quoted 3 lines
I'm surprised you're the first one to encounter this :).
Reviewed-by Alexander Graf <[email protected]>*ping*
Paul, could you maybe pick up this patch?
ping^2
Thomas
Paul Mackerras
AppliedQuoted 14 lines · Thomas Huth
If
kvmppc_handle_exit_pr()callskvmppc_emulate_instruction()to emulate one instruction (in theBOOK3S_INTERRUPT_H_EMUL_ASSISTcase), it callskvmppc_core_queue_program()afterwards ifkvmppc_emulate_instruction()returnedEMULATE_FAIL, so the guest gets an program interrupt for the illegal opcode.
However, thekvmppc_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 ofkvmppc_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 functionkvmppc_emulate_instruction()that should _not_ inject program interrupts, so remove thekvmppc_core_queue_program()here.
Quoted 8 lines
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 <[email protected]>
Thanks, applied to my kvm-ppc-next branch (with adjusted subject).
Paul.