[PATCH v11 0/2] target/riscv: Fix riscv64 KVM migration

Xie Bo posted 2 patches 1 month, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260808125157.1220511-1-xb@ultrarisc.com
Maintainers: Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Chao Liu <chao.liu@processmission.com>
target/riscv/cpu.h           |  4 +++
target/riscv/kvm/kvm-cpu.c   | 62 ++++++++++++++++++++++++++----------
target/riscv/kvm/kvm_riscv.h |  2 +-
target/riscv/machine.c       | 49 ++++++++++++++++++++++++++--
4 files changed, 98 insertions(+), 19 deletions(-)
[PATCH v11 0/2] target/riscv: Fix riscv64 KVM migration
Posted by Xie Bo 1 month, 2 weeks ago
This series revives v9, which was applied to riscv-to-apply.next but did
not reach QEMU master.

RISC-V KVM migration currently loses two pieces of vCPU state: the
privilege mode core register and KVM MP state. The latter leaves secondary
vCPUs in their reset STOPPED state on the destination.

Synchronize the privilege mode through the existing generic CPU VMState,
and carry MP state in a capability-gated KVM-only subsection. The subsection
keeps KVM state out of TCG migration streams. Bump the generic RISC-V CPU
VMState version and minimum version to 12 as required by the new pre_load
hook and subsection.

Changes from v10:
- Bump the RISC-V CPU VMState version_id and minimum_version_id to 12.
- Add Daniel's Reviewed-by tags.

Testing on a native riscv64 host with Linux 6.6.20 and GCC 13.3.0:
- KVM build: riscv64-softmmu, --enable-kvm.
- Non-KVM build: riscv64-softmmu, --disable-kvm.
- Four-vCPU KVM migration on unmodified master: all vCPUs failed to run
  after migration and the guest reported RCU stalls.
- The same migration with this series: CPU0 through CPU3 all ran after
  migration.
- Four user-mode busy workers, one pinned to each vCPU, all made forward
  progress across migration to exercise privilege-mode restoration.

Xie Bo (2):
  target/riscv/kvm: Synchronize privilege mode
  target/riscv/kvm: Preserve MP state across migration

 target/riscv/cpu.h           |  4 +++
 target/riscv/kvm/kvm-cpu.c   | 62 ++++++++++++++++++++++++++----------
 target/riscv/kvm/kvm_riscv.h |  2 +-
 target/riscv/machine.c       | 49 ++++++++++++++++++++++++++--
 4 files changed, 98 insertions(+), 19 deletions(-)

-- 
2.17.1
Re: [PATCH v11 0/2] target/riscv: Fix riscv64 KVM migration
Posted by Xie Bo 1 month ago
Hi,

Now that this series is in master, could it also be considered for
stable-11.1?

Both commits are needed together:

7df9aa5 target/riscv/kvm: Synchronize privilege mode
ddac7cf target/riscv/kvm: Preserve MP state across migration

They fix RISC-V KVM live migration with multiple vCPUs. Without the
second fix, secondary vCPUs can remain stopped after migration; without
the first, the vCPU privilege mode may be restored incorrectly.

I tested the series on native riscv64 hardware with KVM enabled,
including multi-vCPU live migration, a 24-hour post-migration run, and
multiple repeated migrations across two guests. I did not observe guest
hangs or soft lockups.

Thanks,
Xie Bo
Re: [PATCH v11 0/2] target/riscv: Fix riscv64 KVM migration
Posted by Michael Tokarev 1 month ago
On 8/25/26 10:03, Xie Bo wrote:
> Hi,
> 
> Now that this series is in master, could it also be considered for
> stable-11.1?
> 
> Both commits are needed together:
> 
> 7df9aa5 target/riscv/kvm: Synchronize privilege mode
> ddac7cf target/riscv/kvm: Preserve MP state across migration

Heh.  I remember that big riscv pull request.  I processed it before
11.1.1, so changes from it are included in 11.1.1.

However, these two changes didn't have neither Fixes: nor Resolves:
tags, -- this is the criteria for riscv fixes for stable - so I
skipped them :)

Picked these two up now, but it will be about a month before the
next stable release.

Yes, as Alistar noted, it is best to include Cc: qemu-stable@ when
submitting a patch which should be picked up for the stable series.
I understand sometimes it is not obvious, so yes, Cc'ing qemu-stable@
after the fact works too.

Thank you!

/mjt
Re: [PATCH v11 0/2] target/riscv: Fix riscv64 KVM migration
Posted by Alistair Francis 3 weeks, 3 days ago
On Fri, 2026-08-28 at 10:04 +0300, Michael Tokarev wrote:
> On 8/25/26 10:03, Xie Bo wrote:
> > Hi,
> > 
> > Now that this series is in master, could it also be considered for
> > stable-11.1?
> > 
> > Both commits are needed together:
> > 
> > 7df9aa5 target/riscv/kvm: Synchronize privilege mode
> > ddac7cf target/riscv/kvm: Preserve MP state across migration
> 
> Heh.  I remember that big riscv pull request.  I processed it before
> 11.1.1, so changes from it are included in 11.1.1.
> 
> However, these two changes didn't have neither Fixes: nor Resolves:
> tags, -- this is the criteria for riscv fixes for stable - so I
> skipped them :)
> 
> Picked these two up now, but it will be about a month before the
> next stable release.

Thanks!

> 
> Yes, as Alistar noted, it is best to include Cc: qemu-stable@ when
> submitting a patch which should be picked up for the stable series.
> I understand sometimes it is not obvious, so yes, Cc'ing qemu-stable@
> after the fact works too.

Yes please. I do skim the PRs to check for patches to include, but
these ones didn't originally jump out

Alistair

> 
> Thank you!
> 
> /mjt
Re: [PATCH v11 0/2] target/riscv: Fix riscv64 KVM migration
Posted by Alistair Francis 1 month ago
On Tue, 2026-08-25 at 15:03 +0800, Xie Bo wrote:
> Hi,
> 
> Now that this series is in master, could it also be considered for
> stable-11.1?
> 

When sending patches that should be backported please include

"""
Cc: qemu-stable@nongnu.org
"""

in the commit message. Then it would have been picked up

Alistair

> Both commits are needed together:
> 
> 7df9aa5 target/riscv/kvm: Synchronize privilege mode
> ddac7cf target/riscv/kvm: Preserve MP state across migration
> 
> They fix RISC-V KVM live migration with multiple vCPUs. Without the
> second fix, secondary vCPUs can remain stopped after migration;
> without
> the first, the vCPU privilege mode may be restored incorrectly.
> 
> I tested the series on native riscv64 hardware with KVM enabled,
> including multi-vCPU live migration, a 24-hour post-migration run,
> and
> multiple repeated migrations across two guests. I did not observe
> guest
> hangs or soft lockups.
> 
> Thanks,
> Xie Bo
> 
Re: [PATCH v11 0/2] target/riscv: Fix riscv64 KVM migration
Posted by Alistair 1 month, 2 weeks ago
On Sat, 2026-08-08 at 20:51 +0800, Xie Bo wrote:
> This series revives v9, which was applied to riscv-to-apply.next but
> did
> not reach QEMU master.
> 
> RISC-V KVM migration currently loses two pieces of vCPU state: the
> privilege mode core register and KVM MP state. The latter leaves
> secondary
> vCPUs in their reset STOPPED state on the destination.
> 
> Synchronize the privilege mode through the existing generic CPU
> VMState,
> and carry MP state in a capability-gated KVM-only subsection. The
> subsection
> keeps KVM state out of TCG migration streams. Bump the generic RISC-V
> CPU
> VMState version and minimum version to 12 as required by the new
> pre_load
> hook and subsection.
> 
> Changes from v10:
> - Bump the RISC-V CPU VMState version_id and minimum_version_id to
> 12.
> - Add Daniel's Reviewed-by tags.
> 
> Testing on a native riscv64 host with Linux 6.6.20 and GCC 13.3.0:
> - KVM build: riscv64-softmmu, --enable-kvm.
> - Non-KVM build: riscv64-softmmu, --disable-kvm.
> - Four-vCPU KVM migration on unmodified master: all vCPUs failed to
> run
>   after migration and the guest reported RCU stalls.
> - The same migration with this series: CPU0 through CPU3 all ran
> after
>   migration.
> - Four user-mode busy workers, one pinned to each vCPU, all made
> forward
>   progress across migration to exercise privilege-mode restoration.

Thanks!

Applied to riscv-to-apply.next

Alistair

> 
> Xie Bo (2):
>   target/riscv/kvm: Synchronize privilege mode
>   target/riscv/kvm: Preserve MP state across migration
> 
>  target/riscv/cpu.h           |  4 +++
>  target/riscv/kvm/kvm-cpu.c   | 62 ++++++++++++++++++++++++++--------
> --
>  target/riscv/kvm/kvm_riscv.h |  2 +-
>  target/riscv/machine.c       | 49 ++++++++++++++++++++++++++--
>  4 files changed, 98 insertions(+), 19 deletions(-)