Skip to contentSkip to conversation

PCI: Disable ATS via quirk before notifying IOMMU drivers

PATCH Superseded David Matlack 2 participants 7 messages Feb 23 – Feb 25 PCI

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: Disable ATS via quirk before notifying IOMMU drivers

Ensure that PCI devices that have ATS disabled via quirk have it disabled before IOMMU drivers are notified about the device. Otherwise the IOMMU driver will see that the device has ATS enabled during probing and then later it will get disabled.

This fixes at least one bug in the Intel IOMMU driver where it adds the device to an rbtree because it sees ATS is enabled, but then ATS gets disabled via quirk. When the device is destroyed (e.g. hot-unplug, VF destruction, etc.) the driver sees that ATS is disabled and does not remove it from the rbtree. This inevitably leads to a use-after-free and corruption of the rbtree.

Fix this by disabling ATS via quirk during "early" fixups instead of "final" fixups.

Fixes a18615b1cfc0 ("PCI: Disable ATS for specific Intel IPU E2000 devices")
Cc Raghavendra Rao Ananta <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Lu Baolu <[email protected]>
---
 drivers/pci/ats.c    |  3 +++
 drivers/pci/quirks.c | 50 ++++++++++++++++++++++----------------------
 include/linux/pci.h  |  1 +
 3 files changed, 29 insertions(+), 25 deletions(-)
drivers/pci/ats.c +3 -0
index ec6c8dbdc5e9..85306198c232 100644
@@ -24,6 +24,9 @@ void pci_ats_init(struct pci_dev *dev)
 	if (pci_ats_disabled())
 		return;
 
+	if (dev->no_ats)
+		return;
+
 	pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ATS);
 	if (!pos)
 		return;
drivers/pci/quirks.c +25 -25

72 lines not on this page · raw message

include/linux/pci.h +1 -0
index 1c270f1d5123..5880942bba65 100644
@@ -537,6 +537,7 @@ struct pci_dev {
 		struct pci_sriov	*sriov;		/* PF: SR-IOV info */
 		struct pci_dev		*physfn;	/* VF: related PF */
 	};
+	unsigned int	no_ats:1;	/* ATS disabled via quirk */
 	u16		ats_cap;	/* ATS Capability offset */
 	u8		ats_stu;	/* ATS Smallest Translation Unit */
 #endif

base-commit: a95f71ad3e2e224277508e006580c333d0a5fe36

Signature · 1 line
2.53.0.371.g1d285c8824-goog
#1 lore raw
Quoted 12 lines · David Matlack

Ensure that PCI devices that have ATS disabled via quirk have it disabled before IOMMU drivers are notified about the device. Otherwise the IOMMU driver will see that the device has ATS enabled during probing and then later it will get disabled.

This fixes at least one bug in the Intel IOMMU driver where it adds the device to an rbtree because it sees ATS is enabled, but then ATS gets disabled via quirk. When the device is destroyed (e.g. hot-unplug, VF destruction, etc.) the driver sees that ATS is disabled and does not remove it from the rbtree. This inevitably leads to a use-after-free and corruption of the rbtree.

Quoted 2 lines

Fix this by disabling ATS via quirk during "early" fixups instead of "final" fixups.

Hmm... Sounds to me like a premature disablement, but I leave it the experts. What I think about the case, that IOMMU should be probably fixed to avoid such situation for all level of quirks. Can it be feasible?

Quoted 6 lines
Fixes a18615b1cfc0 ("PCI: Disable ATS for specific Intel IPU E2000 devices")
Cc Raghavendra Rao Ananta <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Lu Baolu <[email protected]>

These...

Quoted 2 lines

---

...may go here with the same effect on email, but reducing the unneeded noise in the actual Git history.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 14 lines · Andy Shevchenko
Quoted 12 lines · David Matlack

Ensure that PCI devices that have ATS disabled via quirk have it disabled before IOMMU drivers are notified about the device. Otherwise the IOMMU driver will see that the device has ATS enabled during probing and then later it will get disabled.

This fixes at least one bug in the Intel IOMMU driver where it adds the device to an rbtree because it sees ATS is enabled, but then ATS gets disabled via quirk. When the device is destroyed (e.g. hot-unplug, VF destruction, etc.) the driver sees that ATS is disabled and does not remove it from the rbtree. This inevitably leads to a use-after-free and corruption of the rbtree.

Quoted 4 lines
Quoted 2 lines

Fix this by disabling ATS via quirk during "early" fixups instead of "final" fixups.

Hmm... Sounds to me like a premature disablement, but I leave it the experts.

What do you mean by "premature disablement"?

Quoted 2 lines

What I think about the case, that IOMMU should be probably fixed to avoid such situation for all level of quirks. Can it be feasible?

What do you mean by the "IOMMU should be fixed"? Are you saying the IOMMU should be prepared to handle quirks disabling features on devices after the IOMMU driver is notified about a device?

Quoted 8 lines
Quoted 7 lines
Fixes a18615b1cfc0 ("PCI: Disable ATS for specific Intel IPU E2000 devices")
Cc Raghavendra Rao Ananta <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Lu Baolu <[email protected]>
Quoted 7 lines

These...

Quoted 2 lines

---

...may go here with the same effect on email, but reducing the unneeded noise in the actual Git history.

Ahh, will do. Thanks for the tip.

#3 lore raw
Quoted 10 lines · David Matlack
Quoted 6 lines · Andy Shevchenko
Quoted 2 lines · David Matlack

Fix this by disabling ATS via quirk during "early" fixups instead of "final" fixups.

Hmm... Sounds to me like a premature disablement, but I leave it the experts.

What do you mean by "premature disablement"?

On early stage instead of final stage.

Quoted 6 lines
Quoted 2 lines

What I think about the case, that IOMMU should be probably fixed to avoid such situation for all level of quirks. Can it be feasible?

What do you mean by the "IOMMU should be fixed"? Are you saying the IOMMU should be prepared to handle quirks disabling features on devices after the IOMMU driver is notified about a device?

Something like this, yes. At least the commit message is unclear why "This fixes at least one bug in the Intel IOMMU driver..." not in IOMMU driver code.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
Quoted 6 lines · Andy Shevchenko
Quoted 3 lines · David Matlack
Quoted 1 line · Andy Shevchenko

On Mon, Feb 23, 2026 at 06:40:16PM +0000, David Matlack wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Fix this by disabling ATS via quirk during "early" fixups instead of "final" fixups.

Hmm... Sounds to me like a premature disablement, but I leave it the experts.

What do you mean by "premature disablement"?

On early stage instead of final stage.

Is your concern that applying the quirk at early stage won't be effective because ATS will be enabled after early fixups are applied? To prevent that the patch adds a no_ats bit that blocks ATS enablement after early fixups.

If not that, I guess I am wondering what is your concern from a functional level.

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

What I think about the case, that IOMMU should be probably fixed to avoid such situation for all level of quirks. Can it be feasible?

What do you mean by the "IOMMU should be fixed"? Are you saying the IOMMU should be prepared to handle quirks disabling features on devices after the IOMMU driver is notified about a device?

Something like this, yes. At least the commit message is unclear why "This fixes at least one bug in the Intel IOMMU driver..." not in IOMMU driver code.

Gotcha. It felt wrong to have the IOMMU driver be notified about a device with ATS enabled and then have ATS later disabled. It seem like it would add complexity to the IOMMU drivers to handle such a case, and would be much simpler to have ATS in its final state when the IOMMU driver is notified about the device being created.

But maybe Lu Baolu and David Woodhouse (Intel IOMMU maintainers) can comment if they prefer to handle this in the Intel IOMMU driver.

#5 lore raw
Quoted 6 lines · David Matlack
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · David Matlack
Quoted 1 line · Andy Shevchenko

On Mon, Feb 23, 2026 at 06:40:16PM +0000, David Matlack wrote:

...

Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Fix this by disabling ATS via quirk during "early" fixups instead of "final" fixups.

Hmm... Sounds to me like a premature disablement, but I leave it the experts.

What do you mean by "premature disablement"?

On early stage instead of final stage.

Is your concern that applying the quirk at early stage won't be effective because ATS will be enabled after early fixups are applied?

My concern that applying this quirk too early may affect something else. But I'm not an expert in the PCI mysterious ways, I just share my feelings.

Quoted 17 lines

To prevent that the patch adds a no_ats bit that blocks ATS enablement after early fixups.

If not that, I guess I am wondering what is your concern from a functional level.

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

What I think about the case, that IOMMU should be probably fixed to avoid such situation for all level of quirks. Can it be feasible?

What do you mean by the "IOMMU should be fixed"? Are you saying the IOMMU should be prepared to handle quirks disabling features on devices after the IOMMU driver is notified about a device?

Something like this, yes. At least the commit message is unclear why "This fixes at least one bug in the Intel IOMMU driver..." not in IOMMU driver code.

Quoted 5 lines

Gotcha. It felt wrong to have the IOMMU driver be notified about a device with ATS enabled and then have ATS later disabled. It seem like it would add complexity to the IOMMU drivers to handle such a case, and would be much simpler to have ATS in its final state when the IOMMU driver is notified about the device being created.

Can this be elaborated in the commit message? Then a reviewer will not have questions like me.

Quoted 2 lines

But maybe Lu Baolu and David Woodhouse (Intel IOMMU maintainers) can comment if they prefer to handle this in the Intel IOMMU driver.

I agree that his input may be valuable in this discussion.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw
Quoted 18 lines · Andy Shevchenko
Quoted 6 lines · David Matlack
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · David Matlack
Quoted 1 line · Andy Shevchenko

On Mon, Feb 23, 2026 at 06:40:16PM +0000, David Matlack wrote:

...

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Fix this by disabling ATS via quirk during "early" fixups instead of "final" fixups.

Hmm... Sounds to me like a premature disablement, but I leave it the experts.

What do you mean by "premature disablement"?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

On early stage instead of final stage.

Is your concern that applying the quirk at early stage won't be effective because ATS will be enabled after early fixups are applied?

My concern that applying this quirk too early may affect something else. But I'm not an expert in the PCI mysterious ways, I just share my feelings.

Ahh ok, gotcha. Thanks for the raising the concern.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

What I think about the case, that IOMMU should be probably fixed to avoid such situation for all level of quirks. Can it be feasible?

What do you mean by the "IOMMU should be fixed"? Are you saying the IOMMU should be prepared to handle quirks disabling features on devices after the IOMMU driver is notified about a device?

Something like this, yes. At least the commit message is unclear why "This fixes at least one bug in the Intel IOMMU driver..." not in IOMMU driver code.

Quoted 8 lines
Quoted 5 lines

Gotcha. It felt wrong to have the IOMMU driver be notified about a device with ATS enabled and then have ATS later disabled. It seem like it would add complexity to the IOMMU drivers to handle such a case, and would be much simpler to have ATS in its final state when the IOMMU driver is notified about the device being created.

Can this be elaborated in the commit message? Then a reviewer will not have questions like me.

Will do in v2, thanks for the suggestion.