From: Fabiano Rosas <farosas@linux.ibm.com>
To: Leandro Lupori <leandro.lupori@eldorado.org.br>,
qemu-devel@nongnu.org, qemu-ppc@nongnu.org
Cc: clg@kaod.org, danielhb413@gmail.com, david@gibson.dropbear.id.au,
groug@kaod.org, richard.henderson@linaro.org,
Leandro Lupori <leandro.lupori@eldorado.org.br>
Subject: Re: [PATCH v2 3/3] target/ppc: Check page dir/table base alignment
Date: Fri, 24 Jun 2022 15:47:59 -0300 [thread overview]
Message-ID: <877d55c2zk.fsf@linux.ibm.com> (raw)
In-Reply-To: <20220624171653.143740-4-leandro.lupori@eldorado.org.br>
Leandro Lupori <leandro.lupori@eldorado.org.br> writes:
> Check if each page dir/table base address is properly aligned and
> log a guest error if not, as real hardware behave incorrectly in
> this case.
I think the commit message could be clearer, something like:
According to PowerISA 3.1B, Book III 6.7.6 programming note, the page
directory base addresses are expected to be aligned to their size. Real
hardware seems to rely on that and will access the wrong address if they
are misaligned. This results in a translation failure even if the page
tables seem to be properly populated.
Let's make sure we capture this assumption in the code to help anyone
implementing page tables.
>
> Signed-off-by: Leandro Lupori <leandro.lupori@eldorado.org.br>
> ---
> target/ppc/mmu-radix64.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c
> index 339cf5b4d8..1e7d932893 100644
> --- a/target/ppc/mmu-radix64.c
> +++ b/target/ppc/mmu-radix64.c
> @@ -280,6 +280,14 @@ static int ppc_radix64_next_level(AddressSpace *as, vaddr eaddr,
> *psize -= *nls;
> if (!(pde & R_PTE_LEAF)) { /* Prepare for next iteration */
> *nls = pde & R_PDE_NLS;
> +
> + if ((pde & R_PDE_NLB) & MAKE_64BIT_MASK(0, *nls + 3)) {
> + qemu_log_mask(LOG_GUEST_ERROR,
> + "%s: misaligned page dir/table base: 0x%"VADDR_PRIx
> + " page dir size: 0x"TARGET_FMT_lx"\n",
> + __func__, (pde & R_PDE_NLB), BIT(*nls + 3));
> + }
> +
> index = eaddr >> (*psize - *nls); /* Shift */
> index &= ((1UL << *nls) - 1); /* Mask */
> *pte_addr = (pde & R_PDE_NLB) + (index * sizeof(pde));
> @@ -295,6 +303,13 @@ static int ppc_radix64_walk_tree(AddressSpace *as, vaddr eaddr,
> uint64_t index, pde, rpn, mask;
> int level = 0;
>
> + if (base_addr & MAKE_64BIT_MASK(0, nls + 3)) {
> + qemu_log_mask(LOG_GUEST_ERROR,
> + "%s: misaligned page dir base: 0x%"VADDR_PRIx
> + " page dir size: 0x"TARGET_FMT_lx"\n",
> + __func__, base_addr, BIT(nls + 3));
> + }
> +
> index = eaddr >> (*psize - nls); /* Shift */
> index &= ((1UL << nls) - 1); /* Mask */
> *pte_addr = base_addr + (index * sizeof(pde));
prev parent reply other threads:[~2022-06-24 18:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-24 17:16 [PATCH v2 0/3] ppc: Check for bad Radix configs Leandro Lupori
2022-06-24 17:16 ` [PATCH v2 1/3] ppc: Check partition and process table alignment Leandro Lupori
2022-06-24 18:35 ` Fabiano Rosas
2022-06-24 17:16 ` [PATCH v2 2/3] target/ppc: Improve Radix xlate level validation Leandro Lupori
2022-06-24 18:34 ` Fabiano Rosas
2022-06-24 17:16 ` [PATCH v2 3/3] target/ppc: Check page dir/table base alignment Leandro Lupori
2022-06-24 18:04 ` Richard Henderson
2022-06-24 20:10 ` Leandro Lupori
2022-06-24 18:47 ` Fabiano Rosas [this message]
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=877d55c2zk.fsf@linux.ibm.com \
--to=farosas@linux.ibm.com \
--cc=clg@kaod.org \
--cc=danielhb413@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=groug@kaod.org \
--cc=leandro.lupori@eldorado.org.br \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=richard.henderson@linaro.org \
/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).