Skip to contentSkip to conversation

Last minute ppc migration fixes

PATCH Superseded David Gibson 1 participant 7 messages Nov 21, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Last minute ppc migration fixes

Unfortunately, a bug already slipped into the qemu-2.7 release which breaks migration of the pseries-2.6 machine type from qemu v2.6.0 to qemu v2.7.0. That bug also breaks migration from v2.6.0 to current master. In addition there have been several more changes which have inadvertently broken migration from v2.7.0 to current master for both pseries-2.6 and pseries-2.7 machine types.

One of those was fixed - in a way - by 9b54ca0, however it was done in such a way as to break backwards migration from current master to v2.7.0. It turns out that supporting backwards migration is more important than I realized at the time.

So, this series contains several fixes for migration. Between them, they allow migration both forwards and backwards between qemu v2.6.0 and current master (and therefore, I hope, v2.8.0).

Unfortunately, because of the already released bug, there's no reasonable way to fix migration from current master back to v2.7.0 as well, and, obviously, no way at all to fix the existing breakage between v2.6.0 and v2.7.0. However, I'm also hoping to get patch 1/5 of this series applied to the 2.7 stable branch. If that happens, it should be possible to freely migrate between v2.6.0, v2.7.1 and current master / 2.8, which is about the best we can hope for.

I've done basic testing of these with all the combinations of source and destination being either v2.6.0, v2.7.0 + patch 1/5 and ppc-for-2.8 + this series, and with all the applicable machine types for each of those combinations. Each test was with just a basic default hardware setup, running a RHEL7.3 guest, no fancier combinations.

Dave, could you please sanity check my compatibility sheanningans and send an R-b (and an acked-by for patch 2/5, which isn't strictly ppc related).

Michael, if you could test this on any combinations that occur to you, that would be most helpful.

I'm hoping to get some reviews and squeeze this into v2.8.0, which will mean a pull request within a couple of days.

David Gibson (5): target-ppc: Fix CPU migration from qemu-2.6 <->
later versions migration: Add VMSTATE_UINTTL_TEST() target-ppc:
Allow eventual removal of old migration mistakes Revert "spapr: Fix migration of PCI host bridges from qemu-2.7" spapr: Fix 2.7<->2.8 migration of PCI host bridge

 hw/ppc/spapr.c              | 10 +++++++++
 hw/ppc/spapr_pci.c          | 35 +++++++++++++++++++++--------
 include/hw/pci-host/spapr.h |  6 +++++
 include/migration/cpu.h     |  4 ++++
 target-ppc/cpu.h            |  7 ++++++
 target-ppc/machine.c        | 55 +++++++++++++++++++++++++++++++++++++++++----
 target-ppc/translate_init.c |  6 +++++
 7 files changed, 110 insertions(+), 13 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/5 target-ppc: Fix CPU migration from qemu-2.6 <-> later versions

When migration for target-ppc was converted to vmstate, several VMSTATE_EQUAL() checks were foolishly included of things that really should be internal state. Specifically we verified equality of the insns_flags and insns_flags2 fields, which are used within TCG to determine which groups of instructions are available on this cpu model. Between qemu-2.6 and qemu-2.7 we made some changes to these classes which broke migration.

This path fixes migration both forwards and backwards. On migration from 2.6 to later versions we import the fields into teporary variables, which we then ignore. In migration backwards, we populate the temporary fields from the runtime fields, but mask out the bits which were added after qemu-2.6, allowing the VMSTATE_EQUAL in qemu-2.6 to accept the stream.

---
 target-ppc/cpu.h     |  6 ++++++
 target-ppc/machine.c | 41 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 43 insertions(+), 4 deletions(-)
target-ppc/cpu.h +6 -0
index 1c90adb..7798b2e 100644
@@ -1166,6 +1166,12 @@ struct PowerPCCPU {
     int cpu_dt_id;
     uint32_t max_compat;
     uint32_t cpu_version;
+
+    /* fields used only during migration for compatibility hacks */
+    target_ulong mig_msr_mask;
+    uint64_t mig_insns_flags;
+    uint64_t mig_insns_flags2;
+    uint32_t mig_nb_BATs;
 };
 
 static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env)
target-ppc/machine.c +37 -4

65 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/5 migration: Add VMSTATE_UINTTL_TEST()

In reply to David Gibson

include/migration/cpu.h defines VMSTATE_UINTTL() and several variants for migrating target_ulong fields. It's defined in terms of VMSTATE_UINT32() or VMSTATE_UINT64() as appropriate.

It doesn't, however, include a VMSTATE_UINTTL_TEST() variant, which I'm going to need shortly. So, add it.

---
 include/migration/cpu.h | 4 ++++
 1 file changed, 4 insertions(+)
include/migration/cpu.h +4 -0
index f3abbab..f3d5dfc 100644
@@ -18,6 +18,8 @@
     VMSTATE_UINT64_EQUAL_V(_f, _s, _v)
 #define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v)                        \
     VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)
+#define VMSTATE_UINTTL_TEST(_f, _s, _t)                               \
+    VMSTATE_UINT64_TEST(_f, _s, _t)
 #define vmstate_info_uinttl vmstate_info_uint64
 #else
 #define qemu_put_betl qemu_put_be32
@@ -35,6 +37,8 @@
     VMSTATE_UINT32_EQUAL_V(_f, _s, _v)
 #define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v)                        \
     VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)
+#define VMSTATE_UINTTL_TEST(_f, _s, _t)                               \
+    VMSTATE_UINT32_TEST(_f, _s, _t)
 #define vmstate_info_uinttl vmstate_info_uint32
 #endif
 
Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/5 target-ppc: Allow eventual removal of old migration mistakes

In reply to David Gibson

Until very recently, the vmstate for ppc cpus included some poorly thought out VMSTATE_EQUAL() components, that can easily break migration compatibility, and did so between qemu-2.6 and later versions. A hack was recently added which fixes this migration breakage, but it leaves the unhelpful cruft of these fields in the migration stream.

dThis patch adds a new cpu property allowing these fields to be removed from the stream entirely. This property is enabled by default for the pseries-2.8 machine type - which comes after the fix - and for all non-pseries machine types - which aren't mature enough to care about cross-version migration.

The migration hack remains in place for pseries-2.7 and earlier machine types, allowing backwards and forwards migration with the older machine types.

This restricts the migration compatibility cruft to older machine types, and at least opens the possibility of eventually deprecating and removing it entirely.

Signed-off: David Gibson <[email protected]>

---
 hw/ppc/spapr.c              |  5 +++++
 target-ppc/cpu.h            |  3 ++-
 target-ppc/machine.c        | 48 +++++++++++++++++++++++++++++----------------
 target-ppc/translate_init.c |  6 ++++++
 4 files changed, 44 insertions(+), 18 deletions(-)
hw/ppc/spapr.c +5 -0
index 54b88d3..775ad2e 100644
@@ -2767,6 +2767,11 @@ DEFINE_SPAPR_MACHINE(2_8, "2.8", true);
         .driver   = TYPE_SPAPR_PCI_HOST_BRIDGE,     \
         .property = "mem64_win_size",               \
         .value    = "0",                            \
+    },                                              \
+    {                                               \
+        .driver = TYPE_POWERPC_CPU,                 \
+        .property = "pre-2.8-migration",            \
+        .value    = "on",                           \
     },
 
 static void phb_placement_2_7(sPAPRMachineState *spapr, uint32_t index,
target-ppc/cpu.h +2 -1
index 7798b2e..2a50c43 100644
@@ -1167,7 +1167,8 @@ struct PowerPCCPU {
     uint32_t max_compat;
     uint32_t cpu_version;
 
-    /* fields used only during migration for compatibility hacks */
+    /* Fields related to migration compatibility hacks */
+    bool pre_2_8_migration;
     target_ulong mig_msr_mask;
     uint64_t mig_insns_flags;
     uint64_t mig_insns_flags2;
target-ppc/machine.c +31 -17

72 lines not on this page · raw message

target-ppc/translate_init.c +6 -0
index 208fa1e..626e031 100644
@@ -10520,6 +10520,11 @@ static gchar *ppc_gdb_arch_name(CPUState *cs)
 #endif
 }
 
+static Property ppc_cpu_properties[] = {
+    DEFINE_PROP_BOOL("pre-2.8-migration", PowerPCCPU, pre_2_8_migration, false),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void ppc_cpu_class_init(ObjectClass *oc, void *data)
 {
     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
@@ -10532,6 +10537,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)
     pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_always;
     dc->realize = ppc_cpu_realizefn;
     dc->unrealize = ppc_cpu_unrealizefn;
+    dc->props = ppc_cpu_properties;
 
     pcc->parent_reset = cc->reset;
     cc->reset = ppc_cpu_reset;
Signature · 1 line
2.7.4
#4 lore raw

PATCH 4/5 Revert "spapr: Fix migration of PCI host bridges from qemu-2.7"

In reply to David Gibson

This reverts commit 9b54ca0ba781012eeea4237b7c4832ba2ea81d89.

The commit above corrected a migration breakage between qemu-2.7 and qemu-2.8. However it did so by advancing the migration version for the PCI host bridge, which obviously breaks migration backwards to earlier qemu versions.

Although it's not totally essential, we'd like to maintain the possibility for backwards migration, so revert the change in preparation for a better fix.

---
 hw/ppc/spapr_pci.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
hw/ppc/spapr_pci.c +6 -12
index 661f7d8..e429c94 100644
@@ -1680,25 +1680,19 @@ static int spapr_pci_post_load(void *opaque, int version_id)
     return 0;
 }
 
-static bool version_before_3(void *opaque, int version_id)
-{
-    return version_id < 3;
-}
-
 static const VMStateDescription vmstate_spapr_pci = {
     .name = "spapr_pci",
-    .version_id = 3,
+    .version_id = 2,
     .minimum_version_id = 2,
     .pre_save = spapr_pci_pre_save,
     .post_load = spapr_pci_post_load,
     .fields = (VMStateField[]) {
         VMSTATE_UINT64_EQUAL(buid, sPAPRPHBState),
-        VMSTATE_UNUSED_TEST(version_before_3,
-                            sizeof(uint32_t) /* dma_liobn[0] */
-                            + sizeof(uint64_t) /* mem_win_addr */
-                            + sizeof(uint64_t) /* mem_win_size */
-                            + sizeof(uint64_t) /* io_win_addr */
-                            + sizeof(uint64_t) /* io_win_size */),
+        VMSTATE_UINT32_EQUAL(dma_liobn[0], sPAPRPHBState),
+        VMSTATE_UINT64_EQUAL(mem_win_addr, sPAPRPHBState),
+        VMSTATE_UINT64_EQUAL(mem_win_size, sPAPRPHBState),
+        VMSTATE_UINT64_EQUAL(io_win_addr, sPAPRPHBState),
+        VMSTATE_UINT64_EQUAL(io_win_size, sPAPRPHBState),
         VMSTATE_STRUCT_ARRAY(lsi_table, sPAPRPHBState, PCI_NUM_PINS, 0,
                              vmstate_spapr_pci_lsi, struct spapr_pci_lsi),
         VMSTATE_INT32(msi_devs_num, sPAPRPHBState),
Signature · 1 line
2.7.4
#5 lore raw

PATCH 5/5 spapr: Fix 2.7<->2.8 migration of PCI host bridge

In reply to David Gibson

daa2369 "spapr_pci: Add a 64-bit MMIO window" subtly broke migration from qemu-2.7 to the current version. It split the device's MMIO window into two pieces for 32-bit and 64-bit MMIO.

The patch included backwards compatibility code to convert the old property into the new format. However, the property value was also transferred in the migration stream and compared with a (probably unwise) VMSTATE_EQUAL. So, the "raw" value from 2.7 is compared to the new style converted value from (pre-)2.8 giving a mismatch and migration failure.

Along with the actual field that caused the breakage, there are several other ill-advised VMSTATE_EQUAL()s. To fix forwards migration, we read the values in the stream into scratch variables and ignore them, instead of comparing for equality. To fix backwards migration, we populate those scratch variables in pre_save() with adjusted values to match the old behaviour.

To permit the eventual possibility of removing this cruft from the stream, we only include these compatibility fields if a new 'pre-2.8-migration' property is set. We clear it on the pseries-2.8 machine type, which obviously can't be migrated backwards, but set it on earlier machine type versions.

---
 hw/ppc/spapr.c              |  5 +++++
 hw/ppc/spapr_pci.c          | 33 ++++++++++++++++++++++++++++-----
 include/hw/pci-host/spapr.h |  6 ++++++
 3 files changed, 39 insertions(+), 5 deletions(-)
hw/ppc/spapr.c +5 -0
index 775ad2e..c3269c7 100644
@@ -2772,6 +2772,11 @@ DEFINE_SPAPR_MACHINE(2_8, "2.8", true);
         .driver = TYPE_POWERPC_CPU,                 \
         .property = "pre-2.8-migration",            \
         .value    = "on",                           \
+    },                                              \
+    {                                               \
+        .driver = TYPE_SPAPR_PCI_HOST_BRIDGE,       \
+        .property = "pre-2.8-migration",            \
+        .value    = "on",                           \
     },
 
 static void phb_placement_2_7(sPAPRMachineState *spapr, uint32_t index,
hw/ppc/spapr_pci.c +28 -5
index e429c94..c62c1cb 100644
@@ -1590,6 +1590,8 @@ static Property spapr_phb_properties[] = {
     DEFINE_PROP_UINT64("pgsz", sPAPRPHBState, page_size_mask,
                        (1ULL << 12) | (1ULL << 16)),
     DEFINE_PROP_UINT32("numa_node", sPAPRPHBState, numa_node, -1),
+    DEFINE_PROP_BOOL("pre-2.8-migration", sPAPRPHBState,
+                     pre_2_8_migration, false),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -1636,6 +1638,20 @@ static void spapr_pci_pre_save(void *opaque)
         sphb->msi_devs[i].key = *(uint32_t *) key;
         sphb->msi_devs[i].value = *(spapr_pci_msi *) value;
     }
+
+    if (sphb->pre_2_8_migration) {
+        sphb->mig_liobn = sphb->dma_liobn[0];
+        sphb->mig_mem_win_addr = sphb->mem_win_addr;
+        sphb->mig_mem_win_size = sphb->mem_win_size;
+        sphb->mig_io_win_addr = sphb->io_win_addr;
+        sphb->mig_io_win_size = sphb->io_win_size;
+
+        if ((sphb->mem64_win_size != 0)
+            && (sphb->mem64_win_addr
+                == (sphb->mem_win_addr + sphb->mem_win_size))) {
+            sphb->mig_mem_win_size += sphb->mem64_win_size;
+        }
+    }
 }
 
 /*
@@ -1680,6 +1696,13 @@ static int spapr_pci_post_load(void *opaque, int version_id)
     return 0;
 }
 
+static bool pre_2_8_migration(void *opaque, int version_id)
+{
+    sPAPRPHBState *sphb = opaque;
+
+    return sphb->pre_2_8_migration;
+}
+
 static const VMStateDescription vmstate_spapr_pci = {
     .name = "spapr_pci",
     .version_id = 2,
@@ -1688,11 +1711,11 @@ static const VMStateDescription vmstate_spapr_pci = {
     .post_load = spapr_pci_post_load,
     .fields = (VMStateField[]) {
         VMSTATE_UINT64_EQUAL(buid, sPAPRPHBState),
-        VMSTATE_UINT32_EQUAL(dma_liobn[0], sPAPRPHBState),
-        VMSTATE_UINT64_EQUAL(mem_win_addr, sPAPRPHBState),
-        VMSTATE_UINT64_EQUAL(mem_win_size, sPAPRPHBState),
-        VMSTATE_UINT64_EQUAL(io_win_addr, sPAPRPHBState),
-        VMSTATE_UINT64_EQUAL(io_win_size, sPAPRPHBState),
+        VMSTATE_UINT32_TEST(mig_liobn, sPAPRPHBState, pre_2_8_migration),
+        VMSTATE_UINT64_TEST(mig_mem_win_addr, sPAPRPHBState, pre_2_8_migration),
+        VMSTATE_UINT64_TEST(mig_mem_win_size, sPAPRPHBState, pre_2_8_migration),
+        VMSTATE_UINT64_TEST(mig_io_win_addr, sPAPRPHBState, pre_2_8_migration),
+        VMSTATE_UINT64_TEST(mig_io_win_size, sPAPRPHBState, pre_2_8_migration),
         VMSTATE_STRUCT_ARRAY(lsi_table, sPAPRPHBState, PCI_NUM_PINS, 0,
                              vmstate_spapr_pci_lsi, struct spapr_pci_lsi),
         VMSTATE_INT32(msi_devs_num, sPAPRPHBState),
include/hw/pci-host/spapr.h +6 -0
index b92c1b5..092294e 100644
@@ -79,6 +79,12 @@ struct sPAPRPHBState {
     uint64_t dma64_win_addr;
 
     uint32_t numa_node;
+
+    /* Fields for migration compatibility hacks */
+    bool pre_2_8_migration;
+    uint32_t mig_liobn;
+    hwaddr mig_mem_win_addr, mig_mem_win_size;
+    hwaddr mig_io_win_addr, mig_io_win_size;
 };
 
 #define SPAPR_PCI_MEM_WIN_BUS_OFFSET 0x80000000ULL
Signature · 1 line
2.7.4
#6 lore raw
In reply to David Gibson
Quoted 35 lines · David Gibson

Unfortunately, a bug already slipped into the qemu-2.7 release which breaks migration of the pseries-2.6 machine type from qemu v2.6.0 to qemu v2.7.0. That bug also breaks migration from v2.6.0 to current master. In addition there have been several more changes which have inadvertently broken migration from v2.7.0 to current master for both pseries-2.6 and pseries-2.7 machine types.

One of those was fixed - in a way - by 9b54ca0, however it was done in such a way as to break backwards migration from current master to v2.7.0. It turns out that supporting backwards migration is more important than I realized at the time.

So, this series contains several fixes for migration. Between them, they allow migration both forwards and backwards between qemu v2.6.0 and current master (and therefore, I hope, v2.8.0).

Unfortunately, because of the already released bug, there's no reasonable way to fix migration from current master back to v2.7.0 as well, and, obviously, no way at all to fix the existing breakage between v2.6.0 and v2.7.0. However, I'm also hoping to get patch 1/5 of this series applied to the 2.7 stable branch. If that happens, it should be possible to freely migrate between v2.6.0, v2.7.1 and current master / 2.8, which is about the best we can hope for.

I've done basic testing of these with all the combinations of source and destination being either v2.6.0, v2.7.0 + patch 1/5 and ppc-for-2.8 + this series, and with all the applicable machine types for each of those combinations. Each test was with just a basic default hardware setup, running a RHEL7.3 guest, no fancier combinations.

Dave, could you please sanity check my compatibility sheanningans and send an R-b (and an acked-by for patch 2/5, which isn't strictly ppc related).

Quoted 5 lines

Michael, if you could test this on any combinations that occur to you, that would be most helpful.

I'm hoping to get some reviews and squeeze this into v2.8.0, which will mean a pull request within a couple of days.

Bother, just realised I left a chunk of debug code in there. Will resend momentarily.

Quoted 16 lines

David Gibson (5): target-ppc: Fix CPU migration from qemu-2.6 <->
later versions migration: Add VMSTATE_UINTTL_TEST() target-ppc:
Allow eventual removal of old migration mistakes Revert "spapr: Fix migration of PCI host bridges from qemu-2.7" spapr: Fix 2.7<->2.8 migration of PCI host bridge

 hw/ppc/spapr.c              | 10 +++++++++
 hw/ppc/spapr_pci.c          | 35 +++++++++++++++++++++--------
 include/hw/pci-host/spapr.h |  6 +++++
 include/migration/cpu.h     |  4 ++++
 target-ppc/cpu.h            |  7 ++++++
 target-ppc/machine.c        | 55 +++++++++++++++++++++++++++++++++++++++++----
 target-ppc/translate_init.c |  6 +++++
 7 files changed, 110 insertions(+), 13 deletions(-)
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson