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?
> --- 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