qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Yanfeng <yfliu2008@qq.com>
To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org
Cc: Daniel Henrique Barboza <dbarboza@ventanamicro.com>,
	Weiwei Li <liwei1518@gmail.com>,
	Liu Zhiwei <zhiwei_liu@linux.alibaba.com>,
	Alistair Francis <alistair.francis@wdc.com>
Subject: [PATCH] include virtualization mode as part of priv
Date: Wed, 27 Nov 2024 20:08:30 +0800	[thread overview]
Message-ID: <tencent_6FF30F7E2E640BEE260FD6523B6BA5486908@qq.com> (raw)


When debugging hypervisor extension based programs, it is convenient to see the
current virtualization mode from GDB debugger.

This patch shares the virtualization mode as part of the existing "priv" virtual
register, or more specifically via bit(8).


>From 0d82561b11e1c2835f14ba5460cfff52f0087530 Mon Sep 17 00:00:00 2001
From: Yanfeng Liu <yfliu2008@qq.com>
Date: Mon, 18 Nov 2024 08:03:15 +0800
Subject: [PATCH] riscv/gdb: share virt mode via priv register

This shares virtualization mode together with privilege mode
via the `priv` virtual register over the debug interface.

Check logs with gdb-multiarch 12.1:

```
(gdb) info registers priv
priv           0x101	prv:1 [Supervisor]
(gdb) set $priv = 1
(gdb) info registers priv
priv           0x1	prv:1 [Supervisor]
(gdb) set $priv = 0x101
(gdb) info registers priv
priv           0x101	prv:1 [Supervisor]
(gdb)
```

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
---
 target/riscv/cpu_bits.h |  4 ++++
 target/riscv/gdbstub.c  | 15 +++++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
index 385a2c67c2..cc6dece51a 100644
--- a/target/riscv/cpu_bits.h
+++ b/target/riscv/cpu_bits.h
@@ -623,6 +623,10 @@ typedef enum {
 #define PRV_RESERVED 2
 #define PRV_M 3
 
+/* Share virtualization mode as part of priv register */
+#define PRV_V                (1 << 8)
+
+
 /* RV32 satp CSR field masks */
 #define SATP32_MODE         0x80000000
 #define SATP32_ASID         0x7fc00000
diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c
index c07df972f1..d9e6ad969a 100644
--- a/target/riscv/gdbstub.c
+++ b/target/riscv/gdbstub.c
@@ -212,8 +212,14 @@ static int riscv_gdb_get_virtual(CPUState *cs, GByteArray
*buf, int n)
 #else
         RISCVCPU *cpu = RISCV_CPU(cs);
         CPURISCVState *env = &cpu->env;
+        target_ulong ret = env->priv;
 
-        return gdb_get_regl(buf, env->priv);
+        /* include virtualization mode */
+
+        if (env->virt_enabled) {
+            ret |= PRV_V;
+        }
+        return gdb_get_regl(buf, ret);
 #endif
     }
     return 0;
@@ -225,11 +231,16 @@ static int riscv_gdb_set_virtual(CPUState *cs, uint8_t
*mem_buf, int n)
 #ifndef CONFIG_USER_ONLY
         RISCVCPU *cpu = RISCV_CPU(cs);
         CPURISCVState *env = &cpu->env;
+        target_ulong val = ldtul_p(mem_buf);
 
-        env->priv = ldtul_p(mem_buf) & 0x3;
+        env->priv = val & 0x3;
         if (env->priv == PRV_RESERVED) {
             env->priv = PRV_S;
         }
+
+        /* Update virtualization mode */
+
+        env->virt_enabled = (env->priv != PRV_M && (val & PRV_V) != 0);
 #endif
         return sizeof(target_ulong);
     }
-- 
2.34.1





             reply	other threads:[~2024-11-27 14:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-27 12:08 Yanfeng [this message]
2024-11-28  0:39 ` [PATCH] include virtualization mode as part of priv Alistair Francis
2024-11-28  1:43   ` Yanfeng
2024-11-28  2:43     ` Alistair Francis
2024-11-28  4:05       ` Yanfeng
2024-11-28  4:10         ` Alistair Francis
2024-11-28  4:27           ` Yanfeng
2024-11-28  4:46             ` Alistair Francis
2024-11-28  6:39               ` Yanfeng
2024-11-28 13:02                 ` Daniel Henrique Barboza
2024-11-29  8:36                   ` Yanfeng

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=tencent_6FF30F7E2E640BEE260FD6523B6BA5486908@qq.com \
    --to=yfliu2008@qq.com \
    --cc=alistair.francis@wdc.com \
    --cc=dbarboza@ventanamicro.com \
    --cc=liwei1518@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --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).