Skip to contentSkip to conversation

accel/amdxdna: Remove mmap and export support for ubuf

PATCH Superseded Lizhi Hou 3 participants 4 messages May 15 – May 18

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Lizhi Hou

author maintainer
#0 lore raw

PATCH 1/1 accel/amdxdna: Remove mmap and export support for ubuf

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 <[email protected]>
---
 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(-)
drivers/accel/amdxdna/amdxdna_gem.c +8 -1
index 319d2064fafa..6087264ba1b5 100644
@@ -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 *
drivers/accel/amdxdna/amdxdna_gem.h +2 -0
index 4fc48a1189d2..162e5499f5e0 100644
@@ -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)
drivers/accel/amdxdna/amdxdna_ubuf.c +0 -32
index 3769210c55cc..df4ab225fbf9 100644
@@ -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)
Signature · 1 line
2.34.1
#1 lore raw
kernel test robot noticed the following build warnings:

Hi Lizhi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on linus/master v7.1-rc3 next-20260508] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Lizhi-Hou/accel-amdxdna-Remove-mmap-and-export-support-for-ubuf/20260516-000523
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:    https://lore.kernel.org/r/20260515155332.743097-1-lizhi.hou%40amd.com
patch subject: [PATCH V1] accel/amdxdna: Remove mmap and export support for ubuf
config: x86_64-randconfig-002-20260516 (https://download.01.org/0day-ci/archive/20260516/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260516/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/accel/amdxdna/amdxdna_ubuf.c:86:42: warning: unused variable 'amdxdna_ubuf_vm_ops' [-Wunused-const-variable]
      86 | static const struct vm_operations_struct amdxdna_ubuf_vm_ops = {
         |                                          ^~~~~~~~~~~~~~~~~~~

1 warning generated.

vim +/amdxdna_ubuf_vm_ops +86 drivers/accel/amdxdna/amdxdna_ubuf.c

bd72d4acda1069 Lizhi Hou 2025-07-16 85

bd72d4acda1069 Lizhi Hou 2025-07-16 @86  static const struct vm_operations_struct amdxdna_ubuf_vm_ops = {
bd72d4acda1069 Lizhi Hou 2025-07-16  87  	.fault = amdxdna_ubuf_vm_fault,
bd72d4acda1069 Lizhi Hou 2025-07-16  88  };

bd72d4acda1069 Lizhi Hou 2025-07-16 89

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

#2 lore raw
In reply to Lizhi Hou
Quoted 53 lines · Lizhi Hou

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 <[email protected]>
---
 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(-)
drivers/accel/amdxdna/amdxdna_gem.c +8 -1
index 319d2064fafa..6087264ba1b5 100644
@@ -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 *
drivers/accel/amdxdna/amdxdna_gem.h +0 -0
index 4fc48a1189d2..162e5499f5e0 100644

drivers/accel/amdxdna/amdxdna_gem.h struct amdxdna_gem_obj { · line 58

Quoted 5 lines
drivers/accel/amdxdna/amdxdna_gem.h +2 -0
@@ -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;

That member name could be improved.

drivers/accel/amdxdna/amdxdna_ubuf.c static const struct vm_operations_struct amdxdna_ubuf_vm_ops = { · line 88

Quoted 10 lines
drivers/accel/amdxdna/amdxdna_gem.h +0 -0
 };
 
 #define to_gobj(obj)    (&(obj)->base.base)
drivers/accel/amdxdna/amdxdna_ubuf.c +0 -0
index 3769210c55cc..df4ab225fbf9 100644
@@ -87,42 +87,10 @@ static const struct vm_operations_struct amdxdna_ubuf_vm_ops = {
 	.fault = amdxdna_ubuf_vm_fault,
 };

As pointed out by the kernel test robot the amdxdna_ubuf_vm_ops structure and amdxdna_ubuf_vm_fault function is now dead code, please remove as well.

Apart from that looks good to me,
Christian.

Quoted 40 lines
drivers/accel/amdxdna/amdxdna_ubuf.c +0 -32
-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)
author maintainer
#3 lore raw
Quoted 56 lines · Christian König
Quoted 54 lines · Lizhi Hou

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 <[email protected]>
---
  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(-)
drivers/accel/amdxdna/amdxdna_gem.c +8 -1
index 319d2064fafa..6087264ba1b5 100644
@@ -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 *
drivers/accel/amdxdna/amdxdna_gem.h +0 -0
index 4fc48a1189d2..162e5499f5e0 100644
@@ -54,6 +54,8 @@ struct amdxdna_gem_obj {
 
Quoted 5 lines

drivers/accel/amdxdna/amdxdna_gem.h struct amdxdna_gem_obj { · line 58

Quoted 4 lines
drivers/accel/amdxdna/amdxdna_gem.h +2 -0
  	/* True, if BO is managed by XRT, not application */
  	bool				internal;
+	/* True, if BO is not exportable */
+	bool				pri;

That member name could be improved.

Sure, I will change it to private_buffer.

Quoted 12 lines

drivers/accel/amdxdna/amdxdna_ubuf.c static const struct vm_operations_struct amdxdna_ubuf_vm_ops = { · line 88

Quoted 11 lines
drivers/accel/amdxdna/amdxdna_gem.h +0 -0
  };
 
  #define to_gobj(obj)    (&(obj)->base.base)
drivers/accel/amdxdna/amdxdna_ubuf.c +0 -0
index 3769210c55cc..df4ab225fbf9 100644
@@ -87,42 +87,10 @@ static const struct vm_operations_struct amdxdna_ubuf_vm_ops = {
  	.fault = amdxdna_ubuf_vm_fault,
  };

As pointed out by the kernel test robot the amdxdna_ubuf_vm_ops structure and amdxdna_ubuf_vm_fault function is now dead code, please remove as well.

Will fix this and post V2 patch.

Thanks for reviewing.

Lizhi

Quoted 44 lines

Apart from that looks good to me,
Christian.

Quoted 40 lines
drivers/accel/amdxdna/amdxdna_ubuf.c +0 -32
-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)