From: Leonardo Bras Date: Thu, 20 Feb 2020 17:51:49 +0000 Subject: Re: [PATCH] KVM: PPC: Book3S HV: Treat TM-related invalid form instructions on P9 like the valid one Message-Id: MIME-Version: 1 Content-Type: multipart/mixed; boundary="=-jlIhWTfxHOxfCQ45o+IG" List-Id: References: <20200218211324.23045-1-gromero@linux.ibm.com> In-Reply-To: <20200218211324.23045-1-gromero@linux.ibm.com> To: Gustavo Romero , kvm-ppc@vger.kernel.org, paulus@ozlabs.org Cc: mikey@neuling.org, linuxppc-dev@lists.ozlabs.org --=-jlIhWTfxHOxfCQ45o+IG Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello Gustavo, comments inline: On Tue, 2020-02-18 at 16:13 -0500, Gustavo Romero wrote: > diff --git a/arch/powerpc/kvm/book3s_hv_tm.c b/arch/powerpc/kvm/book3s_hv= _tm.c > index 0db937497169..cc90b8b82329 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. > */ >=20 > +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt > + Could not see where is this used. > #include >=20 > #include > @@ -44,7 +46,18 @@ int kvmhv_p9_tm_emulation(struct kvm_vcpu *vcpu) > u64 newmsr, bescr; > int ra, rs; >=20 > - switch (instr & 0xfc0007ff) { > + /* > + * rfid, rfebb, and mtmsrd encode bit 31 =3D 0 since it's a reserved bi= t > + * in these instructions, so masking bit 31 out doesn't change these > + * instructions. For treclaim., tsr., and trechkpt. instructions if bit > + * 31 =3D 0 then they are per ISA invalid forms, however P9 UM, in sect= ion > + * 4.6.10 Book II Invalid Forms, informs specifically that ignoring bit > + * 31 is an acceptable way to handle these invalid forms that have > + * bit 31 =3D 0. Moreover, for emulation purposes both forms (w/ and wo= / > + * bit 31 set) can generate a softpatch interrupt. Hence both forms > + * are handled below for these instructions so they behave the same way= . > + */ > + switch (instr & PO_XOP_OPCODE_MASK) { >=20 > - case PPC_INST_TRECHKPT: > + /* ignore bit 31, see comment above */ > + case (PPC_INST_TRECHKPT & PO_XOP_OPCODE_MASK): > /* XXX do we need to check for PR=3D0 here? */ > /* check for TM disabled in the HFSCR or MSR */ > if (!(vcpu->arch.hfscr & HFSCR_TM)) { > @@ -208,6 +224,8 @@ int kvmhv_p9_tm_emulation(struct kvm_vcpu *vcpu) > } >=20 Seems good, using the same flag to mask out bit 31 of these macros. They are used only in a few places, and I think removing the macro bit would be ok, but I think your way is better to keep it documented.=20 I just noticed that there is a similar function that uses PPC_INST_TSR: kvmhv_p9_tm_emulation_early @ arch/powerpc/kvm/book3s_hv_tm_builtin.c. Wouldn't it need to be changed as well? > /* 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 emulat= ion", instr); > + > return RESUME_GUEST; > } I suppose this is the right thing to do, but I think it would be better to give this change it's own patch. What do you think? Best regards, Leonardo Bras --=-jlIhWTfxHOxfCQ45o+IG Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEMdeUgIzgjf6YmUyOlQYWtz9SttQFAl5OxzUACgkQlQYWtz9S ttQkYxAAx8gegORSGUOrDvIhbnkhhLC6DodaVy7410rljqks5Wx+R0yMjFsoEx1g a6jOLvmr5Tr52is0EZd9z/OtF8oweo+VakGhGGTnjByZBGWuqvj7LviZYDbIsXYU UExOXD3vdzi8CkUdnWLRn8nDSCGIFDRY3YmZgczIM6JBiLdCOHhSUVBKtYwZsMhK 8cYqEwZL6Yu1tkV1OjI7ZBpucnYljJ9+xPdcPWK8dEqxoYCtcOXm8vIbw4ONAoyG vDKEftPCinjePBYlGwipuMmswKWKJc9K9AO7oktHLsld81hXe3JyzhA8mKE4OT7W v+3gtl8QueexKmg4JvZLY2hIfuNIDTXBYgjpoLtj0OnP3GL/KLgp31govpVOmdNb YkGUMJAGzwulaNHVntpW10bZfKxOuwFvB9VSjL9L5h+3wcCVP7IsReakYnD0+JiV Q06II0NWEMiSWaKaqljYtJWZ0xCxS6RlJw1FdYAzHIQflqHd9PDYreOc86SGm0ND ERNT5IJZrmdMoW9SZuCZG6FzZZSsrOk35W0tssu2alDQPX689ePATgZb+p8KS61J XvuPR8LFmSS73cYZ93508+SVuH8Q8/O1sn3Fnyz2QkJ52sRu9Iqk46fyO7BZ0FLf hMqAvILhLMpBVgLdssAkRk7cpTIv39RuM90baQSTZzstqlCCUo0= =rtFD -----END PGP SIGNATURE----- --=-jlIhWTfxHOxfCQ45o+IG--