From: David Gibson Date: Thu, 27 Sep 2018 05:01:42 +0000 Subject: Re: [RFC PATCH 32/32] KVM: PPC: Book3S HV: Add nested shadow page tables to debugfs Message-Id: <20180927050142.GS30868@umbus.fritz.box> MIME-Version: 1 Content-Type: multipart/mixed; boundary="saoT5+PyEcEjd88F" List-Id: References: <1537524123-9578-33-git-send-email-paulus@ozlabs.org> In-Reply-To: <1537524123-9578-33-git-send-email-paulus@ozlabs.org> To: kvm-ppc@vger.kernel.org --saoT5+PyEcEjd88F Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Sep 21, 2018 at 08:02:03PM +1000, Paul Mackerras wrote: > This adds a list of valid shadow PTEs for each nested guest to > the 'radix' file for the guest in debugfs. This can be useful for > debugging. >=20 > Signed-off-by: Paul Mackerras Reviewed-by: David Gibson > --- > arch/powerpc/include/asm/kvm_book3s_64.h | 1 + > arch/powerpc/kvm/book3s_64_mmu_radix.c | 39 ++++++++++++++++++++++++++= +++--- > arch/powerpc/kvm/book3s_hv_nested.c | 15 ++++++++++++ > 3 files changed, 52 insertions(+), 3 deletions(-) >=20 > diff --git a/arch/powerpc/include/asm/kvm_book3s_64.h b/arch/powerpc/incl= ude/asm/kvm_book3s_64.h > index 84c4c0e..12007f6 100644 > --- a/arch/powerpc/include/asm/kvm_book3s_64.h > +++ b/arch/powerpc/include/asm/kvm_book3s_64.h > @@ -50,6 +50,7 @@ struct rmap_nested { > struct kvm_nested_guest *kvmhv_get_nested(struct kvm *kvm, int lpid, > bool create); > void kvmhv_put_nested(struct kvm_nested_guest *gp); > +int kvmhv_nested_next_lpid(struct kvm *kvm, int lpid); > =20 > /* Power architecture requires HPT is at least 256kiB, at most 64TiB */ > #define PPC_MIN_HPT_ORDER 18 > diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c b/arch/powerpc/kvm/bo= ok3s_64_mmu_radix.c > index 52b2a57..41beb9b 100644 > --- a/arch/powerpc/kvm/book3s_64_mmu_radix.c > +++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c > @@ -978,6 +978,7 @@ struct debugfs_radix_state { > struct kvm *kvm; > struct mutex mutex; > unsigned long gpa; > + int lpid; > int chars_left; > int buf_index; > char buf[128]; > @@ -1019,6 +1020,7 @@ static ssize_t debugfs_radix_read(struct file *file= , char __user *buf, > struct kvm *kvm; > unsigned long gpa; > pgd_t *pgt; > + struct kvm_nested_guest *nested; > pgd_t pgd, *pgdp; > pud_t pud, *pudp; > pmd_t pmd, *pmdp; > @@ -1053,10 +1055,39 @@ static ssize_t debugfs_radix_read(struct file *fi= le, char __user *buf, > } > =20 > gpa =3D p->gpa; > - pgt =3D kvm->arch.pgtable; > - while (len !=3D 0 && gpa < RADIX_PGTABLE_RANGE) { > + nested =3D NULL; > + pgt =3D NULL; > + while (len !=3D 0 && p->lpid >=3D 0) { > + if (gpa >=3D RADIX_PGTABLE_RANGE) { > + gpa =3D 0; > + pgt =3D NULL; > + if (nested) { > + kvmhv_put_nested(nested); > + nested =3D NULL; > + } > + p->lpid =3D kvmhv_nested_next_lpid(kvm, p->lpid); > + p->hdr =3D 0; > + if (p->lpid < 0) > + break; > + } > + if (!pgt) { > + if (p->lpid =3D=3D 0) { > + pgt =3D kvm->arch.pgtable; > + } else { > + nested =3D kvmhv_get_nested(kvm, p->lpid, false); > + if (!nested) { > + gpa =3D RADIX_PGTABLE_RANGE; > + continue; > + } > + pgt =3D nested->shadow_pgtable; > + } > + } > + n =3D 0; > if (!p->hdr) { > - n =3D scnprintf(p->buf, sizeof(p->buf), > + if (p->lpid > 0) > + n =3D scnprintf(p->buf, sizeof(p->buf), > + "\nNested LPID %d: ", p->lpid); > + n +=3D scnprintf(p->buf + n, sizeof(p->buf) - n, > "pgdir: %lx\n", (unsigned long)pgt); > p->hdr =3D 1; > goto copy; > @@ -1122,6 +1153,8 @@ static ssize_t debugfs_radix_read(struct file *file= , char __user *buf, > } > } > p->gpa =3D gpa; > + if (nested) > + kvmhv_put_nested(nested); > =20 > out: > mutex_unlock(&p->mutex); > diff --git a/arch/powerpc/kvm/book3s_hv_nested.c b/arch/powerpc/kvm/book3= s_hv_nested.c > index 0d7cd66..027cc16 100644 > --- a/arch/powerpc/kvm/book3s_hv_nested.c > +++ b/arch/powerpc/kvm/book3s_hv_nested.c > @@ -1182,3 +1182,18 @@ long int kvmhv_nested_page_fault(struct kvm_vcpu *= vcpu) > mutex_unlock(&gp->tlb_lock); > return ret; > } > + > +int kvmhv_nested_next_lpid(struct kvm *kvm, int lpid) > +{ > + int ret =3D -1; > + > + spin_lock(&kvm->mmu_lock); > + while (++lpid <=3D kvm->arch.max_nested_lpid) { > + if (kvm->arch.nested_guests[lpid]) { > + ret =3D lpid; > + break; > + } > + } > + spin_unlock(&kvm->mmu_lock); > + return ret; > +} --=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 --saoT5+PyEcEjd88F Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEdfRlhq5hpmzETofcbDjKyiDZs5IFAlusZDUACgkQbDjKyiDZ s5LmPxAA5Z2x3442BuwOC77JtjpUfBGJak8sSPwCsoAqPJQ+kU5K/q2qVXVmvtXp jCZTvIsAxlEB4gWiFYtBL+JVjxEg7kjquIIVPJ7jYwReTAlkp+WKgKv6xkbhhyiI BMvoi5ZwEfgCbrNGVBzSalKtE8/VIadEzV7d4+t+MtCnz+htsRXm0rEFTU8bVVCK iEYGYt78v/DlsYGJAjfUW6M3MdKfpQ5p9J7qj/fK3Zi/PfGeDhRKpTx53W7WMlk7 LlPRdPzEX7gPOLj1jEi92zOP2qC+YNRlnkQ9kD97966EZRmOZmbay7TC9mvld8d5 8vY62mcypN/EbxOFHVudWhw5GiFHmXgGvhKrK3guoiM5f4Gspfwy+IYlqD6Hcm2V bEcIyfQSaGHDaXbKiCgG37AhPLuc9XDGTrWIMng0bfP3Te9hD4uyo+Mj9/knbQuR nFRqrt7MssuBu6PPujsjCU23JQFriBrqouWoq6wu4FIpSfZTdLsnDzMePZWJPqGT ZJnNOd61RgxUqv+jP3+im+RPlZRrT7Vf08RuxYKIItnkU03cGGCkUen1TYgFIsEZ m07vPln6hs1MBMSxskZhx8XsyIzDVgJucYEF4LR7Zv/eAAQp1XG04psrZANzDMXl bx16hRxhDA0nscNgfPzlqNpRTuUH9MMRAOL6+ebSwIbGnm4LPKE= =xrqr -----END PGP SIGNATURE----- --saoT5+PyEcEjd88F--