From: David Gibson <david@gibson.dropbear.id.au>
To: "Cédric Le Goater" <clg@kaod.org>
Cc: Suraj Jitindar Singh <sjitindarsingh@gmail.com>,
qemu-ppc@nongnu.org, qemu-devel@nongnu.org,
Benjamin Herrenschmidt <benh@kernel.crashing.org>
Subject: Re: [Qemu-devel] [PATCH 06/12] target/ppc: Fix ordering of hash MMU accesses
Date: Tue, 19 Feb 2019 14:52:28 +1100 [thread overview]
Message-ID: <20190219035228.GT9345@umbus.fritz.box> (raw)
In-Reply-To: <20190215170029.15641-7-clg@kaod.org>
[-- Attachment #1: Type: text/plain, Size: 4053 bytes --]
On Fri, Feb 15, 2019 at 06:00:23PM +0100, Cédric Le Goater wrote:
> From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
>
> With mttcg, we can have MMU lookups happening at the same time
> as the guest modifying the page tables.
>
> Since the HPTEs of the hash table MMU contains two words (or
> double worlds on 64-bit), we need to make sure we read them
> in the right order, with the correct memory barrier.
>
> Additionally, when using emulated SPAPR mode, the hypercalls
> writing to the hash table must also perform the udpates in
> the right order.
>
> Note: This part is still not entirely correct
>
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Signed-off-by: Cédric Le Goater <clg@kaod.org>
Yeah, this stuff was written under the assumption it was protected by
the BQL, which is getting less true all the time.
Applied.
> ---
> hw/ppc/spapr.c | 21 +++++++++++++++++++--
> target/ppc/mmu-hash32.c | 6 ++++++
> target/ppc/mmu-hash64.c | 6 ++++++
> 3 files changed, 31 insertions(+), 2 deletions(-)
>
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 60572eb59275..1afe31ee6163 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -1507,8 +1507,25 @@ static void spapr_store_hpte(PPCVirtualHypervisor *vhyp, hwaddr ptex,
> if (!spapr->htab) {
> kvmppc_write_hpte(ptex, pte0, pte1);
> } else {
> - stq_p(spapr->htab + offset, pte0);
> - stq_p(spapr->htab + offset + HASH_PTE_SIZE_64 / 2, pte1);
> + if (pte0 & HPTE64_V_VALID) {
> + stq_p(spapr->htab + offset + HASH_PTE_SIZE_64 / 2, pte1);
> + /*
> + * When setting valid, we write PTE1 first. This ensures
> + * proper synchronization with the reading code in
> + * ppc_hash64_pteg_search()
> + */
> + smp_wmb();
> + stq_p(spapr->htab + offset, pte0);
> + } else {
> + stq_p(spapr->htab + offset, pte0);
> + /*
> + * When clearing it we set PTE0 first. This ensures proper
> + * synchronization with the reading code in
> + * ppc_hash64_pteg_search()
> + */
> + smp_wmb();
> + stq_p(spapr->htab + offset + HASH_PTE_SIZE_64 / 2, pte1);
> + }
> }
> }
>
> diff --git a/target/ppc/mmu-hash32.c b/target/ppc/mmu-hash32.c
> index 03ae3c127985..e8562a7c8780 100644
> --- a/target/ppc/mmu-hash32.c
> +++ b/target/ppc/mmu-hash32.c
> @@ -319,6 +319,12 @@ static hwaddr ppc_hash32_pteg_search(PowerPCCPU *cpu, hwaddr pteg_off,
>
> for (i = 0; i < HPTES_PER_GROUP; i++) {
> pte0 = ppc_hash32_load_hpte0(cpu, pte_offset);
> + /*
> + * pte0 contains the valid bit and must be read before pte1,
> + * otherwise we might see an old pte1 with a new valid bit and
> + * thus an inconsistent hpte value
> + */
> + smp_rmb();
> pte1 = ppc_hash32_load_hpte1(cpu, pte_offset);
>
> if ((pte0 & HPTE32_V_VALID)
> diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
> index f6c822ef917b..b3c4d33faa55 100644
> --- a/target/ppc/mmu-hash64.c
> +++ b/target/ppc/mmu-hash64.c
> @@ -506,6 +506,12 @@ static hwaddr ppc_hash64_pteg_search(PowerPCCPU *cpu, hwaddr hash,
> }
> for (i = 0; i < HPTES_PER_GROUP; i++) {
> pte0 = ppc_hash64_hpte0(cpu, pteg, i);
> + /*
> + * pte0 contains the valid bit and must be read before pte1,
> + * otherwise we might see an old pte1 with a new valid bit and
> + * thus an inconsistent hpte value
> + */
> + smp_rmb();
> pte1 = ppc_hash64_hpte1(cpu, pteg, i);
>
> /* This compares V, B, H (secondary) and the AVPN */
--
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2019-02-19 4:04 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-15 17:00 [Qemu-devel] [PATCH 00/12] ppc: add native hash and radix support for POWER9 Cédric Le Goater
2019-02-15 17:00 ` [Qemu-devel] [PATCH 01/12] target/ppc/spapr: Set LPCR:HR when using Radix mode Cédric Le Goater
2019-02-18 6:12 ` David Gibson
2019-02-15 17:00 ` [Qemu-devel] [PATCH 02/12] target/ppci/mmu: Use LPCR:HR to chose radix vs. hash translation Cédric Le Goater
2019-02-18 6:47 ` David Gibson
2019-02-18 21:20 ` Philippe Mathieu-Daudé
2019-02-19 3:09 ` David Gibson
2019-02-15 17:00 ` [Qemu-devel] [PATCH 03/12] target/ppc: Re-enable RMLS on POWER9 for virtual hypervisors Cédric Le Goater
2019-02-19 3:46 ` David Gibson
2019-02-15 17:00 ` [Qemu-devel] [PATCH 04/12] target/ppc: Fix #include guard in mmu-book3s-v3.h Cédric Le Goater
2019-02-19 3:47 ` David Gibson
2019-02-15 17:00 ` [Qemu-devel] [PATCH 05/12] target/ppc: Cleanup 64-bit MMU includes Cédric Le Goater
2019-02-19 3:49 ` David Gibson
2019-02-15 17:00 ` [Qemu-devel] [PATCH 06/12] target/ppc: Fix ordering of hash MMU accesses Cédric Le Goater
2019-02-19 3:52 ` David Gibson [this message]
2019-02-15 17:00 ` [Qemu-devel] [PATCH 07/12] target/ppc: Add basic support for "new format" HPTE as found on POWER9 Cédric Le Goater
2019-02-19 4:05 ` David Gibson
2019-02-19 4:39 ` David Gibson
2019-02-15 17:00 ` [Qemu-devel] [PATCH 08/12] target/ppc: Fix synchronization of mttcg with broadcast TLB flushes Cédric Le Goater
2019-02-15 17:00 ` [Qemu-devel] [PATCH 09/12] target/ppc: Flush the TLB locally when the LPIDR is written Cédric Le Goater
2019-02-15 17:00 ` [Qemu-devel] [PATCH 10/12] target/ppc: Rename PATB/PATBE -> PATE Cédric Le Goater
2019-02-15 17:00 ` [Qemu-devel] [PATCH 11/12] target/ppc: Support for POWER9 native hash Cédric Le Goater
2019-02-15 17:00 ` [Qemu-devel] [PATCH 12/12] target/ppc: Basic POWER9 bare-metal radix MMU support Cédric Le Goater
2019-02-19 5:19 ` [Qemu-devel] [PATCH 00/12] ppc: add native hash and radix support for POWER9 David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190219035228.GT9345@umbus.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=benh@kernel.crashing.org \
--cc=clg@kaod.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=sjitindarsingh@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).