* [PATCH] hw/pci/pcie: Move hot plug capability check to pre_plug callback
@ 2020-06-01 16:29 Julia Suvorova
2020-06-02 3:54 ` Michael S. Tsirkin
2020-06-04 10:57 ` Igor Mammedov
0 siblings, 2 replies; 5+ messages in thread
From: Julia Suvorova @ 2020-06-01 16:29 UTC (permalink / raw)
To: qemu-devel
Cc: Igor Mammedov, Julia Suvorova, Markus Armbruster,
Michael S. Tsirkin
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.
Signed-off-by: Julia Suvorova <jusual@redhat.com>
---
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(-)
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.
--
2.25.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] hw/pci/pcie: Move hot plug capability check to pre_plug callback
2020-06-01 16:29 [PATCH] hw/pci/pcie: Move hot plug capability check to pre_plug callback Julia Suvorova
@ 2020-06-02 3:54 ` Michael S. Tsirkin
2020-06-02 7:16 ` Julia Suvorova
2020-06-04 10:57 ` Igor Mammedov
1 sibling, 1 reply; 5+ messages in thread
From: Michael S. Tsirkin @ 2020-06-02 3:54 UTC (permalink / raw)
To: Julia Suvorova; +Cc: Igor Mammedov, qemu-devel, Markus Armbruster
On Mon, Jun 01, 2020 at 06:29:34PM +0200, Julia Suvorova 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_add virtio-blk-pci,id=blk0,drive=drive0,bus=rp0
> If hotplug fails on plug_cb, drive0 will be deleted.
>
> Signed-off-by: Julia Suvorova <jusual@redhat.com>
Fixes: 0501e1aa1d32a6 ("hw/pci/pcie: Forbid hot-plug if it's disabled on the slot")
correct?
> ---
> 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(-)
>
> 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.
> --
> 2.25.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] hw/pci/pcie: Move hot plug capability check to pre_plug callback
2020-06-02 3:54 ` Michael S. Tsirkin
@ 2020-06-02 7:16 ` Julia Suvorova
0 siblings, 0 replies; 5+ messages in thread
From: Julia Suvorova @ 2020-06-02 7:16 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: Igor Mammedov, QEMU Developers, Markus Armbruster
On Tue, Jun 2, 2020 at 5:54 AM Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Mon, Jun 01, 2020 at 06:29:34PM +0200, Julia Suvorova 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_add virtio-blk-pci,id=blk0,drive=drive0,bus=rp0
> > If hotplug fails on plug_cb, drive0 will be deleted.
> >
> > Signed-off-by: Julia Suvorova <jusual@redhat.com>
>
>
> Fixes: 0501e1aa1d32a6 ("hw/pci/pcie: Forbid hot-plug if it's disabled on the slot")
>
> correct?
Yes.
> > ---
> > 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(-)
> >
> > 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.
> > --
> > 2.25.4
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] hw/pci/pcie: Move hot plug capability check to pre_plug callback
2020-06-01 16:29 [PATCH] hw/pci/pcie: Move hot plug capability check to pre_plug callback Julia Suvorova
2020-06-02 3:54 ` Michael S. Tsirkin
@ 2020-06-04 10:57 ` Igor Mammedov
2020-06-04 11:14 ` Michael S. Tsirkin
1 sibling, 1 reply; 5+ messages in thread
From: Igor Mammedov @ 2020-06-04 10:57 UTC (permalink / raw)
To: Julia Suvorova; +Cc: Michael S. Tsirkin, qemu-devel, Markus Armbruster
On Mon, 1 Jun 2020 18:29:34 +0200
Julia Suvorova <jusual@redhat.com> 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_add virtio-blk-pci,id=blk0,drive=drive0,bus=rp0
> If hotplug fails on plug_cb, drive0 will be deleted.
>
> Signed-off-by: Julia Suvorova <jusual@redhat.com>
> ---
> Hard to say if it's a bug or generally acceptable behaviour, but seems like
> hotplug_handler_plug should 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.
Acked-by: Igor Mammedov <imammedo@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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] hw/pci/pcie: Move hot plug capability check to pre_plug callback
2020-06-04 10:57 ` Igor Mammedov
@ 2020-06-04 11:14 ` Michael S. Tsirkin
0 siblings, 0 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2020-06-04 11:14 UTC (permalink / raw)
To: Igor Mammedov; +Cc: Julia Suvorova, qemu-devel, Markus Armbruster
On Thu, Jun 04, 2020 at 12:57:55PM +0200, Igor Mammedov wrote:
> On Mon, 1 Jun 2020 18:29:34 +0200
> Julia Suvorova <jusual@redhat.com> 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_add virtio-blk-pci,id=blk0,drive=drive0,bus=rp0
> > If hotplug fails on plug_cb, drive0 will be deleted.
> >
> > Signed-off-by: Julia Suvorova <jusual@redhat.com>
> > ---
> > Hard to say if it's a bug or generally acceptable behaviour, but seems like
> > hotplug_handler_plug should 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.
>
> Acked-by: Igor Mammedov <imammedo@redhat.com>
Makes sense. Julia could you repost with a tweaked commit log
and I'll apply. Thanks!
> >
> > 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.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-06-04 11:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-01 16:29 [PATCH] hw/pci/pcie: Move hot plug capability check to pre_plug callback Julia Suvorova
2020-06-02 3:54 ` Michael S. Tsirkin
2020-06-02 7:16 ` Julia Suvorova
2020-06-04 10:57 ` Igor Mammedov
2020-06-04 11:14 ` Michael S. Tsirkin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).