Blame SOURCES/kvm-pci-bus-let-it-has-higher-migration-priority.patch

4a2fec
From a80ee7295748aeadc1e2c37a71ee46699c9324cb Mon Sep 17 00:00:00 2001
4a2fec
From: Peter Xu <peterx@redhat.com>
4a2fec
Date: Fri, 9 Feb 2018 06:02:44 +0100
4a2fec
Subject: [PATCH 03/15] pci/bus: let it has higher migration priority
4a2fec
4a2fec
RH-Author: Peter Xu <peterx@redhat.com>
4a2fec
Message-id: <20180209060244.17420-1-peterx@redhat.com>
4a2fec
Patchwork-id: 78963
4a2fec
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH] pci/bus: let it has higher migration priority
4a2fec
Bugzilla: 1538953
4a2fec
RH-Acked-by: Marcel Apfelbaum <marcel@redhat.com>
4a2fec
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
4a2fec
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
4a2fec
4a2fec
NOTE: downstream does not have hw/pci-bridge/pcie_pci_bridge.c, so the
4a2fec
      original change to that file is not needed.
4a2fec
4a2fec
In the past, we prioritized IOMMU migration so that we have such a
4a2fec
priority order:
4a2fec
4a2fec
    IOMMU > PCI Devices
4a2fec
4a2fec
When migrating a guest with both vIOMMU and a pcie-root-port, we'll
4a2fec
always migrate vIOMMU first, since pci buses will be seen to have the
4a2fec
same priority of general PCI devices.
4a2fec
4a2fec
That's problematic.
4a2fec
4a2fec
The thing is that PCI bus number information is stored in the root port,
4a2fec
and that is needed by vIOMMU during post_load(), e.g., to figure out
4a2fec
context entry for a device.  If we don't have correct bus numbers for
4a2fec
devices, we won't be able to recover device state of the DMAR memory
4a2fec
regions, and things will be messed up.
4a2fec
4a2fec
So let's boost the PCIe root ports to be even with higher priority:
4a2fec
4a2fec
   PCIe Root Port > IOMMU > PCI Devices
4a2fec
4a2fec
A smoke test shows that this patch fixes bug 1538953.
4a2fec
4a2fec
Also, apply this rule to all the PCI bus/bridge devices: ioh3420,
4a2fec
xio3130_downstream, xio3130_upstream, pcie_pci_bridge, pci-pci bridge,
4a2fec
i82801b11.
4a2fec
4a2fec
I noted that we set pcie_pci_bridge_dev_vmstate twice.  Clean that up
4a2fec
together.
4a2fec
4a2fec
CC: Alex Williamson <alex.williamson@redhat.com>
4a2fec
CC: Marcel Apfelbaum <marcel@redhat.com>
4a2fec
CC: Michael S. Tsirkin <mst@redhat.com>
4a2fec
CC: Dr. David Alan Gilbert <dgilbert@redhat.com>
4a2fec
CC: Juan Quintela <quintela@redhat.com>
4a2fec
CC: Laurent Vivier <lvivier@redhat.com>
4a2fec
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1538953
4a2fec
Reported-by: Maxime Coquelin <maxime.coquelin@redhat.com>
4a2fec
Signed-off-by: Peter Xu <peterx@redhat.com>
4a2fec
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
4a2fec
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
4a2fec
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
4a2fec
(cherry picked from commit 9d6b9db19c4b99ce5a1ad75b490c01edd2c2b0cf)
4a2fec
Signed-off-by: Peter Xu <peterx@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 hw/pci-bridge/gen_pcie_root_port.c | 1 +
4a2fec
 hw/pci-bridge/i82801b11.c          | 1 +
4a2fec
 hw/pci-bridge/ioh3420.c            | 1 +
4a2fec
 hw/pci-bridge/pci_bridge_dev.c     | 1 +
4a2fec
 hw/pci-bridge/xio3130_downstream.c | 1 +
4a2fec
 hw/pci-bridge/xio3130_upstream.c   | 1 +
4a2fec
 include/migration/vmstate.h        | 1 +
4a2fec
 7 files changed, 7 insertions(+)
4a2fec
4a2fec
diff --git a/hw/pci-bridge/gen_pcie_root_port.c b/hw/pci-bridge/gen_pcie_root_port.c
4a2fec
index 0e2f2e8..435fbaa 100644
4a2fec
--- a/hw/pci-bridge/gen_pcie_root_port.c
4a2fec
+++ b/hw/pci-bridge/gen_pcie_root_port.c
4a2fec
@@ -101,6 +101,7 @@ static void gen_rp_realize(DeviceState *dev, Error **errp)
4a2fec
 
4a2fec
 static const VMStateDescription vmstate_rp_dev = {
4a2fec
     .name = "pcie-root-port",
4a2fec
+    .priority = MIG_PRI_PCI_BUS,
4a2fec
     .version_id = 1,
4a2fec
     .minimum_version_id = 1,
4a2fec
     .post_load = pcie_cap_slot_post_load,
4a2fec
diff --git a/hw/pci-bridge/i82801b11.c b/hw/pci-bridge/i82801b11.c
4a2fec
index cb522bf..60df9b2 100644
4a2fec
--- a/hw/pci-bridge/i82801b11.c
4a2fec
+++ b/hw/pci-bridge/i82801b11.c
4a2fec
@@ -80,6 +80,7 @@ err_bridge:
4a2fec
 
4a2fec
 static const VMStateDescription i82801b11_bridge_dev_vmstate = {
4a2fec
     .name = "i82801b11_bridge",
4a2fec
+    .priority = MIG_PRI_PCI_BUS,
4a2fec
     .fields = (VMStateField[]) {
4a2fec
         VMSTATE_PCI_DEVICE(parent_obj, PCIBridge),
4a2fec
         VMSTATE_END_OF_LIST()
4a2fec
diff --git a/hw/pci-bridge/ioh3420.c b/hw/pci-bridge/ioh3420.c
4a2fec
index da4e5bd..a26d104 100644
4a2fec
--- a/hw/pci-bridge/ioh3420.c
4a2fec
+++ b/hw/pci-bridge/ioh3420.c
4a2fec
@@ -85,6 +85,7 @@ static void ioh3420_interrupts_uninit(PCIDevice *d)
4a2fec
 
4a2fec
 static const VMStateDescription vmstate_ioh3420 = {
4a2fec
     .name = "ioh-3240-express-root-port",
4a2fec
+    .priority = MIG_PRI_PCI_BUS,
4a2fec
     .version_id = 1,
4a2fec
     .minimum_version_id = 1,
4a2fec
     .post_load = pcie_cap_slot_post_load,
4a2fec
diff --git a/hw/pci-bridge/pci_bridge_dev.c b/hw/pci-bridge/pci_bridge_dev.c
4a2fec
index d56f663..b2d861d 100644
4a2fec
--- a/hw/pci-bridge/pci_bridge_dev.c
4a2fec
+++ b/hw/pci-bridge/pci_bridge_dev.c
4a2fec
@@ -174,6 +174,7 @@ static bool pci_device_shpc_present(void *opaque, int version_id)
4a2fec
 
4a2fec
 static const VMStateDescription pci_bridge_dev_vmstate = {
4a2fec
     .name = "pci_bridge",
4a2fec
+    .priority = MIG_PRI_PCI_BUS,
4a2fec
     .fields = (VMStateField[]) {
4a2fec
         VMSTATE_PCI_DEVICE(parent_obj, PCIBridge),
4a2fec
         SHPC_VMSTATE(shpc, PCIDevice, pci_device_shpc_present),
4a2fec
diff --git a/hw/pci-bridge/xio3130_downstream.c b/hw/pci-bridge/xio3130_downstream.c
4a2fec
index 1e09d2a..4dd2e65 100644
4a2fec
--- a/hw/pci-bridge/xio3130_downstream.c
4a2fec
+++ b/hw/pci-bridge/xio3130_downstream.c
4a2fec
@@ -161,6 +161,7 @@ static Property xio3130_downstream_props[] = {
4a2fec
 
4a2fec
 static const VMStateDescription vmstate_xio3130_downstream = {
4a2fec
     .name = "xio3130-express-downstream-port",
4a2fec
+    .priority = MIG_PRI_PCI_BUS,
4a2fec
     .version_id = 1,
4a2fec
     .minimum_version_id = 1,
4a2fec
     .post_load = pcie_cap_slot_post_load,
4a2fec
diff --git a/hw/pci-bridge/xio3130_upstream.c b/hw/pci-bridge/xio3130_upstream.c
4a2fec
index 227997c..c5f02a6 100644
4a2fec
--- a/hw/pci-bridge/xio3130_upstream.c
4a2fec
+++ b/hw/pci-bridge/xio3130_upstream.c
4a2fec
@@ -133,6 +133,7 @@ PCIEPort *xio3130_upstream_init(PCIBus *bus, int devfn, bool multifunction,
4a2fec
 
4a2fec
 static const VMStateDescription vmstate_xio3130_upstream = {
4a2fec
     .name = "xio3130-express-upstream-port",
4a2fec
+    .priority = MIG_PRI_PCI_BUS,
4a2fec
     .version_id = 1,
4a2fec
     .minimum_version_id = 1,
4a2fec
     .fields = (VMStateField[]) {
4a2fec
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
4a2fec
index 85e43da..d23555b 100644
4a2fec
--- a/include/migration/vmstate.h
4a2fec
+++ b/include/migration/vmstate.h
4a2fec
@@ -148,6 +148,7 @@ enum VMStateFlags {
4a2fec
 typedef enum {
4a2fec
     MIG_PRI_DEFAULT = 0,
4a2fec
     MIG_PRI_IOMMU,              /* Must happen before PCI devices */
4a2fec
+    MIG_PRI_PCI_BUS,            /* Must happen before IOMMU */
4a2fec
     MIG_PRI_GICV3_ITS,          /* Must happen before PCI devices */
4a2fec
     MIG_PRI_GICV3,              /* Must happen before the ITS */
4a2fec
     MIG_PRI_MAX,
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec