Re: [PATCH v3] PCI: Ensure ATS disabled via quirk before notifying IOMMU drivers

From: Pranjal Shrivastava

Date: Fri May 29 2026 - 16:15:58 EST


On Fri, Apr 03, 2026 at 10:27:50PM +0000, David Matlack wrote:
> Ensure that PCI devices always have ATS disable via quirk before IOMMU
> drivers are notified about the device. Fix this by converting the
> existing quirks from final to header fixups and changing the quirk logic
> to set a new no_ats bit in struct pci_dev that prevents pci_dev.ats_cap
> from ever getting set.
>
> Use header fixups instead of early fixups since not enough of struct
> pci_dev is set up in during early fixups: quirk_amd_harvest_no_ats()
> needs subsystem_device and subsystem_vendor to be set.
>
> This change ensures that pci_ats_supported() always takes quirks into
> account during iommu_ops.probe_device(), when IOMMU drivers are notified
> about devices, and that pci_ats_supported() returns the same value when
> the device is released in iommu_ops.release_device().
>
> Notably, the Intel IOMMU driver uses pci_ats_supported() in
> probe/release to determine whether to add/remove a device from a data
> structure, which easily leads to a use-after-free without this fix.
>
> This change also makes disabling ATS via quirk behave the same way as
> the pci=noats command line option, in that pci_ats_init() bails
> immediately and never initializes pci_dev.ats_cap.
>
> Note: In practice this fix only matters for PCI devices created after
> IOMMU bus notifiers are set up (e.g. hot-plugged devices and VFs).
>
> Fixes: a18615b1cfc0 ("PCI: Disable ATS for specific Intel IPU E2000 devices")
> Closes: https://lore.kernel.org/linux-iommu/aYUQ_HkDJU9kjsUl@xxxxxxxxxx/
> Signed-off-by: David Matlack <dmatlack@xxxxxxxxxx>
> ---
> v3:
> - Clarify in commit message that only devices added after boot are
> affected (Baolu)
> - Use header fixups instead of early to avoid breaking
> quirk_amd_harvest_no_ats() (Sashiko)
> - Use u8 instead of unsigned int for no_ats to avoid affecting the
> offsets of existing fields in struct pci_dev (me)
>
> v2: https://lore.kernel.org/linux-pci/20260327211649.3816010-1-dmatlack@xxxxxxxxxx/
>
> v1: https://lore.kernel.org/linux-pci/20260223184017.688212-1-dmatlack@xxxxxxxxxx/
>
> Cc: Raghavendra Rao Ananta <rananta@xxxxxxxxxx>
> Cc: David Woodhouse <dwmw2@xxxxxxxxxxxxx>
> Cc: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
> Cc: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
>
> drivers/pci/ats.c | 2 +-
> drivers/pci/quirks.c | 50 ++++++++++++++++++++++----------------------
> include/linux/pci.h | 1 +
> 3 files changed, 27 insertions(+), 26 deletions(-)
>

Applying ATS quirks during the HEADER phase seems correct for the IOMMU
drivers to get the right view. I observed side effects due to the quirks
being applied in the FINAL phase [1] which seem to go away with this fix.

Reviewed-by: Pranjal Shrivastava <praan@xxxxxxxxxx>
Tested-by: Pranjal Shrivastava <praan@xxxxxxxxxx>

Thanks,
Praan

[1] https://lore.kernel.org/all/20260504163842.2692314-1-praan@xxxxxxxxxx/