On Thu, Oct 01, 2026 at 10:52:48AM +0000, Aastha Rawat wrote:
> x86 specific migration handlers currently live in common MSHV code. Move
> these handlers into x86 backend and add a generic architecture migration
> initialization hook. ARM MSHV live migration support is not added yet,
> this will allow ARM to add an empty initialization hook.
> 
> Signed-off-by: Aastha Rawat <[email protected]>
> ---
>  accel/mshv/mshv-all.c       | 35 ++++-------------------------------
>  include/system/mshv_int.h   |  1 +
>  target/i386/mshv/mshv-all.c | 34 ++++++++++++++++++++++++++++++++++
>  3 files changed, 39 insertions(+), 31 deletions(-)
> 
> diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c
> index 860f511fcba..efe19a39140 100644
> --- a/accel/mshv/mshv-all.c
> +++ b/accel/mshv/mshv-all.c
> @@ -60,30 +60,6 @@ static int init_mshv(int *mshv_fd)
>      return 0;
>  }
>  
> -static int mshv_load_cleanup(void *opaque)
> -{
> -    CPUState *cpu;
> -    int ret;
> -
> -    ret = mshv_arch_set_partition_msrs(first_cpu);
> -    if (ret < 0) {
> -        error_report("Failed to set partition MSRs: %s", strerror(-ret));
> -        return -1;
> -    }
> -
> -    CPU_FOREACH(cpu) {
> -        ret = mshv_arch_set_mp_state(cpu);
> -        if (ret < 0) {
> -            error_report("Failed to set mp state for vCPU %d: %s",
> -                         cpu->cpu_index, strerror(-ret));
> -            return -1;
> -        }
> -    }
> -
> -    return 0;
> -}
> -
> -
>  static int get_host_partition_property(int mshv_fd, uint32_t property_code,
>                                         uint64_t *value)
>  {
> @@ -519,10 +495,6 @@ static int mshv_init_vcpu(CPUState *cpu)
>      return 0;
>  }
>  
> -static SaveVMHandlers savevm_mshv = {
> -    .load_cleanup = mshv_load_cleanup,
> -};
> -
>  static int mshv_init(AccelState *as, MachineState *ms)
>  {
>      MshvState *s;
> @@ -574,9 +546,10 @@ static int mshv_init(AccelState *as, MachineState *ms)
>                                    0, "mshv-memory");
>      memory_listener_register(&mshv_io_listener, &address_space_io);
>  
> -    register_savevm_live("mshv", 0, 1, &savevm_mshv, s);
> -
> -    mshv_clock_init();
> +    ret = mshv_arch_migration_init(s);
> +    if (ret < 0) {

if this is fallible now, do we need to unwind the previous steps?

> +        return ret;
> +    }
>  
>      return 0;
>  }
> diff --git a/include/system/mshv_int.h b/include/system/mshv_int.h
> index 0e68365c63f..31d2f4381c7 100644
> --- a/include/system/mshv_int.h
> +++ b/include/system/mshv_int.h
> @@ -109,6 +109,7 @@ void mshv_arch_disable_partition_proc_features(
>  int mshv_arch_accel_init(AccelState *as, MachineState *ms, int mshv_fd);
>  int mshv_arch_post_init_vm(int vm_fd);
>  void mshv_setup_hvcall_args(AccelCPUState *state);
> +int mshv_arch_migration_init(MshvState *s);
>  int mshv_get_vp_state(int cpu_fd, struct mshv_get_set_vp_state *state);
>  int mshv_set_vp_state(int cpu_fd, const struct mshv_get_set_vp_state *state);
>  typedef struct mshv_root_hvcall mshv_root_hvcall;
> diff --git a/target/i386/mshv/mshv-all.c b/target/i386/mshv/mshv-all.c
> index f0b43aa86f1..968fe2a4494 100644
> --- a/target/i386/mshv/mshv-all.c
> +++ b/target/i386/mshv/mshv-all.c
> @@ -78,3 +78,37 @@ int mshv_arch_post_init_vm(int vm_fd)
>  
>      return ret;
>  }
> +
> +static int mshv_load_cleanup(void *opaque)
> +{
> +    CPUState *cpu;
> +    int ret;
> +
> +    ret = mshv_arch_set_partition_msrs(first_cpu);
> +    if (ret < 0) {
> +        error_report("Failed to set partition MSRs: %s", strerror(-ret));
> +        return -1;
> +    }
> +
> +    CPU_FOREACH(cpu) {
> +        ret = mshv_arch_set_mp_state(cpu);
> +        if (ret < 0) {
> +            error_report("Failed to set mp state for vCPU %d: %s",
> +                         cpu->cpu_index, strerror(-ret));
> +            return -1;
> +        }
> +    }
> +
> +    return 0;
> +}
> +
> +static SaveVMHandlers savevm_mshv = {
> +    .load_cleanup = mshv_load_cleanup,
> +};
> +
> +int mshv_arch_migration_init(MshvState *s)

mshv_clock_init() also covers pause/resume, so maybe
"mshv_arch_vm_state_init()" would be a better name?

> +{
> +    register_savevm_live("mshv", 0, 1, &savevm_mshv, s);
> +    mshv_clock_init();
> +    return 0;
> +}
> 
> -- 
> 2.45.4

Reply via email to