@@ -670,6 +670,7 @@ void cpu_exec_init(CPUState *cpu, Error **errp)
{
CPUClass *cc = CPU_GET_CLASS(cpu);
Error *local_err = NULL;
+ int migration_id;
cpu->as = NULL;
cpu->num_ases = 0;
@@ -708,11 +709,13 @@ void cpu_exec_init(CPUState *cpu, Error **errp)
(void) cc;
cpu_list_unlock();
#else
+ migration_id = cc->use_migration_id && cpu->migration_id != -1 ?
+ cpu->migration_id : cpu->cpu_index;
if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
- vmstate_register(NULL, cpu->cpu_index, &vmstate_cpu_common, cpu);
+ vmstate_register(NULL, migration_id, &vmstate_cpu_common, cpu);
}
if (cc->vmsd != NULL) {
- vmstate_register(NULL, cpu->cpu_index, cc->vmsd, cpu);
+ vmstate_register(NULL, migration_id, cc->vmsd, cpu);
}
#endif
}
@@ -115,6 +115,8 @@ struct TranslationBlock;
* @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
* note to a 32-bit VM coredump.
* @vmsd: State description for migration.
+ * @use_migration_id: Set to use @migration_id if has been set instead of
+ * cpu_index during vmstate registration.
* @gdb_num_core_regs: Number of core registers accessible to GDB.
* @gdb_core_xml_file: File name for core registers GDB XML description.
* @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop
@@ -177,6 +179,8 @@ typedef struct CPUClass {
void *opaque);
const struct VMStateDescription *vmsd;
+ bool use_migration_id;
+
int gdb_num_core_regs;
const char *gdb_core_xml_file;
gchar * (*gdb_arch_name)(CPUState *cpu);
@@ -273,6 +277,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.
+ * @migration_id: Use as instance_id argument in cpu vmstate_register calls
+ * by default -1, which forces fallback to using legacy cpu_index even if
+ * use_migration_id is true
*
* State of one CPU core or thread.
*/
@@ -360,6 +367,7 @@ 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 migration_id;
};
QTAILQ_HEAD(CPUTailQ, CPUState);
@@ -357,11 +357,24 @@ static int64_t cpu_common_get_arch_id(CPUState *cpu)
return cpu->cpu_index;
}
+static void cpu_common_set_use_migration_id(Object *obj, bool value,
+ Error **err)
+{
+ CPUClass *cc = CPU_GET_CLASS(obj);
+ cc->use_migration_id = value;
+}
+
static void cpu_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
CPUClass *k = CPU_CLASS(klass);
+ k->use_migration_id = true;
+ object_class_property_add_bool(klass, "use-migration-id",
+ NULL,
+ cpu_common_set_use_migration_id,
+ &error_abort);
+
k->class_by_name = cpu_common_class_by_name;
k->parse_features = cpu_common_parse_features;
k->reset = cpu_common_reset;