From: David Gibson Date: Wed, 02 Jan 2019 02:50:10 +0000 Subject: Re: [PATCH 3/5] KVM: PPC: Book3S HV: Apply combination of host and l1 pte rc for nested guest Message-Id: <20190102025010.GG27457@umbus.fritz.box> MIME-Version: 1 Content-Type: multipart/mixed; boundary="L+ofChggJdETEG3Y" List-Id: To: kvm-ppc@vger.kernel.org --L+ofChggJdETEG3Y Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Dec 21, 2018 at 02:28:41PM +1100, Suraj Jitindar Singh wrote: > The shadow page table contains ptes for translations from nested guest > address to host address. Currently when creating these ptes we take the > rc bits from the pte for the L1 guest address to host address > translation. This is incorrect as we must also factor in the rc bits > from the pte for the nested guest address to L1 guest address > translation (as contained in the L1 guest partition table for the nested > guest). >=20 > By not calculating these bits correctly L1 may not have been correctly > notified when it needed to update its rc bits in the partition table it > maintains for its nested guest. >=20 > Modify the code so that the rc bits in the resultant pte for the L2->L0 > translation are the 'and' of the rc bits in the L2->L1 pte and the L1->L0 > pte, also accounting for whether this was a write access when setting > the dirty bit. >=20 > Signed-off-by: Suraj Jitindar Singh Reviewed-by: David Gibson > --- > arch/powerpc/kvm/book3s_hv_nested.c | 3 +++ > 1 file changed, 3 insertions(+) >=20 > diff --git a/arch/powerpc/kvm/book3s_hv_nested.c b/arch/powerpc/kvm/book3= s_hv_nested.c > index 9dfb927ea14f..4a52f82649e5 100644 > --- a/arch/powerpc/kvm/book3s_hv_nested.c > +++ b/arch/powerpc/kvm/book3s_hv_nested.c > @@ -1235,6 +1235,9 @@ static long int __kvmhv_nested_page_fault(struct kv= m_vcpu *vcpu, > perm |=3D gpte.may_read ? 0UL : _PAGE_READ; > perm |=3D gpte.may_write ? 0UL : _PAGE_WRITE; > perm |=3D gpte.may_execute ? 0UL : _PAGE_EXEC; > + /* Only set accessed/dirty (rc) bits if set in host and l1 guest ptes */ > + perm |=3D (gpte.rc & _PAGE_ACCESSED) ? 0UL : _PAGE_ACCESSED; > + perm |=3D ((gpte.rc & _PAGE_DIRTY) && writing) ? 0UL : _PAGE_DIRTY; > pte =3D __pte(pte_val(pte) & ~perm); > =20 > /* What size pte can we insert? */ --=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 --L+ofChggJdETEG3Y Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEdfRlhq5hpmzETofcbDjKyiDZs5IFAlwsJuIACgkQbDjKyiDZ s5L46Q//R7Yq0LlXEUR7/9IpAXgLCH9ynQr3JZs0iTaWuB73pFVL/h1ZUz5xbxCv zm/izciRheMeF6kCU1NPY5m8B2uvbJtuM54QZWQBTEJ/yY1HnOwFuzksHb8G4NzX X77wiSdxvF0LHzViopcYwjup/2DewoHhrjpCb+x7Bfp/x37GQ06rsEeFYPRtBexq vfD+ZrobQta44NFVoiKssqTUz6CHtoSIsnA6myxolcf8VBkH9SJaiTSG13MfNW26 33ZxWDvR/q5lsHSi8XmEkvjl4ghNGDH/LRTCFvSPEXZvLpwtJ07J353FBOGq6Q3T jCr2UKioBs1F2vylLQQ6J3UP+Gry37gGcfPtQxqh+CDJ7DNSc5BBMJVRilHySwcq Hi+9ysXerr6QtMiRnfOXrbebIUvOYYkSOalIDawUUiOZvtU6T824bGSZdHMwOTd+ IEIRsvw5xn/47NcIVXlb1RaPxUYijkhZzShF2pdw3e30as19Y/x/wnMzWX6XZ0bb cLmkmM/mu0A0xVpsTKk0BQlr0Tq1iYW2NLJmT8598JqtxbVVnA2Mw+5TlD3MWoXH Ivj/+cLaFGfYW0RtD7A4Bd3hOIxEQ0qyF2zeExf0bw10WjApRSANxZBmUHeivSZF 66zytgXJtCNQWFAnP2+RwQeAaCHJiG0/HwkEBAxfayGEo4YfN+U= =35jB -----END PGP SIGNATURE----- --L+ofChggJdETEG3Y--