Add CPUState::stable_cpu_id and use that as instance_id in vmstate_register() call.
Introduce has-stable_cpu_id property that allows target machines to optionally switch to using stable_cpu_id instead of cpu_index. This will help allow successful migration in cases where holes are introduced in cpu_index range after CPU hot removals. Suggested-by: Igor Mammedov <imamm...@redhat.com> Signed-off-by: Bharata B Rao <bhar...@linux.vnet.ibm.com> --- exec.c | 6 ++++-- include/qom/cpu.h | 5 +++++ qom/cpu.c | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index fb73910..3b36fe5 100644 --- a/exec.c +++ b/exec.c @@ -619,12 +619,14 @@ static void cpu_release_index(CPUState *cpu) void cpu_vmstate_register(CPUState *cpu) { CPUClass *cc = CPU_GET_CLASS(cpu); + int instance_id = cpu->has_stable_cpu_id ? cpu->stable_cpu_id : + cpu->cpu_index; if (qdev_get_vmsd(DEVICE(cpu)) == NULL) { - vmstate_register(NULL, cpu->cpu_index, &vmstate_cpu_common, cpu); + vmstate_register(NULL, instance_id, &vmstate_cpu_common, cpu); } if (cc->vmsd != NULL) { - vmstate_register(NULL, cpu->cpu_index, cc->vmsd, cpu); + vmstate_register(NULL, instance_id, cc->vmsd, cpu); } } diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 331386f..527c021 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -273,6 +273,9 @@ struct qemu_work_item { * @kvm_fd: vCPU file descriptor for KVM. * @work_mutex: Lock to prevent multiple access to queued_work_*. * @queued_work_first: First asynchronous work pending. + * @stable_cpu_id: Use as instance_id argument in cpu vmstate_register calls + * @has_stable_cpu_id: Set to enforce the use of @stable_cpu_id + * over cpu_index during vmstate registration. * * State of one CPU core or thread. */ @@ -360,6 +363,8 @@ struct CPUState { (absolute value) offset as small as possible. This reduces code size, especially for hosts without large memory offsets. */ uint32_t tcg_exit_req; + int stable_cpu_id; + bool has_stable_cpu_id; }; QTAILQ_HEAD(CPUTailQ, CPUState); diff --git a/qom/cpu.c b/qom/cpu.c index 1095ea1..bae1bf7 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -363,6 +363,11 @@ static int64_t cpu_common_get_arch_id(CPUState *cpu) return cpu->cpu_index; } +static Property cpu_common_properties[] = { + DEFINE_PROP_BOOL("has-stable-cpu-id", CPUState, has_stable_cpu_id, false), + DEFINE_PROP_END_OF_LIST() +}; + static void cpu_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); @@ -394,6 +399,7 @@ static void cpu_class_init(ObjectClass *klass, void *data) * IRQs, adding reset handlers, halting non-first CPUs, ... */ dc->cannot_instantiate_with_device_add_yet = true; + dc->props = cpu_common_properties; } static const TypeInfo cpu_type_info = { -- 2.7.4