hw/pci/pcie: Move hot plug capability check to pre_plug callback
PATCH 1/1 hw/pci/pcie: Move hot plug capability check to pre_plug callback
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.
---
Hard to say if it's a bug or generally acceptable behaviour, but seems like hotplug_handler_plug should never fail.
hw/pci/pcie.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
hw/pci/pcie.c +11 -8
@@ -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.
Signature · 1 line
2.25.4
Quoted 11 lines · Julia Suvorova
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_addvirtio-blk-pci,id=blk0,drive=drive0,bus=rp0
If hotplug fails onplug_cb, drive0 will be deleted.Signed-off-by Julia Suvorova <[email protected]>
correct?
Quoted 53 lines
---
Hard to say if it's a bug or generally acceptable behaviour, but seems likehotplug_handler_plugshould never fail.hw/pci/pcie.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)hw/pci/pcie.c +11
-8@@ -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. Signature · 1 line
2.25.4
Quoted 12 lines · Michael S. Tsirkin
Quoted 10 lines · Julia Suvorova
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_addvirtio-blk-pci,id=blk0,drive=drive0,bus=rp0
If hotplug fails onplug_cb, drive0 will be deleted.
Quoted 6 lines
Quoted 1 line
Signed-off-by Julia Suvorova <[email protected]>Fixes 0501e1aa1d32a6 ("hw/pci/pcie: Forbid hot-plug if it's disabled on the slot")correct?
Yes.
Quoted 54 lines
Quoted 53 lines
---
Hard to say if it's a bug or generally acceptable behaviour, but seems likehotplug_handler_plugshould never fail.hw/pci/pcie.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)hw/pci/pcie.c +11
-9@@ -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. -- 2.25.4
Quoted 10 lines · On Mon, 1 Jun 2020 18:29:34 +0200 Julia Suvorova <[email protected]> wrote:
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_addvirtio-blk-pci,id=blk0,drive=drive0,bus=rp0
If hotplug fails onplug_cb, drive0 will be deleted.
Quoted 4 lines
Signed-off-by Julia Suvorova <[email protected]>---
Hard to say if it's a bug or generally acceptable behaviour, but seems likehotplug_handler_plugshould never fail.
_unplug shouldn't fail the rest are allowed to, but it's hard to unwind intialization cleanly to _plug stage so if it's possible to do checks at _pre_plug time (i.e. before device's realize() is called) we should do so.
Quoted 48 lines
hw/pci/pcie.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)hw/pci/pcie.c +11
-8@@ -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.
Quoted 18 lines · Igor Mammedov
Quoted 10 lines · On Mon, 1 Jun 2020 18:29:34 +0200 Julia Suvorova <[email protected]> wrote:
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_addvirtio-blk-pci,id=blk0,drive=drive0,bus=rp0
If hotplug fails onplug_cb, drive0 will be deleted.Quoted 4 lines
Signed-off-by Julia Suvorova <[email protected]>---
Hard to say if it's a bug or generally acceptable behaviour, but seems likehotplug_handler_plugshould never fail.
Quoted 5 lines
_unplugshouldn't fail the rest are allowed to, but it's hard to unwind intialization cleanly to_plugstage so if it's possible to do checks at_pre_plugtime (i.e. before device'srealize()is called) we should do so.Acked-by Igor Mammedov <[email protected]>
Makes sense. Julia could you repost with a tweaked commit log and I'll apply. Thanks!
Quoted 48 lines
Quoted 48 lines
hw/pci/pcie.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)hw/pci/pcie.c +11
-8@@ -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.