diff mbox series

[v2,1/1] target/riscv: correct csr_ops[CSR_MSECCFG]

Message ID 20231030102105.19501-1-heinrich.schuchardt@canonical.com (mailing list archive)
State Accepted, archived
Headers show
Series [v2,1/1] target/riscv: correct csr_ops[CSR_MSECCFG] | expand

Commit Message

Heinrich Schuchardt Oct. 30, 2023, 10:21 a.m. UTC
The CSR register mseccfg is used by multiple extensions: Smepm and Zkr.

Consider this when checking the existence of the register.

Fixes: 77442380ecbe ("target/riscv: rvk: add CSR support for Zkr")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
v2:
	rebase on alistair23/riscv-to-apply-next
---
 target/riscv/csr.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Alistair Francis Nov. 2, 2023, 12:42 a.m. UTC | #1
On Mon, Oct 30, 2023 at 8:22 PM Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> The CSR register mseccfg is used by multiple extensions: Smepm and Zkr.
>
> Consider this when checking the existence of the register.
>
> Fixes: 77442380ecbe ("target/riscv: rvk: add CSR support for Zkr")
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

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

Alistair

> ---
> v2:
>         rebase on alistair23/riscv-to-apply-next
> ---
>  target/riscv/csr.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index 4ca96ddd1d..fc26b52c88 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -528,11 +528,14 @@ static RISCVException pmp(CPURISCVState *env, int csrno)
>      return RISCV_EXCP_ILLEGAL_INST;
>  }
>
> -static RISCVException smepmp(CPURISCVState *env, int csrno)
> +static RISCVException have_mseccfg(CPURISCVState *env, int csrno)
>  {
>      if (riscv_cpu_cfg(env)->ext_smepmp) {
>          return RISCV_EXCP_NONE;
>      }
> +    if (riscv_cpu_cfg(env)->ext_zkr) {
> +        return RISCV_EXCP_NONE;
> +    }
>
>      return RISCV_EXCP_ILLEGAL_INST;
>  }
> @@ -4766,7 +4769,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
>      [CSR_VSIPH]       = { "vsiph",       aia_hmode32, NULL, NULL, rmw_vsiph },
>
>      /* Physical Memory Protection */
> -    [CSR_MSECCFG]    = { "mseccfg", smepmp, read_mseccfg, write_mseccfg,
> +    [CSR_MSECCFG]    = { "mseccfg",   have_mseccfg, read_mseccfg, write_mseccfg,
>                           .min_priv_ver = PRIV_VERSION_1_11_0           },
>      [CSR_PMPCFG0]    = { "pmpcfg0",   pmp, read_pmpcfg,  write_pmpcfg  },
>      [CSR_PMPCFG1]    = { "pmpcfg1",   pmp, read_pmpcfg,  write_pmpcfg  },
> --
> 2.40.1
>
>
Alistair Francis Nov. 2, 2023, 12:43 a.m. UTC | #2
On Mon, Oct 30, 2023 at 8:22 PM Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> The CSR register mseccfg is used by multiple extensions: Smepm and Zkr.
>
> Consider this when checking the existence of the register.
>
> Fixes: 77442380ecbe ("target/riscv: rvk: add CSR support for Zkr")
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

Thanks!

Applied to riscv-to-apply.next

Alistair

> ---
> v2:
>         rebase on alistair23/riscv-to-apply-next
> ---
>  target/riscv/csr.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index 4ca96ddd1d..fc26b52c88 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -528,11 +528,14 @@ static RISCVException pmp(CPURISCVState *env, int csrno)
>      return RISCV_EXCP_ILLEGAL_INST;
>  }
>
> -static RISCVException smepmp(CPURISCVState *env, int csrno)
> +static RISCVException have_mseccfg(CPURISCVState *env, int csrno)
>  {
>      if (riscv_cpu_cfg(env)->ext_smepmp) {
>          return RISCV_EXCP_NONE;
>      }
> +    if (riscv_cpu_cfg(env)->ext_zkr) {
> +        return RISCV_EXCP_NONE;
> +    }
>
>      return RISCV_EXCP_ILLEGAL_INST;
>  }
> @@ -4766,7 +4769,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
>      [CSR_VSIPH]       = { "vsiph",       aia_hmode32, NULL, NULL, rmw_vsiph },
>
>      /* Physical Memory Protection */
> -    [CSR_MSECCFG]    = { "mseccfg", smepmp, read_mseccfg, write_mseccfg,
> +    [CSR_MSECCFG]    = { "mseccfg",   have_mseccfg, read_mseccfg, write_mseccfg,
>                           .min_priv_ver = PRIV_VERSION_1_11_0           },
>      [CSR_PMPCFG0]    = { "pmpcfg0",   pmp, read_pmpcfg,  write_pmpcfg  },
>      [CSR_PMPCFG1]    = { "pmpcfg1",   pmp, read_pmpcfg,  write_pmpcfg  },
> --
> 2.40.1
>
>
Michael Tokarev Nov. 7, 2023, 4:39 p.m. UTC | #3
30.10.2023 13:21, Heinrich Schuchardt wrote:
> The CSR register mseccfg is used by multiple extensions: Smepm and Zkr.
> 
> Consider this when checking the existence of the register.
> 
> Fixes: 77442380ecbe ("target/riscv: rvk: add CSR support for Zkr")

Is this change worth to pick for -stable (together with 095fe72a128
"Add epmp to extensions list and rename it to smepmp") ?

Thanks,

/mjt
Alistair Francis Nov. 21, 2023, 3:55 a.m. UTC | #4
On Wed, Nov 8, 2023 at 2:40 AM Michael Tokarev <mjt@tls.msk.ru> wrote:
>
> 30.10.2023 13:21, Heinrich Schuchardt wrote:
> > The CSR register mseccfg is used by multiple extensions: Smepm and Zkr.
> >
> > Consider this when checking the existence of the register.
> >
> > Fixes: 77442380ecbe ("target/riscv: rvk: add CSR support for Zkr")
>
> Is this change worth to pick for -stable (together with 095fe72a128
> "Add epmp to extensions list and rename it to smepmp") ?

I don't think we need to back port these.

ePMP/smepmp support was experimental in QEMU, so I don't think we need
to bother back porting fixes.

Alistair

>
> Thanks,
>
> /mjt
>
diff mbox series

Patch

diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index 4ca96ddd1d..fc26b52c88 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -528,11 +528,14 @@  static RISCVException pmp(CPURISCVState *env, int csrno)
     return RISCV_EXCP_ILLEGAL_INST;
 }
 
-static RISCVException smepmp(CPURISCVState *env, int csrno)
+static RISCVException have_mseccfg(CPURISCVState *env, int csrno)
 {
     if (riscv_cpu_cfg(env)->ext_smepmp) {
         return RISCV_EXCP_NONE;
     }
+    if (riscv_cpu_cfg(env)->ext_zkr) {
+        return RISCV_EXCP_NONE;
+    }
 
     return RISCV_EXCP_ILLEGAL_INST;
 }
@@ -4766,7 +4769,7 @@  riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
     [CSR_VSIPH]       = { "vsiph",       aia_hmode32, NULL, NULL, rmw_vsiph },
 
     /* Physical Memory Protection */
-    [CSR_MSECCFG]    = { "mseccfg", smepmp, read_mseccfg, write_mseccfg,
+    [CSR_MSECCFG]    = { "mseccfg",   have_mseccfg, read_mseccfg, write_mseccfg,
                          .min_priv_ver = PRIV_VERSION_1_11_0           },
     [CSR_PMPCFG0]    = { "pmpcfg0",   pmp, read_pmpcfg,  write_pmpcfg  },
     [CSR_PMPCFG1]    = { "pmpcfg1",   pmp, read_pmpcfg,  write_pmpcfg  },