Skip to contentSkip to conversation

target/riscv: Backup/restore mstatus.SD bit when virtual register swapped

PATCH Applied [email protected] 2 participants 3 messages Sep 14, 2021 – Sep 15, 2021 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/riscv: Backup/restore mstatus.SD bit when virtual register swapped

From: Frank Chang <[email protected]>

When virtual registers are swapped, mstatus.SD bit should also be backed up/restored. Otherwise, mstatus.SD bit will be incorrectly kept across the world switches.

---
 target/riscv/cpu_helper.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/riscv/cpu_helper.c +2 -1
index 968cb8046f4..488867b59eb 100644
@@ -111,9 +111,10 @@ bool riscv_cpu_fp_enabled(CPURISCVState *env)
 
 void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env)
 {
+    target_ulong sd = riscv_cpu_is_32bit(env) ? MSTATUS32_SD : MSTATUS64_SD;
     uint64_t mstatus_mask = MSTATUS_MXR | MSTATUS_SUM | MSTATUS_FS |
                             MSTATUS_SPP | MSTATUS_SPIE | MSTATUS_SIE |
-                            MSTATUS64_UXL;
+                            MSTATUS64_UXL | sd;
     bool current_virt = riscv_cpu_virt_enabled(env);
 
     g_assert(riscv_has_ext(env, RVH));
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · On Tue, Sep 14, 2021 at 11:37 AM <[email protected]> wrote:

From: Frank Chang <[email protected]>

When virtual registers are swapped, mstatus.SD bit should also be backed up/restored. Otherwise, mstatus.SD bit will be incorrectly kept across the world switches.

Alistair

Quoted 24 lines
---
 target/riscv/cpu_helper.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/riscv/cpu_helper.c +2 -2
index 968cb8046f4..488867b59eb 100644
@@ -111,9 +111,10 @@ bool riscv_cpu_fp_enabled(CPURISCVState *env)
 
 void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env)
 {
+    target_ulong sd = riscv_cpu_is_32bit(env) ? MSTATUS32_SD : MSTATUS64_SD;
     uint64_t mstatus_mask = MSTATUS_MXR | MSTATUS_SUM | MSTATUS_FS |
                             MSTATUS_SPP | MSTATUS_SPIE | MSTATUS_SIE |
-                            MSTATUS64_UXL;
+                            MSTATUS64_UXL | sd;
     bool current_virt = riscv_cpu_virt_enabled(env);
 
     g_assert(riscv_has_ext(env, RVH));
--

2.25.1

#2 lore raw
In reply to [email protected]
Quoted 9 lines · On Tue, Sep 14, 2021 at 11:37 AM <[email protected]> wrote:

From: Frank Chang <[email protected]>

When virtual registers are swapped, mstatus.SD bit should also be backed up/restored. Otherwise, mstatus.SD bit will be incorrectly kept across the world switches.

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 24 lines
---
 target/riscv/cpu_helper.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/riscv/cpu_helper.c +2 -2
index 968cb8046f4..488867b59eb 100644
@@ -111,9 +111,10 @@ bool riscv_cpu_fp_enabled(CPURISCVState *env)
 
 void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env)
 {
+    target_ulong sd = riscv_cpu_is_32bit(env) ? MSTATUS32_SD : MSTATUS64_SD;
     uint64_t mstatus_mask = MSTATUS_MXR | MSTATUS_SUM | MSTATUS_FS |
                             MSTATUS_SPP | MSTATUS_SPIE | MSTATUS_SIE |
-                            MSTATUS64_UXL;
+                            MSTATUS64_UXL | sd;
     bool current_virt = riscv_cpu_virt_enabled(env);
 
     g_assert(riscv_has_ext(env, RVH));
--

2.25.1