From: Xiaogang.Chen <xiaogang.chen@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: Xiaogang Chen <xiaogang.chen@amd.com>
Subject: [PATCH 2/2] drm/amdgpu: Redirect imported dma-buf mmap request to exporter
Date: Fri, 23 Oct 2026 09:48:13 -0500 [thread overview]
Message-ID: <20261023144813.1220394-2-xiaogang.chen@amd.com> (raw)
In-Reply-To: <20261023144813.1220394-1-xiaogang.chen@amd.com>
From: Xiaogang Chen <xiaogang.chen@amd.com>
The imported GEM object with ttm->page_flags TTM_TT_FLAG_EXTERNAL set and
without TTM_TT_FLAG_EXTERNAL_MAPPABLE set,is only a GPU-side handle for memory
that belongs to the exporter. TTM refuses to build a CPU mapping from it
because those page-table entries would point to pages drm driver does not own.
amdgpu_dma_buf_create_obj creates GEM object for foreign exported buf(not
generated by amdgpu driver) belonging to this catagory. The pages, when GPU
needs them, come from dma_buf_map_attachment on the exporter's scatter/gather
table. The exporter can move or revoke that mapping through move_notify.
A CPU page-table entry installed by the importer would keep the old PFN, and
the importer also does not know the exporter's caching mode or whether the
memory is CPU-visible.
This patch redirects foreign imported dma-buf mmap request to exporter. The
CPU mapping is created by dma_buf_mmap, which points the VMA to the exporter's
file and calls dma_buf->ops->mmap. The exporter's fault handler will fill
page table.
Signed-off-by: Xiaogang Chen <xiaogang.chen@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 4e4814caf61a..d872b4bcb5fc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -369,6 +369,26 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,
static int amdgpu_gem_object_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
{
struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
+ struct dma_buf *dmabuf;
+ int ret;
+
+ /*
+ * A foreign import (udmabuf, for example) does not own the pages.
+ * Point the VMA at the exporter so the later CPU fault uses its
+ * vm_ops. dma_buf_mmap() resets vm_pgoff and holds the dma-buf file.
+ * An amdgpu dma-buf stays on the TTM path below.
+ */
+ dmabuf = obj->import_attach ? obj->import_attach->dmabuf : NULL;
+ if (dmabuf && dmabuf->ops != &amdgpu_dmabuf_ops) {
+ ret = dma_buf_mmap(dmabuf, vma, 0);
+ if (ret)
+ return ret;
+
+ /* Exporter vm_ops will not drop the mapping reference. */
+ drm_gem_object_put(obj);
+ return 0;
+ }
+
if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm))
return -EPERM;
--
2.34.1
next prev parent reply other threads:[~2026-10-23 17:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 14:48 [PATCH 1/2] drm/amdkfd: Get foreign dma-buf info Xiaogang.Chen
2026-10-23 14:48 ` Xiaogang.Chen [this message]
2026-10-27 9:00 ` [PATCH 2/2] drm/amdgpu: Redirect imported dma-buf mmap request to exporter Christian König
2026-10-27 9:02 ` [PATCH 1/2] drm/amdkfd: Get foreign dma-buf info Christian König
2026-10-27 16:38 ` Chen, Xiaogang
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=20261023144813.1220394-2-xiaogang.chen@amd.com \
--to=xiaogang.chen@amd.com \
--cc=amd-gfx@lists.freedesktop.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.