Skip to contentSkip to conversation

target/riscv: make sstateen1-3 reserved bits read-only zero

PATCH In review Harshit Mukhedkar 3 participants 3 messages Oct 21 – Oct 22 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/riscv: make sstateen1-3 reserved bits read-only zero

write_sstateen_1_3() passes SMSTATEEN_STATEEN (bit 63) as the write mask to write_sstateen(). That bit is the SE control bit only in mstateenN/hstateenN, where it gates access to sstateenN. The sstateen1-3 CSRs have no defined bits, and reserved bits must be read-only zero, so bit 63 must not be writable on RV64.

Use a write mask of 0 for sstateen1-3 until bits are defined there.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4726

Fixes 3bee0e40106d ("target/riscv: Add smstateen support")
---
 target/riscv/tcg/csr.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
target/riscv/tcg/csr.c +6 -1
index 063590f56a..d9731421af 100644
@@ -3941,7 +3941,12 @@ static RISCVException write_sstateen0(CPURISCVState *env, int csrno,
 static RISCVException write_sstateen_1_3(CPURISCVState *env, int csrno,
                                          target_ulong new_val, uintptr_t ra)
 {
-    return write_sstateen(env, csrno, SMSTATEEN_STATEEN, new_val);
+    /*
+     * sstateen1-3 have no defined bits yet, so they are read only zero.
+     * Bit 63 is the SE bit only in mstateenN/hstateenN, where it gates
+     * access to sstateenN.
+     */
+    return write_sstateen(env, csrno, 0, new_val);
 }
 
 static RISCVException rmw_mip64(CPURISCVState *env, int csrno,
Signature · 1 line
2.56.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Harshit Mukhedkar

write_sstateen_1_3() passes SMSTATEEN_STATEEN (bit 63) as the write mask to write_sstateen(). That bit is the SE control bit only in mstateenN/hstateenN, where it gates access to sstateenN. The sstateen1-3
CSRs have no defined bits, and reserved bits must be read-only zero, so
bit 63 must not be writable on RV64.

Quoted 6 lines

Use a write mask of 0 for sstateen1-3 until bits are defined there.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4726

Fixes 3bee0e40106d ("target/riscv: Add smstateen support")

Alistair

Quoted 27 lines

---
 target/riscv/tcg/csr.c | 7 ++++++-

 1 file changed, 6 insertions(+), 1 deletion(-)
target/riscv/tcg/csr.c +0 -0
index 063590f56a..d9731421af 100644
@@ -3941,7 +3941,12 @@ static RISCVException
 write_sstateen0(CPURISCVState *env, int csrno,

 static RISCVException write_sstateen_1_3(CPURISCVState *env, int csrno,
                                          target_ulong new_val, uintptr_t ra)
 {
-    return write_sstateen(env, csrno, SMSTATEEN_STATEEN, new_val); +    /*
+     * sstateen1-3 have no defined bits yet, so they are read only zero.
+     * Bit 63 is the SE bit only in mstateenN/hstateenN, where it gates
+     * access to sstateenN.
+     */
+    return write_sstateen(env, csrno, 0, new_val);
 }

 static RISCVException rmw_mip64(CPURISCVState *env, int csrno,

Reviewed-by on v1 1/1
#2 lore raw
In reply to Harshit Mukhedkar
Quoted 6 lines · Harshit Mukhedkar

write_sstateen_1_3() passes SMSTATEEN_STATEEN (bit 63) as the write mask to write_sstateen(). That bit is the SE control bit only in mstateenN/hstateenN, where it gates access to sstateenN. The sstateen1-3 CSRs have no defined bits, and reserved bits must be read-only zero, so bit 63 must not be writable on RV64.

Quoted 6 lines

Use a write mask of 0 for sstateen1-3 until bits are defined there.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4726

Fixes 3bee0e40106d ("target/riscv: Add smstateen support")

Thanks,
Chao

Quoted 25 lines
---
 target/riscv/tcg/csr.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
target/riscv/tcg/csr.c +6 -1
index 063590f56a..d9731421af 100644
@@ -3941,7 +3941,12 @@ static RISCVException write_sstateen0(CPURISCVState *env, int csrno,
 static RISCVException write_sstateen_1_3(CPURISCVState *env, int csrno,
                                          target_ulong new_val, uintptr_t ra)
 {
-    return write_sstateen(env, csrno, SMSTATEEN_STATEEN, new_val);
+    /*
+     * sstateen1-3 have no defined bits yet, so they are read only zero.
+     * Bit 63 is the SE bit only in mstateenN/hstateenN, where it gates
+     * access to sstateenN.
+     */
+    return write_sstateen(env, csrno, 0, new_val);
 }
 
 static RISCVException rmw_mip64(CPURISCVState *env, int csrno,
Signature · 1 line
2.56.0