All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] target/riscv: add satp mode for kvm host cpu
@ 2025-04-27 13:25 Meng Zhuo
  2025-04-28  7:00 ` Andrew Jones
  0 siblings, 1 reply; 6+ messages in thread
From: Meng Zhuo @ 2025-04-27 13:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-riscv, Alistair Francis, Liu Zhiwei, Weiwei Li,
	Palmer Dabbelt, Daniel Henrique Barboza, Meng Zhuo

This patch adds host satp mode while kvm/host cpu satp mode is not
set.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2931
Signed-off-by: Meng Zhuo <mengzhuo@iscas.ac.cn>
---
 target/riscv/kvm/kvm-cpu.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
index 5315134e08..942f942b25 100644
--- a/target/riscv/kvm/kvm-cpu.c
+++ b/target/riscv/kvm/kvm-cpu.c
@@ -953,6 +953,21 @@ static void kvm_riscv_destroy_scratch_vcpu(KVMScratchCPU *scratch)
     close(scratch->kvmfd);
 }
 
+static void kvm_riscv_init_satp_mode(RISCVCPU *cpu, KVMScratchCPU *kvmcpu)
+{
+    CPURISCVState *env = &cpu->env;
+    struct kvm_one_reg reg;
+    int ret;
+    uint64_t val;
+    reg.id = RISCV_CONFIG_REG(env, satp_mode);
+    reg.addr = (uint64_t)&val;
+    ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
+    if (ret != 0) {
+        error_report("Unable to retrieve satp from host, error %d", ret);
+    }
+    env->satp = 1 << val;
+}
+
 static void kvm_riscv_init_machine_ids(RISCVCPU *cpu, KVMScratchCPU *kvmcpu)
 {
     CPURISCVState *env = &cpu->env;
@@ -1212,6 +1227,7 @@ static void riscv_init_kvm_registers(Object *cpu_obj)
     kvm_riscv_init_machine_ids(cpu, &kvmcpu);
     kvm_riscv_init_misa_ext_mask(cpu, &kvmcpu);
     kvm_riscv_init_multiext_cfg(cpu, &kvmcpu);
+    kvm_riscv_init_satp_mode(cpu, &kvmcpu);
 
     kvm_riscv_destroy_scratch_vcpu(&kvmcpu);
 }
@@ -1891,7 +1907,16 @@ static bool kvm_cpu_realize(CPUState *cs, Error **errp)
         }
     }
 
-   return true;
+    RISCVSATPMap *satp_mode = &cpu->cfg.satp_mode;
+    CPURISCVState *env = &cpu->env;
+
+    if (!satp_mode->init && env->satp) {
+        satp_mode->init = env->satp;
+        satp_mode->map = env->satp;
+        satp_mode->supported = env->satp;
+    }
+
+    return true;
 }
 
 void riscv_kvm_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
-- 
2.39.5



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

end of thread, other threads:[~2025-04-28 15:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-27 13:25 [PATCH] target/riscv: add satp mode for kvm host cpu Meng Zhuo
2025-04-28  7:00 ` Andrew Jones
2025-04-28  9:30   ` Radim Krčmář
2025-04-28 12:08     ` Andrew Jones
2025-04-28 13:37       ` Radim Krčmář
2025-04-28 15:36         ` Andrew Jones

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.