Skip to contentSkip to conversation

target/riscv: fix VS-mode sireg access to a counter exception

PATCH New Juliet Mathis 1 participant 1 message Nov 29 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/riscv: fix VS-mode sireg access to a counter exception

When counter delegation is disabled, the counter range is unimplemented. Any access to a counter while in VS-mode should raise an illegal instruction exception.

Any failure to access a register in VS-mode raises a virtual instruction exception without considering the value of menvcfg.CDE.

Our fix raises an illegal instruction exception on failure to access a register in VS-mode if menvcfg.CDE = 0 and vsiselect is within the counter range.

Fixes 5e33a2082715 ("target/riscv: Support generic CSR indirect access")

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4830

---
 target/riscv/tcg/csr.c | 6 ++++++
 1 file changed, 6 insertions(+)
target/riscv/tcg/csr.c +6 -0
index af444e3e6f..ed9ae72c8c 100644
@@ -2923,6 +2923,12 @@ static int rmw_xireg_csrind(CPURISCVState *env, int csrno,
 
     if (xiselect_cd_range(isel)) {
         ret = rmw_xireg_cd(env, csrno, isel, val, new_val, wr_mask);
+
+        if (ret && env->virt_enabled && virt &&
+                !get_field(env->menvcfg, MENVCFG_CDE)) {
+            return RISCV_EXCP_ILLEGAL_INST;
+        }
+
     } else if (xiselect_ctr_range(csrno, isel)) {
         ret = rmw_xireg_ctr(env, csrno, isel, val, new_val, wr_mask);
     } else {
Signature · 1 line
2.56.1.windows.1