All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pci: Refuse to hotplug PCI Devices when the Guest OS is not ready
@ 2020-10-22 11:40 Marcel Apfelbaum
  2020-10-22 12:06 ` Michael S. Tsirkin
                   ` (2 more replies)
  0 siblings, 3 replies; 33+ messages in thread
From: Marcel Apfelbaum @ 2020-10-22 11:40 UTC (permalink / raw)
  To: qemu-devel, mst; +Cc: dgibson, jusual

From: Marcel Apfelbaum <marcel@redhat.com>

During PCIe Root Port's transition from Power-Off to Power-ON (or vice-versa)
the "Slot Control Register" has the "Power Indicator Control"
set to "Blinking" expressing a "power transition" mode.

Any hotplug operation during the "power transition" mode is not permitted
or at least not expected by the Guest OS leading to strange failures.

Detect and refuse hotplug operations in such case.

Signed-off-by: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
---
 hw/pci/pcie.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index 5b48bae0f6..2fe5c1473f 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -410,6 +410,7 @@ void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
     PCIDevice *hotplug_pdev = PCI_DEVICE(hotplug_dev);
     uint8_t *exp_cap = hotplug_pdev->config + hotplug_pdev->exp.exp_cap;
     uint32_t sltcap = pci_get_word(exp_cap + PCI_EXP_SLTCAP);
+    uint32_t sltctl = pci_get_word(exp_cap + PCI_EXP_SLTCTL);
 
     /* Check if hot-plug is disabled on the slot */
     if (dev->hotplugged && (sltcap & PCI_EXP_SLTCAP_HPC) == 0) {
@@ -418,6 +419,12 @@ void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
         return;
     }
 
+    if ((sltctl & PCI_EXP_SLTCTL_PIC) == PCI_EXP_SLTCTL_PWR_IND_BLINK) {
+        error_setg(errp, "Hot-plug failed: %s is in Power Transition",
+                   DEVICE(hotplug_pdev)->id);
+        return;
+    }
+
     pcie_cap_slot_plug_common(PCI_DEVICE(hotplug_dev), dev, errp);
 }
 
-- 
2.17.2



^ permalink raw reply related	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2020-11-15 16:49 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-22 11:40 [PATCH] pci: Refuse to hotplug PCI Devices when the Guest OS is not ready Marcel Apfelbaum
2020-10-22 12:06 ` Michael S. Tsirkin
2020-10-22 12:56   ` David Gibson
2020-10-22 13:15     ` Michael S. Tsirkin
2020-10-23  3:30       ` David Gibson
2020-10-22 13:55     ` Marcel Apfelbaum
2020-10-22 14:01       ` Michael S. Tsirkin
2020-10-22 14:10         ` Marcel Apfelbaum
2020-10-22 14:32           ` Michael S. Tsirkin
2020-10-22 14:50             ` Marcel Apfelbaum
2020-10-22 15:01               ` Michael S. Tsirkin
2020-10-23  3:49                 ` David Gibson
2020-10-23  6:47                   ` Marcel Apfelbaum
2020-10-23 15:54                     ` Michael S. Tsirkin
2020-10-23 17:27                       ` Igor Mammedov
2020-10-26  6:38                         ` David Gibson
2020-10-26  9:17                         ` Peter Krempa
2020-10-26  6:35                     ` David Gibson
2020-10-23  6:26                 ` Marcel Apfelbaum
2020-10-26  6:45                   ` David Gibson
2020-10-27 11:26                     ` Michael S. Tsirkin
2020-10-27 12:54                       ` Igor Mammedov
2020-10-27 13:02                         ` Michael S. Tsirkin
2020-10-28  3:34                           ` David Gibson
2020-10-28  3:31                         ` David Gibson
2020-10-28 15:39                           ` Igor Mammedov
2020-10-28 17:49                             ` Michael S. Tsirkin
2020-10-27 11:30                   ` Michael S. Tsirkin
2020-10-23  3:31       ` David Gibson
2020-11-11 12:35 ` Michael S. Tsirkin
2020-11-15 16:48   ` Marcel Apfelbaum
2020-11-11 16:09 ` Roman Kagan
2020-11-15 16:43   ` Marcel Apfelbaum

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.