Skip to contentSkip to conversation

target/riscv: fix pmp implementation

PATCH In review Alexandre Mergnat 2 participants 4 messages Jul 6, 2020 – Jul 13, 2020 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/riscv: fix pmp implementation

The end address calculation for NA4 mode is wrong because the address used isn't shifted.

That imply all NA4 setup are not applied by the PMP.

The solution is to use the shifted address calculated for start address variable.

Modifications are tested on Zephyr OS userspace test suite which works for other RISC-V boards (E31 and E34 core).

---
 target/riscv/pmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/pmp.c +1 -1
index 9418660f1b..2a2b9f5363 100644
@@ -171,7 +171,7 @@ static void pmp_update_rule(CPURISCVState *env, uint32_t pmp_index)
 
     case PMP_AMATCH_NA4:
         sa = this_addr << 2; /* shift up from [xx:0] to [xx+2:2] */
-        ea = (this_addr + 4u) - 1u;
+        ea = (sa + 4u) - 1u;
         break;
 
     case PMP_AMATCH_NAPOT:
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Alexandre Mergnat

The end address calculation for NA4 mode is wrong because the address used isn't shifted.

That imply all NA4 setup are not applied by the PMP.

I'm not sure what you mean here, can you clarify this?

Quoted 8 lines

The solution is to use the shifted address calculated for start address variable.

Modifications are tested on Zephyr OS userspace test suite which works for other RISC-V boards (E31 and E34 core).

Otherwise:

Alistair

Quoted 21 lines
---
 target/riscv/pmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/pmp.c +1 -2
index 9418660f1b..2a2b9f5363 100644
@@ -171,7 +171,7 @@ static void pmp_update_rule(CPURISCVState *env, uint32_t pmp_index)
 
     case PMP_AMATCH_NA4:
         sa = this_addr << 2; /* shift up from [xx:0] to [xx+2:2] */
-        ea = (this_addr + 4u) - 1u;
+        ea = (sa + 4u) - 1u;
         break;
 
     case PMP_AMATCH_NAPOT:
--

2.17.1

#2 lore raw
Quoted 9 lines · Alistair Francis
Quoted 5 lines · Alexandre Mergnat

The end address calculation for NA4 mode is wrong because the address used isn't shifted.

That imply all NA4 setup are not applied by the PMP.

I'm not sure what you mean here, can you clarify this?

I'm just saying NA4 configuration doesn't work properly on QEMU (It doesn't watch 4byte but a huge range)
because the end address calculation is wrong.

Quoted 37 lines
Quoted 9 lines

The solution is to use the shifted address calculated for start address variable.

Modifications are tested on Zephyr OS userspace test suite which works for other RISC-V boards (E31 and E34 core).

Otherwise:

Alistair

Quoted 21 lines
---
 target/riscv/pmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/pmp.c +1 -2
index 9418660f1b..2a2b9f5363 100644
@@ -171,7 +171,7 @@ static void pmp_update_rule(CPURISCVState *env, uint32_t pmp_index)
 
     case PMP_AMATCH_NA4:
         sa = this_addr << 2; /* shift up from [xx:0] to [xx+2:2] */
-        ea = (this_addr + 4u) - 1u;
+        ea = (sa + 4u) - 1u;
         break;
 
     case PMP_AMATCH_NAPOT:
--

2.17.1

#3 lore raw
Quoted 8 lines · Alexandre Mergnat
Quoted 6 lines · Alistair Francis
Quoted 4 lines · Alexandre Mergnat

The end address calculation for NA4 mode is wrong because the address used isn't shifted.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

That imply all NA4 setup are not applied by the PMP.

I'm not sure what you mean here, can you clarify this?

I'm just saying NA4 configuration doesn't work properly on QEMU (It doesn't watch 4byte but a huge range)
because the end address calculation is wrong.

Ok, I replaced the original sentence with:

It doesn't watch 4 bytes but a huge range because the end address calculation is wrong.

and changed the title to: target/riscv: Fix pmp NA4 implementation

and applied it to the RISC-V tree.

Alistair

Quoted 38 lines
Quoted 38 lines
Quoted 10 lines

The solution is to use the shifted address calculated for start address variable.

Modifications are tested on Zephyr OS userspace test suite which works for other RISC-V boards (E31 and E34 core).

Otherwise:

Alistair

Quoted 21 lines
---
 target/riscv/pmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/pmp.c +1 -2
index 9418660f1b..2a2b9f5363 100644
@@ -171,7 +171,7 @@ static void pmp_update_rule(CPURISCVState *env, uint32_t pmp_index)
 
     case PMP_AMATCH_NA4:
         sa = this_addr << 2; /* shift up from [xx:0] to [xx+2:2] */
-        ea = (this_addr + 4u) - 1u;
+        ea = (sa + 4u) - 1u;
         break;
 
     case PMP_AMATCH_NAPOT:
--

2.17.1