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

wangyang posted 1 patch 1 month, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/6AD0895D.0F1C23.05843@cstnet.cn
Maintainers: Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Chao Liu <chao.liu@processmission.com>
target/riscv/tcg/csr.c | 8 ++++++++
1 file changed, 8 insertions(+)
[PATCH] target/riscv: mask inactive senvcfg.SSE on read
Posted by wangyang 1 month, 1 week ago
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
Signed-off-by: wangyang <wangyang25@otcaix.iscas.ac.cn>
---
 target/riscv/tcg/csr.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/target/riscv/tcg/csr.c b/target/riscv/tcg/csr.c
index 061bc9d..7fd148d 100644
--- a/target/riscv/tcg/csr.c
+++ b/target/riscv/tcg/csr.c
@@ -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;
 }
 
-- 
2.43.0
Re: [PATCH] target/riscv: mask inactive senvcfg.SSE on read
Posted by Alistair Francis 1 month ago
On Thu, 2026-10-15 at 08:05 +0000, wangyang wrote:
> 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
> Signed-off-by: wangyang <wangyang25@otcaix.iscas.ac.cn>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  target/riscv/tcg/csr.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/target/riscv/tcg/csr.c b/target/riscv/tcg/csr.c
> index 061bc9d..7fd148d 100644
> --- a/target/riscv/tcg/csr.c
> +++ b/target/riscv/tcg/csr.c
> @@ -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;
>  }
>