peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0008-Revert-virtio-pci-fix-migration-for-pci-bus-master.patch

fbbbab
From 9d8b817bfe327873c009fa4621c0308e7f3bc5de Mon Sep 17 00:00:00 2001
fbbbab
From: "Michael S. Tsirkin" <mst@redhat.com>
fbbbab
Date: Mon, 29 Sep 2014 11:27:32 +0300
fbbbab
Subject: [PATCH] Revert "virtio-pci: fix migration for pci bus master"
fbbbab
fbbbab
This reverts commit 4d43d3f3c8147ade184df9a1e9e82826edd39e19.
fbbbab
fbbbab
Reported to break PPC guests.
fbbbab
fbbbab
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
fbbbab
(cherry picked from commit 45363e46aeebfc99753389649eac7c7fc22bfe52)
fbbbab
---
fbbbab
 hw/virtio/virtio-pci.c | 39 +++++++++++++++++++--------------------
fbbbab
 1 file changed, 19 insertions(+), 20 deletions(-)
fbbbab
fbbbab
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
fbbbab
index c19c4d6..58ebbcf 100644
fbbbab
--- a/hw/virtio/virtio-pci.c
fbbbab
+++ b/hw/virtio/virtio-pci.c
fbbbab
@@ -86,6 +86,9 @@
fbbbab
  * 12 is historical, and due to x86 page size. */
fbbbab
 #define VIRTIO_PCI_QUEUE_ADDR_SHIFT    12
fbbbab
 
fbbbab
+/* Flags track per-device state like workarounds for quirks in older guests. */
fbbbab
+#define VIRTIO_PCI_FLAG_BUS_MASTER_BUG  (1 << 0)
fbbbab
+
fbbbab
 static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
fbbbab
                                VirtIOPCIProxy *dev);
fbbbab
 
fbbbab
@@ -320,6 +323,14 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
fbbbab
                                      proxy->pci_dev.config[PCI_COMMAND] |
fbbbab
                                      PCI_COMMAND_MASTER, 1);
fbbbab
         }
fbbbab
+
fbbbab
+        /* Linux before 2.6.34 sets the device as OK without enabling
fbbbab
+           the PCI device bus master bit. In this case we need to disable
fbbbab
+           some safety checks. */
fbbbab
+        if ((val & VIRTIO_CONFIG_S_DRIVER_OK) &&
fbbbab
+            !(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
fbbbab
+            proxy->flags |= VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
fbbbab
+        }
fbbbab
         break;
fbbbab
     case VIRTIO_MSI_CONFIG_VECTOR:
fbbbab
         msix_vector_unuse(&proxy->pci_dev, vdev->config_vector);
fbbbab
@@ -469,18 +480,13 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
fbbbab
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
fbbbab
     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
fbbbab
 
fbbbab
-    uint8_t cmd = proxy->pci_dev.config[PCI_COMMAND];
fbbbab
-
fbbbab
     pci_default_write_config(pci_dev, address, val, len);
fbbbab
 
fbbbab
     if (range_covers_byte(address, len, PCI_COMMAND) &&
fbbbab
         !(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER) &&
fbbbab
-        (cmd & PCI_COMMAND_MASTER)) {
fbbbab
-        /* Bus driver disables bus mastering - make it act
fbbbab
-         * as a kind of reset to render the device quiescent. */
fbbbab
+        !(proxy->flags & VIRTIO_PCI_FLAG_BUS_MASTER_BUG)) {
fbbbab
         virtio_pci_stop_ioeventfd(proxy);
fbbbab
-        virtio_reset(vdev);
fbbbab
-        msix_unuse_all_vectors(&proxy->pci_dev);
fbbbab
+        virtio_set_status(vdev, vdev->status & ~VIRTIO_CONFIG_S_DRIVER_OK);
fbbbab
     }
fbbbab
 }
fbbbab
 
fbbbab
@@ -889,19 +895,11 @@ static void virtio_pci_vmstate_change(DeviceState *d, bool running)
fbbbab
     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
fbbbab
 
fbbbab
     if (running) {
fbbbab
-        /* Linux before 2.6.34 drives the device without enabling
fbbbab
-           the PCI device bus master bit. Enable it automatically
fbbbab
-           for the guest. This is a PCI spec violation but so is
fbbbab
-           initiating DMA with bus master bit clear.
fbbbab
-           Note: this only makes a difference when migrating
fbbbab
-           across QEMU versions from an old QEMU, as for new QEMU
fbbbab
-           bus master and driver bits are always in sync.
fbbbab
-           TODO: consider enabling conditionally for compat machine types. */
fbbbab
-        if (vdev->status & (VIRTIO_CONFIG_S_ACKNOWLEDGE |
fbbbab
-                            VIRTIO_CONFIG_S_DRIVER)) {
fbbbab
-            pci_default_write_config(&proxy->pci_dev, PCI_COMMAND,
fbbbab
-                                     proxy->pci_dev.config[PCI_COMMAND] |
fbbbab
-                                     PCI_COMMAND_MASTER, 1);
fbbbab
+        /* Try to find out if the guest has bus master disabled, but is
fbbbab
+           in ready state. Then we have a buggy guest OS. */
fbbbab
+        if ((vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) &&
fbbbab
+            !(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
fbbbab
+            proxy->flags |= VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
fbbbab
         }
fbbbab
         virtio_pci_start_ioeventfd(proxy);
fbbbab
     } else {
fbbbab
@@ -1045,6 +1043,7 @@ static void virtio_pci_reset(DeviceState *qdev)
fbbbab
     virtio_pci_stop_ioeventfd(proxy);
fbbbab
     virtio_bus_reset(bus);
fbbbab
     msix_unuse_all_vectors(&proxy->pci_dev);
fbbbab
+    proxy->flags &= ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
fbbbab
 }
fbbbab
 
fbbbab
 static Property virtio_pci_properties[] = {