On Wed, Oct 22, 2025 at 9:12 PM Daniel Henrique Barboza <[email protected]> wrote: > > This patch was originally made by Gitlab user Bo Gan (@ganboing) 4 > months ago in the context of issue [1]. I asked the author to send a > patch to the mailing list ~3 months ago and got no reply. I'm sending > the patch myself because we already missed 10.1 without this fix. > > I'll also just post verbatim Bo Gan comment in the commit msg: > > "In RISCV Linux with KVM enabled, gdbstub is broken. The > get_physical_address isn't able to page-walk correctly and resolve the > physical page. This is due to that the vcpu is being treated as starting > in M mode even if KVM enabled. However, with KVM, the vcpu is actually > started in S mode. The mmu_idx will give 3 (M), instead of 1 (S), > resulting in Guest PA == VA (wrong)!" > > Set env->priv to PRV_S in kvm_riscv_reset_regs_csr() since the VCPU is > always started in S-mode for KVM. > > [1] https://gitlab.com/qemu-project/qemu/-/issues/2991 > > Cc: [email protected] > Closes: https://gitlab.com/qemu-project/qemu/-/issues/2991 > Originally-by: Bo Gan (@ganboing in Gitlab) > Signed-off-by: Daniel Henrique Barboza <[email protected]>
Reviewed-by: Alistair Francis <[email protected]> Alistair > --- > target/riscv/kvm/kvm-cpu.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c > index 0dd0d59d41..000e44b2b7 100644 > --- a/target/riscv/kvm/kvm-cpu.c > +++ b/target/riscv/kvm/kvm-cpu.c > @@ -705,6 +705,7 @@ static void kvm_riscv_reset_regs_csr(CPURISCVState *env) > env->satp = 0; > env->scounteren = 0; > env->senvcfg = 0; > + env->priv = PRV_S; > } > > static int kvm_riscv_get_regs_fp(CPUState *cs) > -- > 2.51.0 > >
