On Thu, Feb 13, 2020 at 10:15:32AM -0500, Gustavo Romero wrote: > On P9 DD2.2 due to a CPU defect some TM instructions need to be emulated by > KVM. This is handled at first by the hardware raising a softpatch interrupt > when certain TM instructions that need KVM assistance are executed in the > guest. Some TM instructions, although not defined in the Power ISA, might > raise a softpatch interrupt. For instance, 'tresume.' instruction as > defined in the ISA must have bit 31 set (1), but an instruction that > matches 'tresume.' OP and XO opcodes but has bit 31 not set (0), like > 0x7cfe9ddc, also raises a softpatch interrupt, for example, if a code > like the following is executed in the guest it will raise a softpatch > interrupt just like a 'tresume.' when the TM facility is enabled: > > int main() { asm("tabort. 0; .long 0x7cfe9ddc;"); } > > Currently in such a case KVM throws a complete trace like the following: [snip] > and then treats the executed instruction as 'nop' whilst it should actually > be treated as an illegal instruction since it's not defined by the ISA. > > This commit changes the handling of the case above by treating the > unrecognized TM instructions that can raise a softpatch but are not > defined in the ISA as illegal ones instead of as 'nop' and by gently > reporting it to the host instead of throwing a trace. > > Signed-off-by: Gustavo Romero <gromero@xxxxxxxxxxxxx> Reviewed-by: Segher Boessenkool <segher@xxxxxxxxxxxxxxxxxxx> > --- > arch/powerpc/kvm/book3s_hv_tm.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/arch/powerpc/kvm/book3s_hv_tm.c b/arch/powerpc/kvm/book3s_hv_tm.c > index 0db937497169..d342a9e11298 100644 > --- a/arch/powerpc/kvm/book3s_hv_tm.c > +++ b/arch/powerpc/kvm/book3s_hv_tm.c > @@ -3,6 +3,8 @@ > * Copyright 2017 Paul Mackerras, IBM Corp. <paulus@xxxxxxxxxxx> > */ > > +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt > + > #include <linux/kvm_host.h> > > #include <asm/kvm_ppc.h> > @@ -208,6 +210,8 @@ int kvmhv_p9_tm_emulation(struct kvm_vcpu *vcpu) > } > > /* What should we do here? We didn't recognize the instruction */ > - WARN_ON_ONCE(1); > + kvmppc_core_queue_program(vcpu, SRR1_PROGILL); > + pr_warn_ratelimited("Unrecognized TM-related instruction %#x for emulation", instr); > + > return RESUME_GUEST; > } Do we actually know it is TM-related here? Otherwise, looks good to me :-) Segher