The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v3 0/2] PCI/ATS: Disable ATS when ACS TB is set upstream
@ 2026-11-20  0:23 Danny Gonzalez
  2026-11-20  0:23 ` [PATCH v3 1/2] iommu: Track whether pci_dev_reset_iommu_done() needs to restore state Danny Gonzalez
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Danny Gonzalez @ 2026-11-20  0:23 UTC (permalink / raw)
  To: Bjorn Helgaas, Joerg Roedel, Will Deacon, Robin Murphy
  Cc: Rafael J . Wysocki, Len Brown, Jason Gunthorpe, Nicolin Chen,
	Lu Baolu, Kevin Tian, decot, praan, sheenamo, linux-pci, iommu,
	linux-acpi, linux-kernel, Danny Gonzalez

This series disables ATS on endpoints when an upstream bridge has ACS
Translation Blocking (PCI_ACS_TB) enabled, preventing ACS Violations on
translated DMA requests.

Patch 1/2 stops pci_dev_reset_iommu_done() from re-evaluating
pci_ats_supported() and dev_has_iommu() independently from
pci_dev_reset_iommu_prepare(), tracking whether state needs to be
restored via a @restore output flag instead. It can be merged
independently.

Patch 2/2 updates pci_ats_supported() to walk upstream bridges and
return false if any bridge has PCI_ACS_TB set in PCI_ACS_CTRL.

Changes since v2:
 - Add patch 1/2 to track IOMMU reset restore state between
   pci_dev_reset_iommu_prepare() and pci_dev_reset_iommu_done()
 - Move the upstream ACS TB check back into pci_ats_supported(),
   dropping pci_ats_check_acs() and changes to pci-driver.c and pci.h
 - Read PCI_ACS_CTRL directly and check the return value and
   PCI_POSSIBLE_ERROR() so inaccessible bridges are not treated as
   having PCI_ACS_TB set
 - Remove the pci_warn_once() logging and helper function

Changes since v1 (v2, based on Sashiko review):
 - Move the upstream ACS TB check from pci_ats_supported() into
   pci_ats_check_acs() called after pci_enable_acs()
 - Use pci_acs_enabled() instead of reading PCI_ACS_CTRL directly

Danny Gonzalez (2):
  iommu: Track whether pci_dev_reset_iommu_done() needs to restore state
  PCI/ATS: Disable ATS when ACS TB is set upstream

 drivers/iommu/iommu.c  | 14 ++++++++++----
 drivers/pci/ats.c      | 19 +++++++++++++++++++
 drivers/pci/pci-acpi.c |  5 +++--
 drivers/pci/pci.c      | 25 +++++++++++++++----------
 drivers/pci/quirks.c   |  5 +++--
 include/linux/iommu.h  |  9 +++++----
 6 files changed, 55 insertions(+), 22 deletions(-)

-- 
2.56.1.708.g77570a6a1d-goog


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 1/2] iommu: Track whether pci_dev_reset_iommu_done() needs to restore state
  2026-11-20  0:23 [PATCH v3 0/2] PCI/ATS: Disable ATS when ACS TB is set upstream Danny Gonzalez
@ 2026-11-20  0:23 ` Danny Gonzalez
  2026-11-20  0:23 ` [PATCH v3 2/2] PCI/ATS: Disable ATS when ACS TB is set upstream Danny Gonzalez
  2026-11-30 14:32 ` [PATCH v3 0/2] " Pranjal Shrivastava
  2 siblings, 0 replies; 6+ messages in thread
From: Danny Gonzalez @ 2026-11-20  0:23 UTC (permalink / raw)
  To: Bjorn Helgaas, Joerg Roedel, Will Deacon, Robin Murphy
  Cc: Rafael J . Wysocki, Len Brown, Jason Gunthorpe, Nicolin Chen,
	Lu Baolu, Kevin Tian, decot, praan, sheenamo, linux-pci, iommu,
	linux-acpi, linux-kernel, Danny Gonzalez

Currently, pci_dev_reset_iommu_done() relies on the assumption that
pci_ats_supported() and dev_has_iommu() always return the same values
they returned in pci_dev_reset_iommu_prepare(). While that may be true
today, relying on both calls evaluating identically is fragile: if they
ever return different values, gdev->reset_depth, group->recovery_cnt,
group->domain, and gdev->blocked will get out of sync.

Have pci_dev_reset_iommu_prepare() track whether
pci_dev_reset_iommu_done() needs to restore IOMMU state via a @restore
output flag, and pass @restore to pci_dev_reset_iommu_done() instead of
re-evaluating pci_ats_supported() and dev_has_iommu().

Signed-off-by: Danny Gonzalez <digonzal@google.com>
---

v3:
 - New patch based on review feedback to avoid relying on
   pci_ats_supported() and dev_has_iommu() returning identical values
   across pci_dev_reset_iommu_prepare() and pci_dev_reset_iommu_done()

 drivers/iommu/iommu.c  | 14 ++++++++++----
 drivers/pci/pci-acpi.c |  5 +++--
 drivers/pci/pci.c      | 25 +++++++++++++++----------
 drivers/pci/quirks.c   |  5 +++--
 include/linux/iommu.h  |  9 +++++----
 5 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index b486b8bbd1fc..8a563eb38bba 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -4010,6 +4010,7 @@ EXPORT_SYMBOL_NS_GPL(iommu_replace_group_handle, "IOMMUFD_INTERNAL");
 /**
  * pci_dev_reset_iommu_prepare() - Block IOMMU to prepare for a PCI device reset
  * @pdev: PCI device that is going to enter a reset routine
+ * @restore: set to true if pci_dev_reset_iommu_done() needs to restore state
  *
  * The PCIe r6.0, sec 10.3.1 IMPLEMENTATION NOTE recommends to disable and block
  * ATS before initiating a reset. This means that a PCIe device during the reset
@@ -4031,7 +4032,7 @@ EXPORT_SYMBOL_NS_GPL(iommu_replace_group_handle, "IOMMUFD_INTERNAL");
  * case, callers must ensure there will be no racy iommu_release_device() call,
  * which otherwise would UAF the dev->iommu_group pointer.
  */
-int pci_dev_reset_iommu_prepare(struct pci_dev *pdev)
+int pci_dev_reset_iommu_prepare(struct pci_dev *pdev, bool *restore)
 {
 	struct iommu_group *group = pdev->dev.iommu_group;
 	struct group_device *gdev;
@@ -4039,8 +4040,12 @@ int pci_dev_reset_iommu_prepare(struct pci_dev *pdev)
 	void *entry;
 	int ret;
 
-	if (!pci_ats_supported(pdev) || !dev_has_iommu(&pdev->dev))
+	if (!pci_ats_supported(pdev) || !dev_has_iommu(&pdev->dev)) {
+		*restore = false;
 		return 0;
+	}
+
+	*restore = true;
 
 	guard(mutex)(&group->mutex);
 
@@ -4132,6 +4137,7 @@ static bool group_device_dma_alias_is_blocked(struct iommu_group *group,
 /**
  * pci_dev_reset_iommu_done() - Restore IOMMU after a PCI device reset is done
  * @pdev: PCI device that has finished a reset routine
+ * @restore: whether pci_dev_reset_iommu_prepare() blocked the IOMMU
  *
  * After a PCIe device finishes a reset routine, it wants to restore its IOMMU
  * activity, including new translation and cache invalidation, by re-attaching
@@ -4143,14 +4149,14 @@ static bool group_device_dma_alias_is_blocked(struct iommu_group *group,
  * Note that, although unlikely, there is a risk that re-attaching domains might
  * fail due to some unexpected happening like OOM.
  */
-void pci_dev_reset_iommu_done(struct pci_dev *pdev)
+void pci_dev_reset_iommu_done(struct pci_dev *pdev, bool restore)
 {
 	struct iommu_group *group = pdev->dev.iommu_group;
 	struct group_device *gdev;
 	unsigned long pasid;
 	void *entry;
 
-	if (!pci_ats_supported(pdev) || !dev_has_iommu(&pdev->dev))
+	if (!restore)
 		return;
 
 	guard(mutex)(&group->mutex);
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 1150f2fbabf4..83a581796001 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -955,6 +955,7 @@ void pci_set_acpi_fwnode(struct pci_dev *dev)
 int pci_dev_acpi_reset(struct pci_dev *dev, bool probe)
 {
 	acpi_handle handle = ACPI_HANDLE(&dev->dev);
+	bool restore;
 	int ret;
 
 	if (!handle || !acpi_has_method(handle, "_RST"))
@@ -963,7 +964,7 @@ int pci_dev_acpi_reset(struct pci_dev *dev, bool probe)
 	if (probe)
 		return 0;
 
-	ret = pci_dev_reset_iommu_prepare(dev);
+	ret = pci_dev_reset_iommu_prepare(dev, &restore);
 	if (ret) {
 		pci_err(dev, "failed to stop IOMMU for a PCI reset: %d\n", ret);
 		return ret;
@@ -974,7 +975,7 @@ int pci_dev_acpi_reset(struct pci_dev *dev, bool probe)
 		ret = -ENOTTY;
 	}
 
-	pci_dev_reset_iommu_done(dev);
+	pci_dev_reset_iommu_done(dev, restore);
 	return ret;
 }
 
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7c6f2aba8144..087594cc8095 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -4440,6 +4440,7 @@ EXPORT_SYMBOL(pci_wait_for_pending_transaction);
  */
 int pcie_flr(struct pci_dev *dev)
 {
+	bool restore;
 	int ret;
 
 	if (!pci_dev_config_accessible(dev, "FLR"))
@@ -4449,7 +4450,7 @@ int pcie_flr(struct pci_dev *dev)
 		pci_err(dev, "timed out waiting for pending transaction; performing function level reset anyway\n");
 
 	/* Have to call it after waiting for pending DMA transaction */
-	ret = pci_dev_reset_iommu_prepare(dev);
+	ret = pci_dev_reset_iommu_prepare(dev, &restore);
 	if (ret) {
 		pci_err(dev, "failed to stop IOMMU for a PCI reset: %d\n", ret);
 		return ret;
@@ -4469,7 +4470,7 @@ int pcie_flr(struct pci_dev *dev)
 
 	ret = pci_dev_wait(dev, "FLR", PCIE_RESET_READY_POLL_MS);
 done:
-	pci_dev_reset_iommu_done(dev);
+	pci_dev_reset_iommu_done(dev, restore);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(pcie_flr);
@@ -4498,6 +4499,7 @@ EXPORT_SYMBOL_GPL(pcie_reset_flr);
 
 static int pci_af_flr(struct pci_dev *dev, bool probe)
 {
+	bool restore;
 	int ret;
 	int pos;
 	u8 cap;
@@ -4526,7 +4528,7 @@ static int pci_af_flr(struct pci_dev *dev, bool probe)
 		pci_err(dev, "timed out waiting for pending transaction; performing AF function level reset anyway\n");
 
 	/* Have to call it after waiting for pending DMA transaction */
-	ret = pci_dev_reset_iommu_prepare(dev);
+	ret = pci_dev_reset_iommu_prepare(dev, &restore);
 	if (ret) {
 		pci_err(dev, "failed to stop IOMMU for a PCI reset: %d\n", ret);
 		return ret;
@@ -4547,7 +4549,7 @@ static int pci_af_flr(struct pci_dev *dev, bool probe)
 
 	ret = pci_dev_wait(dev, "AF_FLR", PCIE_RESET_READY_POLL_MS);
 done:
-	pci_dev_reset_iommu_done(dev);
+	pci_dev_reset_iommu_done(dev, restore);
 	return ret;
 }
 
@@ -4568,6 +4570,7 @@ static int pci_af_flr(struct pci_dev *dev, bool probe)
  */
 static int pci_pm_reset(struct pci_dev *dev, bool probe)
 {
+	bool restore;
 	u16 csr;
 	int ret;
 
@@ -4584,7 +4587,7 @@ static int pci_pm_reset(struct pci_dev *dev, bool probe)
 	if (dev->current_state != PCI_D0)
 		return -EINVAL;
 
-	ret = pci_dev_reset_iommu_prepare(dev);
+	ret = pci_dev_reset_iommu_prepare(dev, &restore);
 	if (ret) {
 		pci_err(dev, "failed to stop IOMMU for a PCI reset: %d\n", ret);
 		return ret;
@@ -4601,7 +4604,7 @@ static int pci_pm_reset(struct pci_dev *dev, bool probe)
 	pci_dev_d3_sleep(dev);
 
 	ret = pci_dev_wait(dev, "PM D3hot->D0", PCIE_RESET_READY_POLL_MS);
-	pci_dev_reset_iommu_done(dev);
+	pci_dev_reset_iommu_done(dev, restore);
 	return ret;
 }
 
@@ -5033,6 +5036,7 @@ static bool cxl_sbr_masked(struct pci_dev *dev)
 static int pci_reset_bus_function(struct pci_dev *dev, bool probe)
 {
 	struct pci_dev *bridge = pci_upstream_bridge(dev);
+	bool restore;
 	int rc;
 
 	/*
@@ -5042,7 +5046,7 @@ static int pci_reset_bus_function(struct pci_dev *dev, bool probe)
 	if (bridge && pcie_is_cxl(bridge) && cxl_sbr_masked(bridge))
 		return -ENOTTY;
 
-	rc = pci_dev_reset_iommu_prepare(dev);
+	rc = pci_dev_reset_iommu_prepare(dev, &restore);
 	if (rc) {
 		pci_err(dev, "failed to stop IOMMU for a PCI reset: %d\n", rc);
 		return rc;
@@ -5054,7 +5058,7 @@ static int pci_reset_bus_function(struct pci_dev *dev, bool probe)
 
 	rc = pci_parent_bus_reset(dev, probe);
 done:
-	pci_dev_reset_iommu_done(dev);
+	pci_dev_reset_iommu_done(dev, restore);
 	return rc;
 }
 
@@ -5062,6 +5066,7 @@ static int cxl_reset_bus_function(struct pci_dev *dev, bool probe)
 {
 	struct pci_dev *bridge;
 	u16 dvsec, reg, val;
+	bool restore;
 	int rc;
 
 	bridge = pci_upstream_bridge(dev);
@@ -5079,7 +5084,7 @@ static int cxl_reset_bus_function(struct pci_dev *dev, bool probe)
 	if (rc)
 		return -ENOTTY;
 
-	rc = pci_dev_reset_iommu_prepare(dev);
+	rc = pci_dev_reset_iommu_prepare(dev, &restore);
 	if (rc) {
 		pci_err(dev, "failed to stop IOMMU for a PCI reset: %d\n", rc);
 		return rc;
@@ -5099,7 +5104,7 @@ static int cxl_reset_bus_function(struct pci_dev *dev, bool probe)
 		pci_write_config_word(bridge, dvsec + PCI_DVSEC_CXL_PORT_CTL,
 				      reg);
 
-	pci_dev_reset_iommu_done(dev);
+	pci_dev_reset_iommu_done(dev, restore);
 	return rc;
 }
 
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 7f1f47ea2ee4..f6b26467c9e0 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -4404,16 +4404,17 @@ static const struct pci_dev_reset_methods pci_dev_reset_methods[] = {
 static int __pci_dev_specific_reset(struct pci_dev *dev, bool probe,
 				    const struct pci_dev_reset_methods *i)
 {
+	bool restore;
 	int ret;
 
-	ret = pci_dev_reset_iommu_prepare(dev);
+	ret = pci_dev_reset_iommu_prepare(dev, &restore);
 	if (ret) {
 		pci_err(dev, "failed to stop IOMMU for a PCI reset: %d\n", ret);
 		return ret;
 	}
 
 	ret = i->reset(dev, probe);
-	pci_dev_reset_iommu_done(dev);
+	pci_dev_reset_iommu_done(dev, restore);
 	return ret;
 }
 
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index ef5043752a36..7d6e27d0d918 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -1223,8 +1223,8 @@ ioasid_t iommu_alloc_global_pasid(struct device *dev);
 void iommu_free_global_pasid(ioasid_t pasid);
 
 /* PCI device reset functions */
-int pci_dev_reset_iommu_prepare(struct pci_dev *pdev);
-void pci_dev_reset_iommu_done(struct pci_dev *pdev);
+int pci_dev_reset_iommu_prepare(struct pci_dev *pdev, bool *restore);
+void pci_dev_reset_iommu_done(struct pci_dev *pdev, bool restore);
 #else /* CONFIG_IOMMU_API */
 
 struct iommu_ops {};
@@ -1549,12 +1549,13 @@ static inline ioasid_t iommu_alloc_global_pasid(struct device *dev)
 
 static inline void iommu_free_global_pasid(ioasid_t pasid) {}
 
-static inline int pci_dev_reset_iommu_prepare(struct pci_dev *pdev)
+static inline int pci_dev_reset_iommu_prepare(struct pci_dev *pdev, bool *restore)
 {
+	*restore = false;
 	return 0;
 }
 
-static inline void pci_dev_reset_iommu_done(struct pci_dev *pdev)
+static inline void pci_dev_reset_iommu_done(struct pci_dev *pdev, bool restore)
 {
 }
 #endif /* CONFIG_IOMMU_API */
-- 
2.56.1.708.g77570a6a1d-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 2/2] PCI/ATS: Disable ATS when ACS TB is set upstream
  2026-11-20  0:23 [PATCH v3 0/2] PCI/ATS: Disable ATS when ACS TB is set upstream Danny Gonzalez
  2026-11-20  0:23 ` [PATCH v3 1/2] iommu: Track whether pci_dev_reset_iommu_done() needs to restore state Danny Gonzalez
@ 2026-11-20  0:23 ` Danny Gonzalez
  2026-11-30 14:22   ` Pranjal Shrivastava
  2026-11-30 14:32 ` [PATCH v3 0/2] " Pranjal Shrivastava
  2 siblings, 1 reply; 6+ messages in thread
From: Danny Gonzalez @ 2026-11-20  0:23 UTC (permalink / raw)
  To: Bjorn Helgaas, Joerg Roedel, Will Deacon, Robin Murphy
  Cc: Rafael J . Wysocki, Len Brown, Jason Gunthorpe, Nicolin Chen,
	Lu Baolu, Kevin Tian, decot, praan, sheenamo, linux-pci, iommu,
	linux-acpi, linux-kernel, Danny Gonzalez

Enabling ATS allows an endpoint to cache translations and initiate DMA
requests with Translated addresses, which an upstream bridge with ACS
Translation Blocking (PCI_ACS_TB) set will block as ACS Violations.
Because pci_enable_acs() preserves existing PCI_ACS_CTRL bits (e.g., from
firmware, a kexec kernel, or "pci=config_acs=") without relaxing them,
PCI_ACS_TB may remain set on upstream bridges.

Update pci_ats_supported() to walk upstream bridges and return false if
any bridge has PCI_ACS_TB set, leaving the endpoint to use Untranslated
addresses. Ignore bridges whose config read fails or returns an error
response (PCI_POSSIBLE_ERROR()) so inaccessible bridges are not treated
as having PCI_ACS_TB set.

Tested by booting a machine with an endpoint advertising the ATS Capability
behind a Root Port with PCI_ACS_TB set; verified ATS is disabled and the
system boots cleanly.

Signed-off-by: Danny Gonzalez <digonzal@google.com>
---

v3:
 - Move the upstream ACS TB check back into pci_ats_supported(),
   dropping pci_ats_check_acs() and changes to pci-driver.c and pci.h
 - Read PCI_ACS_CTRL directly and check the return value and
   PCI_POSSIBLE_ERROR() so inaccessible bridges are not treated as
   having PCI_ACS_TB set
 - Remove the pci_warn_once() logging and separate helper function

v2 (based on sashiko review):
 - Move the upstream ACS TB check from pci_ats_supported() into
   pci_ats_check_acs() called after pci_enable_acs()
 - Use pci_acs_enabled() instead of reading PCI_ACS_CTRL directly

 drivers/pci/ats.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c
index 9cb23780093d..e3c78a575800 100644
--- a/drivers/pci/ats.c
+++ b/drivers/pci/ats.c
@@ -40,12 +40,31 @@ void pci_ats_init(struct pci_dev *dev)
  */
 bool pci_ats_supported(struct pci_dev *dev)
 {
+	struct pci_dev *bridge;
+
 	if (!dev->ats_cap || dev->untrusted)
 		return false;
 
 	if (dev->is_virtfn)
 		return pci_ats_supported(pci_physfn(dev));
 
+	/* Do not allow ATS if any upstream bridge blocks translation */
+	for (bridge = pci_upstream_bridge(dev); bridge;
+	     bridge = pci_upstream_bridge(bridge)) {
+		u16 ctrl;
+		int ret;
+
+		if (!bridge->acs_cap)
+			continue;
+		ret = pci_read_config_word(bridge,
+					   bridge->acs_cap + PCI_ACS_CTRL,
+					   &ctrl);
+		if (ret || PCI_POSSIBLE_ERROR(ctrl))
+			continue;
+		if (ctrl & PCI_ACS_TB)
+			return false;
+	}
+
 	return true;
 }
 EXPORT_SYMBOL_GPL(pci_ats_supported);
-- 
2.56.1.708.g77570a6a1d-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 2/2] PCI/ATS: Disable ATS when ACS TB is set upstream
  2026-11-20  0:23 ` [PATCH v3 2/2] PCI/ATS: Disable ATS when ACS TB is set upstream Danny Gonzalez
@ 2026-11-30 14:22   ` Pranjal Shrivastava
  0 siblings, 0 replies; 6+ messages in thread
From: Pranjal Shrivastava @ 2026-11-30 14:22 UTC (permalink / raw)
  To: Danny Gonzalez
  Cc: Bjorn Helgaas, Joerg Roedel, Will Deacon, Robin Murphy,
	Rafael J . Wysocki, Len Brown, Jason Gunthorpe, Nicolin Chen,
	Lu Baolu, Kevin Tian, decot, sheenamo, linux-pci, iommu,
	linux-acpi, linux-kernel

On Fri, Nov 20, 2026 at 12:23:11AM +0000, Danny Gonzalez wrote:

Hi Danny,

> Enabling ATS allows an endpoint to cache translations and initiate DMA
> requests with Translated addresses, which an upstream bridge with ACS
> Translation Blocking (PCI_ACS_TB) set will block as ACS Violations.
> Because pci_enable_acs() preserves existing PCI_ACS_CTRL bits (e.g., from
> firmware, a kexec kernel, or "pci=config_acs=") without relaxing them,
> PCI_ACS_TB may remain set on upstream bridges.
> 
> Update pci_ats_supported() to walk upstream bridges and return false if
> any bridge has PCI_ACS_TB set, leaving the endpoint to use Untranslated
> addresses. Ignore bridges whose config read fails or returns an error
> response (PCI_POSSIBLE_ERROR()) so inaccessible bridges are not treated
> as having PCI_ACS_TB set.

As for this approach, could this be a one-time decision instead of a
config read on every call? E.g. evaluate the upstream TB state once the
endpoint is set up for DMA (after its bridges' ACS has been configured)
and record it in a separate pci_dev flag, like the no_ats bit in David's
quirk patch [1], rather than touching ats_cap, which is still needed to
disable and save/restore ATS.

I realize that's close to what v2 did from pci_dma_configure(), but
callers already assume pci_ats_supported() doesn't change:

 - arm-smmu-v3 sizes master->build_invs from it at probe but re-checks
   it on every attach, so a false -> true flip (which ignoring read
   errors now allows) makes arm_smmu_master_build_invs() hit
   WARN_ON(num_invs >= max_invs) and the attach fails.

 - vt-d, AMD and arm-smmu-v3 decide to use ATS before they enable it,
   and WARN_ON(pci_enable_ats()) on the assumption that it can't fail.
   pci_enable_ats() re-checks pci_ats_supported(), so a true -> false
   flip in between trips those WARNs. My WARN_ON in pci_prepare_ats() 
   makes the same assumption [2]

> Tested by booting a machine with an endpoint advertising the ATS Capability
> behind a Root Port with PCI_ACS_TB set; verified ATS is disabled and the
> system boots cleanly.
> 
> Signed-off-by: Danny Gonzalez <digonzal@google.com>
> ---
> 
> v3:
>  - Move the upstream ACS TB check back into pci_ats_supported(),
>    dropping pci_ats_check_acs() and changes to pci-driver.c and pci.h
>  - Read PCI_ACS_CTRL directly and check the return value and
>    PCI_POSSIBLE_ERROR() so inaccessible bridges are not treated as
>    having PCI_ACS_TB set
>  - Remove the pci_warn_once() logging and separate helper function
> 
> v2 (based on sashiko review):
>  - Move the upstream ACS TB check from pci_ats_supported() into
>    pci_ats_check_acs() called after pci_enable_acs()
>  - Use pci_acs_enabled() instead of reading PCI_ACS_CTRL directly
> 
>  drivers/pci/ats.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c
> index 9cb23780093d..e3c78a575800 100644
> --- a/drivers/pci/ats.c
> +++ b/drivers/pci/ats.c
> @@ -40,12 +40,31 @@ void pci_ats_init(struct pci_dev *dev)
>   */
>  bool pci_ats_supported(struct pci_dev *dev)
>  {
> +	struct pci_dev *bridge;
> +
>  	if (!dev->ats_cap || dev->untrusted)
>  		return false;
>  
>  	if (dev->is_virtfn)
>  		return pci_ats_supported(pci_physfn(dev));
>  
> +	/* Do not allow ATS if any upstream bridge blocks translation */
> +	for (bridge = pci_upstream_bridge(dev); bridge;
> +	     bridge = pci_upstream_bridge(bridge)) {

IIRC, Leon's patch [3] has a similar walk for P2P routes in p2pdma.c
(see pci_p2pdma_path_blocks_translation()) which also handles the Intel
SPT/UPT root ports' nonstandard ACS Control that a plain 
acs_cap + PCI_ACS_CTRL read misses. I think we could lift out the common
logic and use it at both places?

> +		u16 ctrl;
> +		int ret;
> +
> +		if (!bridge->acs_cap)
> +			continue;
> +		ret = pci_read_config_word(bridge,
> +					   bridge->acs_cap + PCI_ACS_CTRL,
> +					   &ctrl);
> +		if (ret || PCI_POSSIBLE_ERROR(ctrl))
> +			continue;
> +		if (ctrl & PCI_ACS_TB)
> +			return false;
> +	}
> +
>  	return true;
>  }
>  EXPORT_SYMBOL_GPL(pci_ats_supported);
> -- 
> 2.56.1.708.g77570a6a1d-goog
> 

Thanks,
Praan

[1] https://lore.kernel.org/all/20261110003353.1824793-1-dmatlack@google.com/
[2] https://lore.kernel.org/all/20261001233338.918408-2-praan@google.com/
[3] https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git/commit/?h=next&id=9469bccaa3526dc3896cd59d4f25093fa1ae9a65

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 0/2] PCI/ATS: Disable ATS when ACS TB is set upstream
  2026-11-20  0:23 [PATCH v3 0/2] PCI/ATS: Disable ATS when ACS TB is set upstream Danny Gonzalez
  2026-11-20  0:23 ` [PATCH v3 1/2] iommu: Track whether pci_dev_reset_iommu_done() needs to restore state Danny Gonzalez
  2026-11-20  0:23 ` [PATCH v3 2/2] PCI/ATS: Disable ATS when ACS TB is set upstream Danny Gonzalez
@ 2026-11-30 14:32 ` Pranjal Shrivastava
  2026-11-30 20:00   ` Jason Gunthorpe
  2 siblings, 1 reply; 6+ messages in thread
From: Pranjal Shrivastava @ 2026-11-30 14:32 UTC (permalink / raw)
  To: Danny Gonzalez
  Cc: Bjorn Helgaas, Joerg Roedel, Will Deacon, Robin Murphy,
	Rafael J . Wysocki, Len Brown, Jason Gunthorpe, Nicolin Chen,
	Lu Baolu, Kevin Tian, decot, sheenamo, linux-pci, iommu,
	linux-acpi, linux-kernel, skhawaja, dmatlack

On Fri, Nov 20, 2026 at 12:23:09AM +0000, Danny Gonzalez wrote:

Hi Danny,

> This series disables ATS on endpoints when an upstream bridge has ACS
> Translation Blocking (PCI_ACS_TB) enabled, preventing ACS Violations on
> translated DMA requests.
> 

+David, Sami

I'd like to discuss a tangential problem here.

AFAIU, today nothing checks the upstream ports' TB before enabling ATS,
so once TB is set, every Translation Request and Translated TLP from the
endpoint is blocked as an ACS Violation. TB can legitimately be set by
firmware or by "pci=config_acs=" in the current kernel, hence ATS
enablement has to respect it regardless, and I agree with checking it.

However, a case where we kexec (not Live Update) into a new kernel looks
like a separate problem though: the previous kernel set TB (e.g. it 
booted with pci=noats, which makes pci_std_enable_acs() set it), 
and since pci_enable_acs() keeps existing bits, the next kernel inherits
it and can't tell it apart from a firmware setting. I don't think a 
plain (non Live Update) kexec should hand its ACS policy to the next 
kernel. 

I'm wondering it the outgoing kernel should restore the ACS control it
found at boot when shutting down for kexec? That might need
pci_enable_acs() to remember the value it found, but then the next
kernel would start from the firmware's settings, as on a cold boot.

Thanks,
Praan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 0/2] PCI/ATS: Disable ATS when ACS TB is set upstream
  2026-11-30 14:32 ` [PATCH v3 0/2] " Pranjal Shrivastava
@ 2026-11-30 20:00   ` Jason Gunthorpe
  0 siblings, 0 replies; 6+ messages in thread
From: Jason Gunthorpe @ 2026-11-30 20:00 UTC (permalink / raw)
  To: Pranjal Shrivastava
  Cc: Danny Gonzalez, Bjorn Helgaas, Joerg Roedel, Will Deacon,
	Robin Murphy, Rafael J . Wysocki, Len Brown, Nicolin Chen,
	Lu Baolu, Kevin Tian, decot, sheenamo, linux-pci, iommu,
	linux-acpi, linux-kernel, skhawaja, dmatlack

On Mon, Nov 30, 2026 at 02:32:05PM +0000, Pranjal Shrivastava wrote:
> On Fri, Nov 20, 2026 at 12:23:09AM +0000, Danny Gonzalez wrote:
> 
> Hi Danny,
> 
> > This series disables ATS on endpoints when an upstream bridge has ACS
> > Translation Blocking (PCI_ACS_TB) enabled, preventing ACS Violations on
> > translated DMA requests.
> > 
> 
> +David, Sami
> 
> I'd like to discuss a tangential problem here.
> 
> AFAIU, today nothing checks the upstream ports' TB before enabling ATS,
> so once TB is set, every Translation Request and Translated TLP from the
> endpoint is blocked as an ACS Violation. TB can legitimately be set by
> firmware or by "pci=config_acs=" in the current kernel, hence ATS
> enablement has to respect it regardless, and I agree with checking it.
> 
> However, a case where we kexec (not Live Update) into a new kernel looks
> like a separate problem though: the previous kernel set TB (e.g. it 
> booted with pci=noats, which makes pci_std_enable_acs() set it), 
> and since pci_enable_acs() keeps existing bits, the next kernel inherits
> it and can't tell it apart from a firmware setting. I don't think a 
> plain (non Live Update) kexec should hand its ACS policy to the next 
> kernel. 
> 
> I'm wondering it the outgoing kernel should restore the ACS control it
> found at boot when shutting down for kexec? That might need
> pci_enable_acs() to remember the value it found, but then the next
> kernel would start from the firmware's settings, as on a cold boot.

I think kexec without live update is fine to consider the predecessor
kernel "firwmare" and inherent the ACS settings.. This seems so niche
I wouldn't invest any code in trying to do anything about it at least.

Jason

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-30 20:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20  0:23 [PATCH v3 0/2] PCI/ATS: Disable ATS when ACS TB is set upstream Danny Gonzalez
2026-11-20  0:23 ` [PATCH v3 1/2] iommu: Track whether pci_dev_reset_iommu_done() needs to restore state Danny Gonzalez
2026-11-20  0:23 ` [PATCH v3 2/2] PCI/ATS: Disable ATS when ACS TB is set upstream Danny Gonzalez
2026-11-30 14:22   ` Pranjal Shrivastava
2026-11-30 14:32 ` [PATCH v3 0/2] " Pranjal Shrivastava
2026-11-30 20:00   ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox