On Wed, 18 Sept 2024 at 07:06, Andrew Jones <ajo...@ventanamicro.com> wrote: > > On Tue, Sep 17, 2024 at 06:45:21PM GMT, Heinrich Schuchardt wrote: > ... > > When thinking about the migration of virtual machines shouldn't QEMU be in > > control of the initial state of vcpus instead of KVM? > > > > Thinking about this more, I'm inclined to agree. Initial state and reset > state should be traits of the VMM (potentially influenced by the user) > rather than KVM.
Mmm. IIRC the way this works on Arm at least is that at some point post-reset and before running the VM we do a QEMU->kernel state sync, which means that whatever the kernel does with the CPU state doesn't matter, only what QEMU's idea of reset is. Looking at the source I think the way this happens is that kvm_cpu_synchronize_post_reset() arranges to do a kvm_arch_put_registers(). (For Arm we have to do some fiddling around to make sure our CPU state is in the right place for that put_registers to DTRT, which is what kvm_arm_reset_vcpu() is doing, but that's a consequence of the way we chose to handle migration and in particular migration of system registers rather than something necessarily every architecture wants to be doing.) This also works for reset of the vCPU on a guest-reboot. We don't tell KVM to reset the vCPU, we just set up the vCPU state on the QEMU side and then do a QEMU->kernel state sync of it. -- PMM