Received: from eggs.gnu.org ([2001:4830:134:3::10]:56080) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XS8gr-0005Rl-Bl for qemu-devel@nongnu.org; Thu, 11 Sep 2014 14:01:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XS8gk-0004Oc-UG for qemu-devel@nongnu.org; Thu, 11 Sep 2014 14:01:53 -0400 Date: Thu, 11 Sep 2014 21:04:58 +0300 From: "Michael S. Tsirkin" Message-ID: <1410458625-29217-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH v3] virtio-pci: enable bus master for old guests List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Cedric Le Goater , qemu-stable@nongnu.org, Anthony Liguori commit cc943c36faa192cd4b32af8fe5edb31894017d35 pci: Use bus master address space for delivering MSI/MSI-X messages breaks virtio-net for rhel6.[56] x86 guests because they don't enable bus mastering for virtio PCI devices. For the same reason, rhel6.[56] ppc64 guests cannot boot on a virtio-blk disk anymore. Old guests forgot to enable bus mastering, enable it automatically on DRIVER (ppc64 guests may never reach DRIVER_OK). We also need to prevent these old guests to disable bus mastering (this happens when the driver probes the device). And we must also re-enable bus mastering after migration. Cc: qemu-stable@nongnu.org Reported-by: Greg Kurz Signed-off-by: Michael S. Tsirkin [ old guest detection on DRIVER, squashed patch from Michael S. Tsirkin to re-enable bus mastering, Greg Kurz ] Tested-by: Cedric Le Goater Signed-off-by: Greg Kurz Signed-off-by: Michael S. Tsirkin --- So, below seems mostly correct. I still think it's too complex, and I have an idea for a much simpler patch. Will try sending that next week. hw/virtio/virtio-pci.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index ddb5da1..81a6ea6 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -314,12 +314,14 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) msix_unuse_all_vectors(&proxy->pci_dev); } - /* Linux before 2.6.34 sets the device as OK without enabling + /* Linux before 2.6.34 drives the device 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) && + if ((val & VIRTIO_CONFIG_S_DRIVER) && !(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { proxy->flags |= VIRTIO_PCI_FLAG_BUS_MASTER_BUG; + memory_region_set_enabled(&proxy->pci_dev.bus_master_enable_region, + true); } break; case VIRTIO_MSI_CONFIG_VECTOR: @@ -473,10 +475,15 @@ 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)) { - virtio_pci_stop_ioeventfd(proxy); - virtio_set_status(vdev, vdev->status & ~VIRTIO_CONFIG_S_DRIVER_OK); + !(pci_dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { + if (proxy->flags & VIRTIO_PCI_FLAG_BUS_MASTER_BUG) { + memory_region_set_enabled(&proxy->pci_dev.bus_master_enable_region, + true); + } else { + virtio_pci_stop_ioeventfd(proxy); + virtio_set_status(vdev, vdev->status & ~(VIRTIO_CONFIG_S_DRIVER_OK| + VIRTIO_CONFIG_S_DRIVER)); + } } } @@ -887,9 +894,11 @@ static void virtio_pci_vmstate_change(DeviceState *d, bool running) 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) && + if ((vdev->status & VIRTIO_CONFIG_S_DRIVER) && !(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { proxy->flags |= VIRTIO_PCI_FLAG_BUS_MASTER_BUG; + memory_region_set_enabled(&proxy->pci_dev.bus_master_enable_region, + true); } virtio_pci_start_ioeventfd(proxy); } else { -- MST