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

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