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

Re: [PATCH v1 3/3] xen/pci: add discovered PCI device at boot


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Mykyta Poturai <Mykyta_Poturai@xxxxxxxx>
  • Date: Tue, 12 Aug 2025 11:09:57 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • 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=7CV0EefV+zCVZHjjF/2P4lNAwLrdiOMUMEiXIP4Iqtg=; b=KpyIcRclx5jZyPk9SRhBjh/LoF2VKndpVHBJ4ZHNro8kTDT69lxk7s9iYnSnJH8D8d88PKpRrDPzG6LEJNUP+kU/jFFS46bmfLor3MtR5uXKjVgW6sARq+2doauDUqiAPQcpoHZxvM/NoVNERvsGA4/CyUK0jSE+Yva6IiWw4M4di/atsYY98kbFp2VNlBwAUTVy48I0v58RfpUqCwzJEcDWRPRvlGolChH3noUwsQC5BDU5O/PTH7mdFZTA2oHE7wUuP0RWZ31tzb/BTjjNQV56b6zYWJf46IiSsTP+Ml554jgNNTn1AHAtE8kS5qdl5YX6zFBmgmQkgJ2jXmE4GQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FEQS/IfWViIuznv3eEEvRUhQdCzWSse5bVeI72MQ3uLg5szHnuFOrdVrNL/BauJH32kaBxn0anynCCU3mKiUi3p8cwLjPzthPAZCxxy3j5d2dG6G/TjD2cagkN/JosByGi3RfzVQaKqMAS33BodLaNxuQy1EuiMm9HwZPZrbdoRkLh8lx8F4KMTSVcQMzGLktDcIdpz2pgMm5q5iE1weygUB2ZQZQUdDJTXku8/3sFYHI5YkbicF0Rvh2LAAnQBkO+px/XA0E45jnjJBWVUeaKKfLiTomJDXJWpwyWbgguYFR11Tht4JiNxH0is7pd/jgLnGHNZ/VMtGM9nloCC5fQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Luca Fancellu <luca.fancellu@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 12 Aug 2025 11:10:08 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHcAsXVA3qngHqyPEewy8MzwqQRRrRSL/eAgAy9wYA=
  • Thread-topic: [PATCH v1 3/3] xen/pci: add discovered PCI device at boot

On 04.08.25 11:35, Jan Beulich wrote:
> On 01.08.2025 11:22, Mykyta Poturai wrote:
>> Create add_discovered_pci_devices function that calls pci_device_add
>> on every PCI device discovered.
>> The devices will be added to dom_io so that they can be assigned
>> later to other domains.
> 
> And why's the intermediate step necessary? IOW can't they be assigned to their
> target domains right away, and only whatever's left would go to DOM_IO?

For Dom0less case, guest domains are not yet created at this point.

>> --- a/xen/drivers/passthrough/pci.c
>> +++ b/xen/drivers/passthrough/pci.c
>> @@ -1180,6 +1180,34 @@ int __init scan_pci_devices(void)
>>       return ret;
>>   }
>>   
>> +static int __init _add_discovered_pci_devices(struct pci_seg *pseg, void 
>> *arg)
>> +{
>> +    struct pci_dev *pdev;
>> +    int ret = 0;
>> +
>> +    list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )
>> +    {
>> +        ret = pci_add_device(dom_io, pdev->seg, pdev->bus, pdev->devfn, 
>> NULL,
>> +                             NUMA_NO_NODE);
>> +        if ( ret < 0 )
>> +        {
>> +            printk(XENLOG_ERR
>> +                   "%pp: Failure adding the discovered pci device (Error 
>> %d)\n",
>> +                   &pdev->sbdf, ret);
>> +            break;
>> +        }
>> +    }
>> +
>> +    return ret;
>> +}
>> +
>> +void __init add_discovered_pci_devices(void)
>> +{
>> +    pcidevs_lock();
>> +    pci_segments_iterate(_add_discovered_pci_devices, NULL);
>> +    pcidevs_unlock();
>> +}
> 
> This looks to merely be a specialized form of what ...
> 
>>   struct setup_hwdom {
>>       struct domain *d;
>>       int (*handler)(uint8_t devfn, struct pci_dev *pdev);
> 
> ... follows below here. By generalizing what we have (perhaps from the top, 
> i.e.
> iommu_hwdom_init()), you'd also avoid violating Misra rule 2.1 on x86, as you 
> add
> unreachable code there.
> 
> Jan

Can you please elaborate a little further on how you see this 
generalization? With routines you mentioned being specifically for 
hwdom, which may not exist, and the different approaches to PCI 
initialization on Arm/x86 (as far as I understand on x86 all of the PCI 
related stuff is initialized from iommu helpers, while Arm has a 
dedicated init step) I am afraid I can't find a nice point of contact to 
generalize this, but I can be missing somthing due to unfamiliarity with 
x86 code.

Another way of addressing possible MISRA violation I can see is moving 
the add_discovered_pci_devices to xen/arch/arm/pci/pci.c so it will only 
be compiled when used.

-- 
Mykyta

 


Rackspace

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