qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] hw/pci/pci: Fix slot check for plugged devices
@ 2020-10-06 12:59 Julia Suvorova
  2020-10-07  7:39 ` Stefano Garzarella
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Suvorova @ 2020-10-06 12:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Julia Suvorova, Michael S. Tsirkin

If devfn is assigned automatically, 'else' clauses will never be
executed. And if it does not matter for the reserved and available
devfn, because we have already checked it, the check for function0
needs to be done again.

Steps to reproduce:
1. Run QEMU with:
        -M q35 \
        -device pcie-root-port,id=rp,.. \
        -device pci-device,bus=rp
2. Add a new device to the same port:
        device_add pci-device,bus=rp

The last command will add the device to slot 1 instead of
failing with "PCI: slot 0 function 0 already occupied..."

Signed-off-by: Julia Suvorova <jusual@redhat.com>
---
v2:
    * add example to the commit message [Michael]

 hw/pci/pci.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index de0fae10ab..ae132b0b52 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1034,8 +1034,9 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev,
                    PCI_SLOT(devfn), PCI_FUNC(devfn), name,
                    bus->devices[devfn]->name);
         return NULL;
-    } else if (dev->hotplugged &&
-               pci_get_function_0(pci_dev)) {
+    };
+
+    if (dev->hotplugged && pci_get_function_0(pci_dev)) {
         error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
                    " new func %s cannot be exposed to guest.",
                    PCI_SLOT(pci_get_function_0(pci_dev)->devfn),
-- 
2.25.4



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

* Re: [PATCH v2] hw/pci/pci: Fix slot check for plugged devices
  2020-10-06 12:59 [PATCH v2] hw/pci/pci: Fix slot check for plugged devices Julia Suvorova
@ 2020-10-07  7:39 ` Stefano Garzarella
  2020-10-07 10:38   ` Julia Suvorova
  0 siblings, 1 reply; 3+ messages in thread
From: Stefano Garzarella @ 2020-10-07  7:39 UTC (permalink / raw)
  To: Julia Suvorova; +Cc: Igor Mammedov, qemu-devel, Michael S. Tsirkin

On Tue, Oct 06, 2020 at 02:59:08PM +0200, Julia Suvorova wrote:
> If devfn is assigned automatically, 'else' clauses will never be
> executed. And if it does not matter for the reserved and available
> devfn, because we have already checked it, the check for function0
> needs to be done again.
> 
> Steps to reproduce:
> 1. Run QEMU with:
>         -M q35 \
>         -device pcie-root-port,id=rp,.. \
>         -device pci-device,bus=rp
> 2. Add a new device to the same port:
>         device_add pci-device,bus=rp
> 
> The last command will add the device to slot 1 instead of
> failing with "PCI: slot 0 function 0 already occupied..."
> 
> Signed-off-by: Julia Suvorova <jusual@redhat.com>
> ---
> v2:
>     * add example to the commit message [Michael]
> 
>  hw/pci/pci.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index de0fae10ab..ae132b0b52 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -1034,8 +1034,9 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev,
>                     PCI_SLOT(devfn), PCI_FUNC(devfn), name,
>                     bus->devices[devfn]->name);
>          return NULL;
> -    } else if (dev->hotplugged &&
> -               pci_get_function_0(pci_dev)) {
> +    };
        ^
This semicolon seems unnecessary, can we take it out?

Thanks,
Stefano

> +
> +    if (dev->hotplugged && pci_get_function_0(pci_dev)) {
>          error_setg(errp, "PCI: slot %d function 0 already ocuppied by %s,"
>                     " new func %s cannot be exposed to guest.",
>                     PCI_SLOT(pci_get_function_0(pci_dev)->devfn),
> -- 
> 2.25.4
> 
> 



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

* Re: [PATCH v2] hw/pci/pci: Fix slot check for plugged devices
  2020-10-07  7:39 ` Stefano Garzarella
@ 2020-10-07 10:38   ` Julia Suvorova
  0 siblings, 0 replies; 3+ messages in thread
From: Julia Suvorova @ 2020-10-07 10:38 UTC (permalink / raw)
  To: Stefano Garzarella; +Cc: Igor Mammedov, QEMU Developers, Michael S. Tsirkin

On Wed, Oct 7, 2020 at 9:39 AM Stefano Garzarella <sgarzare@redhat.com> wrote:
>
> On Tue, Oct 06, 2020 at 02:59:08PM +0200, Julia Suvorova wrote:
> > If devfn is assigned automatically, 'else' clauses will never be
> > executed. And if it does not matter for the reserved and available
> > devfn, because we have already checked it, the check for function0
> > needs to be done again.
> >
> > Steps to reproduce:
> > 1. Run QEMU with:
> >         -M q35 \
> >         -device pcie-root-port,id=rp,.. \
> >         -device pci-device,bus=rp
> > 2. Add a new device to the same port:
> >         device_add pci-device,bus=rp
> >
> > The last command will add the device to slot 1 instead of
> > failing with "PCI: slot 0 function 0 already occupied..."
> >
> > Signed-off-by: Julia Suvorova <jusual@redhat.com>
> > ---
> > v2:
> >     * add example to the commit message [Michael]
> >
> >  hw/pci/pci.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> > index de0fae10ab..ae132b0b52 100644
> > --- a/hw/pci/pci.c
> > +++ b/hw/pci/pci.c
> > @@ -1034,8 +1034,9 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev,
> >                     PCI_SLOT(devfn), PCI_FUNC(devfn), name,
> >                     bus->devices[devfn]->name);
> >          return NULL;
> > -    } else if (dev->hotplugged &&
> > -               pci_get_function_0(pci_dev)) {
> > +    };
>         ^
> This semicolon seems unnecessary, can we take it out?

Oops, thanks for pointing out.



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

end of thread, other threads:[~2020-10-07 10:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-06 12:59 [PATCH v2] hw/pci/pci: Fix slot check for plugged devices Julia Suvorova
2020-10-07  7:39 ` Stefano Garzarella
2020-10-07 10:38   ` Julia Suvorova

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).