From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796048583; b=3Zgv5YQDrZffme0l+2zwtujRbEL/PD/jnLiE9Utq1/7aHprYEQAa9bQH4bJUujnc/N8G I5KKrayBd6oLsX9JtLedWFx0wITHDcljVVMS/DYPcynsQ9fVqlSpYH2sKdsrLjck6XFQZ mY06XSENV0uH3vSzCFLevGMCDLoZsv9691YPeJam9tY44R3XYuF8Pbz2/axwswhH4+/US d9gFSqwQWuNhRl3h50tAR81sRrBMOzQ93DuJmmjEhl8MRSWT6Oj1tqiWF6eHIc5Yw0Uqx oTw+ROfoe5QWRHo15kAlkL2GEbltnwi6NRDA0O/h9omyfIHA9KOiiDeng+SFL8mPd4w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796048583; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=eh6VXMoSqMq7CH3QbLANiOHbhSbiiiZv9WvN1NMqPus=; b=E0zeZbV1bS7GF96IcdFM5Oe97IhP6SWRBT9HcFfR+X5bcs9DnVSfc5BzZf1mdkRqoO3b e6YpUndcMh3UHIgV4B42foLl23Kw1gzUpPXbj/PgDTrGQmChQH4eokmVOyPponHcSG2A/ bZl6Q3CdA6o7YOlDNmjcF72ffAxVKAHyibwd8kZLI3jS2HVTsFC2xgsuJLyoAjOJ77mM9 C+lvcQH3dglX26Rpv9rLbegIchz8uWI09RT2+IqkZDtJ0c5eSVNIQsbUACl3gsb3Evcdx FQWahlF4yUuJZOVC1DzDFIMzldVVLtKPISS4Rwz14P8z+Mf4xucWU9mRMd5nMvVY0cQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=pLCep9Qa; arc=none smtp.remote-ip=209.85.214.171 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB027606A327 for ; Mon, 30 Nov 2026 14:23:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BB027606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=pLCep9Qa Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2f0e8bbc7a4so228135ad.1 for ; Mon, 30 Nov 2026 06:23:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796048582; x=1796653382; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=eh6VXMoSqMq7CH3QbLANiOHbhSbiiiZv9WvN1NMqPus=; b=pLCep9Qab0OcQOAelEbK+aul0LheGVj9n5uAau+eLWqs7O4I8bQ2nr2T0eLq3t8tN7 Dd+ZF4K4LzsGbMSezXP/LORTdIVLJcRtfGVmlW0uhR52kC/qtRsLj01vC4urPm0cIYAC NAHOI6Dy4kJugkCOPuTADGJqUs91WdGIUmzvdnLppuvs87dDj3iENr1u3W2mfJj3U6mX vWFM/W462d2sRGnUoNZo6aY4NAUuq4DMmbEnbCDZIqgfThRAWPRO+f1EXmIQENolvB2R KctTBEq2gQmm0bWbuL7ZJKoMY2g+P0CxoPiY82eke998rOqOu8/FPmQyTy4neKfZ2IRF 2rEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796048582; x=1796653382; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=eh6VXMoSqMq7CH3QbLANiOHbhSbiiiZv9WvN1NMqPus=; b=mylRp2y/Rnxe8td8QN9c4GTXzJCsdGxINCQ2p/Ks4vhrstAIwmZ89dcLikVZUijE9E pK/7aoc+uN/uuK07imUOe41a8cwcNN6NrYBmvrOs/2PWbHY9tbx+nryWMymTgGo8jlvP Ciwk1YPEX3imxhM24JVgIksrX6nEWjisnfCaiJc0kZDdLh3gLIufV856v6IXdyuSNLib lBHFLDL1Zk5tPnmyM4HGW9xKPnOGjeihY9v3A7iCW2OFA9lM9jhs3zHrpYjCb4qvMq/d 2jlqCkckmvgyOGDW8a0wovLNCmDmofEPRmnYNyJ6xinpBymEQgiXfzSasDKZgWGkiaa1 Qsyg== X-Forwarded-Encrypted: i=1; AL+hErGOimtN2xvLes0NvMTshZA6DrhjS7oWca4rPJyiINDxJ1c+LgUdQZY+ygJ6vdAygCqOUCE76gkDomgq0Qc=@vger.kernel.org X-Gm-Message-State: APuU4Z/9x19F3ysSKppgCzT456HEc46jARFARmA8vTpnvsGFyMnFkUeo Mvc/m1IDnrGye0efFXhAZai/4hyP3CEm7INUUuoVBg6DPXJEaYLWnc2BoSDbrOgLig== X-Gm-Gg: AZFdTZfOi6nd29H5GlPo5J0iuPAGYhRQyYfpp7e3rWYdtiK0s/T9B3nB2uJMhjOyO+2 Lmse+vkXunq9b0KumiOdNeopqllXVoNUEDB/i+JiX1yt505zQ6gliPwDFoT3JBCvYPMmMiPHUOh ghofi3tuOKstT4V+mn1IneWc5MQ+LZozVpH5oD81/RozNoWzBw1DeyBvckCR3zTD87+fn409DYP HrhZtJYeQgOO3HgzEyBJ3suGzeTi5gGPQX15OuUi1VJV8EtFvUBYaM+q4y0Sm+eAa2C/PIv3aaB u5LHM4hhgJpmXABbHZbgbKT6EJHiRmSMmc3oap5pfeLJub1oS1fpw84T7jb6ndJj3NZsPtnW2KX MvvRaS76tCVTvZpHzpl9/kKjymePkaBf5fWyxd+lrjpcTwpaiHKiDc5+LfcLVEIXUvzmk3V7DPy DubxWRxPNpV28Zix7MQ6LQYxWjrkDd8SK7KjXXK5WbwiWxN82UqkgaoFxy4nR9RgWH8NiTy+T+X 6+500J5fZT+2HrP27tzOJaCR5dsfGJ9BWoxBUm3NPwG+MRMcWlniAwSVfqFhhnnZECswjYTtiHg mmWLtuwA7k3ShfgXE/4eBGAJy5UZJo8UYy7/rABBn1RXa9/23bnIvHYWMlQypvs09a8= X-Received: by 2002:a17:902:e950:b0:2e6:12af:5b04 with SMTP id d9443c01a7336-2f0615b8824mr32121495ad.0.1796048581455; Mon, 30 Nov 2026 06:23:01 -0800 (PST) Received: from google.com (105.211.142.34.bc.googleusercontent.com. [34.142.211.105]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b405ffa98esm55436680a91.17.2026.11.30.06.22.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 06:23:00 -0800 (PST) Date: Mon, 30 Nov 2026 14:22:54 +0000 From: Pranjal Shrivastava 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@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 Message-ID: References: <20261120002311.394649-1-digonzal@google.com> <20261120002311.394649-3-digonzal@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 > --- > > 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