[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 28/58] hw/pci/pcie: Move hot plug capability check to pre_plug
From: |
Michael S. Tsirkin |
Subject: |
[PULL v2 28/58] hw/pci/pcie: Move hot plug capability check to pre_plug callback |
Date: |
Fri, 12 Jun 2020 10:52:04 -0400 |
From: Julia Suvorova <jusual@redhat.com>
Check for hot plug capability earlier to avoid removing devices attached
during the initialization process.
Run qemu with an unattached drive:
-drive file=$FILE,if=none,id=drive0 \
-device pcie-root-port,id=rp0,slot=3,bus=pcie.0,hotplug=off
Hotplug a block device:
device_add virtio-blk-pci,id=blk0,drive=drive0,bus=rp0
If hotplug fails on plug_cb, drive0 will be deleted.
Fixes: 0501e1aa1d32a6 ("hw/pci/pcie: Forbid hot-plug if it's disabled on the
slot")
Acked-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Julia Suvorova <jusual@redhat.com>
Message-Id: <20200604125947.881210-1-jusual@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/pci/pcie.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index f50e10b8fb..5b9c022d91 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -407,6 +407,17 @@ static void pcie_cap_slot_plug_common(PCIDevice
*hotplug_dev, DeviceState *dev,
void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
Error **errp)
{
+ 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);
+
+ /* Check if hot-plug is disabled on the slot */
+ if (dev->hotplugged && (sltcap & PCI_EXP_SLTCAP_HPC) == 0) {
+ error_setg(errp, "Hot-plug failed: unsupported by the port device
'%s'",
+ DEVICE(hotplug_pdev)->id);
+ return;
+ }
+
pcie_cap_slot_plug_common(PCI_DEVICE(hotplug_dev), dev, errp);
}
@@ -415,7 +426,6 @@ void pcie_cap_slot_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);
PCIDevice *pci_dev = PCI_DEVICE(dev);
/* Don't send event when device is enabled during qemu machine creation:
@@ -431,13 +441,6 @@ void pcie_cap_slot_plug_cb(HotplugHandler *hotplug_dev,
DeviceState *dev,
return;
}
- /* Check if hot-plug is disabled on the slot */
- if ((sltcap & PCI_EXP_SLTCAP_HPC) == 0) {
- error_setg(errp, "Hot-plug failed: unsupported by the port device
'%s'",
- DEVICE(hotplug_pdev)->id);
- return;
- }
-
/* To enable multifunction hot-plug, we just ensure the function
* 0 added last. When function 0 is added, we set the sltsta and
* inform OS via event notification.
--
MST
- [PULL v2 21/58] bios-tables-test: Generate reference tables for Q35/TPM-TIS, (continued)
[PULL v2 24/58] virtio-balloon: unref the iothread when unrealizing, Michael S. Tsirkin, 2020/06/12
[PULL v2 22/58] virtio-balloon: fix free page hinting without an iothread, Michael S. Tsirkin, 2020/06/12
[PULL v2 23/58] virtio-balloon: fix free page hinting check on unrealize, Michael S. Tsirkin, 2020/06/12
[PULL v2 27/58] MAINTAINERS: Fix the classification of bios-tables-test-allowed-diff.h, Michael S. Tsirkin, 2020/06/12
[PULL v2 28/58] hw/pci/pcie: Move hot plug capability check to pre_plug callback,
Michael S. Tsirkin <=
[PULL v2 29/58] pci: assert configuration access is within bounds, Michael S. Tsirkin, 2020/06/12
[PULL v2 26/58] virtio-balloon: Provide an interface for free page reporting, Michael S. Tsirkin, 2020/06/12
[PULL v2 33/58] hw/pci-host: Use the IEC binary prefix definitions, Michael S. Tsirkin, 2020/06/12
[PULL v2 34/58] char-socket: return -1 in case of disconnect during tcp_chr_write, Michael S. Tsirkin, 2020/06/12
[PULL v2 35/58] vhost-user-blk: delay vhost_user_blk_disconnect, Michael S. Tsirkin, 2020/06/12
[PULL v2 37/58] Add vhost-user helper to get MemoryRegion data, Michael S. Tsirkin, 2020/06/12
[PULL v2 36/58] Add helper to populate vhost-user message regions, Michael S. Tsirkin, 2020/06/12
[PULL v2 38/58] Add VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS, Michael S. Tsirkin, 2020/06/12
[PULL v2 39/58] Transmit vhost-user memory regions individually, Michael S. Tsirkin, 2020/06/12