qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Ani Sinha <anisinha@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>,
	Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
	Julia Suvorova <jusual@redhat.com>,
	qemu-devel@nongnu.org
Subject: Re: [PATCH] hw/pci: prevent hotplug of devices on pcie-root-ports with wrong devfn address
Date: Wed, 14 Jun 2023 16:52:38 -0400	[thread overview]
Message-ID: <20230614165051-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <E6BFF3BE-42D8-4651-99B1-D4BF6C1D17B1@redhat.com>

On Wed, Jun 14, 2023 at 10:31:40PM +0530, Ani Sinha wrote:
> 
> 
> > On 14-Jun-2023, at 6:31 PM, Igor Mammedov <imammedo@redhat.com> wrote:
> > 
> > On Wed, 14 Jun 2023 18:01:50 +0530
> > Ani Sinha <anisinha@redhat.com> wrote:
> > 
> >> PCIE root ports only allow one device on slot 0/function 0. When hotplugging a
> >> device on a pcie root port, make sure that the device address passed is
> >> always 0x00 that represents slot 0 and function 0. Any other slot value and
> >> function value would be illegal on a root port.
> >> 
> >> CC: jusual@redhat.com
> >> CC: imammedo@redhat.com
> >> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2128929
> >> Signed-off-by: Ani Sinha <anisinha@redhat.com>
> >> ---
> >> hw/pci/pci.c | 9 +++++++++
> >> 1 file changed, 9 insertions(+)
> >> 
> >> Note:
> >> I tested this with both native and acpi hotplug enabled on pcie. The
> >> check seems to work on both.
> >> 
> >> (qemu)  netdev_add socket,id=hostnet1,listen=:1234
> >> (qemu) device_add e1000e,netdev=hostnet1,mac=00:11:22:33:44:03,id=net1,bus=pci.6,addr=0x2.0x5
> >> Error: PCI: slot 2 function 5 is not valid for e1000e
> >> (qemu) device_add e1000e,netdev=hostnet1,mac=00:11:22:33:44:03,id=net1,bus=pci.6,addr=0x0.0
> >> (qemu) info network
> >> net1: index=0,type=nic,model=e1000e,macaddr=00:11:22:33:44:03
> >> \ hostnet1: index=0,type=socket,
> >> (qemu) device_del net1
> >> (qemu) info network
> >> hostnet1: index=0,type=socket,
> >> 
> >> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> >> index bf38905b7d..bc39322dfd 100644
> >> --- a/hw/pci/pci.c
> >> +++ b/hw/pci/pci.c
> >> @@ -64,6 +64,7 @@ bool pci_available = true;
> >> static char *pcibus_get_dev_path(DeviceState *dev);
> >> static char *pcibus_get_fw_dev_path(DeviceState *dev);
> >> static void pcibus_reset(BusState *qbus);
> >> +static bool pcie_has_upstream_port(PCIDevice *dev);
> >> 
> >> static Property pci_props[] = {
> >>     DEFINE_PROP_PCI_DEVFN("addr", PCIDevice, devfn, -1),
> >> @@ -1189,6 +1190,14 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev,
> >>                    name);
> >> 
> >>        return NULL;
> >> +    } else if (dev->hotplugged &&
> > 
> >> +               !pci_is_vf(pci_dev) &&
> >> +               pcie_has_upstream_port(pci_dev) 
> > can you clarify what above 2 lines are here for?
> > 
> > you can't hotplug anything into upstream port (only downstream)
> 
> This code checks if the hot plugged device is being plugged into a pcie root port. For pcie root ports, only slot 0 can be used. Please see 3f1e1478db2d67098d9 . The conditional check just above this hunk therefore checks for unoccupied function 0 in slot 0 if the device is plugged into an upstream pcie root port. I think for hot plugs, only function 0 is allowed.

Not really. The way we hotplug a multifunction device is by first
populating all functions != 0, then finally pupulating function 0
which is when the event triggers.

> 
> As for vf, I am not sure. I believe for vfs the restriction is not valid. I just kept the check based on the conditional just prior to it.
> 
> > and why _vf() is here also not clear.
> > 
> >> && devfn) {
> >> +        /* For an upstream PCIE port, we only support one device at slot 0 */
> >> +        error_setg(errp, "PCI: slot %d function %d is not valid for %s",
> >> +                   PCI_SLOT(devfn), PCI_FUNC(devfn), name);
> >> +        return NULL;
> >> +
> >>     }
> >> 
> >>     pci_dev->devfn = devfn;



  reply	other threads:[~2023-06-14 20:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-14 12:31 [PATCH] hw/pci: prevent hotplug of devices on pcie-root-ports with wrong devfn address Ani Sinha
2023-06-14 13:01 ` Igor Mammedov
2023-06-14 17:01   ` Ani Sinha
2023-06-14 20:52     ` Michael S. Tsirkin [this message]
2023-06-15  3:28       ` Ani Sinha
2023-06-14 14:22 ` Michael S. Tsirkin
2023-06-14 16:39   ` Ani Sinha
2023-06-14 20:53     ` Michael S. Tsirkin
2023-06-15  3:28       ` Ani Sinha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230614165051-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=anisinha@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=jusual@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).