From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: "Leon Romanovsky" <leon@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Logan Gunthorpe" <logang@deltatee.com>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
"Joerg Roedel (AMD)" <joro@8bytes.org>,
"Will Deacon" <will@kernel.org>,
"Robin Murphy" <robin.murphy@arm.com>,
"Christian König" <christian.koenig@amd.com>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, iommu@lists.linux.dev,
Tushar Dave <tdave@nvidia.com>,
linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linaro-mm-sig@lists.linaro.org, linux-rdma@vger.kernel.org,
kvm@vger.kernel.org, Chaitanya Kulkarni <kch@nvidia.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jens Axboe <axboe@kernel.dk>, Alex Williamson <alex@shazbot.org>,
Ankit Agrawal <ankita@nvidia.com>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
Sumit Semwal <sumit.semwal@linaro.org>
Subject: Re: [PATCH v8 22/23] PCI/P2PDMA: Evaluate the ATS path for clients with ATS enabled
Date: Mon, 28 Sep 2026 14:43:06 +0200 [thread overview]
Message-ID: <e61fcc1552447e628b7ec938ac7e4e36555ebec2.camel@linux.intel.com> (raw)
In-Reply-To: <20260928-fix-p2p-acs-v4-0-v8-22-404453b9c435@nvidia.com>
On Mon, 2026-09-28 at 14:19 +0300, Leon Romanovsky wrote:
> From: Leon Romanovsky <leonro@nvidia.com>
>
> P2PDMA assumes every client issues Untranslated Requests. A device
> with
> ATS enabled may translate any address it is handed, including a bus
> address, and Translation Blocking can reject its Translated Requests
> on
> a route the Untranslated answer called usable.
>
> Unless the client declared per-mapping ATS, take the Address Type
> from
> its ATS Enable bit. Never hand such a client bus addresses: only an
> IOVA
> survives translation, and whatever it issues untranslated goes
> through
> the host bridge, whose route must therefore be usable. Apply this
> after
> the cache, which keeps holding answers that depend only on the
> topology.
>
> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> ---
> Documentation/driver-api/pci/p2pdma.rst | 8 ++++++
> drivers/pci/p2pdma.c | 50
> +++++++++++++++++++++++++++++++--
> include/linux/pci-p2pdma.h | 3 +-
> 3 files changed, 58 insertions(+), 3 deletions(-)
>
> diff --git a/Documentation/driver-api/pci/p2pdma.rst
> b/Documentation/driver-api/pci/p2pdma.rst
> index 7a7f29f455b0..bf9f96c07b58 100644
> --- a/Documentation/driver-api/pci/p2pdma.rst
> +++ b/Documentation/driver-api/pci/p2pdma.rst
> @@ -40,6 +40,14 @@ A client therefore describes its traffic with
> ``enum pci_p2pdma_tlp_flags``
> and asks ``pci_p2pdma_map_type_tlp()``. ``pci_p2pdma_map_type()``
> answers for
> the default: strictly ordered Requests carrying an Untranslated
> address.
>
> +The PCIe ATS Enable bit covers the whole device, and most devices
> translate
> +any address they are handed once it is set. Unless a driver has
> declared with
> +``pcim_p2pdma_set_ats_per_mapping()`` that its device chooses ATS
> per mapping,
> +that bit rather than the flags decides the Address Type, and a
> client with ATS
> +enabled is never handed a bus address, which it would translate as
> though it
> +were an IOVA. Its Translated Requests may still route directly, but
> anything
> +it issues untranslated reaches the host bridge, so that route has to
> work too.
> +
> The two directions are decided independently. Translation Blocking
> (TB),
> Direct Translated P2P (DT), Request Redirect (RR) and Egress Control
> (EC) on
> the client-side port decide the Request:
> diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c
> index ae676509f9f3..ca79af2e64c7 100644
> --- a/drivers/pci/p2pdma.c
> +++ b/drivers/pci/p2pdma.c
> @@ -1595,6 +1595,41 @@ void pcim_p2pdma_set_ats_per_mapping(struct
> pci_dev *pdev)
> }
> EXPORT_SYMBOL_GPL(pcim_p2pdma_set_ats_per_mapping);
>
> +static unsigned int pci_p2pdma_client_tlp_flags(struct pci_dev
> *client,
> + unsigned int
> tlp_flags)
> +{
> + if (client->ats_enabled)
> + return tlp_flags | PCI_P2PDMA_TLP_TRANSLATED;
> +
> + return tlp_flags & ~PCI_P2PDMA_TLP_TRANSLATED;
> +}
> +
> +/*
> + * A client that translates every address it is handed cannot be
> handed a bus
> + * address, which it would translate as though it were an IOVA. Its
> Translated
> + * Requests may still route directly, but a Request it issues
> without a
> + * translation carries the IOVA to the host bridge, so that route
> has to work
> + * as well.
> + */
> +static enum pci_p2pdma_map_type
> +pci_p2pdma_client_map_type(struct pci_dev *provider, struct pci_dev
> *client,
> + bool per_mapping, enum
> pci_p2pdma_map_type type)
> +{
> + if (per_mapping || !client->ats_enabled ||
> + type != PCI_P2PDMA_MAP_BUS_ADDR)
> + return type;
> +
> + pci_dbg(client,
> + "P2PDMA ACS: provider=%s bus address withheld; ATS
> is enabled for the whole client\n",
> + pci_name(provider));
> +
> + if (cpu_supports_p2pdma() ||
> + host_bridge_whitelist(provider, client, false))
> + return PCI_P2PDMA_MAP_THRU_HOST_BRIDGE;
> +
> + return PCI_P2PDMA_MAP_NOT_SUPPORTED;
> +}
> +
> /**
> * pci_p2pdma_map_type_tlp - Determine the mapping type for P2PDMA
> transfers
> * @provider: P2PDMA provider structure
> @@ -1609,6 +1644,11 @@
> EXPORT_SYMBOL_GPL(pcim_p2pdma_set_ats_per_mapping);
> * ACS routes a peer-to-peer transaction by the attributes its TLPs
> carry, so
> * the answer depends on @tlp_flags. A caller that passes flags its
> traffic
> * does not match gets a mapping the fabric will not deliver.
> + *
> + * Only a client whose driver called
> pcim_p2pdma_set_ats_per_mapping() takes
> + * the Address Type from @tlp_flags. For any other client its ATS
> Enable bit
> + * decides, and a client that translates every address it is handed
> never gets
> + * %PCI_P2PDMA_MAP_BUS_ADDR.
> */
> enum pci_p2pdma_map_type
> pci_p2pdma_map_type_tlp(struct p2pdma_provider *provider, struct
> device *dev,
> @@ -1620,6 +1660,7 @@ pci_p2pdma_map_type_tlp(struct p2pdma_provider
> *provider, struct device *dev,
> struct pci_p2pdma *p2pdma;
> struct pci_dev *client;
> bool provider_state;
> + bool per_mapping;
> int dist;
>
> if (!pdev->p2pdma) {
> @@ -1639,6 +1680,9 @@ pci_p2pdma_map_type_tlp(struct p2pdma_provider
> *provider, struct device *dev,
> cache_index = map_types_idx(client);
>
> rcu_read_lock();
> + /* The declaration belongs to the client, the cache to the
> provider. */
> + p2pdma = rcu_dereference(client->p2pdma);
> + per_mapping = p2pdma && p2pdma->ats_per_mapping;
> p2pdma = rcu_dereference(pdev->p2pdma);
>
> if (p2pdma)
> @@ -1646,6 +1690,8 @@ pci_p2pdma_map_type_tlp(struct p2pdma_provider
> *provider, struct device *dev,
> cache_index));
> provider_state = !!p2pdma;
> rcu_read_unlock();
> + if (!per_mapping)
> + tlp_flags = pci_p2pdma_client_tlp_flags(client,
> tlp_flags);
> type = pci_p2pdma_map_types_unpack(cached, tlp_flags);
> pci_dbg(client,
> "P2PDMA ACS: map lookup provider=%s index=%#lx tlp-
> flags=%#x cached=%s(%d) provider-state=%u\n",
> @@ -1653,10 +1699,10 @@ pci_p2pdma_map_type_tlp(struct
> p2pdma_provider *provider, struct device *dev,
> pci_p2pdma_map_type_name(type), type,
> provider_state);
>
> if (type == PCI_P2PDMA_MAP_UNKNOWN)
> - return calc_map_type_and_dist(pdev, client, &dist,
> tlp_flags,
> + type = calc_map_type_and_dist(pdev, client, &dist,
> tlp_flags,
> true);
>
> - return type;
> + return pci_p2pdma_client_map_type(pdev, client, per_mapping,
> type);
> }
>
> void __pci_p2pdma_update_state(struct pci_p2pdma_map_state *state,
> diff --git a/include/linux/pci-p2pdma.h b/include/linux/pci-p2pdma.h
> index 543a09426a11..8d96659df9df 100644
> --- a/include/linux/pci-p2pdma.h
> +++ b/include/linux/pci-p2pdma.h
> @@ -207,7 +207,8 @@ static inline struct pci_dev
> *pci_p2pmem_find(struct device *client)
> * @dev: Client device that initiates the transfer
> *
> * Same as pci_p2pdma_map_type_tlp() for a client issuing strictly
> ordered
> - * Requests that carry an Untranslated address.
> + * Requests. Their Address Type is Untranslated unless the client
> enables ATS
> + * for the whole device.
> */
> static inline enum pci_p2pdma_map_type
> pci_p2pdma_map_type(struct p2pdma_provider *provider, struct device
> *dev)
next prev parent reply other threads:[~2026-09-28 12:43 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 11:19 [PATCH v8 00/23] PCI/P2PDMA: Route peer-to-peer DMA by TLP class Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 01/23] PCI/P2PDMA: Document the TLP attribute assumptions Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 02/23] PCI/P2PDMA: Derive routing from directional ACS controls Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 03/23] PCI: Reject unreadable ACS controls in isolation checks Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 04/23] PCI/P2PDMA: Evaluate ACS controls at the path divergence Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 05/23] PCI/P2PDMA: Document directional ACS routing Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 06/23] PCI/P2PDMA: Collect the path's ACS controls before deciding Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 07/23] PCI/P2PDMA: Answer routing per TLP class Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 08/23] PCI/P2PDMA: Route Relaxed Ordering Completions directly Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 09/23] PCI/P2PDMA: Reject Translated Requests blocked by Translation Blocking Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 10/23] PCI/P2PDMA: Route Translated Requests under Direct Translated P2P Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 11/23] PCI/P2PDMA: Log detailed ACS routing diagnostics Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 12/23] PCI/P2PDMA: Add KUnit tests for the ACS routing decisions Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 13/23] PCI/P2PDMA: Test the ACS P2P routing walk Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 14/23] PCI: Add KUnit coverage for ACS isolation checks Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 15/23] PCI/P2PDMA: Document TLP-class routing Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 16/23] dma-buf: Let importers ask how peer-to-peer traffic is routed Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 17/23] vfio/pci: Hand out the P2PDMA provider behind a dma-buf Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 18/23] RDMA/uverbs: " Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 19/23] RDMA/mlx5: Ask P2PDMA whether ATS takes a direct peer-to-peer route Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 20/23] PCI/P2PDMA: Let a client declare that it selects ATS per mapping Leon Romanovsky
2026-09-28 12:44 ` Thomas Hellström
2026-09-28 11:19 ` [PATCH v8 21/23] RDMA/mlx5: Declare to P2PDMA that ATS is selected per memory key Leon Romanovsky
2026-09-28 11:19 ` [PATCH v8 22/23] PCI/P2PDMA: Evaluate the ATS path for clients with ATS enabled Leon Romanovsky
2026-09-28 12:43 ` Thomas Hellström [this message]
2026-09-28 11:19 ` [PATCH v8 23/23] PCI/P2PDMA: Test the routing of " Leon Romanovsky
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=e61fcc1552447e628b7ec938ac7e4e36555ebec2.camel@linux.intel.com \
--to=thomas.hellstrom@linux.intel.com \
--cc=alex@shazbot.org \
--cc=ankita@nvidia.com \
--cc=axboe@kernel.dk \
--cc=bhelgaas@google.com \
--cc=christian.koenig@amd.com \
--cc=corbet@lwn.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=kch@nvidia.com \
--cc=kvm@vger.kernel.org \
--cc=leon@kernel.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=rdunlap@infradead.org \
--cc=robin.murphy@arm.com \
--cc=skhan@linuxfoundation.org \
--cc=sumit.semwal@linaro.org \
--cc=tdave@nvidia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®