From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XLqw2-0001b5-QI for qemu-devel@nongnu.org; Mon, 25 Aug 2014 05:51:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XLqvt-0004YY-FY for qemu-devel@nongnu.org; Mon, 25 Aug 2014 05:51:34 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:32476) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XLqvt-0004YC-84 for qemu-devel@nongnu.org; Mon, 25 Aug 2014 05:51:25 -0400 Message-ID: <1408960268.14053.205.camel@abi.no.oracle.com> From: Knut Omang Date: Mon, 25 Aug 2014 11:51:08 +0200 In-Reply-To: <33183CC9F5247A488A2544077AF1902086D6E3B9@SZXEMA503-MBS.china.huawei.com> References: <1408614466-17596-1-git-send-email-arei.gonglei@huawei.com> <1408614466-17596-3-git-send-email-arei.gonglei@huawei.com> <1408957176.14053.177.camel@abi.no.oracle.com> <33183CC9F5247A488A2544077AF1902086D6E3B9@SZXEMA503-MBS.china.huawei.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 2/2] pci: add check for pcie root ports and downstream ports List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Gonglei (Arei)" Cc: "peter.crosthwaite@xilinx.com" , "Huangweidong (C)" , "marcel.a@redhat.com" , "armbru@redhat.com" , "mst@redhat.com" , Luonengjun , "qemu-devel@nongnu.org" , "Huangpeng (Peter)" , "pbonzini@redhat.com" , "imammedo@redhat.com" , "afaerber@suse.de" On Mon, 2014-08-25 at 09:23 +0000, Gonglei (Arei) wrote: > > -----Original Message----- > > From: Knut Omang [mailto:knut.omang@oracle.com] > > Subject: Re: [Qemu-devel] [PATCH v2 2/2] pci: add check for pcie root ports and > > downstream ports > > > > On Thu, 2014-08-21 at 17:47 +0800, arei.gonglei@huawei.com wrote: > > > From: Gonglei > > > > > > If ARI Forwarding is disabled, according to PCIe spec > > > section 7.3.1, only slot 0 with the device attached to > > > logic bus representing the link from downstream > > > ports and root ports. > > > > > > So, adding check for PCIe downstream ports and root ports, > > > which avoid useless operation, both hotplug and coldplug. > > > > > > Signed-off-by: Gonglei > > > --- > > > hw/pci/pci.c | 51 > > +++++++++++++++++++++++++++++++++++++++++++++++++++ > > > 1 file changed, 51 insertions(+) > > > > > > diff --git a/hw/pci/pci.c b/hw/pci/pci.c > > > index daeaeac..aa0af0c 100644 > > > --- a/hw/pci/pci.c > > > +++ b/hw/pci/pci.c > > > @@ -773,6 +773,52 @@ static int pci_init_multifunction(PCIBus *bus, > > PCIDevice *dev) > > > return 0; > > > } > > > > > > +static int pci_check_pcie_port(PCIBus *bus, PCIDevice *dev) > > > +{ > > > + Object *obj = OBJECT(bus); > > > + > > > + if (pci_bus_is_root(bus)) { > > > + return 0; > > > + } > > > + > > > + if (object_dynamic_cast(obj, TYPE_PCIE_BUS)) { > > > + DeviceState *parent = qbus_get_parent(BUS(obj)); > > > + PCIDevice *pci_dev = PCI_DEVICE(parent); > > > + uint8_t port_type; > > > + /* > > > + * Root ports and downstream ports of switches are the hot > > > + * pluggable ports in a PCI Express hierarchy. > > > + * PCI Express supports chip-to-chip interconnect, a PCIe link can > > > + * only connect one pci device/Switch/EndPoint or PCI-bridge. > > > + * > > > + * 7.3. Configuration Transaction Rules (PCI Express specification > > 3.0) > > > + * 7.3.1. Device Number > > > + * > > > + * Downstream Ports that do not have ARI Forwarding enabled > > must > > > + * associate only Device 0 with the device attached to the Logical > > Bus > > > + * representing the Link from the Port. > > > + * > > > + * If ARI Forwarding is not enabled on root ports and downstream > > > + * ports, only support the devices with slot non-0, regardless of > > > + * hotplug or coldplug. > > > + */ > > > > My interpretation of this section of the spec is that if ARI forwarding > > is not available, only the normal 8 functions can be accessed for each > > device, eg. device/functions 0.0 -> 0.7 - if a device has more than 8 > > functions, it will need the second device's namespace, eg. devfn 1.0++, > > which would not be routed correctly in a non-ari forward capable device. > > > Yes. > > > As far as I understand, with this fix you restrict an non-ARI capable > > switch to only expose one device? > > > Yes. Otherwise it will confuse users who configure a device with 'slot > 0 ', > and the interface return OK, but the guest os report errors as below: > > [ 159.035250] Pciehp 0000:05:00.0:pcie24: Button pressed on Slot (0 - 4) > [ 159.035274] Pciehp 0000:05:00.0:pcie24: Card present on Slot (0 - 4) > [ 159.036517] Pciehp 0000:05:00.0:pcie24: PCI slot #0 - 4 - powering on due to button press. > [ 159.188049] Pciehp 0000:05:00.0:pcie24: Failed to check link status > [ 159.201968] Pciehp 0000:05:00.0:pcie24: Card not present on Slot (0 - 4) > [ 159.202529] Pciehp 0000:05:00.0:pcie24: Already disabled on Slot (0 - 4) Ah - I see! I think this also explains why I have been seeing this error and failure to hotplug recently (with an ARIfwd enabled root port and an ARI capable device)... It seems your patch is preventing this from happening in the non-arifwd case, but will still be a problem with a single ARI capable device if ARIfwd is enabled, even if no more than one function is exposed by the device? Best regards, Knut > Best regards, > -Gonglei > > > Knut > > > > > + port_type = pcie_cap_get_type(pci_dev); > > > + if (port_type == PCI_EXP_TYPE_DOWNSTREAM || > > > + port_type == PCI_EXP_TYPE_ROOT_PORT) { > > > + if (!pcie_cap_is_ari_enabled(pci_dev)) { > > > + if (PCI_SLOT(dev->devfn) != 0) { > > > + error_report("PCIe: Port's ARI Forwarding is > > disabled, " > > > + "device can't be populated in > > slot %d", > > > + PCI_SLOT(dev->devfn)); > > > + return -1; > > > + } > > > + } > > > + } > > > + } > > > + > > > + return 0; > > > +} > > > + > > > static void pci_config_alloc(PCIDevice *pci_dev) > > > { > > > int config_size = pci_config_size(pci_dev); > > > @@ -827,6 +873,11 @@ static PCIDevice > > *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, > > > > > > pci_dev->bus = bus; > > > pci_dev->devfn = devfn; > > > + > > > + if (pci_check_pcie_port(bus, pci_dev)) { > > > + return NULL; > > > + } > > > + > > > dma_as = pci_device_iommu_address_space(pci_dev); > > > > > > memory_region_init_alias(&pci_dev->bus_master_enable_region, > > >