yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-pcie_root_port-Add-hotplug-disabling-option.patch

ddf19c
From 8587278a20283851081d4d282d11ef6bafd17dc2 Mon Sep 17 00:00:00 2001
ddf19c
From: Julia Suvorova <jusual@redhat.com>
ddf19c
Date: Tue, 17 Mar 2020 13:56:39 -0400
ddf19c
Subject: [PATCH 1/2] pcie_root_port: Add hotplug disabling option
ddf19c
MIME-Version: 1.0
ddf19c
Content-Type: text/plain; charset=UTF-8
ddf19c
Content-Transfer-Encoding: 8bit
ddf19c
ddf19c
RH-Author: Julia Suvorova <jusual@redhat.com>
ddf19c
Message-id: <20200317135639.65085-1-jusual@redhat.com>
ddf19c
Patchwork-id: 94367
ddf19c
O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH 1/1] pcie_root_port: Add hotplug disabling option
ddf19c
Bugzilla: 1790899
ddf19c
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
ddf19c
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
ddf19c
RH-Acked-by: Peter Xu <peterx@redhat.com>
ddf19c
ddf19c
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1790899
ddf19c
BRANCH: rhel-av-8.2.1
ddf19c
UPSTREAM: merged
ddf19c
BREW: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=27302449
ddf19c
ddf19c
Make hot-plug/hot-unplug on PCIe Root Ports optional to allow libvirt
ddf19c
manage it and restrict unplug for the whole machine. This is going to
ddf19c
prevent user-initiated unplug in guests (Windows mostly).
ddf19c
Hotplug is enabled by default.
ddf19c
Usage:
ddf19c
    -device pcie-root-port,hotplug=off,...
ddf19c
ddf19c
If you want to disable hot-unplug on some downstream ports of one
ddf19c
switch, disable hot-unplug on PCIe Root Port connected to the upstream
ddf19c
port as well as on the selected downstream ports.
ddf19c
ddf19c
Discussion related:
ddf19c
    https://lists.gnu.org/archive/html/qemu-devel/2020-02/msg00530.html
ddf19c
ddf19c
Signed-off-by: Julia Suvorova <jusual@redhat.com>
ddf19c
Message-Id: <20200226174607.205941-1-jusual@redhat.com>
ddf19c
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
ddf19c
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
ddf19c
Reviewed-by: Ján Tomko <jtomko@redhat.com>
ddf19c
(cherry picked from commit 530a0963184e57e71a5b538e9161f115df533e96)
ddf19c
Signed-off-by: Jon Maloy <jmaloy.redhat.com>
ddf19c
---
ddf19c
 hw/pci-bridge/pcie_root_port.c     |  2 +-
ddf19c
 hw/pci-bridge/xio3130_downstream.c |  2 +-
ddf19c
 hw/pci/pcie.c                      | 11 +++++++----
ddf19c
 hw/pci/pcie_port.c                 |  1 +
ddf19c
 include/hw/pci/pcie.h              |  2 +-
ddf19c
 include/hw/pci/pcie_port.h         |  3 +++
ddf19c
 6 files changed, 14 insertions(+), 7 deletions(-)
ddf19c
ddf19c
diff --git a/hw/pci-bridge/pcie_root_port.c b/hw/pci-bridge/pcie_root_port.c
ddf19c
index 012c2cb12c..db80e2ec23 100644
ddf19c
--- a/hw/pci-bridge/pcie_root_port.c
ddf19c
+++ b/hw/pci-bridge/pcie_root_port.c
ddf19c
@@ -94,7 +94,7 @@ static void rp_realize(PCIDevice *d, Error **errp)
ddf19c
 
ddf19c
     pcie_cap_arifwd_init(d);
ddf19c
     pcie_cap_deverr_init(d);
ddf19c
-    pcie_cap_slot_init(d, s->slot);
ddf19c
+    pcie_cap_slot_init(d, s);
ddf19c
     pcie_cap_root_init(d);
ddf19c
 
ddf19c
     pcie_chassis_create(s->chassis);
ddf19c
diff --git a/hw/pci-bridge/xio3130_downstream.c b/hw/pci-bridge/xio3130_downstream.c
ddf19c
index a9f084b863..4489ce4a40 100644
ddf19c
--- a/hw/pci-bridge/xio3130_downstream.c
ddf19c
+++ b/hw/pci-bridge/xio3130_downstream.c
ddf19c
@@ -94,7 +94,7 @@ static void xio3130_downstream_realize(PCIDevice *d, Error **errp)
ddf19c
     }
ddf19c
     pcie_cap_flr_init(d);
ddf19c
     pcie_cap_deverr_init(d);
ddf19c
-    pcie_cap_slot_init(d, s->slot);
ddf19c
+    pcie_cap_slot_init(d, s);
ddf19c
     pcie_cap_arifwd_init(d);
ddf19c
 
ddf19c
     pcie_chassis_create(s->chassis);
ddf19c
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
ddf19c
index 08718188bb..0eb3a2a5d2 100644
ddf19c
--- a/hw/pci/pcie.c
ddf19c
+++ b/hw/pci/pcie.c
ddf19c
@@ -495,7 +495,7 @@ void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev,
ddf19c
 
ddf19c
 /* pci express slot for pci express root/downstream port
ddf19c
    PCI express capability slot registers */
ddf19c
-void pcie_cap_slot_init(PCIDevice *dev, uint16_t slot)
ddf19c
+void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s)
ddf19c
 {
ddf19c
     uint32_t pos = dev->exp.exp_cap;
ddf19c
 
ddf19c
@@ -505,13 +505,16 @@ void pcie_cap_slot_init(PCIDevice *dev, uint16_t slot)
ddf19c
     pci_long_test_and_clear_mask(dev->config + pos + PCI_EXP_SLTCAP,
ddf19c
                                  ~PCI_EXP_SLTCAP_PSN);
ddf19c
     pci_long_test_and_set_mask(dev->config + pos + PCI_EXP_SLTCAP,
ddf19c
-                               (slot << PCI_EXP_SLTCAP_PSN_SHIFT) |
ddf19c
+                               (s->slot << PCI_EXP_SLTCAP_PSN_SHIFT) |
ddf19c
                                PCI_EXP_SLTCAP_EIP |
ddf19c
-                               PCI_EXP_SLTCAP_HPS |
ddf19c
-                               PCI_EXP_SLTCAP_HPC |
ddf19c
                                PCI_EXP_SLTCAP_PIP |
ddf19c
                                PCI_EXP_SLTCAP_AIP |
ddf19c
                                PCI_EXP_SLTCAP_ABP);
ddf19c
+    if (s->hotplug) {
ddf19c
+        pci_long_test_and_set_mask(dev->config + pos + PCI_EXP_SLTCAP,
ddf19c
+                                   PCI_EXP_SLTCAP_HPS |
ddf19c
+                                   PCI_EXP_SLTCAP_HPC);
ddf19c
+    }
ddf19c
 
ddf19c
     if (dev->cap_present & QEMU_PCIE_SLTCAP_PCP) {
ddf19c
         pci_long_test_and_set_mask(dev->config + pos + PCI_EXP_SLTCAP,
ddf19c
diff --git a/hw/pci/pcie_port.c b/hw/pci/pcie_port.c
ddf19c
index c19a9be592..36dac33d98 100644
ddf19c
--- a/hw/pci/pcie_port.c
ddf19c
+++ b/hw/pci/pcie_port.c
ddf19c
@@ -147,6 +147,7 @@ static const TypeInfo pcie_port_type_info = {
ddf19c
 static Property pcie_slot_props[] = {
ddf19c
     DEFINE_PROP_UINT8("chassis", PCIESlot, chassis, 0),
ddf19c
     DEFINE_PROP_UINT16("slot", PCIESlot, slot, 0),
ddf19c
+    DEFINE_PROP_BOOL("hotplug", PCIESlot, hotplug, true),
ddf19c
     DEFINE_PROP_END_OF_LIST()
ddf19c
 };
ddf19c
 
ddf19c
diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h
ddf19c
index 7064875835..14c58ebdb6 100644
ddf19c
--- a/include/hw/pci/pcie.h
ddf19c
+++ b/include/hw/pci/pcie.h
ddf19c
@@ -104,7 +104,7 @@ void pcie_cap_deverr_reset(PCIDevice *dev);
ddf19c
 void pcie_cap_lnkctl_init(PCIDevice *dev);
ddf19c
 void pcie_cap_lnkctl_reset(PCIDevice *dev);
ddf19c
 
ddf19c
-void pcie_cap_slot_init(PCIDevice *dev, uint16_t slot);
ddf19c
+void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s);
ddf19c
 void pcie_cap_slot_reset(PCIDevice *dev);
ddf19c
 void pcie_cap_slot_get(PCIDevice *dev, uint16_t *slt_ctl, uint16_t *slt_sta);
ddf19c
 void pcie_cap_slot_write_config(PCIDevice *dev,
ddf19c
diff --git a/include/hw/pci/pcie_port.h b/include/hw/pci/pcie_port.h
ddf19c
index 7515430087..7072cc8731 100644
ddf19c
--- a/include/hw/pci/pcie_port.h
ddf19c
+++ b/include/hw/pci/pcie_port.h
ddf19c
@@ -55,6 +55,9 @@ struct PCIESlot {
ddf19c
 
ddf19c
     /* Disable ACS (really for a pcie_root_port) */
ddf19c
     bool        disable_acs;
ddf19c
+
ddf19c
+    /* Indicates whether hot-plug is enabled on the slot */
ddf19c
+    bool        hotplug;
ddf19c
     QLIST_ENTRY(PCIESlot) next;
ddf19c
 };
ddf19c
 
ddf19c
-- 
ddf19c
2.18.2
ddf19c