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

Re: [PATCH v8 1/3] xen/pci: introduce PF<->VF links


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • Date: Mon, 25 Nov 2024 11:20:03 -0500
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=56FSmCZmzqkiLDtcIj/w388Am0xxIzp7LIQ1gUTN+3c=; b=LmQVJFPrWXsuMPIzpb6afbxxNyzO2Jl102dCEf05Hjo6BjDObGITQkmLxLsP23Nq9sYqmHIE5W+hrKOrrSN/BIx0+n7Cd2TqXt20HR6aVsjjCQ3z9cHNP1YxkuImJy/+7HFWS0+D8aDGWq9EzKIiEQ31yTghgX1L0E2MkxTk7PzXBSxkFhaHuZu71TbF2suNutiT+xoTphBbKoasJ09C1FzU2txazR7JvLYJbHDQbVSKpYPFibVjmJuUJNdGfLTJ3iGy0A390/S9X6NNBTUat2yyA3Xs8RXhzk+L1WM4sLgN16zrRkFG0zgdsrtyoO58JvBSaTGpGYEg0TiChSX1Zg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dByhgXLebWfI2TS/CidApe4zKf4U4C+GI8WdHHJ6wKGECcV050xsMIna2rq8CtLI4R8rcH612isaZR9h+m5o+uMXJEXHFIVF5OwNlouPj0wWn6U5rfzwFRUCtEaFg6/YQwB4cUQbLdGOvjnccb6Ek9ZRf6pzLbr+JsQRbcbOjHjqASi9czmPR+mC45d5HozgTp/22Ph1XrZ5fLSjvDsv8q7GSj/YyXMfSr4VnDBsrcalxfGeTVJCvBWetTKAWuh9qxQ/FGnQar0xvFgkuhAMqAE8FkC/SrziJcWw2UhKq49u4vDcFpami5cJgcYibh0pknwifX1yUTEF/pB06PV6UQ==
  • Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, "Stefano Stabellini" <sstabellini@xxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 25 Nov 2024 16:20:23 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 11/25/24 11:08, Jan Beulich wrote:
> On 15.11.2024 17:09, Stewart Hildebrand wrote:
>> Add links between a VF's struct pci_dev and its associated PF struct
>> pci_dev.
>>
>> The hardware domain is expected to remove the associated VFs before
>> removing the PF. If removal happens out of order, print a warning and
>> return an error. This means that VFs can only exist with an associated
>> PF.
>>
>> Additionally, if the hardware domain attempts to remove a PF with VFs
>> still present, mark the PF and VFs broken, because Linux Dom0 has been
>> observed to not respect the error returned.
>>
>> Move the calls to pci_get_pdev() and pci_add_device() down to avoid
>> dropping and re-acquiring the pcidevs_lock().
>>
>> Check !pdev->pf_pdev before adding the VF to the list to guard against
>> adding it multiple times.
>>
>> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
> 
> Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>

Thanks!

>> @@ -698,12 +691,48 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,
>>      if ( info )
>>      {
>>          pdev->info = *info;
>> -        /*
>> -         * VF's 'is_extfn' field is used to indicate whether its PF is an
>> -         * extended function.
>> -         */
>>          if ( pdev->info.is_virtfn )
>> -            pdev->info.is_extfn = pf_is_extfn;
>> +        {
>> +            struct pci_dev *pf_pdev =
>> +                pci_get_pdev(NULL, PCI_SBDF(seg, info->physfn.bus,
>> +                                            info->physfn.devfn));
>> +
>> +            if ( !pf_pdev )
>> +            {
>> +                ret = pci_add_device(seg, info->physfn.bus, 
>> info->physfn.devfn,
>> +                                     NULL, node);
>> +                if ( ret )
>> +                {
>> +                    printk(XENLOG_WARNING
>> +                           "Failed to add SR-IOV device PF %pp for VF 
>> %pp\n",
>> +                           &PCI_SBDF(seg, info->physfn.bus, 
>> info->physfn.devfn),
>> +                           &pdev->sbdf);
>> +                    free_pdev(pseg, pdev);
>> +                    goto out;
>> +                }
>> +                pf_pdev = pci_get_pdev(NULL, PCI_SBDF(seg, info->physfn.bus,
>> +                                                      info->physfn.devfn));
>> +                if ( !pf_pdev )
>> +                {
>> +                    printk(XENLOG_ERR
>> +                           "Inconsistent PCI state: failed to find newly 
>> added PF %pp for VF %pp\n",
>> +                           &PCI_SBDF(seg, info->physfn.bus, 
>> info->physfn.devfn),
>> +                           &pdev->sbdf);
>> +                    ASSERT_UNREACHABLE();
>> +                    free_pdev(pseg, pdev);
>> +                    ret = -EILSEQ;
>> +                    goto out;
>> +                }
>> +            }
>> +
>> +            if ( !pdev->pf_pdev )
>> +            {
>> +                /* VF inherits its 'is_extfn' from PF */
>> +                pdev->info.is_extfn = pf_pdev->info.is_extfn;
>> +                list_add(&pdev->vf_list, &pf_pdev->vf_list);
>> +                pdev->pf_pdev = pf_pdev;
> 
> As a general pattern, I think filling fields before adding to lists is 
> preferable.
> For now it doesn't really matter here (lock held here and while removing), yet
> still: Thoughts towards flipping the last two lines above, perhaps while 
> committing?

I'm OK with that, feel free to do so.



 


Rackspace

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