Skip to contentSkip to conversation

target/arm: Limit LPA2 effective output address when TCR.DS == 0

PATCH Applied Ard Biesheuvel 3 participants 3 messages Nov 16, 2022 – Nov 17, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/arm: Limit LPA2 effective output address when TCR.DS == 0

With LPA2, the effective output address size is at most 48 bits when TCR.DS == 0. This case is currently unhandled in the page table walker, where we happily assume LVA/64k granule when outputsize > 48 and param.ds == 0, resulting in the wrong conversion to be used from a page table descriptor to a physical address.

    if (outputsize > 48) {
        if (param.ds) {
            descaddr |= extract64(descriptor, 8, 2) << 50;
        } else {
            descaddr |= extract64(descriptor, 12, 4) << 48;
        }

So cap the outputsize to 48 when TCR.DS is cleared, as per the architecture.

Cc Peter Maydell <[email protected]>
Cc Philippe Mathieu-Daudé <[email protected]>
Cc Richard Henderson <[email protected]>
---
 target/arm/ptw.c | 8 ++++++++
 1 file changed, 8 insertions(+)
target/arm/ptw.c +8 -0
index 3745ac9723474332..9a6277d862fac229 100644
@@ -1222,6 +1222,14 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw,
         ps = MIN(ps, param.ps);
         assert(ps < ARRAY_SIZE(pamax_map));
         outputsize = pamax_map[ps];
+
+        /*
+         * With LPA2, the effective output address (OA) size is at most 48 bits
+         * unless TCR.DS == 1
+         */
+        if (!param.ds && param.gran != Gran64K) {
+            outputsize = MIN(outputsize, 48);
+        }
     } else {
         param = aa32_va_parameters(env, address, mmu_idx);
         level = 1;
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Ard Biesheuvel
target/arm/ptw.c +0 -0
index 3745ac9723474332..9a6277d862fac229 100644
@@ -1222,6 +1222,14 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw,
          ps = MIN(ps, param.ps);

target/arm/ptw.c static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, · line 1232

Quoted 10 lines
target/arm/ptw.c +8 -0
          assert(ps < ARRAY_SIZE(pamax_map));
          outputsize = pamax_map[ps];
+
+        /*
+         * With LPA2, the effective output address (OA) size is at most 48 bits
+         * unless TCR.DS == 1
+         */
+        if (!param.ds && param.gran != Gran64K) {
+            outputsize = MIN(outputsize, 48);
+        }

I thought about moving this back into aa64_va_parameters, similar to how we bound tsz, but since this is the only use of param.ps, this placement is as good as any.

r~

#2 lore raw
Quoted 21 lines · Richard Henderson
Quoted 6 lines · Ard Biesheuvel
target/arm/ptw.c +0 -0
index 3745ac9723474332..9a6277d862fac229 100644
@@ -1222,6 +1222,14 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw,
          ps = MIN(ps, param.ps);

target/arm/ptw.c static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, · line 1232

Quoted 10 lines
target/arm/ptw.c +8 -0
          assert(ps < ARRAY_SIZE(pamax_map));
          outputsize = pamax_map[ps];
+
+        /*
+         * With LPA2, the effective output address (OA) size is at most 48 bits
+         * unless TCR.DS == 1
+         */
+        if (!param.ds && param.gran != Gran64K) {
+            outputsize = MIN(outputsize, 48);
+        }
Quoted 2 lines

I thought about moving this back into aa64_va_parameters, similar to how we bound tsz, but since this is the only use of param.ps, this placement is as good as any.

Applied to target-arm.next, thanks.

-- PMM