target/riscv: Check Svnapot PTE before updating A/D bits
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
@@ -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)
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.
Signed-off-by dodochicha <[email protected]>
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@@ -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)) { + returnTRANSLATE_FAIL;
+ }
+ }
+
target_ulongupdated_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'sbenefit. */
target_ulongvpn = addr >> PGSHIFT;
- if (riscv_cpu_cfg(env)->ext_svnapot && (pte &PTE_N)) { -napot_bits= ctzl(ppn) + 1;
- if ((i != (levels - 1)) || (napot_bits!= 4)) { - returnTRANSLATE_FAIL;
- }
- }
-
napot_mask= (1 <<napot_bits) - 1;
*physical = (((ppn & ~napot_mask) | (vpn &napot_mask) | (vpn & (((target_ulong)1 << ptshift) - 1))
Alistair
AppliedQuoted 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
Signed-off-by dodochicha <[email protected]>---
target/riscv/tcg/cpu_helper.c | 14 +++++++-------1 file changed, 7 insertions(+), 7 deletions(-)target/riscv/tcg/cpu_helper.c +0
-0@@ -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)) { + returnTRANSLATE_FAIL;
+ }
+ }
+
target_ulongupdated_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'sbenefit. */
target_ulongvpn = addr >> PGSHIFT;
- if (riscv_cpu_cfg(env)->ext_svnapot && (pte &PTE_N)) { -napot_bits= ctzl(ppn) + 1;
- if ((i != (levels - 1)) || (napot_bits!= 4)) { - returnTRANSLATE_FAIL;
- }
- }
-
napot_mask= (1 <<napot_bits) - 1;
*physical = (((ppn & ~napot_mask) | (vpn &napot_mask) | (vpn & (((target_ulong)1 << ptshift) - 1))