thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-migration-Change-SaveStateEntry.instance_id-into-uin.patch

ddf19c
From 38a032829b6b8d523b4cee05f732031e66fc2e41 Mon Sep 17 00:00:00 2001
ddf19c
From: Peter Xu <peterx@redhat.com>
ddf19c
Date: Fri, 31 Jan 2020 17:12:56 +0000
ddf19c
Subject: [PATCH 14/15] migration: Change SaveStateEntry.instance_id into
ddf19c
 uint32_t
ddf19c
ddf19c
RH-Author: Peter Xu <peterx@redhat.com>
ddf19c
Message-id: <20200131171257.1066593-3-peterx@redhat.com>
ddf19c
Patchwork-id: 93629
ddf19c
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH 2/3] migration: Change SaveStateEntry.instance_id into uint32_t
ddf19c
Bugzilla: 1529231
ddf19c
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
ddf19c
RH-Acked-by: Juan Quintela <quintela@redhat.com>
ddf19c
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
ddf19c
ddf19c
It was always used as 32bit, so define it as used to be clear.
ddf19c
Instead of using -1 as the auto-gen magic value, we switch to
ddf19c
UINT32_MAX.  We also make sure that we don't auto-gen this value to
ddf19c
avoid overflowed instance IDs without being noticed.
ddf19c
ddf19c
Suggested-by: Juan Quintela <quintela@redhat.com>
ddf19c
Signed-off-by: Peter Xu <peterx@redhat.com>
ddf19c
Reviewed-by: Juan Quintela <quintela@redhat.com>
ddf19c
Signed-off-by: Juan Quintela <quintela@redhat.com>
ddf19c
(cherry picked from commit 93062e23619e057743757ee53bf7f8e07f7a3710)
ddf19c
Signed-off-by: Peter Xu <peterx@redhat.com>
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
ddf19c
Conflicts:
ddf19c
  include/migration/vmstate.h
ddf19c
  migration/savevm.c
ddf19c
  stubs/vmstate.c
ddf19c
    Due to missing 3cad405bab ("vmstate: replace DeviceState with
ddf19c
    VMStateIf", 2020-01-06)
ddf19c
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 hw/intc/apic_common.c        |  2 +-
ddf19c
 include/migration/register.h |  2 +-
ddf19c
 include/migration/vmstate.h  |  2 +-
ddf19c
 migration/savevm.c           | 18 ++++++++++--------
ddf19c
 stubs/vmstate.c              |  2 +-
ddf19c
 5 files changed, 14 insertions(+), 12 deletions(-)
ddf19c
ddf19c
diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
ddf19c
index f2c3a7f..54b8731 100644
ddf19c
--- a/hw/intc/apic_common.c
ddf19c
+++ b/hw/intc/apic_common.c
ddf19c
@@ -268,7 +268,7 @@ static void apic_common_realize(DeviceState *dev, Error **errp)
ddf19c
     APICCommonState *s = APIC_COMMON(dev);
ddf19c
     APICCommonClass *info;
ddf19c
     static DeviceState *vapic;
ddf19c
-    int instance_id = s->id;
ddf19c
+    uint32_t instance_id = s->id;
ddf19c
 
ddf19c
     info = APIC_COMMON_GET_CLASS(s);
ddf19c
     info->realize(dev, errp);
ddf19c
diff --git a/include/migration/register.h b/include/migration/register.h
ddf19c
index a13359a..f3ba10b 100644
ddf19c
--- a/include/migration/register.h
ddf19c
+++ b/include/migration/register.h
ddf19c
@@ -69,7 +69,7 @@ typedef struct SaveVMHandlers {
ddf19c
 } SaveVMHandlers;
ddf19c
 
ddf19c
 int register_savevm_live(const char *idstr,
ddf19c
-                         int instance_id,
ddf19c
+                         uint32_t instance_id,
ddf19c
                          int version_id,
ddf19c
                          const SaveVMHandlers *ops,
ddf19c
                          void *opaque);
ddf19c
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
ddf19c
index 883f1cf..296609c 100644
ddf19c
--- a/include/migration/vmstate.h
ddf19c
+++ b/include/migration/vmstate.h
ddf19c
@@ -1158,7 +1158,7 @@ bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque);
ddf19c
 #define  VMSTATE_INSTANCE_ID_ANY  -1
ddf19c
 
ddf19c
 /* Returns: 0 on success, -1 on failure */
ddf19c
-int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
ddf19c
+int vmstate_register_with_alias_id(DeviceState *dev, uint32_t instance_id,
ddf19c
                                    const VMStateDescription *vmsd,
ddf19c
                                    void *base, int alias_id,
ddf19c
                                    int required_for_version,
ddf19c
diff --git a/migration/savevm.c b/migration/savevm.c
ddf19c
index e2e8e0a..a80bb52 100644
ddf19c
--- a/migration/savevm.c
ddf19c
+++ b/migration/savevm.c
ddf19c
@@ -233,7 +233,7 @@ typedef struct CompatEntry {
ddf19c
 typedef struct SaveStateEntry {
ddf19c
     QTAILQ_ENTRY(SaveStateEntry) entry;
ddf19c
     char idstr[256];
ddf19c
-    int instance_id;
ddf19c
+    uint32_t instance_id;
ddf19c
     int alias_id;
ddf19c
     int version_id;
ddf19c
     /* version id read from the stream */
ddf19c
@@ -665,10 +665,10 @@ void dump_vmstate_json_to_file(FILE *out_file)
ddf19c
     fclose(out_file);
ddf19c
 }
ddf19c
 
ddf19c
-static int calculate_new_instance_id(const char *idstr)
ddf19c
+static uint32_t calculate_new_instance_id(const char *idstr)
ddf19c
 {
ddf19c
     SaveStateEntry *se;
ddf19c
-    int instance_id = 0;
ddf19c
+    uint32_t instance_id = 0;
ddf19c
 
ddf19c
     QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
ddf19c
         if (strcmp(idstr, se->idstr) == 0
ddf19c
@@ -676,6 +676,8 @@ static int calculate_new_instance_id(const char *idstr)
ddf19c
             instance_id = se->instance_id + 1;
ddf19c
         }
ddf19c
     }
ddf19c
+    /* Make sure we never loop over without being noticed */
ddf19c
+    assert(instance_id != VMSTATE_INSTANCE_ID_ANY);
ddf19c
     return instance_id;
ddf19c
 }
ddf19c
 
ddf19c
@@ -730,7 +732,7 @@ static void savevm_state_handler_insert(SaveStateEntry *nse)
ddf19c
    Meanwhile pass -1 as instance_id if you do not already have a clearly
ddf19c
    distinguishing id for all instances of your device class. */
ddf19c
 int register_savevm_live(const char *idstr,
ddf19c
-                         int instance_id,
ddf19c
+                         uint32_t instance_id,
ddf19c
                          int version_id,
ddf19c
                          const SaveVMHandlers *ops,
ddf19c
                          void *opaque)
ddf19c
@@ -784,7 +786,7 @@ void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque)
ddf19c
     }
ddf19c
 }
ddf19c
 
ddf19c
-int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
ddf19c
+int vmstate_register_with_alias_id(DeviceState *dev, uint32_t instance_id,
ddf19c
                                    const VMStateDescription *vmsd,
ddf19c
                                    void *opaque, int alias_id,
ddf19c
                                    int required_for_version,
ddf19c
@@ -1600,7 +1602,7 @@ int qemu_save_device_state(QEMUFile *f)
ddf19c
     return qemu_file_get_error(f);
ddf19c
 }
ddf19c
 
ddf19c
-static SaveStateEntry *find_se(const char *idstr, int instance_id)
ddf19c
+static SaveStateEntry *find_se(const char *idstr, uint32_t instance_id)
ddf19c
 {
ddf19c
     SaveStateEntry *se;
ddf19c
 
ddf19c
@@ -2267,7 +2269,7 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis)
ddf19c
     /* Find savevm section */
ddf19c
     se = find_se(idstr, instance_id);
ddf19c
     if (se == NULL) {
ddf19c
-        error_report("Unknown savevm section or instance '%s' %d. "
ddf19c
+        error_report("Unknown savevm section or instance '%s' %"PRIu32". "
ddf19c
                      "Make sure that your current VM setup matches your "
ddf19c
                      "saved VM setup, including any hotplugged devices",
ddf19c
                      idstr, instance_id);
ddf19c
@@ -2291,7 +2293,7 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis)
ddf19c
 
ddf19c
     ret = vmstate_load(f, se);
ddf19c
     if (ret < 0) {
ddf19c
-        error_report("error while loading state for instance 0x%x of"
ddf19c
+        error_report("error while loading state for instance 0x%"PRIx32" of"
ddf19c
                      " device '%s'", instance_id, idstr);
ddf19c
         return ret;
ddf19c
     }
ddf19c
diff --git a/stubs/vmstate.c b/stubs/vmstate.c
ddf19c
index e1e89b8..4ed5cc6 100644
ddf19c
--- a/stubs/vmstate.c
ddf19c
+++ b/stubs/vmstate.c
ddf19c
@@ -4,7 +4,7 @@
ddf19c
 const VMStateDescription vmstate_dummy = {};
ddf19c
 
ddf19c
 int vmstate_register_with_alias_id(DeviceState *dev,
ddf19c
-                                   int instance_id,
ddf19c
+                                   uint32_t instance_id,
ddf19c
                                    const VMStateDescription *vmsd,
ddf19c
                                    void *base, int alias_id,
ddf19c
                                    int required_for_version,
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c