qemu-riscv.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Weiwei Li <liweiwei@iscas.ac.cn>
To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org
Cc: palmer@dabbelt.com, alistair.francis@wdc.com,
	bin.meng@windriver.com, dbarboza@ventanamicro.com,
	zhiwei_liu@linux.alibaba.com, wangjunqiang@iscas.ac.cn,
	lazyparser@gmail.com, Weiwei Li <liweiwei@iscas.ac.cn>
Subject: [PATCH 1/4] target/riscv: Make MPV only work when MPP != PRV_M
Date: Mon, 29 May 2023 20:17:16 +0800	[thread overview]
Message-ID: <20230529121719.179507-2-liweiwei@iscas.ac.cn> (raw)
In-Reply-To: <20230529121719.179507-1-liweiwei@iscas.ac.cn>

Upon MRET or explicit memory access with MPRV=1, MPV should be ignored
when MPP=PRV_M.

Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn>
Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn>
---
 target/riscv/cpu_helper.c | 3 ++-
 target/riscv/op_helper.c  | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
index 09ea227ceb..bd892c05d4 100644
--- a/target/riscv/cpu_helper.c
+++ b/target/riscv/cpu_helper.c
@@ -46,7 +46,8 @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch)
 
         if (mode == PRV_M && get_field(status, MSTATUS_MPRV)) {
             mode = get_field(env->mstatus, MSTATUS_MPP);
-            virt = get_field(env->mstatus, MSTATUS_MPV);
+            virt = get_field(env->mstatus, MSTATUS_MPV) &&
+                   (mode != PRV_M);
             if (virt) {
                 status = env->vsstatus;
             }
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
index f563dc3981..9cdb9cdd06 100644
--- a/target/riscv/op_helper.c
+++ b/target/riscv/op_helper.c
@@ -335,7 +335,8 @@ target_ulong helper_mret(CPURISCVState *env)
         riscv_raise_exception(env, RISCV_EXCP_INST_ACCESS_FAULT, GETPC());
     }
 
-    target_ulong prev_virt = get_field(env->mstatus, MSTATUS_MPV);
+    target_ulong prev_virt = get_field(env->mstatus, MSTATUS_MPV) &&
+                             (prev_priv != PRV_M);
     mstatus = set_field(mstatus, MSTATUS_MIE,
                         get_field(mstatus, MSTATUS_MPIE));
     mstatus = set_field(mstatus, MSTATUS_MPIE, 1);
-- 
2.25.1



  reply	other threads:[~2023-05-29 12:18 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-29 12:17 [PATCH 0/4] target/riscv: Fix mstatus related problems Weiwei Li
2023-05-29 12:17 ` Weiwei Li [this message]
2023-05-30 20:23   ` [PATCH 1/4] target/riscv: Make MPV only work when MPP != PRV_M Daniel Henrique Barboza
2023-05-31  0:27     ` Weiwei Li
2023-05-31  9:28       ` Daniel Henrique Barboza
2023-05-31  9:28   ` Daniel Henrique Barboza
2023-06-01  5:24   ` Alistair Francis
2023-06-12  2:45   ` LIU Zhiwei
2023-06-12  3:10     ` Weiwei Li
2023-06-12  3:30       ` LIU Zhiwei
2023-05-29 12:17 ` [PATCH 2/4] target/riscv: Remove check on mode for MPRV Weiwei Li
2023-05-30 20:25   ` Daniel Henrique Barboza
2023-05-31  9:28   ` Daniel Henrique Barboza
2023-06-01  5:27   ` Alistair Francis
2023-06-01  6:43     ` Weiwei Li
2023-06-01 23:03       ` Alistair Francis
2023-06-02  1:31         ` Weiwei Li
2023-06-02 21:01           ` Richard Henderson
2023-06-03 13:46             ` Weiwei Li
2023-05-29 12:17 ` [PATCH 3/4] target/riscv: Support MSTATUS.MPV/GVA only when RVH is enabled Weiwei Li
2023-05-30 20:26   ` Daniel Henrique Barboza
2023-06-01  5:28   ` Alistair Francis
2023-06-12  3:08   ` LIU Zhiwei
2023-06-12  3:16     ` Weiwei Li
2023-06-12  3:18       ` LIU Zhiwei
2023-06-12  4:35         ` Weiwei Li
2023-06-12  5:40           ` LIU Zhiwei
2023-06-12  7:27             ` Weiwei Li
2023-05-29 12:17 ` [PATCH 4/4] target/riscv: Remove redundant assignment to SXL Weiwei Li
2023-05-30 20:28   ` Daniel Henrique Barboza
2023-06-01  5:31   ` Alistair Francis
2023-06-12  5:55   ` LIU Zhiwei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230529121719.179507-2-liweiwei@iscas.ac.cn \
    --to=liweiwei@iscas.ac.cn \
    --cc=alistair.francis@wdc.com \
    --cc=bin.meng@windriver.com \
    --cc=dbarboza@ventanamicro.com \
    --cc=lazyparser@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=wangjunqiang@iscas.ac.cn \
    --cc=zhiwei_liu@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).