Received: from eggs.gnu.org ([209.51.188.92]:60728) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJu1N-0006TH-Pu for qemu-devel@nongnu.org; Fri, 26 Apr 2019 02:07:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hJu1M-0005iA-N0 for qemu-devel@nongnu.org; Fri, 26 Apr 2019 02:07:41 -0400 From: David Gibson Date: Fri, 26 Apr 2019 16:06:26 +1000 Message-Id: <20190426060627.18153-36-david@gibson.dropbear.id.au> In-Reply-To: <20190426060627.18153-1-david@gibson.dropbear.id.au> References: <20190426060627.18153-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 35/36] ppc/hash32: Rework R and C bit updates List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: peter.maydell@linaro.org Cc: gkurz@kaod.org, clg@kaod.org, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, Benjamin Herrenschmidt , David Gibson From: Benjamin Herrenschmidt With MT-TCG, we are now running translation in a racy way, thus we need to mimic hardware when it comes to updating the R and C bits, by doing byte stores. Signed-off-by: Benjamin Herrenschmidt Signed-off-by: C=C3=A9dric Le Goater Message-Id: <20190411080004.8690-5-clg@kaod.org> Signed-off-by: David Gibson --- target/ppc/mmu-hash32.c | 45 ++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/target/ppc/mmu-hash32.c b/target/ppc/mmu-hash32.c index 3f4dee835e..55cf156a0b 100644 --- a/target/ppc/mmu-hash32.c +++ b/target/ppc/mmu-hash32.c @@ -345,6 +345,24 @@ static hwaddr ppc_hash32_pteg_search(PowerPCCPU *cpu= , hwaddr pteg_off, return -1; } =20 +static void ppc_hash32_set_r(PowerPCCPU *cpu, hwaddr pte_offset, uint32_= t pte1) +{ + target_ulong base =3D ppc_hash32_hpt_base(cpu); + hwaddr offset =3D pte_offset + 6; + + /* The HW performs a non-atomic byte update */ + stb_phys(CPU(cpu)->as, base + offset, ((pte1 >> 8) & 0xff) | 0x01); +} + +static void ppc_hash32_set_c(PowerPCCPU *cpu, hwaddr pte_offset, uint64_= t pte1) +{ + target_ulong base =3D ppc_hash32_hpt_base(cpu); + hwaddr offset =3D pte_offset + 7; + + /* The HW performs a non-atomic byte update */ + stb_phys(CPU(cpu)->as, base + offset, (pte1 & 0xff) | 0x80); +} + static hwaddr ppc_hash32_htab_lookup(PowerPCCPU *cpu, target_ulong sr, target_ulong eaddr= , ppc_hash_pte32_t *pte) @@ -403,7 +421,6 @@ int ppc_hash32_handle_mmu_fault(PowerPCCPU *cpu, vadd= r eaddr, int rwx, hwaddr pte_offset; ppc_hash_pte32_t pte; int prot; - uint32_t new_pte1; const int need_prot[] =3D {PAGE_READ, PAGE_WRITE, PAGE_EXEC}; hwaddr raddr; =20 @@ -519,20 +536,20 @@ int ppc_hash32_handle_mmu_fault(PowerPCCPU *cpu, va= ddr eaddr, int rwx, =20 /* 8. Update PTE referenced and changed bits if necessary */ =20 - new_pte1 =3D pte.pte1 | HPTE32_R_R; /* set referenced bit */ - if (rwx =3D=3D 1) { - new_pte1 |=3D HPTE32_R_C; /* set changed (dirty) bit */ - } else { - /* - * Treat the page as read-only for now, so that a later write - * will pass through this function again to set the C bit - */ - prot &=3D ~PAGE_WRITE; - } - - if (new_pte1 !=3D pte.pte1) { - ppc_hash32_store_hpte1(cpu, pte_offset, new_pte1); + if (!(pte.pte1 & HPTE32_R_R)) { + ppc_hash32_set_r(cpu, pte_offset, pte.pte1); } + if (!(pte.pte1 & HPTE32_R_C)) { + if (rwx =3D=3D 1) { + ppc_hash32_set_c(cpu, pte_offset, pte.pte1); + } else { + /* + * Treat the page as read-only for now, so that a later writ= e + * will pass through this function again to set the C bit + */ + prot &=3D ~PAGE_WRITE; + } + } =20 /* 9. Determine the real address from the PTE */ =20 --=20 2.20.1