[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v7 10/12] vpci: add initial support for virtual PCI bus topology


  • To: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 21 Jun 2023 14:06:14 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HzDCKPXt3E150ts+tNMv5iwq+ySNu/Tkpv8Q+i81QZ0=; b=Duo/o7anLYllYXK9JsyCOOMnafY7pkU2flIw5BrxWiFpgBYEd4Np+qjVxn+ITb2qSC7dselXdiHaMZPlXtm9tXFZXdPbhUM7kVh9xE/LDHXd105qlRCe/Jtj+yao2tBFq7DCktMWjoJqhXmwZ7yjSKOG3NQP6OIroLlY3/XoXLtMeWfGWqMRgEt60YWDbV0a3kGqYxaPwP63jCfWaZZSp46tzfu9njOXQhwDqiNsipceKfi9ksZQzjgTRlk3nK+Ti/q+gv3+g7NUOPu65RfX2dFRtbz/Rv1vvLvu/6UMmjtU8YopjO4GQb3N2DbOOeo32Isfmyn8QR+ArlLiGakSdg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eEZb47cg5Mn5wkYIUpKrHUs5Ydvz3MHOxF2/RKZmoT0XsMC/OR3gkPI7a0x8HY2xj1vhW769et7N1vEuSapCtiIA89Qtuy1INKUFexjRw2bpICPCKWeaG135xiL2GaO1FUt2NjddNv/Dw6olF6otMIDSxMEBGYujRlOBX20lJSicMXW9OnXkCbpsm3wQeG2hlcNIEsF8CjG9b4D37dO2M8MS+RzGydgp0XaFxNAdKYZynBYfNBDh4U25tCsBOOVgGUtlhWhyrfYDVd2F7vn4YSSenHPkm/4AVOBgOEgCdPdvuUBTmHA+LzQGf5JCo9+HSZO/j485OZJjFzxgk6GDfg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 21 Jun 2023 12:06:29 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 13.06.2023 12:32, Volodymyr Babchuk wrote:
> @@ -121,6 +124,62 @@ int vpci_add_handlers(struct pci_dev *pdev)
>  }
>  
>  #ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT
> +static int add_virtual_device(struct pci_dev *pdev)
> +{
> +    struct domain *d = pdev->domain;
> +    pci_sbdf_t sbdf = { 0 };
> +    unsigned long new_dev_number;
> +
> +    if ( is_hardware_domain(d) )
> +        return 0;
> +
> +    ASSERT(pcidevs_locked());
> +
> +    /*
> +     * Each PCI bus supports 32 devices/slots at max or up to 256 when
> +     * there are multi-function ones which are not yet supported.
> +     */
> +    if ( pdev->info.is_extfn )
> +    {
> +        gdprintk(XENLOG_ERR, "%pp: only function 0 passthrough supported\n",
> +                 &pdev->sbdf);
> +        return -EOPNOTSUPP;
> +    }
> +
> +    new_dev_number = find_first_zero_bit(d->vpci_dev_assigned_map,
> +                                         VPCI_MAX_VIRT_DEV);
> +    if ( new_dev_number >= VPCI_MAX_VIRT_DEV )
> +        return -ENOSPC;
> +
> +    __set_bit(new_dev_number, &d->vpci_dev_assigned_map);

Since the find-and-set can't easily be atomic, the lock used here (
asserted to be held above) needs to be the same as ...

> +    /*
> +     * Both segment and bus number are 0:
> +     *  - we emulate a single host bridge for the guest, e.g. segment 0
> +     *  - with bus 0 the virtual devices are seen as embedded
> +     *    endpoints behind the root complex
> +     *
> +     * TODO: add support for multi-function devices.
> +     */
> +    sbdf.devfn = PCI_DEVFN(new_dev_number, 0);
> +    pdev->vpci->guest_sbdf = sbdf;
> +
> +    return 0;
> +
> +}
> +
> +static void vpci_remove_virtual_device(const struct pci_dev *pdev)
> +{
> +    write_lock(&pdev->domain->vpci_rwlock);
> +    if ( pdev->vpci )
> +    {
> +        __clear_bit(pdev->vpci->guest_sbdf.dev,
> +                    &pdev->domain->vpci_dev_assigned_map);
> +        pdev->vpci->guest_sbdf.sbdf = ~0;
> +    }
> +    write_unlock(&pdev->domain->vpci_rwlock);

... the one used here.

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.