From: Fuad Tabba <fuad.tabba@linux.dev>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org,
Richard Henderson <richard.henderson@linaro.org>,
Gustavo Romero <gromero@redhat.com>,
Will Deacon <will@kernel.org>,
Itaru Kitayama <itaru.kitayama@linux.dev>,
Fuad Tabba <tabba@google.com>
Subject: [PATCH v2 2/3] target/arm: Use the 52-bit TTBR base address layout when TCR.DS is set
Date: Wed, 7 Oct 2026 09:00:18 +0100 [thread overview]
Message-ID: <20261007080019.350315-3-fuad.tabba@linux.dev> (raw)
In-Reply-To: <20261007080019.350315-1-fuad.tabba@linux.dev>
With TCR.DS set, TTBR[5:2] hold bits [51:48] of the translation table
base address, whatever the OA size. If the effective OA size is below
52 bits, setting any of them is a level 0 Address size fault
(AArch64_S1TTBaseAddress(), AArch64_S1Walk()).
get_phys_addr_lpae() uses the 52-bit layout only when the OA size is
over 48 bits. With TCR.DS set and an IPS of 48 bits, it takes TTBR[5:2]
as base address bits [5:2] instead. A guest that sets them gets no
fault: the walk either succeeds with TTBR[5:2] ignored, or reads its
first descriptor from the wrong address. VTTBR walks with VTCR.DS take
the same path.
Use the 52-bit layout whenever TCR.DS is set, and check the whole base
address against the OA size.
Fixes: ef56c2425e5f ("target/arm: Implement FEAT_LPA2")
Cc: qemu-stable@nongnu.org
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
target/arm/ptw.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/target/arm/ptw.c b/target/arm/ptw.c
index 6cff52d592..2e67d02493 100644
--- a/target/arm/ptw.c
+++ b/target/arm/ptw.c
@@ -2107,18 +2107,21 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw,
descaddr = extract64(ttbr, 0, 48);
/*
- * With a 52-bit OA (FEAT_LPA or FEAT_LPA2), bits [51:48] of descaddr are
- * in [5:2] of TTBR, and bits [5:0] of the base address are zero: a table
- * under 64 bytes is still 64-byte aligned (R_KBLCR).
+ * With a 52-bit OA (FEAT_LPA or FEAT_LPA2), or with TCR.DS set at any OA
+ * size, bits [51:48] of descaddr are in [5:2] of TTBR, and bits [5:0] of
+ * the base address are zero: a table under 64 bytes is still 64-byte
+ * aligned (R_KBLCR).
*
- * Otherwise, if the base address is out of range, raise AddressSizeFault.
- * In the pseudocode, this is !IsZero(baseregister<47:outputsize>),
- * but we've just cleared the bits above 47, so simplify the test.
+ * If the base address is out of range, raise AddressSizeFault.
+ * In the pseudocode, this is !IsZero(address<NUM_PABITS-1:outputsize>)
+ * in AArch64_OAOutOfRange(), but descaddr has no bits set above 51,
+ * so simplify the test.
*/
- if (outputsize > 48) {
+ if (outputsize > 48 || param.ds) {
descaddr &= ~MAKE_64BIT_MASK(0, 6);
descaddr |= extract64(ttbr, 2, 4) << 48;
- } else if (descaddr >> outputsize) {
+ }
+ if (descaddr >> outputsize) {
level = 0;
fi->type = ARMFault_AddressSize;
goto do_fault;
--
2.39.5
next prev parent reply other threads:[~2026-10-07 9:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 8:00 [PATCH v2 0/3] target/arm: Fix the TTBR table base address in its 52-bit layout Fuad Tabba
2026-10-07 8:00 ` [PATCH v2 1/3] target/arm: Clear TTBR[5:0] from a 52-bit table base address Fuad Tabba
2026-10-07 16:55 ` Gustavo Romero
2026-10-07 8:00 ` Fuad Tabba [this message]
2026-10-07 16:55 ` [PATCH v2 2/3] target/arm: Use the 52-bit TTBR base address layout when TCR.DS is set Gustavo Romero
2026-10-07 8:00 ` [PATCH v2 3/3] tests/tcg/aarch64: Add a test for the 52-bit TTBR base address layout Fuad Tabba
2026-10-07 16:56 ` Gustavo Romero
2026-10-07 21:29 ` Fuad Tabba
2026-10-08 16:40 ` Gustavo Romero
2026-10-08 18:01 ` Fuad Tabba
2026-10-09 8:13 ` Gustavo Romero
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=20261007080019.350315-3-fuad.tabba@linux.dev \
--to=fuad.tabba@linux.dev \
--cc=gromero@redhat.com \
--cc=itaru.kitayama@linux.dev \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=tabba@google.com \
--cc=will@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.