@samitouri / QOSamiQemu / commits / 7df9aa5f6d

target/riscv/kvm: Synchronize privilege mode

The KVM core register synchronization currently omits the vCPU privilege mode. As a result, env.priv can be stale when the migration stream is saved and the destination can restore the vCPU in the wrong mode. Read and write the KVM core mode register together with the other core registers. The generic RISC-V CPU VMState already carries env.priv, so no migration format change is required. Signed-off-by: Xie Bo <xb@ultrarisc.com> Reviewed-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com> Message-ID: <20260808125157.1220511-2-xb@ultrarisc.com> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Xie Bo committed Aug 8, 2026 at 20:51 UTC 7df9aa5f6d600584c556776505253e849b3902ee
1 file changed +12
target/riscv/kvm/kvm-cpu.c
+12
@@ -603,6 +603,12 @@ static int kvm_riscv_get_regs_core(CPUState *cs)
603 }
604 env->pc = reg;
605
606 + ret = kvm_get_one_reg(cs, RISCV_CORE_REG(mode), &reg);
607 + if (ret) {
608 + return ret;
609 + }
610 + env->priv = reg;
611 +
612 for (i = 1; i < 32; i++) {
613 uint64_t id = KVM_RISCV_REG_ID_ULONG(KVM_REG_RISCV_CORE, i);
614 ret = kvm_get_one_reg(cs, id, &reg);
@@ -628,6 +634,12 @@ static int kvm_riscv_put_regs_core(CPUState *cs)
634 return ret;
635 }
636
637 + reg = env->priv;
638 + ret = kvm_set_one_reg(cs, RISCV_CORE_REG(mode), &reg);
639 + if (ret) {
640 + return ret;
641 + }
642 +
643 for (i = 1; i < 32; i++) {
644 uint64_t id = KVM_RISCV_REG_ID_ULONG(KVM_REG_RISCV_CORE, i);
645 reg = env->gpr[i];