From: Sabuj Pattanayek <sabujp@google.com>
To: "Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, David Airlie <airlied@gmail.com>,
Simona Vetter <simona@ffwll.ch>,
stable@vger.kernel.org, Sabuj Pattanayek <sabujp@google.com>
Subject: [PATCH] drm/amdgpu: check importer DMA addressing for P2P DMA-buf attachments
Date: Tue, 3 Nov 2026 18:03:21 -0800 [thread overview]
Message-ID: <20261104020321.77378-1-sabujp@google.com> (raw)
amdgpu_dma_buf_attach() currently keeps attach->peer2peer enabled for
non-XGMI attachments whenever pci_p2pdma_distance() returns >= 0.
However, pci_p2pdma_distance() only verifies PCIe bridge topology and
does not check whether the importing device can DMA-address the
exporter's VRAM BAR physical address range.
When amdgpu_dma_buf_map() maps a VRAM BO for P2P via
amdgpu_vram_mgr_alloc_sgt() -> dma_map_resource(), if the importing
device is not behind a translating IOMMU DMA domain (IOMMU_DOMAIN_DMA or
IOMMU_DOMAIN_DMA_FQ) -- for example, when booted with iommu=pt or when
quirks_force_identity_mapping() places a GPU connected directly to an
AMD root port into IOMMU_DOMAIN_IDENTITY -- dma_direct_map_phys() checks
dma_capable() against the importer's DMA mask.
On systems where the exporter's 64-bit VRAM BAR is mapped above the
importer's DMA mask (such as a Radeon PRO W6400 with BAR 0 at
0x48030000000 paired with a 40-bit DMA mask Radeon PRO WX 3200 / Polaris
12 importer), dma_direct_map_phys() fails with DMA_MAPPING_ERROR and
warns:
[ 18.421053] amdgpu 0000:c1:00.0: DMA addr 0x0000048038000000+8388608 overflow (mask ffffffffff, bus limit 0)
Because attach->peer2peer remained true, amdgpu_dma_buf_map() attempts
VRAM P2P mapping and fails with -EBUSY instead of falling back to GTT.
In multi-GPU desktop setups driving displays across both GPUs, this
breaks cross-GPU PRIME buffer sharing and causes compositors such as
gnome-shell and Xorg to fail command submission or crash on startup,
leaving the desktop unusable without manual IOMMU or sysfs workarounds.
Mirror the IOMMU remapping and BAR DMA mask check from
amdgpu_device_is_peer_accessible() (commit 75f0efbc4b3b ("drm/amdgpu:
Take IOMMU remapping into account for p2p checks")) in
amdgpu_dma_buf_attach() via a new amdgpu_dma_buf_is_p2p_addressable()
helper. Disabling attach->peer2peer when the importer cannot address the
exporter's VRAM aperture allows amdgpu_dma_buf_pin() and
amdgpu_dma_buf_map() to transparently fall back to GTT (system memory),
eliminating the DMA mapping overflow and restoring working multi-GPU
PRIME buffer sharing out of the box.
Fixes: 48262cd9499c ("drm/amdgpu: add checks if DMA-buf P2P is supported")
Cc: stable@vger.kernel.org
Signed-off-by: Sabuj Pattanayek <sabujp@google.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 31 ++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
index bbe518757907..837330831eb2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
@@ -42,6 +42,7 @@
#include <drm/ttm/ttm_tt.h>
#include <linux/dma-buf.h>
#include <linux/dma-fence-array.h>
+#include <linux/iommu.h>
#include <linux/pci-p2pdma.h>
#include <linux/pm_runtime.h>
@@ -68,6 +69,33 @@ static struct amdgpu_device *dma_buf_attach_adev(struct dma_buf_attachment *atta
return NULL;
}
+/**
+ * amdgpu_dma_buf_is_p2p_addressable - Check if importer can DMA-map exporter BAR
+ *
+ * @adev: exporter amdgpu_device
+ * @attach: DMA-buf attachment
+ *
+ * Returns:
+ * True if the importing device can address the exporter's CPU-visible VRAM
+ * aperture either via IOMMU DMA remapping or directly within its DMA mask.
+ */
+static bool amdgpu_dma_buf_is_p2p_addressable(struct amdgpu_device *adev,
+ struct dma_buf_attachment *attach)
+{
+ struct iommu_domain *domain = iommu_get_domain_for_dev(attach->dev);
+ resource_size_t aper_limit;
+
+ if (domain && (domain->type == IOMMU_DOMAIN_DMA ||
+ domain->type == IOMMU_DOMAIN_DMA_FQ))
+ return true;
+
+ if (!adev->gmc.aper_size)
+ return false;
+
+ aper_limit = adev->gmc.aper_base + adev->gmc.aper_size - 1;
+ return aper_limit <= dma_get_mask(attach->dev);
+}
+
/**
* amdgpu_dma_buf_attach - &dma_buf_ops.attach implementation
*
@@ -98,7 +126,8 @@ static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf,
attach->peer2peer = false;
if (!amdgpu_dmabuf_is_xgmi_accessible(attach_adev, bo) &&
- pci_p2pdma_distance(adev->pdev, attach->dev, false) < 0)
+ (pci_p2pdma_distance(adev->pdev, attach->dev, false) < 0 ||
+ !amdgpu_dma_buf_is_p2p_addressable(adev, attach)))
attach->peer2peer = false;
/*
--
2.56.0.385.gac671c819a-goog
reply other threads:[~2026-11-04 2:03 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261104020321.77378-1-sabujp@google.com \
--to=sabujp@google.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=stable@vger.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®