[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DCTJ3N8W4PCL.9XCHFVGS62SF@ventanamicro.com>
Date: Mon, 15 Sep 2025 18:52:56 +0200
From: Radim Krčmář <rkrcmar@...tanamicro.com>
To: "Jinyu Tang" <tjytimi@....com>, "Anup Patel" <anup@...infault.org>,
"Atish Patra" <atish.patra@...ux.dev>, "Andrew Jones"
<ajones@...tanamicro.com>, "Conor Dooley" <conor.dooley@...rochip.com>,
"Yong-Xuan Wang" <yongxuan.wang@...ive.com>, "Paul Walmsley"
<paul.walmsley@...ive.com>, "Nutty Liu" <nutty.liu@...mail.com>
Cc: <kvm@...r.kernel.org>, <kvm-riscv@...ts.infradead.org>,
<linux-riscv@...ts.infradead.org>, <linux-kernel@...r.kernel.org>,
"Tianshun Sun" <stsmail163@....com>
Subject: Re: [RFC PATCH] kvm/riscv: Add ctxsstatus and ctxhstatus for
migration
2025-09-15T23:27:31+08:00, Jinyu Tang <tjytimi@....com>:
> When migrating a VM which guest running in user mode
> (e.g., executing a while(1) application), the target
> VM fails to run because it loses the information of
> guest_context.hstatus and guest_context.sstatus. The
> VM uses the initialized values instead of the correct ones.
>
> This patch adds two new context registers (ctxsstatus and
> ctxhstatus) to the kvm_vcpu_csr structure and implements
> the necessary KVM get and set logic to preserve these values
> during migration.
>
> QEMU needs to be updated to support these new registers.
> See https://github.com/tjy-zhu/qemu
> for the corresponding QEMU changes.
>
> I'm not sure if adding these CSR registers is a right way. RISCV
> KVM doesn't have API to save these two context csrs now. I will
> submit the corresponding QEMU patch to the QEMU community if
> KVM has API to get and set them.
I don't think it is...
> Signed-off-by: Jinyu Tang <tjytimi@....com>
> Tested-by: Tianshun Sun <stsmail163@....com>
> ---
> diff --git a/arch/riscv/kvm/vcpu_onereg.c b/arch/riscv/kvm/vcpu_onereg.c
> @@ -489,6 +489,12 @@ static int kvm_riscv_vcpu_general_get_csr(struct kvm_vcpu *vcpu,
> if (reg_num >= sizeof(struct kvm_riscv_csr) / sizeof(unsigned long))
> return -ENOENT;
>
> + if (reg_num == KVM_REG_RISCV_CSR_REG(ctxsstatus))
> + csr->ctxsstatus = vcpu->arch.guest_context.sstatus;
Userspace can set guest privilege mode via KVM_REG_RISCV_CORE_REG(mode).
This does propagate to guest_context.sstatus, which is otherwise
internal KVM state, so we definitely shouldn't expose it directly.
> +
> + if (reg_num == KVM_REG_RISCV_CSR_REG(ctxhstatus))
> + csr->ctxhstatus = vcpu->arch.guest_context.hstatus;
Neither should userspace be able to directly set hstatus.
KVM should derive it from other userspace configuration.
What isn't correctly reflected in hstatus?
Thanks.
Powered by blists - more mailing lists