From: David Gibson Date: Tue, 05 Feb 2019 02:21:09 +0000 Subject: Re: [PATCH] KVM: PPC: Book3S PR: Add emulation for slbfee. instruction Message-Id: <20190205022109.GB22661@umbus.fritz.box> MIME-Version: 1 Content-Type: multipart/mixed; boundary="0eh6TmSyL6TZE2Uz" List-Id: References: <20190204110618.GA938@blackberry> In-Reply-To: <20190204110618.GA938@blackberry> To: kvm-ppc@vger.kernel.org --0eh6TmSyL6TZE2Uz Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Feb 04, 2019 at 06:07:40PM +0100, C=E9dric Le Goater wrote: > On 2/4/19 12:06 PM, Paul Mackerras wrote: > > Recent kernels, since commit e15a4fea4dee ("powerpc/64s/hash: Add > > some SLB debugging tests", 2018-10-03) use the slbfee. instruction, > > which PR KVM currently does not have code to emulate. Consequently > > recent kernels fail to boot under PR KVM. This adds emulation of > > slbfee., enabling these kernels to boot successfully. >=20 > I still see a problem with a PR guest which I don't think this patch=20 > is supposed to solve : >=20 > [ 0.022884] kernel tried to execute exec-protected page (c000000001630= afc) -exploit attempt? (uid: 0) > [ 0.022984] BUG: Unable to handle kernel instruction fetch > [ 0.023023] Faulting instruction address: 0xc000000001630afc > [ 0.023080] Oops: Kernel access of bad area, sig: 11 [#1] > [ 0.023119] LE SMP NR_CPUS=3D1024 NUMA pSeries > [ 0.023167] Modules linked in: > [ 0.023207] CPU: 3 PID: 0 Comm: swapper/3 Not tainted 5.0.0-rc5+ #7 > [ 0.023255] NIP: c000000001630afc LR: c00000000000ac8c CTR: c00000003= fffbc00 > [ 0.023311] REGS: c00000003ffbfa70 TRAP: 0400 Not tainted (5.0.0-rc= 5+) > [ 0.023358] MSR: a000000010001033 CR: 24000288 = XER: 00000000 > [ 0.023422] CFAR: 0000000000000000 IRQMASK: 1=20 > [ 0.023422] GPR00: 0000000000000000 c00000003ffbfd00 c000000001580600 = c00000003ffbfd70=20 > [ 0.023422] GPR04: 0000000000000000 c0000001ff5d16f0 0000000000000000 = 0000000000000808=20 > [ 0.023422] GPR08: 0000000000000000 0000000000000000 0000000000000002 = 0000000000000900=20 > [ 0.023422] GPR12: a000000000009033 c00000003fffbc00 c0000001fc233f90 = 0000000000000000=20 > [ 0.023422] GPR16: 0000000000000000 0000000000000000 0000000000000003 = c0000000000503d0=20 > [ 0.023422] GPR20: c0000000015b0124 0000000000000400 0000000000000000 = c0000000015adc70=20 > [ 0.023422] GPR24: c00000000172fe28 0000000000000000 0000000000080000 = 0000000000000000=20 > [ 0.023422] GPR28: c0000000015affb8 0000000000000001 0000000000000008 = c0000000015a9c18=20 > [ 0.023912] NIP [c000000001630afc] kvm_tmp+0x162c/0x100000 > [ 0.023956] LR [c00000000000ac8c] soft_nmi_common+0xcc/0xd0 >=20 > Any idea where that comes from ? So, I know that PR is currently broken because it doesn't support all the page sizes / segment sizes that qemu wants it to (I sacrificed PR support for consistency in the environment we present to the guest). I don't know if the crash above is that or something else, though. >=20 > Thanks, >=20 > C.=20 >=20 > >=20 > > Signed-off-by: Paul Mackerras > > --- > > arch/powerpc/include/asm/kvm_host.h | 1 + > > arch/powerpc/kvm/book3s_32_mmu.c | 1 + > > arch/powerpc/kvm/book3s_64_mmu.c | 14 ++++++++++++++ > > arch/powerpc/kvm/book3s_emulate.c | 18 ++++++++++++++++++ > > 4 files changed, 34 insertions(+) > >=20 > > diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include= /asm/kvm_host.h > > index 0f98f00..0914303 100644 > > --- a/arch/powerpc/include/asm/kvm_host.h > > +++ b/arch/powerpc/include/asm/kvm_host.h > > @@ -377,6 +377,7 @@ struct kvmppc_mmu { > > void (*slbmte)(struct kvm_vcpu *vcpu, u64 rb, u64 rs); > > u64 (*slbmfee)(struct kvm_vcpu *vcpu, u64 slb_nr); > > u64 (*slbmfev)(struct kvm_vcpu *vcpu, u64 slb_nr); > > + int (*slbfee)(struct kvm_vcpu *vcpu, gva_t eaddr, ulong *ret_slb); > > void (*slbie)(struct kvm_vcpu *vcpu, u64 slb_nr); > > void (*slbia)(struct kvm_vcpu *vcpu); > > /* book3s */ > > diff --git a/arch/powerpc/kvm/book3s_32_mmu.c b/arch/powerpc/kvm/book3s= _32_mmu.c > > index 6121699..6f789f6 100644 > > --- a/arch/powerpc/kvm/book3s_32_mmu.c > > +++ b/arch/powerpc/kvm/book3s_32_mmu.c > > @@ -425,6 +425,7 @@ void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcp= u) > > mmu->slbmte =3D NULL; > > mmu->slbmfee =3D NULL; > > mmu->slbmfev =3D NULL; > > + mmu->slbfee =3D NULL; > > mmu->slbie =3D NULL; > > mmu->slbia =3D NULL; > > } > > diff --git a/arch/powerpc/kvm/book3s_64_mmu.c b/arch/powerpc/kvm/book3s= _64_mmu.c > > index c92dd25..d4b967f 100644 > > --- a/arch/powerpc/kvm/book3s_64_mmu.c > > +++ b/arch/powerpc/kvm/book3s_64_mmu.c > > @@ -435,6 +435,19 @@ static void kvmppc_mmu_book3s_64_slbmte(struct kvm= _vcpu *vcpu, u64 rs, u64 rb) > > kvmppc_mmu_map_segment(vcpu, esid << SID_SHIFT); > > } > > =20 > > +static int kvmppc_mmu_book3s_64_slbfee(struct kvm_vcpu *vcpu, gva_t ea= ddr, > > + ulong *ret_slb) > > +{ > > + struct kvmppc_slb *slbe =3D kvmppc_mmu_book3s_64_find_slbe(vcpu, eadd= r); > > + > > + if (slbe) { > > + *ret_slb =3D slbe->origv; > > + return 0; > > + } > > + *ret_slb =3D 0; > > + return -ENOENT; > > +} > > + > > static u64 kvmppc_mmu_book3s_64_slbmfee(struct kvm_vcpu *vcpu, u64 slb= _nr) > > { > > struct kvmppc_slb *slbe; > > @@ -670,6 +683,7 @@ void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcp= u) > > mmu->slbmte =3D kvmppc_mmu_book3s_64_slbmte; > > mmu->slbmfee =3D kvmppc_mmu_book3s_64_slbmfee; > > mmu->slbmfev =3D kvmppc_mmu_book3s_64_slbmfev; > > + mmu->slbfee =3D kvmppc_mmu_book3s_64_slbfee; > > mmu->slbie =3D kvmppc_mmu_book3s_64_slbie; > > mmu->slbia =3D kvmppc_mmu_book3s_64_slbia; > > mmu->xlate =3D kvmppc_mmu_book3s_64_xlate; > > diff --git a/arch/powerpc/kvm/book3s_emulate.c b/arch/powerpc/kvm/book3= s_emulate.c > > index 8c7e933..6ef7c5f 100644 > > --- a/arch/powerpc/kvm/book3s_emulate.c > > +++ b/arch/powerpc/kvm/book3s_emulate.c > > @@ -47,6 +47,7 @@ > > #define OP_31_XOP_SLBMFEV 851 > > #define OP_31_XOP_EIOIO 854 > > #define OP_31_XOP_SLBMFEE 915 > > +#define OP_31_XOP_SLBFEE 979 > > =20 > > #define OP_31_XOP_TBEGIN 654 > > #define OP_31_XOP_TABORT 910 > > @@ -416,6 +417,23 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run,= struct kvm_vcpu *vcpu, > > =20 > > vcpu->arch.mmu.slbia(vcpu); > > break; > > + case OP_31_XOP_SLBFEE: > > + if (!(inst & 1) || !vcpu->arch.mmu.slbfee) { > > + return EMULATE_FAIL; > > + } else { > > + ulong b, t; > > + ulong cr =3D kvmppc_get_cr(vcpu) & ~CR0_MASK; > > + > > + b =3D kvmppc_get_gpr(vcpu, rb); > > + if (!vcpu->arch.mmu.slbfee(vcpu, b, &t)) > > + cr |=3D 2 << CR0_SHIFT; > > + kvmppc_set_gpr(vcpu, rt, t); > > + /* copy XER[SO] bit to CR0[SO] */ > > + cr |=3D (vcpu->arch.regs.xer & 0x80000000) >> > > + (31 - CR0_SHIFT); > > + kvmppc_set_cr(vcpu, cr); > > + } > > + break; > > case OP_31_XOP_SLBMFEE: > > if (!vcpu->arch.mmu.slbmfee) { > > emulated =3D EMULATE_FAIL; > >=20 >=20 --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --0eh6TmSyL6TZE2Uz Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEdfRlhq5hpmzETofcbDjKyiDZs5IFAlxY8xIACgkQbDjKyiDZ s5JmiA//RAckuls++I3ycVywQj48PwvBZ9dpq4CcXkUM3wh2ULPfjGZJvJlWhVwU doBwLELxHNrAn4KSXIaHMSeqIlKJDFeDqgKykPtDxdNbWj79uhVXJZze/NkQlCy0 D4vWklwdqQB1SJqImCq9afziCxQy/nbfGyqSZVxEHfyH7e9jrNlkY7V490V0i8sS JhlByX84207NIqgrvXLrvp0HWHez8ZJ7RcIZ+FqgQnJ+rl4nC1j4eDG51w4QNgZY 3lZPUX2ZkrIfJ+9Rge9fG20TeeatiNUm0ngPNu6231YThXNs0fJV29ur++QXY9EH WVW6sa/vqYjf/fKWjzUfSlRT973iIILJQDtq6nN88jv7fBwITtlHfBcCYzUNoP71 hvduquxVakXAa0AzAf2Eic3nJzxVt8b3YjmcaWVp2sQX8ebQiFyeB444ZiwIT4wg syRX3fhbJTrKqlM33Ao/7bs7ePB2dQ7WiUjgp/pl7WCjbW1nRkVCKXwrwJMBysd3 420FtLMV8m243M6BeG7rKYuEZWfh8qv22dfPQJGBXNjESAFTsdgmTw0LLrE9Sekp yPJVOWXPpRNGvEfZy/6OkaAwbhT77g14F6Ab/nS8M2NunZwxLPtle9OpreQ3tqgb aeIfUFbeQgP8PLlVcl5CUCW4qMvQuZftoBbtCMmBswb3PZG4a08= =oQEC -----END PGP SIGNATURE----- --0eh6TmSyL6TZE2Uz--