Skip to contentSkip to conversation

fw_cfg: unbreak migration compatibility for 2.4 and earlier machines

PATCH In review Laszlo Ersek 3 participants 3 messages Feb 18, 2016 – Feb 19, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fw_cfg: unbreak migration compatibility for 2.4 and earlier machines

When I reviewed Marc's fw_cfg DMA patches, I completely missed that the way we set dma_enabled would break migration.

Gerd explained the right way (see reference below): dma_enabled should be set to true by default, and only true->false transitions should be possible:

- when the user requests that with

-global fw_cfg_mem.dma_enabled=off

or

-global fw_cfg_io.dma_enabled=off

as appropriate for the platform,

- when HW_COMPAT_2_4 dictates it,

- when board code initializes fw_cfg without requesting DMA support.

Cc: Marc Marí <[email protected]>
Cc: Gerd Hoffmann <[email protected]>
Cc: Alexandre DERUMIER <[email protected]>
Cc: [email protected]
Ref: http://thread.gmane.org/gmane.comp.emulators.qemu/390272/focus=391042
Ref: https://bugs.launchpad.net/qemu/+bug/1536487

---

Notes:
Tested the following cases with gdb, using qemu-system-x86_64, setting a breakpoint on (s->dma_enabled) in fw_cfg_init_io_dma():

* no special params (DMA enabled)
* -global fw_cfg_io.dma_enabled=off (DMA disabled)
* -M pc-i440fx-2.4 (DMA disabled), similarly with 2.3 and Q35 too

Also tested the memory mapped case in practice, using qemu-system-aarch64 -M virt, -kernel / -initrd / -append, with guest UEFI:
* no special params (DMA enabled)
* -global fw_cfg_mem.dma_enabled=off (DMA disabled)

Not tested:
* actual migration
* when board code doesn't request DMA support

Testing feedback from people who use migration would be nice.

 include/hw/compat.h |  8 ++++++++
 hw/nvram/fw_cfg.c   | 20 ++++++++++++--------
 2 files changed, 20 insertions(+), 8 deletions(-)
include/hw/compat.h +8 -0
index 2ebe739fcb5c..a5dbbf8984b1 100644
@@ -42,6 +42,14 @@
         .driver   = "virtio-pci",\
         .property = "migrate-extra",\
         .value    = "off",\
+    },{\
+        .driver   = "fw_cfg_mem",\
+        .property = "dma_enabled",\
+        .value    = "off",\
+    },{\
+        .driver   = "fw_cfg_io",\
+        .property = "dma_enabled",\
+        .value    = "off",\
     },
 
 #define HW_COMPAT_2_3 \
hw/nvram/fw_cfg.c +12 -8
index 79c5742b3362..f3acb47bd4dc 100644
@@ -778,17 +778,19 @@ FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,
     DeviceState *dev;
     FWCfgState *s;
     uint32_t version = FW_CFG_VERSION;
-    bool dma_enabled = dma_iobase && dma_as;
+    bool dma_requested = dma_iobase && dma_as;
 
     dev = qdev_create(NULL, TYPE_FW_CFG_IO);
     qdev_prop_set_uint32(dev, "iobase", iobase);
     qdev_prop_set_uint32(dev, "dma_iobase", dma_iobase);
-    qdev_prop_set_bit(dev, "dma_enabled", dma_enabled);
+    if (!dma_requested) {
+        qdev_prop_set_bit(dev, "dma_enabled", false);
+    }
 
     fw_cfg_init1(dev);
     s = FW_CFG(dev);
 
-    if (dma_enabled) {
+    if (s->dma_enabled) {
         /* 64 bits for the address field */
         s->dma_as = dma_as;
         s->dma_addr = 0;
@@ -814,11 +816,13 @@ FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
     SysBusDevice *sbd;
     FWCfgState *s;
     uint32_t version = FW_CFG_VERSION;
-    bool dma_enabled = dma_addr && dma_as;
+    bool dma_requested = dma_addr && dma_as;
 
     dev = qdev_create(NULL, TYPE_FW_CFG_MEM);
     qdev_prop_set_uint32(dev, "data_width", data_width);
-    qdev_prop_set_bit(dev, "dma_enabled", dma_enabled);
+    if (!dma_requested) {
+        qdev_prop_set_bit(dev, "dma_enabled", false);
+    }
 
     fw_cfg_init1(dev);
 
@@ -828,7 +832,7 @@ FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
 
     s = FW_CFG(dev);
 
-    if (dma_enabled) {
+    if (s->dma_enabled) {
         s->dma_as = dma_as;
         s->dma_addr = 0;
         sysbus_mmio_map(sbd, 2, dma_addr);
@@ -873,7 +877,7 @@ static Property fw_cfg_io_properties[] = {
     DEFINE_PROP_UINT32("iobase", FWCfgIoState, iobase, -1),
     DEFINE_PROP_UINT32("dma_iobase", FWCfgIoState, dma_iobase, -1),
     DEFINE_PROP_BOOL("dma_enabled", FWCfgIoState, parent_obj.dma_enabled,
-                     false),
+                     true),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -913,7 +917,7 @@ static const TypeInfo fw_cfg_io_info = {
 static Property fw_cfg_mem_properties[] = {
     DEFINE_PROP_UINT32("data_width", FWCfgMemState, data_width, -1),
     DEFINE_PROP_BOOL("dma_enabled", FWCfgMemState, parent_obj.dma_enabled,
-                     false),
+                     true),
     DEFINE_PROP_END_OF_LIST(),
 };
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 2 lines · Laszlo Ersek

When I reviewed Marc's fw_cfg DMA patches, I completely missed that the way we set dma_enabled would break migration.

Patch looks fine to me ...

Quoted 5 lines

Not tested:
* actual migration
* when board code doesn't request DMA support

Testing feedback from people who use migration would be nice.

... but some actual migration testing would be great indeed.

thanks,
Gerd

#2 lore raw
Quoted 1 line
Quoted 1 line

... but some actual migration testing would be great indeed.

I have sent a patched version build to proxmox users for testing, I'm waiting for their results

----- Mail original -----
De: "kraxel" <[email protected]>
À: "Laszlo Ersek" <[email protected]>
Cc: "qemu-devel" <[email protected]>, "Marc Mar?" <[email protected]>, "aderumier" <[email protected]>, "qemu-stable" <[email protected]> Envoyé: Vendredi 19 Février 2016 08:09:54
Objet: Re: [PATCH] fw_cfg: unbreak migration compatibility for 2.4 and earlier machines

Quoted 2 lines · Laszlo Ersek

When I reviewed Marc's fw_cfg DMA patches, I completely missed that the way we set dma_enabled would break migration.

Patch looks fine to me ...

Quoted 5 lines

Not tested:
* actual migration
* when board code doesn't request DMA support

Testing feedback from people who use migration would be nice.

... but some actual migration testing would be great indeed.

thanks,
Gerd