* [PATCH V1] accel/amdxdna: Remove mmap and export support for ubuf
@ 2026-05-15 15:53 Lizhi Hou
2026-05-15 22:56 ` Claude review: " Claude Code Review Bot
2026-05-15 22:56 ` Claude Code Review Bot
0 siblings, 2 replies; 3+ messages in thread
From: Lizhi Hou @ 2026-05-15 15:53 UTC (permalink / raw)
To: ogabbay, quic_jhugo, mario.limonciello, karol.wachowski
Cc: Lizhi Hou, linux-kernel, linaro-mm-sig, dri-devel,
christian.koenig, simona, max.zhen, sonal.santan
Ubuf pages should not be mmaped or exported. Remove the ubuf mmap callback
and return -EOPNOTSUPP when exporting ubuf objects.
ubuf vmap is also removed for there is not a real use case yet.
Fixes: bd72d4acda10 ("accel/amdxdna: Support user space allocated buffer")
Cc: Christian Koenig <christian.koenig@amd.com>
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
---
drivers/accel/amdxdna/amdxdna_gem.c | 9 +++++++-
drivers/accel/amdxdna/amdxdna_gem.h | 2 ++
drivers/accel/amdxdna/amdxdna_ubuf.c | 32 ----------------------------
3 files changed, 10 insertions(+), 33 deletions(-)
diff --git a/drivers/accel/amdxdna/amdxdna_gem.c b/drivers/accel/amdxdna/amdxdna_gem.c
index 319d2064fafa..6087264ba1b5 100644
--- a/drivers/accel/amdxdna/amdxdna_gem.c
+++ b/drivers/accel/amdxdna/amdxdna_gem.c
@@ -492,6 +492,9 @@ static struct dma_buf *amdxdna_gem_prime_export(struct drm_gem_object *gobj, int
struct amdxdna_gem_obj *abo = to_xdna_obj(gobj);
DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
+ if (abo->pri)
+ return ERR_PTR(-EOPNOTSUPP);
+
if (abo->dma_buf) {
get_dma_buf(abo->dma_buf);
return abo->dma_buf;
@@ -716,6 +719,7 @@ amdxdna_gem_create_ubuf_object(struct drm_device *dev, struct amdxdna_drm_create
{
struct amdxdna_dev *xdna = to_xdna_dev(dev);
struct amdxdna_drm_va_tbl va_tbl;
+ struct amdxdna_gem_obj *abo;
struct drm_gem_object *gobj;
struct dma_buf *dma_buf;
@@ -742,7 +746,10 @@ amdxdna_gem_create_ubuf_object(struct drm_device *dev, struct amdxdna_drm_create
dma_buf_put(dma_buf);
- return to_xdna_obj(gobj);
+ abo = to_xdna_obj(gobj);
+ abo->pri = true;
+
+ return abo;
}
static struct amdxdna_gem_obj *
diff --git a/drivers/accel/amdxdna/amdxdna_gem.h b/drivers/accel/amdxdna/amdxdna_gem.h
index 4fc48a1189d2..162e5499f5e0 100644
--- a/drivers/accel/amdxdna/amdxdna_gem.h
+++ b/drivers/accel/amdxdna/amdxdna_gem.h
@@ -54,6 +54,8 @@ struct amdxdna_gem_obj {
/* True, if BO is managed by XRT, not application */
bool internal;
+ /* True, if BO is not exportable */
+ bool pri;
};
#define to_gobj(obj) (&(obj)->base.base)
diff --git a/drivers/accel/amdxdna/amdxdna_ubuf.c b/drivers/accel/amdxdna/amdxdna_ubuf.c
index 3769210c55cc..df4ab225fbf9 100644
--- a/drivers/accel/amdxdna/amdxdna_ubuf.c
+++ b/drivers/accel/amdxdna/amdxdna_ubuf.c
@@ -87,42 +87,10 @@ static const struct vm_operations_struct amdxdna_ubuf_vm_ops = {
.fault = amdxdna_ubuf_vm_fault,
};
-static int amdxdna_ubuf_mmap(struct dma_buf *dbuf, struct vm_area_struct *vma)
-{
- struct amdxdna_ubuf_priv *ubuf = dbuf->priv;
-
- vma->vm_ops = &amdxdna_ubuf_vm_ops;
- vma->vm_private_data = ubuf;
- vm_flags_set(vma, VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP);
-
- return 0;
-}
-
-static int amdxdna_ubuf_vmap(struct dma_buf *dbuf, struct iosys_map *map)
-{
- struct amdxdna_ubuf_priv *ubuf = dbuf->priv;
- void *kva;
-
- kva = vmap(ubuf->pages, ubuf->nr_pages, VM_MAP, PAGE_KERNEL);
- if (!kva)
- return -EINVAL;
-
- iosys_map_set_vaddr(map, kva);
- return 0;
-}
-
-static void amdxdna_ubuf_vunmap(struct dma_buf *dbuf, struct iosys_map *map)
-{
- vunmap(map->vaddr);
-}
-
static const struct dma_buf_ops amdxdna_ubuf_dmabuf_ops = {
.map_dma_buf = amdxdna_ubuf_map,
.unmap_dma_buf = amdxdna_ubuf_unmap,
.release = amdxdna_ubuf_release,
- .mmap = amdxdna_ubuf_mmap,
- .vmap = amdxdna_ubuf_vmap,
- .vunmap = amdxdna_ubuf_vunmap,
};
static int readonly_va_entry(struct amdxdna_drm_va_entry *va_ent)
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Claude review: accel/amdxdna: Remove mmap and export support for ubuf
2026-05-15 15:53 [PATCH V1] accel/amdxdna: Remove mmap and export support for ubuf Lizhi Hou
@ 2026-05-15 22:56 ` Claude Code Review Bot
2026-05-15 22:56 ` Claude Code Review Bot
1 sibling, 0 replies; 3+ messages in thread
From: Claude Code Review Bot @ 2026-05-15 22:56 UTC (permalink / raw)
To: dri-devel-reviews
Overall Series Review
Subject: accel/amdxdna: Remove mmap and export support for ubuf
Author: Lizhi Hou <lizhi.hou@amd.com>
Patches: 1
Reviewed: 2026-05-16T08:56:25.802864
---
This is a single patch that removes mmap, vmap, and vunmap support from the `amdxdna_ubuf_dmabuf_ops` and blocks re-export of ubuf-backed GEM objects. The intent is reasonable: ubuf wraps user-pinned pages, and re-exporting or mmapping through the dma-buf is problematic (the user already has direct access to the memory). The patch is small and the deletion side is clean. However, there are two issues worth discussing: dead code left behind, and a poorly named flag.
---
Generated by Claude Code Patch Reviewer
^ permalink raw reply [flat|nested] 3+ messages in thread
* Claude review: accel/amdxdna: Remove mmap and export support for ubuf
2026-05-15 15:53 [PATCH V1] accel/amdxdna: Remove mmap and export support for ubuf Lizhi Hou
2026-05-15 22:56 ` Claude review: " Claude Code Review Bot
@ 2026-05-15 22:56 ` Claude Code Review Bot
1 sibling, 0 replies; 3+ messages in thread
From: Claude Code Review Bot @ 2026-05-15 22:56 UTC (permalink / raw)
To: dri-devel-reviews
Patch Review
**Dead code: `amdxdna_ubuf_vm_ops` and `amdxdna_ubuf_vm_fault` are now orphaned.**
The patch removes `amdxdna_ubuf_mmap` which was the sole user of `amdxdna_ubuf_vm_ops`, which in turn was the sole user of `amdxdna_ubuf_vm_fault`. After this patch, both `amdxdna_ubuf_vm_fault` (line 72) and `amdxdna_ubuf_vm_ops` (line 86) in `amdxdna_ubuf.c` are dead code. They should be removed in this patch to avoid a compiler warning (`-Wunused-function` for the static `amdxdna_ubuf_vm_fault`). This will actually cause a build failure with `-Werror`, which the kernel uses.
**Flag naming: `pri` is cryptic and misleading.**
The new field:
```c
/* True, if BO is not exportable */
bool pri;
```
The name `pri` doesn't convey "not exportable." It could be misread as "priority" or "primary" or "private." A name like `no_export` or `unexportable` would be immediately clear. Even `private` (spelled out) would be better. The comment helps, but a self-documenting name costs nothing.
**The export-blocking logic is correct but could be more robust.**
The check in `amdxdna_gem_prime_export`:
```c
if (abo->pri)
return ERR_PTR(-EOPNOTSUPP);
```
This correctly prevents re-export. The ubuf object is created through `amdxdna_gem_prime_import` and then marked with `abo->pri = true`, which will prevent it from being re-exported through the shmem funcs' `.export = amdxdna_gem_prime_export` path.
**No mmap blocking on the GEM object side.**
The patch removes `amdxdna_ubuf_mmap` from the dma-buf ops, which prevents mmap through the dma-buf fd. However, ubuf objects are imported via `drm_gem_shmem_prime_import_sg_table`, and the resulting GEM shmem object has `.mmap = amdxdna_gem_obj_mmap` set via `amdxdna_gem_shmem_funcs`. The commit message says "ubuf pages should not be mmaped" — should `amdxdna_gem_obj_mmap` also check `abo->pri` and reject the mmap? If the intent is only to block the dma-buf mmap path (since user already has the pages mapped), this should be clarified in the commit message. If GEM mmap should also be blocked, it's missing.
**Summary:**
- **Must fix:** Remove the now-dead `amdxdna_ubuf_vm_fault` and `amdxdna_ubuf_vm_ops` — this will cause a build warning/error.
- **Should fix:** Rename `pri` to something self-documenting (`no_export`, `unexportable`, etc.).
- **Should clarify:** Whether GEM-object-level mmap should also be blocked for ubuf objects, or only dma-buf mmap. If only dma-buf mmap, update the commit message to be precise.
---
Generated by Claude Code Patch Reviewer
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-15 22:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-15 15:53 [PATCH V1] accel/amdxdna: Remove mmap and export support for ubuf Lizhi Hou
2026-05-15 22:56 ` Claude review: " Claude Code Review Bot
2026-05-15 22:56 ` Claude Code Review Bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox