On Tue, 3 Mar 2026 at 14:39, Eric Auger <[email protected]> wrote:
>
> This removes the need for explicitly allocating cpreg_vmstate arrays.
> On post save we simply point to cpreg arrays and set the length
> accordingly.
>
> Remove VMSTATE_VARRAY_INT32 for cpreg_vmstate_array_len as now
> the array is dynamically allocated.
>
> Also add a trace point on post_load to trace potential mismatch
> between the number of incoming cpregs versus current ones.
>
> Signed-off-by: Eric Auger <[email protected]>
> Suggested-by: Peter Maydell <[email protected]>
>
> ---
>
> v1 -> v2:
> - also modifies the allocation of cpureg_vmstate_* in
>   target/arm/whpx/whpx-all.c
> - added Peter's suggested comment on cpu_pre_save()
> - free the the vmstate arrays on post_load
> - add assert on pre_load
> - fix comment aboy length check in machine.c



> diff --git a/target/arm/machine.c b/target/arm/machine.c
> index bbaae344492..aa617dd64db 100644
> --- a/target/arm/machine.c
> +++ b/target/arm/machine.c
> @@ -1,5 +1,6 @@
>  #include "qemu/osdep.h"
>  #include "cpu.h"
> +#include "trace.h"
>  #include "qemu/error-report.h"
>  #include "system/kvm.h"
>  #include "system/tcg.h"
> @@ -984,11 +985,14 @@ static int cpu_pre_save(void *opaque)
>          }
>      }
>
> +    /*
> +     * On outbound migration, send the data in our cpreg_{values,indexes}
> +     * arrays. The migration code will not allocate anything, but just
> +     * reads the data pointed to by the VMSTATE_VARRAY_INT32_ALLOC() fields.
> +     */
> +    cpu->cpreg_vmstate_indexes = cpu->cpreg_indexes;
> +    cpu->cpreg_vmstate_values = cpu->cpreg_values;
>      cpu->cpreg_vmstate_array_len = cpu->cpreg_array_len;
> -    memcpy(cpu->cpreg_vmstate_indexes, cpu->cpreg_indexes,
> -           cpu->cpreg_array_len * sizeof(uint64_t));
> -    memcpy(cpu->cpreg_vmstate_values, cpu->cpreg_values,
> -           cpu->cpreg_array_len * sizeof(uint64_t));
>
>      return 0;
>  }
> @@ -1034,6 +1038,9 @@ static int cpu_pre_load(void *opaque)
>          pmu_op_start(env);
>      }
>
> +    g_assert(!cpu->cpreg_vmstate_indexes);
> +    g_assert(!cpu->cpreg_vmstate_values);
> +
>      return 0;
>  }

You missed clearing the pointers in post_save -- I think these
asserts will fire if you do a vmsave and then follow it with
a vmload in the same VM.

Otherwise
Reviewed-by: Peter Maydell <[email protected]>

thanks
-- PMM

Reply via email to