From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson Subject: Re: [PATCH v2] KVM: PPC: Book3S HV: Make HPT resizing work on POWER9 Date: Fri, 9 Feb 2018 10:40:34 +1100 Message-ID: <20180208234034.GF11634@umbus.fritz.box> References: <20180207090445.GC19335@fergus.ozlabs.ibm.com> <20180207090605.GD19335@fergus.ozlabs.ibm.com> <20180207091135.GE19335@fergus.ozlabs.ibm.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="5CUMAwwhRxlRszMD" Cc: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org To: Paul Mackerras Return-path: Received: from ozlabs.org ([103.22.144.67]:35305 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751343AbeBHXku (ORCPT ); Thu, 8 Feb 2018 18:40:50 -0500 Content-Disposition: inline In-Reply-To: <20180207091135.GE19335@fergus.ozlabs.ibm.com> Sender: kvm-owner@vger.kernel.org List-ID: --5CUMAwwhRxlRszMD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Feb 07, 2018 at 08:11:35PM +1100, Paul Mackerras wrote: > From: David Gibson >=20 > This adds code to enable the HPT resizing code to work on POWER9, > which uses a slightly modified HPT entry format compared to POWER8. > On POWER9, we convert HPTEs read from the HPT from the new format to > the old format so that the rest of the HPT resizing code can work as > before. HPTEs written to the new HPT are converted to the new format > as the last step before writing them into the new HPT. >=20 > This takes out the checks added by commit bcd3bb63dbc8 ("KVM: PPC: > Book3S HV: Disable HPT resizing on POWER9 for now", 2017-02-18), > now that HPT resizing works on POWER9. >=20 > On POWER9, when we pivot to the new HPT, we now call > kvmppc_setup_partition_table() to update the partition table in order > to make the hardware use the new HPT. >=20 > [paulus@ozlabs.org - added kvmppc_setup_partition_table() call, > wrote commit message.] >=20 > Signed-off-by: Paul Mackerras Reviewed-by: David Gibson > --- > v2: Include change to powerpc.c, which somehow got missed in v1. >=20 > arch/powerpc/kvm/book3s_64_mmu_hv.c | 30 +++++++++++++++++++++++------- > arch/powerpc/kvm/powerpc.c | 3 +-- > 2 files changed, 24 insertions(+), 9 deletions(-) >=20 > diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3= s_64_mmu_hv.c > index d196499..cb34be7 100644 > --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c > +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c > @@ -1261,6 +1261,11 @@ static unsigned long resize_hpt_rehash_hpte(struct= kvm_resize_hpt *resize, > /* Nothing to do */ > goto out; > =20 > + if (cpu_has_feature(CPU_FTR_ARCH_300)) { > + rpte =3D be64_to_cpu(hptep[1]); > + vpte =3D hpte_new_to_old_v(vpte, rpte); > + } > + > /* Unmap */ > rev =3D &old->rev[idx]; > guest_rpte =3D rev->guest_rpte; > @@ -1290,7 +1295,6 @@ static unsigned long resize_hpt_rehash_hpte(struct = kvm_resize_hpt *resize, > =20 > /* Reload PTE after unmap */ > vpte =3D be64_to_cpu(hptep[0]); > - > BUG_ON(vpte & HPTE_V_VALID); > BUG_ON(!(vpte & HPTE_V_ABSENT)); > =20 > @@ -1299,6 +1303,12 @@ static unsigned long resize_hpt_rehash_hpte(struct= kvm_resize_hpt *resize, > goto out; > =20 > rpte =3D be64_to_cpu(hptep[1]); > + > + if (cpu_has_feature(CPU_FTR_ARCH_300)) { > + vpte =3D hpte_new_to_old_v(vpte, rpte); > + rpte =3D hpte_new_to_old_r(rpte); > + } > + > pshift =3D kvmppc_hpte_base_page_shift(vpte, rpte); > avpn =3D HPTE_V_AVPN_VAL(vpte) & ~(((1ul << pshift) - 1) >> 23); > pteg =3D idx / HPTES_PER_GROUP; > @@ -1336,6 +1346,10 @@ static unsigned long resize_hpt_rehash_hpte(struct= kvm_resize_hpt *resize, > new_hptep =3D (__be64 *)(new->virt + (new_idx << 4)); > =20 > replace_vpte =3D be64_to_cpu(new_hptep[0]); > + if (cpu_has_feature(CPU_FTR_ARCH_300)) { > + unsigned long replace_rpte =3D be64_to_cpu(new_hptep[1]); > + replace_vpte =3D hpte_new_to_old_v(replace_vpte, replace_rpte); > + } > =20 > if (replace_vpte & (HPTE_V_VALID | HPTE_V_ABSENT)) { > BUG_ON(new->order >=3D old->order); > @@ -1351,6 +1365,11 @@ static unsigned long resize_hpt_rehash_hpte(struct= kvm_resize_hpt *resize, > /* Discard the previous HPTE */ > } > =20 > + if (cpu_has_feature(CPU_FTR_ARCH_300)) { > + rpte =3D hpte_old_to_new_r(vpte, rpte); > + vpte =3D hpte_old_to_new_v(vpte); > + } > + > new_hptep[1] =3D cpu_to_be64(rpte); > new->rev[new_idx].guest_rpte =3D guest_rpte; > /* No need for a barrier, since new HPT isn't active */ > @@ -1368,12 +1387,6 @@ static int resize_hpt_rehash(struct kvm_resize_hpt= *resize) > unsigned long i; > int rc; > =20 > - /* > - * resize_hpt_rehash_hpte() doesn't handle the new-format HPTEs > - * that POWER9 uses, and could well hit a BUG_ON on POWER9. > - */ > - if (cpu_has_feature(CPU_FTR_ARCH_300)) > - return -EIO; > for (i =3D 0; i < kvmppc_hpt_npte(&kvm->arch.hpt); i++) { > rc =3D resize_hpt_rehash_hpte(resize, i); > if (rc !=3D 0) > @@ -1404,6 +1417,9 @@ static void resize_hpt_pivot(struct kvm_resize_hpt = *resize) > =20 > synchronize_srcu_expedited(&kvm->srcu); > =20 > + if (cpu_has_feature(CPU_FTR_ARCH_300)) > + kvmppc_setup_partition_table(kvm); > + > resize_hpt_debug(resize, "resize_hpt_pivot() done\n"); > } > =20 > diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c > index b4010b8..47c7a30 100644 > --- a/arch/powerpc/kvm/powerpc.c > +++ b/arch/powerpc/kvm/powerpc.c > @@ -633,8 +633,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, lon= g ext) > r =3D 1; > break; > case KVM_CAP_SPAPR_RESIZE_HPT: > - /* Disable this on POWER9 until code handles new HPTE format */ > - r =3D !!hv_enabled && !cpu_has_feature(CPU_FTR_ARCH_300); > + r =3D !!hv_enabled; > break; > #endif > #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE --=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 --5CUMAwwhRxlRszMD Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEdfRlhq5hpmzETofcbDjKyiDZs5IFAlp83/IACgkQbDjKyiDZ s5LlMA//amiVWS6JA4C2BRQW+AX+p5M5VcF8SM3LcCrJ5CyolUEwoiTKnBjpGTYR cW3PB0g1wnblMopn84X3olOJQU8h0XdxTzLMTih/IzGFgvi5RTGYcdufHtiSzOvs 3R/WcaZwqSvNKyiY8EwoIJN0PSLC1K/qZ0WB3tzLVtgYfqkpEVFfAm1Nt+dJID8o YYBqjNrR/W+yb3C91GBX3GZHVOy2meWy38io+4MN75w4SvZtWH+f8dX5s9t3Zwdo X9PkHwismnoDeu9iBwnIccBRyQVRZnhiopj027bu+gOUjMWwFvJuElbSvkenDBEq 15jKm2oQEVhluuVxSW0MpggMuvDafktKxbF7ZAZIOjzczD0brnf/4vsI/NdrBYkt gNvVtT27148K9DVVLL2Uv9qFVZ7xX0/HgWDQi+uLvp+FbZv3L6T7A/BNgvZUeFHx /4Pf8Y7+eTI9sc2CqywzmIw9OJ68pEdzHSg89F2FlRU4bXxVktT4iBmGstQOxE8e BpEtfyPDGlj2+p4EWW71VDMvm/VqiwOwMvp7bAkdxSXBTh/WJBsWiksQ8gf44grT ruElqzzzjs1Ku74QV0/3elAjICP7n/GY6X15eF8R1VkVD1HLejXpi6q/IB43cbCK R/rTCfMjesAomDhSkhE/WCIBoh0niu3wSzxbZgtQh6V1ByMKE54= =zN74 -----END PGP SIGNATURE----- --5CUMAwwhRxlRszMD--