qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Alexander Graf <agraf@suse.de>,
	qemu-ppc@nongnu.org, Anthony Liguori <aliguori@amazon.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>
Subject: [Qemu-devel] [PULL 07/29] virtio-pci: fix migration for pci bus master
Date: Mon, 3 Nov 2014 14:45:04 +0200	[thread overview]
Message-ID: <1415018633-16041-8-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1415018633-16041-1-git-send-email-mst@redhat.com>

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.

Cc: Greg Kurz <gkurz@linux.vnet.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Alexander Graf <agraf@suse.de>
---
 hw/virtio/virtio-pci.h |  5 +++++
 include/hw/compat.h    | 35 +++++++++++++++++++++++++++++++++++
 include/hw/i386/pc.h   | 26 ++------------------------
 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, 62 insertions(+), 44 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..313682a
--- /dev/null
+++ b/include/hw/compat.h
@@ -0,0 +1,35 @@
+#ifndef HW_COMPAT_H
+#define HW_COMPAT_H
+
+#define HW_COMPAT_2_1 \
+        {\
+            .driver   = "intel-hda",\
+            .property = "old_msi_addr",\
+            .value    = "on",\
+        },{\
+            .driver   = "VGA",\
+            .property = "qemu-extended-regs",\
+            .value    = "off",\
+        },{\
+            .driver   = "secondary-vga",\
+            .property = "qemu-extended-regs",\
+            .value    = "off",\
+        },{\
+            .driver   = "virtio-scsi-pci",\
+            .property = "any_layout",\
+            .value    = "off",\
+        },{\
+            .driver   = "usb-mouse",\
+            .property = "usb_version",\
+            .value    = stringify(1),\
+        },{\
+            .driver   = "usb-kbd",\
+            .property = "usb_version",\
+            .value    = stringify(1),\
+        },{\
+            .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 c4ee520..02a1d61 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"
 
@@ -301,31 +302,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",\
-        },{\
-            .driver   = "VGA",\
-            .property = "qemu-extended-regs",\
-            .value    = "off",\
-        },{\
-            .driver   = "secondary-vga",\
-            .property = "qemu-extended-regs",\
-            .value    = "off",\
-        },{\
-            .driver   = "usb-mouse",\
-            .property = "usb_version",\
-            .value    = stringify(1),\
-        },{\
-            .driver   = "usb-kbd",\
-            .property = "usb_version",\
-            .value    = stringify(1),\
-        }
-
 #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 061f4d9..ddc885e 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -474,7 +474,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 9c44cd6..f533a94 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -370,7 +370,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 45764a7..0a2bfe6 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 e490ade..dde1d73 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

  parent reply	other threads:[~2014-11-03 12:45 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-03 12:44 [Qemu-devel] [PULL 00/29] pc, virtio, misc bugfixes Michael S. Tsirkin
2014-11-03 12:44 ` [Qemu-devel] [PULL 01/29] smbios: Fix assertion on socket count calculation Michael S. Tsirkin
2014-11-03 12:44 ` [Qemu-devel] [PULL 02/29] well-defined listing order for machine types Michael S. Tsirkin
2014-11-03 12:44 ` [Qemu-devel] [PULL 03/29] i386/pc: add piix and q35 machtypes to sorting families for -M \? Michael S. Tsirkin
2014-11-03 12:44 ` [Qemu-devel] [PULL 04/29] pc: Fix disabling of vapic for compat PC models Michael S. Tsirkin
2014-11-03 12:44 ` [Qemu-devel] [PULL 05/29] i386: Add an ACPI_EXTRACT_NAME_BUFFER16 directive Michael S. Tsirkin
2014-11-03 12:45 ` [Qemu-devel] [PULL 06/29] pcie: change confused comment clearer Michael S. Tsirkin
2014-11-03 12:45 ` Michael S. Tsirkin [this message]
2014-11-03 12:45 ` [Qemu-devel] [PULL 08/29] intel_iommu: fix VTD_SID_TO_BUS Michael S. Tsirkin
2014-11-03 12:45 ` [Qemu-devel] [PULL 09/29] tests: fix rebuild-expected-aml.sh for acpi-test rename Michael S. Tsirkin
2014-11-03 12:45 ` [Qemu-devel] [PULL 10/29] acpi: create separate file for TCPA log Michael S. Tsirkin
2014-11-03 12:45 ` [Qemu-devel] [PULL 11/29] acpi/cpu: add cpu hotplug callback function to match hotplug_handler API Michael S. Tsirkin
2014-11-03 12:45 ` [Qemu-devel] [PULL 12/29] acpi:ich9: convert cpu hotplug to " Michael S. Tsirkin
2014-11-03 12:45 ` [Qemu-devel] [PULL 13/29] acpi:piix4: " Michael S. Tsirkin
2014-11-03 12:45 ` [Qemu-devel] [PULL 14/29] pc: add cpu hotplug handler to PC_MACHINE Michael S. Tsirkin
2014-11-03 12:45 ` [Qemu-devel] [PULL 15/29] pc: Update rtc_cmos in pc_cpu_plug Michael S. Tsirkin
2014-11-03 12:45 ` [Qemu-devel] [PULL 16/29] qom/cpu: remove the unused CPU hot-plug notifier Michael S. Tsirkin
2014-11-03 12:45 ` [Qemu-devel] [PULL 17/29] cpu-hotplug: rename function for better readability Michael S. Tsirkin
2014-11-03 12:45 ` [Qemu-devel] [PULL 18/29] acpi/cpu-hotplug: introduce helper function to keep bit setting in one place Michael S. Tsirkin
2014-11-03 12:45 ` [Qemu-devel] [PULL 19/29] -machine vmport=off: Allow disabling of VMWare ioport emulation Michael S. Tsirkin
2014-11-03 12:45 ` [Qemu-devel] [PULL 20/29] hw/pci: fixed error flow in pci_qdev_init Michael S. Tsirkin
2014-11-03 12:45 ` [Qemu-devel] [PULL 21/29] hw/pci: fixed hotplug crash when using rombar=0 with devices having romfile Michael S. Tsirkin
2014-11-03 12:45 ` [Qemu-devel] [PULL 22/29] hw/virtio/vring/event_idx: fix the vring_avail_event error Michael S. Tsirkin
2014-11-03 12:45 ` [Qemu-devel] [PULL 23/29] pc: Add pc_compat_2_1() function Michael S. Tsirkin
2014-11-03 12:46 ` [Qemu-devel] [PULL 24/29] smbios: Encode UUID according to SMBIOS specification Michael S. Tsirkin
2014-11-03 12:46 ` [Qemu-devel] [PULL 25/29] hw/i386/acpi-build.c: Fix memory leak in acpi_build_tables_cleanup() Michael S. Tsirkin
2014-11-03 12:46 ` [Qemu-devel] [PULL 26/29] qemu-char: fix tcp_get_fds Michael S. Tsirkin
2014-11-03 12:46 ` [Qemu-devel] [PULL 27/29] vhost-user: fix mmap offset calculation Michael S. Tsirkin
2014-11-03 12:46 ` [Qemu-devel] [PULL 28/29] vga: add default display to machine class Michael S. Tsirkin
2014-11-03 12:46 ` [Qemu-devel] [PULL 29/29] vga: flip qemu 2.2 pc machine types from cirrus to stdvga Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1415018633-16041-8-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=agraf@suse.de \
    --cc=aliguori@amazon.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).