target/riscv/csr.c: allow regular mstatus MPV/GVA writes again
PATCH 1/1 target/riscv/csr.c: allow regular mstatus MPV/GVA writes again
In commit 18645f195789 we removed the capability of MPV/GVA writes by software, claiming that the ISA says that these bits are changed by the implementation (i.e. hardware).
This fact alone can't be interpret as "so software can't change them". The ISA never mentions that, and we shouldn't just assume read/write accesses based on whether hardware updates it or not. M-mode software can do whatever they want, unless clearly stated in the ISA, and that includes mstatus MPV and GVA updates.
And in fact existing software is writing to these bits, as reported by Fangyu in [1], and that change ended up causing real problems in the end.
Revert "target/riscv/csr.c: do not allow mstatus MPV/GVA writes".
This reverts commit 18645f19578955ec5ff2c40cd2c8753d6bc460c2.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
--- target/riscv/tcg/csr.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
target/riscv/tcg/csr.c +4 -1
@@ -2108,6 +2108,9 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno, }if (xl !=MXL_RV32 || env->debugger) { +if (riscv_has_ext (env,RVH )) { + mask |=MSTATUS_MPV |MSTATUS_GVA ; + }if ((val &MSTATUS64_SXL ) !=0 ) { mask |=MSTATUS64_SXL ; val =riscv_write_uxl (env, val,MSTATUS64_SXL );
@@ -2150,7 +2153,7 @@ static RISCVException write_mstatush(CPURISCVState *env, int csrno, target_ulong val, uintptr_t ra) { uint64_t valh = (uint64_t)val << 32; -uint64_t mask =0 ; +uint64_t mask =riscv_has_ext (env,RVH ) ?MSTATUS_MPV |MSTATUS_GVA :0 ;if (riscv_cpu_cfg (env)->ext_smdbltrp) { mask |=MSTATUS_MDT ;
Signature · 1 line
2.43.0
Quoted 20 lines · Daniel Henrique Barboza
In commit
18645f195789we removed the capability of MPV/GVA writes by software, claiming that the ISA says that these bits are changed by the
implementation (i.e. hardware).This fact alone can't be interpret as "so software can't change them".
The ISA never mentions that, and we shouldn't just assume read/write accesses based on whether hardware updates it or not. M-mode software
can do whatever they want, unless clearly stated in the ISA, and that includes mstatus MPV and GVA updates.And in fact existing software is writing to these bits, as reported by
Fangyu in [1], and that change ended up causing real problems in the end.Revert "
target/riscv/csr.c: do not allow mstatus MPV/GVA writes".
Quoted 8 lines
This reverts commit
18645f19578955ec5ff2c40cd2c8753d6bc460c2.[1]
https://lore.kernel.org/qemu-devel/[email protected]/Reported-by Fangyu Yu <[email protected]>Signed-off-by Daniel Henrique Barboza
Alistair
Quoted 30 lines
---
target/riscv/tcg/csr.c | 5 ++++-1 file changed, 4 insertions(+), 1 deletion(-)target/riscv/tcg/csr.c +0
-0@@ -2108,6 +2108,9 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno, }
if (xl !=MXL_RV32||env->debugger) {
+ if (riscv_has_ext(env, RVH)) {
+ mask |=MSTATUS_MPV|MSTATUS_GVA;
+ }
if ((val &MSTATUS64_SXL) != 0) {
mask |=MSTATUS64_SXL;
val =riscv_write_uxl(env, val, MSTATUS64_SXL);target/riscv/tcg/csr.c +1
-1@@ -2150,7 +2153,7 @@ static RISCVException write_mstatush(CPURISCVState *env, int csrno, target_ulong val, uintptr_t ra) { uint64_t valh = (uint64_t)val << 32; - uint64_t mask = 0; + uint64_t mask = riscv_has_ext(env, RVH) ? MSTATUS_MPV |MSTATUS_GVA :0 ;
if (riscv_cpu_cfg(env)->ext_smdbltrp) {
mask |=MSTATUS_MDT;