Skip to contentSkip to conversation

target/riscv: pmp: Ignore writes when RW=01

PATCH Superseded Mayuresh Chitale 2 participants 4 messages Sep 25, 2023 – Oct 11, 2023 RISC-V

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 target/riscv: pmp: Ignore writes when RW=01

As per the Priv spec: "The R, W, and X fields form a collective WARL field for which the combinations with R=0 and W=1 are reserved." However currently such writes are not ignored as ought to be. The combinations with RW=01 are allowed only when the Smepmp extension is enabled and mseccfg.MML is set.

---
 target/riscv/pmp.c | 5 +++++
 1 file changed, 5 insertions(+)
target/riscv/pmp.c +5 -0
index 5b14eb511a..8e25f145e0 100644
@@ -120,6 +120,11 @@ static void pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val)
         if (locked) {
             qemu_log_mask(LOG_GUEST_ERROR, "ignoring pmpcfg write - locked\n");
         } else {
+            /* If !mseccfg.MML then ignore writes with encoding RW=01 */
+            if ((val & PMP_WRITE) && !(val & PMP_READ) &&
+                !MSECCFG_MML_ISSET(env)) {
+                val &= ~(PMP_WRITE | PMP_READ);
+            }
             env->pmp_state.pmp[pmp_index].cfg_reg = val;
             pmp_update_rule(env, pmp_index);
         }
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Mayuresh Chitale

As per the Priv spec: "The R, W, and X fields form a collective WARL field for which the combinations with R=0 and W=1 are reserved." However currently such writes are not ignored as ought to be. The combinations with RW=01 are allowed only when the Smepmp extension is enabled and mseccfg.MML is set.

Alistair

Quoted 24 lines
---
 target/riscv/pmp.c | 5 +++++
 1 file changed, 5 insertions(+)
target/riscv/pmp.c +5 -1
index 5b14eb511a..8e25f145e0 100644
@@ -120,6 +120,11 @@ static void pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val)
         if (locked) {
             qemu_log_mask(LOG_GUEST_ERROR, "ignoring pmpcfg write - locked\n");
         } else {
+            /* If !mseccfg.MML then ignore writes with encoding RW=01 */
+            if ((val & PMP_WRITE) && !(val & PMP_READ) &&
+                !MSECCFG_MML_ISSET(env)) {
+                val &= ~(PMP_WRITE | PMP_READ);
+            }
             env->pmp_state.pmp[pmp_index].cfg_reg = val;
             pmp_update_rule(env, pmp_index);
         }
--

2.34.1

#2 lore raw
In reply to Mayuresh Chitale
Quoted 8 lines · Mayuresh Chitale

As per the Priv spec: "The R, W, and X fields form a collective WARL field for which the combinations with R=0 and W=1 are reserved." However currently such writes are not ignored as ought to be. The combinations with RW=01 are allowed only when the Smepmp extension is enabled and mseccfg.MML is set.

Do you mind rebasing this on
https://github.com/alistair23/qemu/tree/riscv-to-apply.next

Alistair

Quoted 24 lines
---
 target/riscv/pmp.c | 5 +++++
 1 file changed, 5 insertions(+)
target/riscv/pmp.c +5 -1
index 5b14eb511a..8e25f145e0 100644
@@ -120,6 +120,11 @@ static void pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val)
         if (locked) {
             qemu_log_mask(LOG_GUEST_ERROR, "ignoring pmpcfg write - locked\n");
         } else {
+            /* If !mseccfg.MML then ignore writes with encoding RW=01 */
+            if ((val & PMP_WRITE) && !(val & PMP_READ) &&
+                !MSECCFG_MML_ISSET(env)) {
+                val &= ~(PMP_WRITE | PMP_READ);
+            }
             env->pmp_state.pmp[pmp_index].cfg_reg = val;
             pmp_update_rule(env, pmp_index);
         }
--

2.34.1

#3 lore raw
Quoted 10 lines · Alistair Francis
Quoted 7 lines · Mayuresh Chitale

As per the Priv spec: "The R, W, and X fields form a collective WARL field for which the combinations with R=0 and W=1 are reserved." However currently such writes are not ignored as ought to be. The combinations with RW=01 are allowed only when the Smepmp extension is enabled and mseccfg.MML is set.

Quoted 4 lines
Quoted 1 line

Do you mind rebasing this on
https://github.com/alistair23/qemu/tree/riscv-to-apply.next

Ok, will do that.

Quoted 27 lines

Alistair

Quoted 24 lines
---
 target/riscv/pmp.c | 5 +++++
 1 file changed, 5 insertions(+)
target/riscv/pmp.c +5 -1
index 5b14eb511a..8e25f145e0 100644
@@ -120,6 +120,11 @@ static void pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val)
         if (locked) {
             qemu_log_mask(LOG_GUEST_ERROR, "ignoring pmpcfg write - locked\n");
         } else {
+            /* If !mseccfg.MML then ignore writes with encoding RW=01 */
+            if ((val & PMP_WRITE) && !(val & PMP_READ) &&
+                !MSECCFG_MML_ISSET(env)) {
+                val &= ~(PMP_WRITE | PMP_READ);
+            }
             env->pmp_state.pmp[pmp_index].cfg_reg = val;
             pmp_update_rule(env, pmp_index);
         }
--

2.34.1