target/riscv: make sstateen1-3 reserved bits read-only zero
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
--- target/riscv/tcg/csr.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
target/riscv/tcg/csr.c +6 -1
@@ -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
Quoted 8 lines · Harshit Mukhedkar
write_sstateen_1_3()passesSMSTATEEN_STATEEN(bit 63) as the write mask towrite_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")Signed-off-by Harshit Mukhedkar <[email protected]>
Alistair
Quoted 27 lines
---
target/riscv/tcg/csr.c | 7 ++++++-1 file changed, 6 insertions(+), 1 deletion(-)target/riscv/tcg/csr.c +0
-0@@ -3941,7 +3941,12 @@ static RISCVException write_sstateen0(CPURISCVState *env, int csrno,static RISCVException write_sstateen_1_3(CPURISCVState *env, int csrno,
target_ulongnew_val,uintptr_tra)
{
- returnwrite_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.
+ */
+ returnwrite_sstateen(env, csrno, 0, new_val);
}
static RISCVException rmw_mip64(CPURISCVState *env, int csrno,
Quoted 6 lines · Harshit Mukhedkar
write_sstateen_1_3()passesSMSTATEEN_STATEEN(bit 63) as the write mask towrite_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")Signed-off-by Harshit Mukhedkar <[email protected]>
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@@ -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