All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] target/arm: Fix AArch64 range TLBI granule check and 32-bit length shift overflow
@ 2026-12-03 17:45 Xudong Zhang
  0 siblings, 0 replies; only message in thread
From: Xudong Zhang @ 2026-12-03 17:45 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-arm, Peter Maydell, Xudong Zhang

Fix two `FEAT_TLBIRANGE` decoding defects in `tlbi_aa64_get_range()`
(`target/arm/tcg/tlb-insns.c`) per the Arm Architecture Reference Manual for
A-profile architecture (Arm DDI 0487, §C5.5.2 "TLBI RVAALE1IS, TLBI
RVAALE1ISNXS" / "TLBI RVAE1IS, TLBI RVAE1ISNXS" and §D8.10, formerly §D5.10.2,
"TLB maintenance instructions"):
1. Stop rejecting AArch64 range TLBI operations when the operand `TG` differs
   from the issuing PE's `TCR_ELx.TG` (reject only reserved `TG == 0` /
   `GranInvalid`).
2. Widen `(num + 1)` to `uint64_t` before shifting by `(exponent + page_shift)`
   so 4 GiB 4 KiB-granule ranges do not wrap to `0` in 32-bit `unsigned int`
   and 64 KiB `SCALE = 3` ranges (shift count `32`) do not invoke C undefined
   behavior.

Reproducer: https://gist.github.com/canxin121/2b9f9b72365ddc21539b137eeba73ed2
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/5101
Signed-off-by: Xudong Zhang <boxzxd@gmail.com>
---
 target/arm/tcg/tlb-insns.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/target/arm/tcg/tlb-insns.c b/target/arm/tcg/tlb-insns.c
index b24eb57788..fc2ac118c8 100644
--- a/target/arm/tcg/tlb-insns.c
+++ b/target/arm/tcg/tlb-insns.c
@@ -853,8 +853,12 @@ static TLBIRange tlbi_aa64_get_range(CPUARMState *env, ARMMMUIdx mmuidx,
     page_size_granule = extract64(value, 46, 2);
     gran = tlbi_range_tg_to_gran_size(page_size_granule);
 
-    /* The granule encoded in value must match the granule in use. */
-    if (gran != param.gran || gran == GranInvalid) {
+    /*
+     * Per Arm DDI 0487, TG specifies the translation granule of matching TLB
+     * entries rather than requiring equality with the issuing PE's current
+     * TCR_ELx.TG. Only TG == 0 (GranInvalid) is reserved.
+     */
+    if (gran == GranInvalid) {
         qemu_log_mask(LOG_GUEST_ERROR, "Invalid tlbi page size granule %d\n",
                       page_size_granule);
         return ret;
@@ -865,7 +869,7 @@ static TLBIRange tlbi_aa64_get_range(CPUARMState *env, ARMMMUIdx mmuidx,
     scale = extract64(value, 44, 2);
     exponent = (5 * scale) + 1;
 
-    ret.length = (num + 1) << (exponent + page_shift);
+    ret.length = (uint64_t)(num + 1) << (exponent + page_shift);
 
     if (param.select) {
         ret.base = sextract64(value, 0, 37);
-- 
2.43.0



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-03 17:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 17:45 [PATCH] target/arm: Fix AArch64 range TLBI granule check and 32-bit length shift overflow Xudong Zhang

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.