target/riscv: pmp: Ignore writes when RW=01
PATCH 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 | 8 ++++++++ 1 file changed, 8 insertions(+)
target/riscv/pmp.c +8 -0
@@ -119,6 +119,14 @@ static bool 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 (env->pmp_state.pmp[pmp_index].cfg_reg != val) { +/* If !mseccfg.MML then ignore writes with encoding RW=01 */ +if ((val &PMP_WRITE ) && !(val &PMP_READ ) && + (!riscv_cpu_cfg (env)->ext_smepmp || + !MSECCFG_MML_ISSET (env))) { + val &= ~(PMP_WRITE |PMP_READ ); + val |= env->pmp_state.pmp[pmp_index].cfg_reg & + (PMP_WRITE |PMP_READ ); + } env->pmp_state.pmp[pmp_index].cfg_reg = val;pmp_update_rule_addr (env, pmp_index);return true;
Signature · 1 line
2.34.1
Quoted 17 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.
Signed-off-by Mayuresh Chitale <[email protected]>--- target/riscv/pmp.c | 8 ++++++++ 1 file changed, 8 insertions(+)target/riscv/pmp.c +0
-0
target/riscv/pmp.c static bool pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val) · line 125
Quoted 7 lines
target/riscv/pmp.c +4
-0@@ -119,6 +119,14 @@ static bool 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 (env->pmp_state.pmp[pmp_index].cfg_reg != val) { +/* If !mseccfg.MML then ignore writes with encoding RW=01 */ +if ((val &PMP_WRITE ) && !(val &PMP_READ ) && + (!riscv_cpu_cfg (env)->ext_smepmp || + !MSECCFG_MML_ISSET (env))) {
MSECCFG_MML can only be set if ext_smepmp exists, so I don't think we need both checks here
target/riscv/pmp.c static bool pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val) · line 128
Quoted 3 lines
target/riscv/pmp.c +3
-0+ val &= ~(PMP_WRITE |PMP_READ ); + val |= env->pmp_state.pmp[pmp_index].cfg_reg & + (PMP_WRITE |PMP_READ );
Why do we restore the previous value? It's a WARL so we should just guarantee a legal value (which would be 0x0 I guess)
Alistair
Quoted 8 lines
target/riscv/pmp.c +1
-1+ } env->pmp_state.pmp[pmp_index].cfg_reg = val;pmp_update_rule_addr (env, pmp_index);return true; --2.34.1
Quoted 15 lines · Alistair Francis
Quoted 12 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.
Signed-off-by Mayuresh Chitale <[email protected]>--- target/riscv/pmp.c | 8 ++++++++ 1 file changed, 8 insertions(+)
Quoted 15 lines
target/riscv/pmp.c static bool pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val) · line 125
Quoted 12 lines
target/riscv/pmp.c +4
-0@@ -119,6 +119,14 @@ static bool 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 (env->pmp_state.pmp[pmp_index].cfg_reg != val) { +/* If !mseccfg.MML then ignore writes with encoding RW=01 */ +if ((val &PMP_WRITE ) && !(val &PMP_READ ) && + (!riscv_cpu_cfg (env)->ext_smepmp || + !MSECCFG_MML_ISSET (env))) {
MSECCFG_MMLcan only be set ifext_smepmpexists, so I don't think we need both checks here
Ok.
Quoted 7 lines
target/riscv/pmp.c static bool pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val) · line 128
Quoted 4 lines
target/riscv/pmp.c +3
-0+ val &= ~(PMP_WRITE |PMP_READ ); + val |= env->pmp_state.pmp[pmp_index].cfg_reg & + (PMP_WRITE |PMP_READ );Why do we restore the previous value? It's a WARL so we should just guarantee a legal value (which would be
0x0I guess)
Yes. It can be set to 0x0.
Quoted 11 lines
Alistair
Quoted 8 lines
target/riscv/pmp.c +1
-1+ } env->pmp_state.pmp[pmp_index].cfg_reg = val;pmp_update_rule_addr (env, pmp_index);return true; --2.34.1