Skip to contentSkip to conversation

target/riscv: gate envcfg CBO fields on extensions

PATCH Applied 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: gate envcfg CBO fields on extensions

The envcfg CBO fields are provided by Zicbom and Zicboz. Keep them read-only zero when the corresponding extension is absent in all three envcfg CSRs.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4225

---
 target/riscv/tcg/csr.c | 37 +++++++++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 4 deletions(-)
target/riscv/tcg/csr.c +33 -4
index 061bc9d..96c513b 100644
@@ -3224,10 +3224,19 @@ static RISCVException write_menvcfg(CPURISCVState *env, int csrno,
                                     target_ulong val, uintptr_t ra)
 {
     const RISCVCPUConfig *cfg = riscv_cpu_cfg(env);
-    uint64_t mask = MENVCFG_FIOM | MENVCFG_CBIE | MENVCFG_CBCFE |
-                    MENVCFG_CBZE;
+    uint64_t mask = MENVCFG_FIOM;
     bool stce_changed = false;
 
+    /* CBIE/CBCFE are read-only zero when Zicbom is not implemented. */
+    if (cfg->ext_zicbom) {
+        mask |= MENVCFG_CBIE | MENVCFG_CBCFE;
+    }
+
+    /* CBZE is read-only zero when Zicboz is not implemented. */
+    if (cfg->ext_zicboz) {
+        mask |= MENVCFG_CBZE;
+    }
+
     /*
      * menvcfg.LPE (Zicfilp) and menvcfg.SSE (Zicfiss) reside in the low
      * 32 bits and are defined for both RV32 and RV64, so they must be
@@ -3328,8 +3337,18 @@ static RISCVException read_senvcfg(CPURISCVState *env, int csrno,
 static RISCVException write_senvcfg(CPURISCVState *env, int csrno,
                                     target_ulong val, uintptr_t ra)
 {
-    uint64_t mask = SENVCFG_FIOM | SENVCFG_CBIE | SENVCFG_CBCFE | SENVCFG_CBZE;
+    uint64_t mask = SENVCFG_FIOM;
     RISCVException ret;
+
+    /* CBIE/CBCFE are read-only zero when Zicbom is not implemented. */
+    if (env_archcpu(env)->cfg.ext_zicbom) {
+        mask |= SENVCFG_CBIE | SENVCFG_CBCFE;
+    }
+
+    /* CBZE is read-only zero when Zicboz is not implemented. */
+    if (env_archcpu(env)->cfg.ext_zicboz) {
+        mask |= SENVCFG_CBZE;
+    }
     /* Update PMM field only if the value is valid according to Zjpm v1.0 */
     if (env_archcpu(env)->cfg.ext_ssnpm &&
         riscv_cpu_mxl(env) == MXL_RV64 &&
@@ -3386,10 +3405,20 @@ static RISCVException write_henvcfg(CPURISCVState *env, int csrno,
                                     target_ulong val, uintptr_t ra)
 {
     const RISCVCPUConfig *cfg = riscv_cpu_cfg(env);
-    uint64_t mask = HENVCFG_FIOM | HENVCFG_CBIE | HENVCFG_CBCFE | HENVCFG_CBZE;
+    uint64_t mask = HENVCFG_FIOM;
     RISCVException ret;
     bool stce_changed = false;
 
+    /* CBIE/CBCFE are read-only zero when Zicbom is not implemented. */
+    if (cfg->ext_zicbom) {
+        mask |= HENVCFG_CBIE | HENVCFG_CBCFE;
+    }
+
+    /* CBZE is read-only zero when Zicboz is not implemented. */
+    if (cfg->ext_zicboz) {
+        mask |= HENVCFG_CBZE;
+    }
+
     ret = smstateen_acc_ok(env, 0, SMSTATEEN0_HSENVCFG);
     if (ret != RISCV_EXCP_NONE) {
         return ret;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 7 lines · wangyang

The envcfg CBO fields are provided by Zicbom and Zicboz. Keep them read-only zero when the corresponding extension is absent in all three
envcfg CSRs.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4225

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 83 lines

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

 1 file changed, 33 insertions(+), 4 deletions(-)
target/riscv/tcg/csr.c +1 -2
index 061bc9d..96c513b 100644
@@ -3224,10 +3224,19 @@ static RISCVException
 write_menvcfg(CPURISCVState *env, int csrno,
                                      target_ulong val, uintptr_t ra)
  {
      const RISCVCPUConfig *cfg = riscv_cpu_cfg(env);
-    uint64_t mask = MENVCFG_FIOM | MENVCFG_CBIE | MENVCFG_CBCFE |
-                    MENVCFG_CBZE;
+    uint64_t mask = MENVCFG_FIOM;
      bool stce_changed = false;


+    /* CBIE/CBCFE are read-only zero when Zicbom is not implemented. */
+    if (cfg->ext_zicbom) {
+        mask |= MENVCFG_CBIE | MENVCFG_CBCFE;
+    }

target/riscv/tcg/csr.c +6 -0
+
+    /* CBZE is read-only zero when Zicboz is not implemented. */
+    if (cfg->ext_zicboz) {
+        mask |= MENVCFG_CBZE;
+    }
+

     /*
      * menvcfg.LPE (Zicfilp) and menvcfg.SSE (Zicfiss) reside in the low
      * 32 bits and are defined for both RV32 and RV64, so they must be

target/riscv/tcg/csr.c +11 -1
@@ -3328,8 +3337,18 @@ static RISCVException
 read_senvcfg(CPURISCVState *env, int csrno,
  static RISCVException write_senvcfg(CPURISCVState *env, int csrno,
                                      target_ulong val, uintptr_t ra)
  {
-    uint64_t mask = SENVCFG_FIOM | SENVCFG_CBIE | SENVCFG_CBCFE |
 SENVCFG_CBZE;
+    uint64_t mask = SENVCFG_FIOM;
      RISCVException ret;
+
+    /* CBIE/CBCFE are read-only zero when Zicbom is not implemented.
 */
+    if (env_archcpu(env)->cfg.ext_zicbom) {
+        mask |= SENVCFG_CBIE | SENVCFG_CBCFE;
+    }
+
+    /* CBZE is read-only zero when Zicboz is not implemented. */
+    if (env_archcpu(env)->cfg.ext_zicboz) {
+        mask |= SENVCFG_CBZE;
+    }

     /* Update PMM field only if the value is valid according to Zjpm v1.0 */
     if (env_archcpu(env)->cfg.ext_ssnpm && riscv_cpu_mxl(env) == MXL_RV64 &&

target/riscv/tcg/csr.c +1 -1
@@ -3386,10 +3405,20 @@ static RISCVException
 write_henvcfg(CPURISCVState *env, int csrno,
                                      target_ulong val, uintptr_t ra)
  {
      const RISCVCPUConfig *cfg = riscv_cpu_cfg(env);
-    uint64_t mask = HENVCFG_FIOM | HENVCFG_CBIE | HENVCFG_CBCFE |
 HENVCFG_CBZE;
+    uint64_t mask = HENVCFG_FIOM;
      RISCVException ret;
      bool stce_changed = false;


+    /* CBIE/CBCFE are read-only zero when Zicbom is not implemented. */
+    if (cfg->ext_zicbom) {
+        mask |= HENVCFG_CBIE | HENVCFG_CBCFE;
+    }

target/riscv/tcg/csr.c +6 -0
+
+    /* CBZE is read-only zero when Zicboz is not implemented. */
+    if (cfg->ext_zicboz) {
+        mask |= HENVCFG_CBZE;
+    }
+

     ret = smstateen_acc_ok(env, 0, SMSTATEEN0_HSENVCFG); if (ret != RISCV_EXCP_NONE) {
         return ret;