qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] target/riscv: Simplify helper_sret() a little bit
@ 2022-12-07  9:00 Bin Meng
  2022-12-07  9:00 ` [PATCH 2/2] target/riscv: Clear mstatus.MPRV when leaving M-mode for priv spec 1.12+ Bin Meng
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Bin Meng @ 2022-12-07  9:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alistair Francis, Bin Meng, Palmer Dabbelt, qemu-riscv

There are 2 paths in helper_sret() and the same mstatus update codes
are replicated. Extract the common parts to simplify it a little bit.

Signed-off-by: Bin Meng <bmeng@tinylab.org>
---

 target/riscv/op_helper.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
index d7af7f056b..a047d38152 100644
--- a/target/riscv/op_helper.c
+++ b/target/riscv/op_helper.c
@@ -149,21 +149,21 @@ target_ulong helper_sret(CPURISCVState *env)
     }
 
     mstatus = env->mstatus;
+    prev_priv = get_field(mstatus, MSTATUS_SPP);
+    mstatus = set_field(mstatus, MSTATUS_SIE,
+                        get_field(mstatus, MSTATUS_SPIE));
+    mstatus = set_field(mstatus, MSTATUS_SPIE, 1);
+    mstatus = set_field(mstatus, MSTATUS_SPP, PRV_U);
+    env->mstatus = mstatus;
 
     if (riscv_has_ext(env, RVH) && !riscv_cpu_virt_enabled(env)) {
         /* We support Hypervisor extensions and virtulisation is disabled */
         target_ulong hstatus = env->hstatus;
 
-        prev_priv = get_field(mstatus, MSTATUS_SPP);
         prev_virt = get_field(hstatus, HSTATUS_SPV);
 
         hstatus = set_field(hstatus, HSTATUS_SPV, 0);
-        mstatus = set_field(mstatus, MSTATUS_SPP, 0);
-        mstatus = set_field(mstatus, SSTATUS_SIE,
-                            get_field(mstatus, SSTATUS_SPIE));
-        mstatus = set_field(mstatus, SSTATUS_SPIE, 1);
 
-        env->mstatus = mstatus;
         env->hstatus = hstatus;
 
         if (prev_virt) {
@@ -171,14 +171,6 @@ target_ulong helper_sret(CPURISCVState *env)
         }
 
         riscv_cpu_set_virt_enabled(env, prev_virt);
-    } else {
-        prev_priv = get_field(mstatus, MSTATUS_SPP);
-
-        mstatus = set_field(mstatus, MSTATUS_SIE,
-                            get_field(mstatus, MSTATUS_SPIE));
-        mstatus = set_field(mstatus, MSTATUS_SPIE, 1);
-        mstatus = set_field(mstatus, MSTATUS_SPP, PRV_U);
-        env->mstatus = mstatus;
     }
 
     riscv_cpu_set_mode(env, prev_priv);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] target/riscv: Clear mstatus.MPRV when leaving M-mode for priv spec 1.12+
  2022-12-07  9:00 [PATCH 1/2] target/riscv: Simplify helper_sret() a little bit Bin Meng
@ 2022-12-07  9:00 ` Bin Meng
  2022-12-08  4:17   ` Alistair Francis
  2022-12-08  5:43   ` Alistair Francis
  2022-12-08  4:16 ` [PATCH 1/2] target/riscv: Simplify helper_sret() a little bit Alistair Francis
  2022-12-08 22:43 ` Wilfred Mallawa
  2 siblings, 2 replies; 6+ messages in thread
From: Bin Meng @ 2022-12-07  9:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alistair Francis, Bin Meng, Palmer Dabbelt, qemu-riscv

Since priv spec v1.12, MRET and SRET now clear mstatus.MPRV when
leaving M-mode.

Signed-off-by: Bin Meng <bmeng@tinylab.org>

---

 target/riscv/op_helper.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
index a047d38152..878bcb03b8 100644
--- a/target/riscv/op_helper.c
+++ b/target/riscv/op_helper.c
@@ -154,6 +154,9 @@ target_ulong helper_sret(CPURISCVState *env)
                         get_field(mstatus, MSTATUS_SPIE));
     mstatus = set_field(mstatus, MSTATUS_SPIE, 1);
     mstatus = set_field(mstatus, MSTATUS_SPP, PRV_U);
+    if (env->priv_ver >= PRIV_VERSION_1_12_0) {
+        mstatus = set_field(mstatus, MSTATUS_MPRV, 0);
+    }
     env->mstatus = mstatus;
 
     if (riscv_has_ext(env, RVH) && !riscv_cpu_virt_enabled(env)) {
@@ -203,6 +206,9 @@ target_ulong helper_mret(CPURISCVState *env)
     mstatus = set_field(mstatus, MSTATUS_MPIE, 1);
     mstatus = set_field(mstatus, MSTATUS_MPP, PRV_U);
     mstatus = set_field(mstatus, MSTATUS_MPV, 0);
+    if ((env->priv_ver >= PRIV_VERSION_1_12_0) && (prev_priv != PRV_M)) {
+        mstatus = set_field(mstatus, MSTATUS_MPRV, 0);
+    }
     env->mstatus = mstatus;
     riscv_cpu_set_mode(env, prev_priv);
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] target/riscv: Simplify helper_sret() a little bit
  2022-12-07  9:00 [PATCH 1/2] target/riscv: Simplify helper_sret() a little bit Bin Meng
  2022-12-07  9:00 ` [PATCH 2/2] target/riscv: Clear mstatus.MPRV when leaving M-mode for priv spec 1.12+ Bin Meng
@ 2022-12-08  4:16 ` Alistair Francis
  2022-12-08 22:43 ` Wilfred Mallawa
  2 siblings, 0 replies; 6+ messages in thread
From: Alistair Francis @ 2022-12-08  4:16 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Alistair Francis, Bin Meng, Palmer Dabbelt,
	qemu-riscv

On Wed, Dec 7, 2022 at 7:05 PM Bin Meng <bmeng@tinylab.org> wrote:
>
> There are 2 paths in helper_sret() and the same mstatus update codes
> are replicated. Extract the common parts to simplify it a little bit.
>
> Signed-off-by: Bin Meng <bmeng@tinylab.org>

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

Alistair

> ---
>
>  target/riscv/op_helper.c | 20 ++++++--------------
>  1 file changed, 6 insertions(+), 14 deletions(-)
>
> diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
> index d7af7f056b..a047d38152 100644
> --- a/target/riscv/op_helper.c
> +++ b/target/riscv/op_helper.c
> @@ -149,21 +149,21 @@ target_ulong helper_sret(CPURISCVState *env)
>      }
>
>      mstatus = env->mstatus;
> +    prev_priv = get_field(mstatus, MSTATUS_SPP);
> +    mstatus = set_field(mstatus, MSTATUS_SIE,
> +                        get_field(mstatus, MSTATUS_SPIE));
> +    mstatus = set_field(mstatus, MSTATUS_SPIE, 1);
> +    mstatus = set_field(mstatus, MSTATUS_SPP, PRV_U);
> +    env->mstatus = mstatus;
>
>      if (riscv_has_ext(env, RVH) && !riscv_cpu_virt_enabled(env)) {
>          /* We support Hypervisor extensions and virtulisation is disabled */
>          target_ulong hstatus = env->hstatus;
>
> -        prev_priv = get_field(mstatus, MSTATUS_SPP);
>          prev_virt = get_field(hstatus, HSTATUS_SPV);
>
>          hstatus = set_field(hstatus, HSTATUS_SPV, 0);
> -        mstatus = set_field(mstatus, MSTATUS_SPP, 0);
> -        mstatus = set_field(mstatus, SSTATUS_SIE,
> -                            get_field(mstatus, SSTATUS_SPIE));
> -        mstatus = set_field(mstatus, SSTATUS_SPIE, 1);
>
> -        env->mstatus = mstatus;
>          env->hstatus = hstatus;
>
>          if (prev_virt) {
> @@ -171,14 +171,6 @@ target_ulong helper_sret(CPURISCVState *env)
>          }
>
>          riscv_cpu_set_virt_enabled(env, prev_virt);
> -    } else {
> -        prev_priv = get_field(mstatus, MSTATUS_SPP);
> -
> -        mstatus = set_field(mstatus, MSTATUS_SIE,
> -                            get_field(mstatus, MSTATUS_SPIE));
> -        mstatus = set_field(mstatus, MSTATUS_SPIE, 1);
> -        mstatus = set_field(mstatus, MSTATUS_SPP, PRV_U);
> -        env->mstatus = mstatus;
>      }
>
>      riscv_cpu_set_mode(env, prev_priv);
> --
> 2.34.1
>
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] target/riscv: Clear mstatus.MPRV when leaving M-mode for priv spec 1.12+
  2022-12-07  9:00 ` [PATCH 2/2] target/riscv: Clear mstatus.MPRV when leaving M-mode for priv spec 1.12+ Bin Meng
@ 2022-12-08  4:17   ` Alistair Francis
  2022-12-08  5:43   ` Alistair Francis
  1 sibling, 0 replies; 6+ messages in thread
From: Alistair Francis @ 2022-12-08  4:17 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Alistair Francis, Bin Meng, Palmer Dabbelt,
	qemu-riscv

On Wed, Dec 7, 2022 at 7:11 PM Bin Meng <bmeng@tinylab.org> wrote:
>
> Since priv spec v1.12, MRET and SRET now clear mstatus.MPRV when
> leaving M-mode.
>
> Signed-off-by: Bin Meng <bmeng@tinylab.org>

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

Alistair

>
> ---
>
>  target/riscv/op_helper.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
> index a047d38152..878bcb03b8 100644
> --- a/target/riscv/op_helper.c
> +++ b/target/riscv/op_helper.c
> @@ -154,6 +154,9 @@ target_ulong helper_sret(CPURISCVState *env)
>                          get_field(mstatus, MSTATUS_SPIE));
>      mstatus = set_field(mstatus, MSTATUS_SPIE, 1);
>      mstatus = set_field(mstatus, MSTATUS_SPP, PRV_U);
> +    if (env->priv_ver >= PRIV_VERSION_1_12_0) {
> +        mstatus = set_field(mstatus, MSTATUS_MPRV, 0);
> +    }
>      env->mstatus = mstatus;
>
>      if (riscv_has_ext(env, RVH) && !riscv_cpu_virt_enabled(env)) {
> @@ -203,6 +206,9 @@ target_ulong helper_mret(CPURISCVState *env)
>      mstatus = set_field(mstatus, MSTATUS_MPIE, 1);
>      mstatus = set_field(mstatus, MSTATUS_MPP, PRV_U);
>      mstatus = set_field(mstatus, MSTATUS_MPV, 0);
> +    if ((env->priv_ver >= PRIV_VERSION_1_12_0) && (prev_priv != PRV_M)) {
> +        mstatus = set_field(mstatus, MSTATUS_MPRV, 0);
> +    }
>      env->mstatus = mstatus;
>      riscv_cpu_set_mode(env, prev_priv);
>
> --
> 2.34.1
>
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] target/riscv: Clear mstatus.MPRV when leaving M-mode for priv spec 1.12+
  2022-12-07  9:00 ` [PATCH 2/2] target/riscv: Clear mstatus.MPRV when leaving M-mode for priv spec 1.12+ Bin Meng
  2022-12-08  4:17   ` Alistair Francis
@ 2022-12-08  5:43   ` Alistair Francis
  1 sibling, 0 replies; 6+ messages in thread
From: Alistair Francis @ 2022-12-08  5:43 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Alistair Francis, Bin Meng, Palmer Dabbelt,
	qemu-riscv

On Wed, Dec 7, 2022 at 7:11 PM Bin Meng <bmeng@tinylab.org> wrote:
>
> Since priv spec v1.12, MRET and SRET now clear mstatus.MPRV when
> leaving M-mode.
>
> Signed-off-by: Bin Meng <bmeng@tinylab.org>

Thanks!

Applied to riscv-to-apply.next

Alistair

>
> ---
>
>  target/riscv/op_helper.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
> index a047d38152..878bcb03b8 100644
> --- a/target/riscv/op_helper.c
> +++ b/target/riscv/op_helper.c
> @@ -154,6 +154,9 @@ target_ulong helper_sret(CPURISCVState *env)
>                          get_field(mstatus, MSTATUS_SPIE));
>      mstatus = set_field(mstatus, MSTATUS_SPIE, 1);
>      mstatus = set_field(mstatus, MSTATUS_SPP, PRV_U);
> +    if (env->priv_ver >= PRIV_VERSION_1_12_0) {
> +        mstatus = set_field(mstatus, MSTATUS_MPRV, 0);
> +    }
>      env->mstatus = mstatus;
>
>      if (riscv_has_ext(env, RVH) && !riscv_cpu_virt_enabled(env)) {
> @@ -203,6 +206,9 @@ target_ulong helper_mret(CPURISCVState *env)
>      mstatus = set_field(mstatus, MSTATUS_MPIE, 1);
>      mstatus = set_field(mstatus, MSTATUS_MPP, PRV_U);
>      mstatus = set_field(mstatus, MSTATUS_MPV, 0);
> +    if ((env->priv_ver >= PRIV_VERSION_1_12_0) && (prev_priv != PRV_M)) {
> +        mstatus = set_field(mstatus, MSTATUS_MPRV, 0);
> +    }
>      env->mstatus = mstatus;
>      riscv_cpu_set_mode(env, prev_priv);
>
> --
> 2.34.1
>
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] target/riscv: Simplify helper_sret() a little bit
  2022-12-07  9:00 [PATCH 1/2] target/riscv: Simplify helper_sret() a little bit Bin Meng
  2022-12-07  9:00 ` [PATCH 2/2] target/riscv: Clear mstatus.MPRV when leaving M-mode for priv spec 1.12+ Bin Meng
  2022-12-08  4:16 ` [PATCH 1/2] target/riscv: Simplify helper_sret() a little bit Alistair Francis
@ 2022-12-08 22:43 ` Wilfred Mallawa
  2 siblings, 0 replies; 6+ messages in thread
From: Wilfred Mallawa @ 2022-12-08 22:43 UTC (permalink / raw)
  To: bmeng@tinylab.org, qemu-devel@nongnu.org
  Cc: bin.meng@windriver.com, palmer@dabbelt.com, Alistair Francis,
	qemu-riscv@nongnu.org

On Wed, 2022-12-07 at 17:00 +0800, Bin Meng wrote:
> There are 2 paths in helper_sret() and the same mstatus update codes
> are replicated. Extract the common parts to simplify it a little bit.
> 
> Signed-off-by: Bin Meng <bmeng@tinylab.org>
Reviewed-by: Wilfred Mallawa <wilfred.mallawa@wdc.com>

Wilfred
> ---
> 
>  target/riscv/op_helper.c | 20 ++++++--------------
>  1 file changed, 6 insertions(+), 14 deletions(-)
> 
> diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
> index d7af7f056b..a047d38152 100644
> --- a/target/riscv/op_helper.c
> +++ b/target/riscv/op_helper.c
> @@ -149,21 +149,21 @@ target_ulong helper_sret(CPURISCVState *env)
>      }
>  
>      mstatus = env->mstatus;
> +    prev_priv = get_field(mstatus, MSTATUS_SPP);
> +    mstatus = set_field(mstatus, MSTATUS_SIE,
> +                        get_field(mstatus, MSTATUS_SPIE));
> +    mstatus = set_field(mstatus, MSTATUS_SPIE, 1);
> +    mstatus = set_field(mstatus, MSTATUS_SPP, PRV_U);
> +    env->mstatus = mstatus;
>  
>      if (riscv_has_ext(env, RVH) && !riscv_cpu_virt_enabled(env)) {
>          /* We support Hypervisor extensions and virtulisation is
> disabled */
>          target_ulong hstatus = env->hstatus;
>  
> -        prev_priv = get_field(mstatus, MSTATUS_SPP);
>          prev_virt = get_field(hstatus, HSTATUS_SPV);
>  
>          hstatus = set_field(hstatus, HSTATUS_SPV, 0);
> -        mstatus = set_field(mstatus, MSTATUS_SPP, 0);
> -        mstatus = set_field(mstatus, SSTATUS_SIE,
> -                            get_field(mstatus, SSTATUS_SPIE));
> -        mstatus = set_field(mstatus, SSTATUS_SPIE, 1);
>  
> -        env->mstatus = mstatus;
>          env->hstatus = hstatus;
>  
>          if (prev_virt) {
> @@ -171,14 +171,6 @@ target_ulong helper_sret(CPURISCVState *env)
>          }
>  
>          riscv_cpu_set_virt_enabled(env, prev_virt);
> -    } else {
> -        prev_priv = get_field(mstatus, MSTATUS_SPP);
> -
> -        mstatus = set_field(mstatus, MSTATUS_SIE,
> -                            get_field(mstatus, MSTATUS_SPIE));
> -        mstatus = set_field(mstatus, MSTATUS_SPIE, 1);
> -        mstatus = set_field(mstatus, MSTATUS_SPP, PRV_U);
> -        env->mstatus = mstatus;
>      }
>  
>      riscv_cpu_set_mode(env, prev_priv);


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-12-08 22:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-07  9:00 [PATCH 1/2] target/riscv: Simplify helper_sret() a little bit Bin Meng
2022-12-07  9:00 ` [PATCH 2/2] target/riscv: Clear mstatus.MPRV when leaving M-mode for priv spec 1.12+ Bin Meng
2022-12-08  4:17   ` Alistair Francis
2022-12-08  5:43   ` Alistair Francis
2022-12-08  4:16 ` [PATCH 1/2] target/riscv: Simplify helper_sret() a little bit Alistair Francis
2022-12-08 22:43 ` Wilfred Mallawa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).