On Wed, Sep 24, 2025 at 08:49:26PM +0100, Robin Murphy wrote:
[...]
I don't doubt that the current code doesn't detect presence or use of IOMMU until later. But that feels like an implementation defect because logically the IOMMU is upstream of any PCI device that uses it, so architecturally I would expect it to be *possible* to detect it before PCI enumeration.
More to the point, it's not at all obvious how to infer that 'iommu-map' in the devicetree means the IOMMU will be used.
Indeed, I would say the way to go down that route would be to echo what we do for "iommus", and defer probing the entire host controller driver until the targets of an "iommu-map" are either present or assumed to never be appearing. (And of course an ACPI equivalent for that would be tricky...)
Maybe we should just call pci_enable_acs() only when the iommu is detected for the device? But ofc, this is not possible for non-OF platforms as they tend to call pci_request_acs() pretty early.
However, even that isn't necessarily the full solution, as just as it's not really appropriate for PCI to force ACS without knowing whether an IOMMU is actually present to make it meaningful, it's also not strictly appropriate for an IOMMU driver to request ACS globally without knowing that it actually serves any relevant PCIe devices. Even in the ideal scenario, I think the point of actually knowing is still a bit too late for the current API design:
pci_device_add pci_init_capabilities pci_acs_init pci_enable_acs device_add iommu_bus_notifier iommu_probe_device //logically, request ACS for dev here
(at the moment, iommu_probe_device() will actually end up calling into the same of_iommu_configure()->pci_request_acs() path, but the plan is still to eventually shorten and streamline that.)
What is worrying me is that of_iommu_configure() is called for each PCI device, as opposed to just one time on other platforms. But I think that's a good thing to have as the IOMMU driver can have a per-device ACS policy, instead of a global one.
I guess we might want to separate the actual ACS enablement from the basic capability init, or at least perhaps just call pci_enable_acs() again after the IOMMU notifier may have changed the policy?
Is this applicable to other platforms as well? Not just OF?
- Mani