All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pranjal Shrivastava <praan@google.com>
To: Danny Gonzalez <digonzal@google.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Len Brown <lenb@kernel.org>, Jason Gunthorpe <jgg@nvidia.com>,
	Nicolin Chen <nicolinc@nvidia.com>,
	Lu Baolu <baolu.lu@linux.intel.com>,
	Kevin Tian <kevin.tian@intel.com>,
	decot@google.com, sheenamo@google.com, linux-pci@vger.kernel.org,
	iommu@lists.linux.dev, linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/2] PCI/ATS: Disable ATS when ACS TB is set upstream
Date: Mon, 30 Nov 2026 14:22:54 +0000	[thread overview]
Message-ID: <aw2Gvmpwj90pM5Rm@google.com> (raw)
In-Reply-To: <20261120002311.394649-3-digonzal@google.com>

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

  parent reply	other threads:[~2026-11-30 14:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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:33   ` sashiko-bot
2026-11-20  0:23 ` [PATCH v3 2/2] PCI/ATS: Disable ATS when ACS TB is set upstream Danny Gonzalez
2026-11-20  0:34   ` sashiko-bot
2026-11-30 14:22   ` Pranjal Shrivastava [this message]
2026-11-30 14:32 ` [PATCH v3 0/2] " Pranjal Shrivastava
2026-11-30 20:00   ` Jason Gunthorpe
2026-12-02  0:06     ` David Matlack

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aw2Gvmpwj90pM5Rm@google.com \
    --to=praan@google.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=decot@google.com \
    --cc=digonzal@google.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=nicolinc@nvidia.com \
    --cc=rafael@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=sheenamo@google.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.