Skip to contentSkip to conversation

target/riscv: mask inactive senvcfg.SSE on read

PATCH In review wangyang 2 participants 2 messages Oct 15 – Oct 22 RISC-V

lore
Share & tools
lore

wangyang

author
#0 lore raw

PATCH 1/1 target/riscv: mask inactive senvcfg.SSE on read

The CFI rules make senvcfg.SSE read as zero when menvcfg.SSE is clear. In VU mode it also reads as zero when henvcfg.SSE is clear. Mask the readback to match those rules.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4224

---
 target/riscv/tcg/csr.c | 8 ++++++++
 1 file changed, 8 insertions(+)
target/riscv/tcg/csr.c +8 -0
index 061bc9d..7fd148d 100644
@@ -3322,6 +3322,14 @@ static RISCVException read_senvcfg(CPURISCVState *env, int csrno,
     }
 
     *val = env->senvcfg;
+
+    if (env_archcpu(env)->cfg.ext_zicfiss) {
+        if (!(env->menvcfg & MENVCFG_SSE) ||
+            (env->virt_enabled && !(env->henvcfg & HENVCFG_SSE))) {
+            *val &= ~SENVCFG_SSE;
+        }
+    }
+
     return RISCV_EXCP_NONE;
 }
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · wangyang

The CFI rules make senvcfg.SSE read as zero when menvcfg.SSE is clear.
In VU mode it also reads as zero when henvcfg.SSE is clear. Mask the readback to match those rules.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4224

Alistair

Quoted 24 lines

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

 1 file changed, 8 insertions(+)
target/riscv/tcg/csr.c +0 -0
index 061bc9d..7fd148d 100644
@@ -3322,6 +3322,14 @@ static RISCVException
 read_senvcfg(CPURISCVState *env, int csrno,
      }


     *val = env->senvcfg;

target/riscv/tcg/csr.c +8 -0
+
+    if (env_archcpu(env)->cfg.ext_zicfiss) {
+        if (!(env->menvcfg & MENVCFG_SSE) ||
+            (env->virt_enabled && !(env->henvcfg & HENVCFG_SSE))) {
+            *val &= ~SENVCFG_SSE;
+        }
+    }
+

     return RISCV_EXCP_NONE;
 }