qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3] virtio-pci: fix migration for pci bus master
@ 2014-10-20  6:58 Michael S. Tsirkin
  2014-10-20 14:15 ` Greg Kurz
  2014-10-20 16:08 ` Alexander Graf
  0 siblings, 2 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2014-10-20  6:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-ppc, Alexander Graf, Anthony Liguori

Current support for bus master (clearing OK bit) together with the need to
support guests which do not enable PCI bus mastering, leads to extra state in
VIRTIO_PCI_FLAG_BUS_MASTER_BUG bit, which isn't robust in case of cross-version
migration for the case when guests use the device before setting DRIVER_OK.

Rip out this code, and replace it:
-   Modern QEMU doesn't need VIRTIO_PCI_FLAG_BUS_MASTER_BUG
    so just drop it for latest machine type.
-   For compat machine types, set PCI_COMMAND if DRIVER_OK
    is set.

As this is needed for 2.1 for both pc and ppc, move PC_COMPAT macros from pc.h
to a new common header.

Reviewed-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
Tested-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---

Alexander, could you pls ack me merging this?
Thanks!


changes from v2:
    drop default = -1 from ppc - was a typo, reported by Greg

 hw/virtio/virtio-pci.h |  5 +++++
 include/hw/compat.h    | 16 ++++++++++++++++
 include/hw/i386/pc.h   | 10 ++--------
 hw/i386/pc_piix.c      |  2 +-
 hw/i386/pc_q35.c       |  2 +-
 hw/ppc/spapr.c         |  7 +++++++
 hw/virtio/virtio-pci.c | 29 +++++++++++------------------
 7 files changed, 43 insertions(+), 28 deletions(-)
 create mode 100644 include/hw/compat.h

diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index 1cea157..8873b6d 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -53,6 +53,11 @@ typedef struct VirtioBusClass VirtioPCIBusClass;
 #define VIRTIO_PCI_BUS_CLASS(klass) \
         OBJECT_CLASS_CHECK(VirtioPCIBusClass, klass, TYPE_VIRTIO_PCI_BUS)
 
+/* Need to activate work-arounds for buggy guests at vmstate load. */
+#define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT  0
+#define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
+    (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
+
 /* Performance improves when virtqueue kick processing is decoupled from the
  * vcpu thread using ioeventfd for some devices. */
 #define VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT 1
diff --git a/include/hw/compat.h b/include/hw/compat.h
new file mode 100644
index 0000000..47f6ff5
--- /dev/null
+++ b/include/hw/compat.h
@@ -0,0 +1,16 @@
+#ifndef HW_COMPAT_H
+#define HW_COMPAT_H
+
+#define HW_COMPAT_2_1 \
+        {\
+            .driver   = "intel-hda",\
+            .property = "old_msi_addr",\
+            .value    = "on",\
+        },\
+        {\
+            .driver   = "virtio-pci",\
+            .property = "virtio-pci-bus-master-bug-migration",\
+            .value    = "on",\
+        }
+
+#endif /* HW_COMPAT_H */
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index bae023a..82ad046 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -14,6 +14,7 @@
 #include "sysemu/sysemu.h"
 #include "hw/pci/pci.h"
 #include "hw/boards.h"
+#include "hw/compat.h"
 
 #define HPET_INTCAP "hpet-intcap"
 
@@ -307,15 +308,8 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);
 int e820_get_num_entries(void);
 bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
 
-#define PC_COMPAT_2_1 \
-        {\
-            .driver   = "intel-hda",\
-            .property = "old_msi_addr",\
-            .value    = "on",\
-        }
-
 #define PC_COMPAT_2_0 \
-        PC_COMPAT_2_1, \
+        HW_COMPAT_2_1, \
         {\
             .driver   = "virtio-scsi-pci",\
             .property = "any_layout",\
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 553afdd..a1634ab 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -502,7 +502,7 @@ static QEMUMachine pc_i440fx_machine_v2_1 = {
     .name = "pc-i440fx-2.1",
     .init = pc_init_pci,
     .compat_props = (GlobalProperty[]) {
-        PC_COMPAT_2_1,
+        HW_COMPAT_2_1,
         { /* end of list */ }
     },
 };
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index a199043..f330f7a 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -365,7 +365,7 @@ static QEMUMachine pc_q35_machine_v2_1 = {
     .name = "pc-q35-2.1",
     .init = pc_q35_init,
     .compat_props = (GlobalProperty[]) {
-        PC_COMPAT_2_1,
+        HW_COMPAT_2_1,
         { /* end of list */ }
     },
 };
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 2becc9f..623f626 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -57,6 +57,8 @@
 #include "trace.h"
 #include "hw/nmi.h"
 
+#include "hw/compat.h"
+
 #include <libfdt.h>
 
 /* SLOF memory layout:
@@ -1689,10 +1691,15 @@ static const TypeInfo spapr_machine_info = {
 static void spapr_machine_2_1_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
+    static GlobalProperty compat_props[] = {
+        HW_COMPAT_2_1,
+        { /* end of list */ }
+    };
 
     mc->name = "pseries-2.1";
     mc->desc = "pSeries Logical Partition (PAPR compliant) v2.1";
     mc->is_default = 0;
+    mc->compat_props = compat_props;
 }
 
 static const TypeInfo spapr_machine_2_1_info = {
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index a827cd4..a499a3c 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -86,9 +86,6 @@
  * 12 is historical, and due to x86 page size. */
 #define VIRTIO_PCI_QUEUE_ADDR_SHIFT    12
 
-/* Flags track per-device state like workarounds for quirks in older guests. */
-#define VIRTIO_PCI_FLAG_BUS_MASTER_BUG  (1 << 0)
-
 static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
                                VirtIOPCIProxy *dev);
 
@@ -323,14 +320,6 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
                                      proxy->pci_dev.config[PCI_COMMAND] |
                                      PCI_COMMAND_MASTER, 1);
         }
-
-        /* Linux before 2.6.34 sets the device as OK without enabling
-           the PCI device bus master bit. In this case we need to disable
-           some safety checks. */
-        if ((val & VIRTIO_CONFIG_S_DRIVER_OK) &&
-            !(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
-            proxy->flags |= VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
-        }
         break;
     case VIRTIO_MSI_CONFIG_VECTOR:
         msix_vector_unuse(&proxy->pci_dev, vdev->config_vector);
@@ -483,8 +472,7 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
     pci_default_write_config(pci_dev, address, val, len);
 
     if (range_covers_byte(address, len, PCI_COMMAND) &&
-        !(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER) &&
-        !(proxy->flags & VIRTIO_PCI_FLAG_BUS_MASTER_BUG)) {
+        !(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
         virtio_pci_stop_ioeventfd(proxy);
         virtio_set_status(vdev, vdev->status & ~VIRTIO_CONFIG_S_DRIVER_OK);
     }
@@ -895,11 +883,15 @@ static void virtio_pci_vmstate_change(DeviceState *d, bool running)
     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
 
     if (running) {
-        /* Try to find out if the guest has bus master disabled, but is
-           in ready state. Then we have a buggy guest OS. */
-        if ((vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) &&
+        /* Old QEMU versions did not set bus master enable on status write.
+         * Detect DRIVER set and enable it.
+         */
+        if ((proxy->flags & VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION) &&
+            (vdev->status & VIRTIO_CONFIG_S_DRIVER) &&
             !(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
-            proxy->flags |= VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
+            pci_default_write_config(&proxy->pci_dev, PCI_COMMAND,
+                                     proxy->pci_dev.config[PCI_COMMAND] |
+                                     PCI_COMMAND_MASTER, 1);
         }
         virtio_pci_start_ioeventfd(proxy);
     } else {
@@ -1040,10 +1032,11 @@ static void virtio_pci_reset(DeviceState *qdev)
     virtio_pci_stop_ioeventfd(proxy);
     virtio_bus_reset(bus);
     msix_unuse_all_vectors(&proxy->pci_dev);
-    proxy->flags &= ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
 }
 
 static Property virtio_pci_properties[] = {
+    DEFINE_PROP_BIT("virtio-pci-bus-master-bug-migration", VirtIOPCIProxy, flags,
+                    VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT, false),
     DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
     DEFINE_PROP_END_OF_LIST(),
 };
-- 
MST

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH v3] virtio-pci: fix migration for pci bus master
  2014-10-20  6:58 [Qemu-devel] [PATCH v3] virtio-pci: fix migration for pci bus master Michael S. Tsirkin
@ 2014-10-20 14:15 ` Greg Kurz
  2014-10-20 16:08 ` Alexander Graf
  1 sibling, 0 replies; 9+ messages in thread
From: Greg Kurz @ 2014-10-20 14:15 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: qemu-ppc, qemu-devel, Anthony Liguori, Alexander Graf

On Mon, 20 Oct 2014 09:58:50 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> Current support for bus master (clearing OK bit) together with the need to
> support guests which do not enable PCI bus mastering, leads to extra state in
> VIRTIO_PCI_FLAG_BUS_MASTER_BUG bit, which isn't robust in case of cross-version
> migration for the case when guests use the device before setting DRIVER_OK.
> 
> Rip out this code, and replace it:
> -   Modern QEMU doesn't need VIRTIO_PCI_FLAG_BUS_MASTER_BUG
>     so just drop it for latest machine type.
> -   For compat machine types, set PCI_COMMAND if DRIVER_OK
>     is set.
> 
> As this is needed for 2.1 for both pc and ppc, move PC_COMPAT macros from pc.h
> to a new common header.
> 
> Reviewed-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> Tested-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> 
> Alexander, could you pls ack me merging this?
> Thanks!
> 

This patch conflicts with the following commit in Alex's ppc-next branch:

commit 6dd65a940532eaac42a302c30964b0d42967e187
Author: David Gibson <david@gibson.dropbear.id.au>
Date:   Mon Sep 8 15:30:31 2014 +1000

    spapr: Cleanup machine naming conventions, and prepare for 2.2 release

Easy to fix though.

Alex,

I can send the rebased version if you want.

Cheers.

--
Greg

> 
> changes from v2:
>     drop default = -1 from ppc - was a typo, reported by Greg
> 
>  hw/virtio/virtio-pci.h |  5 +++++
>  include/hw/compat.h    | 16 ++++++++++++++++
>  include/hw/i386/pc.h   | 10 ++--------
>  hw/i386/pc_piix.c      |  2 +-
>  hw/i386/pc_q35.c       |  2 +-
>  hw/ppc/spapr.c         |  7 +++++++
>  hw/virtio/virtio-pci.c | 29 +++++++++++------------------
>  7 files changed, 43 insertions(+), 28 deletions(-)
>  create mode 100644 include/hw/compat.h
> 
> diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
> index 1cea157..8873b6d 100644
> --- a/hw/virtio/virtio-pci.h
> +++ b/hw/virtio/virtio-pci.h
> @@ -53,6 +53,11 @@ typedef struct VirtioBusClass VirtioPCIBusClass;
>  #define VIRTIO_PCI_BUS_CLASS(klass) \
>          OBJECT_CLASS_CHECK(VirtioPCIBusClass, klass, TYPE_VIRTIO_PCI_BUS)
> 
> +/* Need to activate work-arounds for buggy guests at vmstate load. */
> +#define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT  0
> +#define VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION \
> +    (1 << VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT)
> +
>  /* Performance improves when virtqueue kick processing is decoupled from the
>   * vcpu thread using ioeventfd for some devices. */
>  #define VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT 1
> diff --git a/include/hw/compat.h b/include/hw/compat.h
> new file mode 100644
> index 0000000..47f6ff5
> --- /dev/null
> +++ b/include/hw/compat.h
> @@ -0,0 +1,16 @@
> +#ifndef HW_COMPAT_H
> +#define HW_COMPAT_H
> +
> +#define HW_COMPAT_2_1 \
> +        {\
> +            .driver   = "intel-hda",\
> +            .property = "old_msi_addr",\
> +            .value    = "on",\
> +        },\
> +        {\
> +            .driver   = "virtio-pci",\
> +            .property = "virtio-pci-bus-master-bug-migration",\
> +            .value    = "on",\
> +        }
> +
> +#endif /* HW_COMPAT_H */
> diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
> index bae023a..82ad046 100644
> --- a/include/hw/i386/pc.h
> +++ b/include/hw/i386/pc.h
> @@ -14,6 +14,7 @@
>  #include "sysemu/sysemu.h"
>  #include "hw/pci/pci.h"
>  #include "hw/boards.h"
> +#include "hw/compat.h"
> 
>  #define HPET_INTCAP "hpet-intcap"
> 
> @@ -307,15 +308,8 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);
>  int e820_get_num_entries(void);
>  bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
> 
> -#define PC_COMPAT_2_1 \
> -        {\
> -            .driver   = "intel-hda",\
> -            .property = "old_msi_addr",\
> -            .value    = "on",\
> -        }
> -
>  #define PC_COMPAT_2_0 \
> -        PC_COMPAT_2_1, \
> +        HW_COMPAT_2_1, \
>          {\
>              .driver   = "virtio-scsi-pci",\
>              .property = "any_layout",\
> diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> index 553afdd..a1634ab 100644
> --- a/hw/i386/pc_piix.c
> +++ b/hw/i386/pc_piix.c
> @@ -502,7 +502,7 @@ static QEMUMachine pc_i440fx_machine_v2_1 = {
>      .name = "pc-i440fx-2.1",
>      .init = pc_init_pci,
>      .compat_props = (GlobalProperty[]) {
> -        PC_COMPAT_2_1,
> +        HW_COMPAT_2_1,
>          { /* end of list */ }
>      },
>  };
> diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
> index a199043..f330f7a 100644
> --- a/hw/i386/pc_q35.c
> +++ b/hw/i386/pc_q35.c
> @@ -365,7 +365,7 @@ static QEMUMachine pc_q35_machine_v2_1 = {
>      .name = "pc-q35-2.1",
>      .init = pc_q35_init,
>      .compat_props = (GlobalProperty[]) {
> -        PC_COMPAT_2_1,
> +        HW_COMPAT_2_1,
>          { /* end of list */ }
>      },
>  };
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 2becc9f..623f626 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -57,6 +57,8 @@
>  #include "trace.h"
>  #include "hw/nmi.h"
> 
> +#include "hw/compat.h"
> +
>  #include <libfdt.h>
> 
>  /* SLOF memory layout:
> @@ -1689,10 +1691,15 @@ static const TypeInfo spapr_machine_info = {
>  static void spapr_machine_2_1_class_init(ObjectClass *oc, void *data)
>  {
>      MachineClass *mc = MACHINE_CLASS(oc);
> +    static GlobalProperty compat_props[] = {
> +        HW_COMPAT_2_1,
> +        { /* end of list */ }1
> +    };
> 
>      mc->name = "pseries-2.1";
>      mc->desc = "pSeries Logical Partition (PAPR compliant) v2.1";
>      mc->is_default = 0;
> +    mc->compat_props = compat_props;
>  }
> 
>  static const TypeInfo spapr_machine_2_1_info = {
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index a827cd4..a499a3c 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -86,9 +86,6 @@
>   * 12 is historical, and due to x86 page size. */
>  #define VIRTIO_PCI_QUEUE_ADDR_SHIFT    12
> 
> -/* Flags track per-device state like workarounds for quirks in older guests. */
> -#define VIRTIO_PCI_FLAG_BUS_MASTER_BUG  (1 << 0)
> -
>  static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
>                                 VirtIOPCIProxy *dev);
> 
> @@ -323,14 +320,6 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
>                                       proxy->pci_dev.config[PCI_COMMAND] |
>                                       PCI_COMMAND_MASTER, 1);
>          }
> -
> -        /* Linux before 2.6.34 sets the device as OK without enabling
> -           the PCI device bus master bit. In this case we need to disable
> -           some safety checks. */
> -        if ((val & VIRTIO_CONFIG_S_DRIVER_OK) &&
> -            !(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
> -            proxy->flags |= VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
> -        }
>          break;
>      case VIRTIO_MSI_CONFIG_VECTOR:
>          msix_vector_unuse(&proxy->pci_dev, vdev->config_vector);
> @@ -483,8 +472,7 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
>      pci_default_write_config(pci_dev, address, val, len);
> 
>      if (range_covers_byte(address, len, PCI_COMMAND) &&
> -        !(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER) &&1
> -        !(proxy->flags & VIRTIO_PCI_FLAG_BUS_MASTER_BUG)) {
> +        !(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
>          virtio_pci_stop_ioeventfd(proxy);
>          virtio_set_status(vdev, vdev->status & ~VIRTIO_CONFIG_S_DRIVER_OK);
>      }
> @@ -895,11 +883,15 @@ static void virtio_pci_vmstate_change(DeviceState *d, bool running)
>      VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
> 
>      if (running) {
> -        /* Try to find out if the guest has bus master disabled, but is
> -           in ready state. Then we have a buggy guest OS. */
> -        if ((vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) &&
> +        /* Old QEMU versions did not set bus master enable on status write.
> +         * Detect DRIVER set and enable it.
> +         */
> +        if ((proxy->flags & VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION) &&
> +            (vdev->status & VIRTIO_CONFIG_S_DRIVER) &&
>              !(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
> -            proxy->flags |= VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
> +            pci_default_write_config(&proxy->pci_dev, PCI_COMMAND,
> +                                     proxy->pci_dev.config[PCI_COMMAND] |
> +                                     PCI_COMMAND_MASTER, 1);
>          }
>          virtio_pci_start_ioeventfd(proxy);
>      } else {
> @@ -1040,10 +1032,11 @@ static void virtio_pci_reset(DeviceState *qdev)
>      virtio_pci_stop_ioeventfd(proxy);
>      virtio_bus_reset(bus);
>      msix_unuse_all_vectors(&proxy->pci_dev);
> -    proxy->flags &= ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
>  }
> 
>  static Property virtio_pci_properties[] = {
> +    DEFINE_PROP_BIT("virtio-pci-bus-master-bug-migration", VirtIOPCIProxy, flags,
> +                    VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT, false),
>      DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
>      DEFINE_PROP_END_OF_LIST(),
>  };

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH v3] virtio-pci: fix migration for pci bus master
  2014-10-20  6:58 [Qemu-devel] [PATCH v3] virtio-pci: fix migration for pci bus master Michael S. Tsirkin
  2014-10-20 14:15 ` Greg Kurz
@ 2014-10-20 16:08 ` Alexander Graf
  2014-10-20 16:40   ` Greg Kurz
  2014-10-21 10:16   ` Michael S. Tsirkin
  1 sibling, 2 replies; 9+ messages in thread
From: Alexander Graf @ 2014-10-20 16:08 UTC (permalink / raw)
  To: Michael S. Tsirkin, qemu-devel; +Cc: qemu-ppc, Anthony Liguori



On 20.10.14 08:58, Michael S. Tsirkin wrote:
> Current support for bus master (clearing OK bit) together with the need to
> support guests which do not enable PCI bus mastering, leads to extra state in
> VIRTIO_PCI_FLAG_BUS_MASTER_BUG bit, which isn't robust in case of cross-version
> migration for the case when guests use the device before setting DRIVER_OK.
> 
> Rip out this code, and replace it:
> -   Modern QEMU doesn't need VIRTIO_PCI_FLAG_BUS_MASTER_BUG
>     so just drop it for latest machine type.
> -   For compat machine types, set PCI_COMMAND if DRIVER_OK
>     is set.
> 
> As this is needed for 2.1 for both pc and ppc, move PC_COMPAT macros from pc.h
> to a new common header.
> 
> Reviewed-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> Tested-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> 
> Alexander, could you pls ack me merging this?
> Thanks!

Have you tried whether this works with old kernel versions? We
introduced the broken flag for very specific old kernel versions that
got their flags wrong IIRC.


Alex

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH v3] virtio-pci: fix migration for pci bus master
  2014-10-20 16:08 ` Alexander Graf
@ 2014-10-20 16:40   ` Greg Kurz
  2014-10-21 10:16   ` Michael S. Tsirkin
  1 sibling, 0 replies; 9+ messages in thread
From: Greg Kurz @ 2014-10-20 16:40 UTC (permalink / raw)
  To: Alexander Graf; +Cc: qemu-ppc, qemu-devel, Anthony Liguori, Michael S. Tsirkin

On Mon, 20 Oct 2014 18:08:56 +0200
Alexander Graf <agraf@suse.de> wrote:

> 
> 
> On 20.10.14 08:58, Michael S. Tsirkin wrote:
> > Current support for bus master (clearing OK bit) together with the need to
> > support guests which do not enable PCI bus mastering, leads to extra state in
> > VIRTIO_PCI_FLAG_BUS_MASTER_BUG bit, which isn't robust in case of cross-version
> > migration for the case when guests use the device before setting DRIVER_OK.
> > 
> > Rip out this code, and replace it:
> > -   Modern QEMU doesn't need VIRTIO_PCI_FLAG_BUS_MASTER_BUG
> >     so just drop it for latest machine type.
> > -   For compat machine types, set PCI_COMMAND if DRIVER_OK
> >     is set.
> > 
> > As this is needed for 2.1 for both pc and ppc, move PC_COMPAT macros from pc.h
> > to a new common header.
> > 
> > Reviewed-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> > Tested-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> > 
> > Alexander, could you pls ack me merging this?
> > Thanks!
> 
> Have you tried whether this works with old kernel versions? We
> introduced the broken flag for very specific old kernel versions that
> got their flags wrong IIRC.
> 

This is a follow-up to the following commit:

commit e43c0b2ea5574efb0bedebf6a7d05916eefeba52
Author: Michael S. Tsirkin <mst@redhat.com>
Date:   Thu Sep 11 18:45:33 2014 +0200

    virtio-pci: enable bus master for old guests

The goal was to support *again* buggy guests that do DMA without
enabling bus master, since QEMU now uses the bus master address
space for delivering MSI/MSI-x messages.

We were missing some bits to support cross version migration.
Thanks to Michael's patch, I could migrate a buggy RHEL 6.5 guest
from QEMU v2.1 to QEMU master.

> 
> Alex
> 

Cheers.

--
Greg

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH v3] virtio-pci: fix migration for pci bus master
  2014-10-20 16:08 ` Alexander Graf
  2014-10-20 16:40   ` Greg Kurz
@ 2014-10-21 10:16   ` Michael S. Tsirkin
  2014-10-21 11:35     ` Alexander Graf
  1 sibling, 1 reply; 9+ messages in thread
From: Michael S. Tsirkin @ 2014-10-21 10:16 UTC (permalink / raw)
  To: Alexander Graf; +Cc: qemu-ppc, qemu-devel, Anthony Liguori

On Mon, Oct 20, 2014 at 06:08:56PM +0200, Alexander Graf wrote:
> 
> 
> On 20.10.14 08:58, Michael S. Tsirkin wrote:
> > Current support for bus master (clearing OK bit) together with the need to
> > support guests which do not enable PCI bus mastering, leads to extra state in
> > VIRTIO_PCI_FLAG_BUS_MASTER_BUG bit, which isn't robust in case of cross-version
> > migration for the case when guests use the device before setting DRIVER_OK.
> > 
> > Rip out this code, and replace it:
> > -   Modern QEMU doesn't need VIRTIO_PCI_FLAG_BUS_MASTER_BUG
> >     so just drop it for latest machine type.
> > -   For compat machine types, set PCI_COMMAND if DRIVER_OK
> >     is set.
> > 
> > As this is needed for 2.1 for both pc and ppc, move PC_COMPAT macros from pc.h
> > to a new common header.
> > 
> > Reviewed-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> > Tested-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> > 
> > Alexander, could you pls ack me merging this?
> > Thanks!
> 
> Have you tried whether this works with old kernel versions? We
> introduced the broken flag for very specific old kernel versions that
> got their flags wrong IIRC.
> 
> 
> Alex

Yes. The point is that since 2.1 the broken flag isn't effective
anymore: when bus master is off, PCI blocks outgoing transactions and
setting internal flags isn't going to help.

Instead, we detect a buggy guest and immediately enable bus master for
it - no need for a separate flag.



-- 
MST

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH v3] virtio-pci: fix migration for pci bus master
  2014-10-21 10:16   ` Michael S. Tsirkin
@ 2014-10-21 11:35     ` Alexander Graf
  2014-10-21 12:10       ` Michael S. Tsirkin
  0 siblings, 1 reply; 9+ messages in thread
From: Alexander Graf @ 2014-10-21 11:35 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: qemu-ppc, qemu-devel, Anthony Liguori



On 21.10.14 12:16, Michael S. Tsirkin wrote:
> On Mon, Oct 20, 2014 at 06:08:56PM +0200, Alexander Graf wrote:
>>
>>
>> On 20.10.14 08:58, Michael S. Tsirkin wrote:
>>> Current support for bus master (clearing OK bit) together with the need to
>>> support guests which do not enable PCI bus mastering, leads to extra state in
>>> VIRTIO_PCI_FLAG_BUS_MASTER_BUG bit, which isn't robust in case of cross-version
>>> migration for the case when guests use the device before setting DRIVER_OK.
>>>
>>> Rip out this code, and replace it:
>>> -   Modern QEMU doesn't need VIRTIO_PCI_FLAG_BUS_MASTER_BUG
>>>     so just drop it for latest machine type.
>>> -   For compat machine types, set PCI_COMMAND if DRIVER_OK
>>>     is set.
>>>
>>> As this is needed for 2.1 for both pc and ppc, move PC_COMPAT macros from pc.h
>>> to a new common header.
>>>
>>> Reviewed-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
>>> Tested-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
>>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>>> ---
>>>
>>> Alexander, could you pls ack me merging this?
>>> Thanks!
>>
>> Have you tried whether this works with old kernel versions? We
>> introduced the broken flag for very specific old kernel versions that
>> got their flags wrong IIRC.
>>
>>
>> Alex
> 
> Yes. The point is that since 2.1 the broken flag isn't effective
> anymore: when bus master is off, PCI blocks outgoing transactions and
> setting internal flags isn't going to help.
> 
> Instead, we detect a buggy guest and immediately enable bus master for
> it - no need for a separate flag.

Ok, works for me then.


Alex

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH v3] virtio-pci: fix migration for pci bus master
  2014-10-21 11:35     ` Alexander Graf
@ 2014-10-21 12:10       ` Michael S. Tsirkin
  2014-10-21 12:12         ` Alexander Graf
  2014-10-21 12:36         ` Greg Kurz
  0 siblings, 2 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2014-10-21 12:10 UTC (permalink / raw)
  To: Alexander Graf; +Cc: qemu-ppc, qemu-devel, Anthony Liguori

On Tue, Oct 21, 2014 at 01:35:39PM +0200, Alexander Graf wrote:
> 
> 
> On 21.10.14 12:16, Michael S. Tsirkin wrote:
> > On Mon, Oct 20, 2014 at 06:08:56PM +0200, Alexander Graf wrote:
> >>
> >>
> >> On 20.10.14 08:58, Michael S. Tsirkin wrote:
> >>> Current support for bus master (clearing OK bit) together with the need to
> >>> support guests which do not enable PCI bus mastering, leads to extra state in
> >>> VIRTIO_PCI_FLAG_BUS_MASTER_BUG bit, which isn't robust in case of cross-version
> >>> migration for the case when guests use the device before setting DRIVER_OK.
> >>>
> >>> Rip out this code, and replace it:
> >>> -   Modern QEMU doesn't need VIRTIO_PCI_FLAG_BUS_MASTER_BUG
> >>>     so just drop it for latest machine type.
> >>> -   For compat machine types, set PCI_COMMAND if DRIVER_OK
> >>>     is set.
> >>>
> >>> As this is needed for 2.1 for both pc and ppc, move PC_COMPAT macros from pc.h
> >>> to a new common header.
> >>>
> >>> Reviewed-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> >>> Tested-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> >>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> >>> ---
> >>>
> >>> Alexander, could you pls ack me merging this?
> >>> Thanks!
> >>
> >> Have you tried whether this works with old kernel versions? We
> >> introduced the broken flag for very specific old kernel versions that
> >> got their flags wrong IIRC.
> >>
> >>
> >> Alex
> > 
> > Yes. The point is that since 2.1 the broken flag isn't effective
> > anymore: when bus master is off, PCI blocks outgoing transactions and
> > setting internal flags isn't going to help.
> > 
> > Instead, we detect a buggy guest and immediately enable bus master for
> > it - no need for a separate flag.
> 
> Ok, works for me then.
> 
> 
> Alex

cool.
Gerd tells me there's a conflict with your next tree:
would you like for me to wait until it's merged,
or go ahead and send pull request and rebase yours on top?

-- 
MST

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH v3] virtio-pci: fix migration for pci bus master
  2014-10-21 12:10       ` Michael S. Tsirkin
@ 2014-10-21 12:12         ` Alexander Graf
  2014-10-21 12:36         ` Greg Kurz
  1 sibling, 0 replies; 9+ messages in thread
From: Alexander Graf @ 2014-10-21 12:12 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: qemu-ppc, qemu-devel, Anthony Liguori



On 21.10.14 14:10, Michael S. Tsirkin wrote:
> On Tue, Oct 21, 2014 at 01:35:39PM +0200, Alexander Graf wrote:
>>
>>
>> On 21.10.14 12:16, Michael S. Tsirkin wrote:
>>> On Mon, Oct 20, 2014 at 06:08:56PM +0200, Alexander Graf wrote:
>>>>
>>>>
>>>> On 20.10.14 08:58, Michael S. Tsirkin wrote:
>>>>> Current support for bus master (clearing OK bit) together with the need to
>>>>> support guests which do not enable PCI bus mastering, leads to extra state in
>>>>> VIRTIO_PCI_FLAG_BUS_MASTER_BUG bit, which isn't robust in case of cross-version
>>>>> migration for the case when guests use the device before setting DRIVER_OK.
>>>>>
>>>>> Rip out this code, and replace it:
>>>>> -   Modern QEMU doesn't need VIRTIO_PCI_FLAG_BUS_MASTER_BUG
>>>>>     so just drop it for latest machine type.
>>>>> -   For compat machine types, set PCI_COMMAND if DRIVER_OK
>>>>>     is set.
>>>>>
>>>>> As this is needed for 2.1 for both pc and ppc, move PC_COMPAT macros from pc.h
>>>>> to a new common header.
>>>>>
>>>>> Reviewed-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
>>>>> Tested-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
>>>>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>>>>> ---
>>>>>
>>>>> Alexander, could you pls ack me merging this?
>>>>> Thanks!
>>>>
>>>> Have you tried whether this works with old kernel versions? We
>>>> introduced the broken flag for very specific old kernel versions that
>>>> got their flags wrong IIRC.
>>>>
>>>>
>>>> Alex
>>>
>>> Yes. The point is that since 2.1 the broken flag isn't effective
>>> anymore: when bus master is off, PCI blocks outgoing transactions and
>>> setting internal flags isn't going to help.
>>>
>>> Instead, we detect a buggy guest and immediately enable bus master for
>>> it - no need for a separate flag.
>>
>> Ok, works for me then.
>>
>>
>> Alex
> 
> cool.
> Gerd tells me there's a conflict with your next tree:
> would you like for me to wait until it's merged,
> or go ahead and send pull request and rebase yours on top?

Whoever sends it first wins I'd say ;)


Alex

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH v3] virtio-pci: fix migration for pci bus master
  2014-10-21 12:10       ` Michael S. Tsirkin
  2014-10-21 12:12         ` Alexander Graf
@ 2014-10-21 12:36         ` Greg Kurz
  1 sibling, 0 replies; 9+ messages in thread
From: Greg Kurz @ 2014-10-21 12:36 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: qemu-ppc, Alexander Graf, Anthony Liguori, qemu-devel

On Tue, 21 Oct 2014 15:10:22 +0300
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Tue, Oct 21, 2014 at 01:35:39PM +0200, Alexander Graf wrote:
> > 
> > 
> > On 21.10.14 12:16, Michael S. Tsirkin wrote:
> > > On Mon, Oct 20, 2014 at 06:08:56PM +0200, Alexander Graf wrote:
> > >>
> > >>
> > >> On 20.10.14 08:58, Michael S. Tsirkin wrote:
> > >>> Current support for bus master (clearing OK bit) together with the need to
> > >>> support guests which do not enable PCI bus mastering, leads to extra state in
> > >>> VIRTIO_PCI_FLAG_BUS_MASTER_BUG bit, which isn't robust in case of cross-version
> > >>> migration for the case when guests use the device before setting DRIVER_OK.
> > >>>
> > >>> Rip out this code, and replace it:
> > >>> -   Modern QEMU doesn't need VIRTIO_PCI_FLAG_BUS_MASTER_BUG
> > >>>     so just drop it for latest machine type.
> > >>> -   For compat machine types, set PCI_COMMAND if DRIVER_OK
> > >>>     is set.
> > >>>
> > >>> As this is needed for 2.1 for both pc and ppc, move PC_COMPAT macros from pc.h
> > >>> to a new common header.
> > >>>
> > >>> Reviewed-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> > >>> Tested-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> > >>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > >>> ---
> > >>>
> > >>> Alexander, could you pls ack me merging this?
> > >>> Thanks!
> > >>
> > >> Have you tried whether this works with old kernel versions? We
> > >> introduced the broken flag for very specific old kernel versions that
> > >> got their flags wrong IIRC.
> > >>
> > >>
> > >> Alex
> > > 
> > > Yes. The point is that since 2.1 the broken flag isn't effective
> > > anymore: when bus master is off, PCI blocks outgoing transactions and
> > > setting internal flags isn't going to help.
> > > 
> > > Instead, we detect a buggy guest and immediately enable bus master for
> > > it - no need for a separate flag.
> > 
> > Ok, works for me then.
> > 
> > 
> > Alex
> 
> cool.
> Gerd tells me there's a conflict with your next tree:
> would you like for me to wait until it's merged,
> or go ahead and send pull request and rebase yours on top?
> 

This patch also needs to be rebased on current master actually
because PC_COMPAT_2_1 in include/hw/i386/pc.h got changed.

Cheers.

--
Greg

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-10-21 12:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-20  6:58 [Qemu-devel] [PATCH v3] virtio-pci: fix migration for pci bus master Michael S. Tsirkin
2014-10-20 14:15 ` Greg Kurz
2014-10-20 16:08 ` Alexander Graf
2014-10-20 16:40   ` Greg Kurz
2014-10-21 10:16   ` Michael S. Tsirkin
2014-10-21 11:35     ` Alexander Graf
2014-10-21 12:10       ` Michael S. Tsirkin
2014-10-21 12:12         ` Alexander Graf
2014-10-21 12:36         ` Greg Kurz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).