cryptospore / rpms / qemu-kvm

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