@samitouri / QOSamiQemu / commits / dd7ceff23d

target/riscv: Remove unconditional MENVCFG_CDE from mask

Currently, the MENVCFG_CDE (Counter Delegation Enable) bit is unconditionally included in the base write mask for CSR_MENVCFG. This make the subsequent conditional check `(cfg->ext_smcdeleg ? MENVCFG_CDE : 0)` completely ineffective, as a bitwise OR cannot clear a bit that is already set. Fix this by removing MENVCFG_CDE from the initial base mask. The bit will now only be writable when explicitly granted by the `ext_smcdeleg` configuration. This issue was discovered and reported by SpecHunter, an AI-driven architecture specification analysis tool. Link: https://github.com/yizishun/rv-isa-sec/blob/master/output/riscv-isa-manual/pr-2601/qemu.txt Signed-off-by: Zishun Yi <vulab@iscas.ac.cn> Reviewed-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com> Message-ID: <20260511040534.2862443-1-vulab@iscas.ac.cn> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Zishun Yi committed May 11, 2026 at 12:05 UTC dd7ceff23de23a9c0f17c506662e7512fedc6df0
1 file changed +1 -1
target/riscv/csr.c
+1 -1
@@ -3177,7 +3177,7 @@ static RISCVException write_menvcfg(CPURISCVState *env, int csrno,
3177 {
3178 const RISCVCPUConfig *cfg = riscv_cpu_cfg(env);
3179 uint64_t mask = MENVCFG_FIOM | MENVCFG_CBIE | MENVCFG_CBCFE |
3180 - MENVCFG_CBZE | MENVCFG_CDE;
3180 + MENVCFG_CBZE;
3181 bool stce_changed = false;
3182
3183 if (riscv_cpu_mxl(env) == MXL_RV64) {