Skip to contentSkip to conversation

target/riscv: Check Svnapot PTE before updating A/D bits

PATCH Applied dodochicha 2 participants 3 messages Oct 5 – Oct 7 RISC-V

lore
Share & tools
lore

dodochicha

author
#0 lore raw

PATCH 1/1 target/riscv: Check Svnapot PTE before updating A/D bits

Reserved Svnapot PTE encodings must raise a page fault without modifying the PTE. Currently the A/D bits may be updated before the Svnapot encoding is validated.

Move the Svnapot validation before the A/D update so reserved PTEs fault without changing the PTE.

---
 target/riscv/tcg/cpu_helper.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
target/riscv/tcg/cpu_helper.c +7 -7
index 07d9222652..105f2f1927 100644
@@ -1403,6 +1403,13 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
         return sstack_page ? TRANSLATE_PMP_FAIL : TRANSLATE_FAIL;
     }
 
+    if (riscv_cpu_cfg(env)->ext_svnapot && (pte & PTE_N)) {
+        napot_bits = ctzl(ppn) + 1;
+        if ((i != (levels - 1)) || (napot_bits != 4)) {
+            return TRANSLATE_FAIL;
+        }
+    }
+
     target_ulong updated_pte = pte;
 
     /*
@@ -1473,13 +1480,6 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
     /* For superpage mappings, make a fake leaf PTE for the TLB's benefit. */
     target_ulong vpn = addr >> PGSHIFT;
 
-    if (riscv_cpu_cfg(env)->ext_svnapot && (pte & PTE_N)) {
-        napot_bits = ctzl(ppn) + 1;
-        if ((i != (levels - 1)) || (napot_bits != 4)) {
-            return TRANSLATE_FAIL;
-        }
-    }
-
     napot_mask = (1 << napot_bits) - 1;
     *physical = (((ppn & ~napot_mask) | (vpn & napot_mask) |
                   (vpn & (((target_ulong)1 << ptshift) - 1))
Signature · 1 line
2.50.1 (Apple Git-155)
Reviewed-by Alistair Francis on v1 1/1
#1 lore raw
Quoted 8 lines · dodochicha

Reserved Svnapot PTE encodings must raise a page fault without modifying the PTE. Currently the A/D bits may be updated before the Svnapot encoding is validated.

Move the Svnapot validation before the A/D update so reserved PTEs fault without changing the PTE.

Alistair

Quoted 40 lines

---
 target/riscv/tcg/cpu_helper.c | 14 +++++++-------

 1 file changed, 7 insertions(+), 7 deletions(-)
target/riscv/tcg/cpu_helper.c +0 -0
index 07d9222652..105f2f1927 100644
@@ -1403,6 +1403,13 @@ static int get_physical_address(CPURISCVState
 *env, hwaddr *physical,
          return sstack_page ? TRANSLATE_PMP_FAIL : TRANSLATE_FAIL;
      }


+    if (riscv_cpu_cfg(env)->ext_svnapot && (pte & PTE_N)) { +        napot_bits = ctzl(ppn) + 1;
+        if ((i != (levels - 1)) || (napot_bits != 4)) { +            return TRANSLATE_FAIL;
+        }
+    }
+
     target_ulong updated_pte = pte;

     /*

target/riscv/tcg/cpu_helper.c +0 -0
@@ -1473,13 +1480,6 @@ static int get_physical_address(CPURISCVState
 *env, hwaddr *physical,
      /* For superpage mappings, make a fake leaf PTE for the TLB's

benefit. */
     target_ulong vpn = addr >> PGSHIFT;

-    if (riscv_cpu_cfg(env)->ext_svnapot && (pte & PTE_N)) { -        napot_bits = ctzl(ppn) + 1;
-        if ((i != (levels - 1)) || (napot_bits != 4)) { -            return TRANSLATE_FAIL;
-        }
-    }
-
     napot_mask = (1 << napot_bits) - 1;
     *physical = (((ppn & ~napot_mask) | (vpn & napot_mask) | (vpn & (((target_ulong)1 << ptshift) - 1))

Applied
#2 lore raw
In reply to dodochicha
Quoted 7 lines · dodochicha

Reserved Svnapot PTE encodings must raise a page fault without modifying the PTE. Currently the A/D bits may be updated before the Svnapot encoding is validated.

Move the Svnapot validation before the A/D update so reserved PTEs fault without changing the PTE.

In future please wrap your commit messages at around 70 characters.

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 41 lines

---
 target/riscv/tcg/cpu_helper.c | 14 +++++++-------

 1 file changed, 7 insertions(+), 7 deletions(-)
target/riscv/tcg/cpu_helper.c +0 -0
index 07d9222652..105f2f1927 100644
@@ -1403,6 +1403,13 @@ static int get_physical_address(CPURISCVState
 *env, hwaddr *physical,
          return sstack_page ? TRANSLATE_PMP_FAIL : TRANSLATE_FAIL;
      }


+    if (riscv_cpu_cfg(env)->ext_svnapot && (pte & PTE_N)) { +        napot_bits = ctzl(ppn) + 1;
+        if ((i != (levels - 1)) || (napot_bits != 4)) { +            return TRANSLATE_FAIL;
+        }
+    }
+
     target_ulong updated_pte = pte;

     /*

target/riscv/tcg/cpu_helper.c +0 -0
@@ -1473,13 +1480,6 @@ static int get_physical_address(CPURISCVState
 *env, hwaddr *physical,
      /* For superpage mappings, make a fake leaf PTE for the TLB's

benefit. */
     target_ulong vpn = addr >> PGSHIFT;

-    if (riscv_cpu_cfg(env)->ext_svnapot && (pte & PTE_N)) { -        napot_bits = ctzl(ppn) + 1;
-        if ((i != (levels - 1)) || (napot_bits != 4)) { -            return TRANSLATE_FAIL;
-        }
-    }
-
     napot_mask = (1 << napot_bits) - 1;
     *physical = (((ppn & ~napot_mask) | (vpn & napot_mask) | (vpn & (((target_ulong)1 << ptshift) - 1))