Skip to contentSkip to conversation

accel/amdxdna: Remove mmap and export support for ubuf

PATCH In review Lizhi Hou 3 participants 4 messages May 18 – May 19

Subsystems (2)
lore
Share & tools
lore

Lizhi Hou

author maintainer
#0 lore raw

PATCH v2 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]>

---
v2:
Remove dead code amdxdna_ubuf_vm_ops structure and amdxdna_ubuf_vm_fault function.
Rename Non-exportable buffer flag from 'pri' to 'private_buffer'

 drivers/accel/amdxdna/amdxdna_gem.c  |  9 ++++-
 drivers/accel/amdxdna/amdxdna_gem.h  |  2 ++
 drivers/accel/amdxdna/amdxdna_ubuf.c | 50 ----------------------------
 3 files changed, 10 insertions(+), 51 deletions(-)
drivers/accel/amdxdna/amdxdna_gem.c +8 -1
index 319d2064fafa..6b9b556de555 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->private_buffer)
+		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->private_buffer = true;
+
+	return abo;
 }
 
 static struct amdxdna_gem_obj *
drivers/accel/amdxdna/amdxdna_gem.h +2 -0
index 4fc48a1189d2..957305ccb485 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				private_buffer;
 };
 
 #define to_gobj(obj)    (&(obj)->base.base)
drivers/accel/amdxdna/amdxdna_ubuf.c +0 -50

60 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 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]>
Quoted 123 lines

---
v2:
Remove dead code amdxdna_ubuf_vm_ops structure and amdxdna_ubuf_vm_fault function.
Rename Non-exportable buffer flag from 'pri' to 'private_buffer'

  drivers/accel/amdxdna/amdxdna_gem.c  |  9 ++++-
  drivers/accel/amdxdna/amdxdna_gem.h  |  2 ++
  drivers/accel/amdxdna/amdxdna_ubuf.c | 50 ----------------------------
  3 files changed, 10 insertions(+), 51 deletions(-)
drivers/accel/amdxdna/amdxdna_gem.c +8 -1
index 319d2064fafa..6b9b556de555 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->private_buffer)
+		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->private_buffer = true;
+
+	return abo;
  }
 
  static struct amdxdna_gem_obj *
drivers/accel/amdxdna/amdxdna_gem.h +2 -0
index 4fc48a1189d2..957305ccb485 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				private_buffer;
  };
 
  #define to_gobj(obj)    (&(obj)->base.base)
drivers/accel/amdxdna/amdxdna_ubuf.c +0 -50
index 3769210c55cc..bb60fb80467e 100644
@@ -69,60 +69,10 @@ static void amdxdna_ubuf_release(struct dma_buf *dbuf)
  	kfree(ubuf);
  }
 
-static vm_fault_t amdxdna_ubuf_vm_fault(struct vm_fault *vmf)
-{
-	struct vm_area_struct *vma = vmf->vma;
-	struct amdxdna_ubuf_priv *ubuf;
-	unsigned long pfn;
-	pgoff_t pgoff;
-
-	ubuf = vma->vm_private_data;
-	pgoff = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
-
-	pfn = page_to_pfn(ubuf->pages[pgoff]);
-	return vmf_insert_pfn(vma, vmf->address, pfn);
-}
-
-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)
Reviewed-by on v2 1/1
#2 lore raw
In reply to Lizhi Hou
Quoted 8 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]>
Quoted 123 lines

---
v2:
Remove dead code amdxdna_ubuf_vm_ops structure and amdxdna_ubuf_vm_fault function.
Rename Non-exportable buffer flag from 'pri' to 'private_buffer'

 drivers/accel/amdxdna/amdxdna_gem.c  |  9 ++++-
 drivers/accel/amdxdna/amdxdna_gem.h  |  2 ++
 drivers/accel/amdxdna/amdxdna_ubuf.c | 50 ----------------------------
 3 files changed, 10 insertions(+), 51 deletions(-)
drivers/accel/amdxdna/amdxdna_gem.c +8 -1
index 319d2064fafa..6b9b556de555 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->private_buffer)
+		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->private_buffer = true;
+
+	return abo;
 }
 
 static struct amdxdna_gem_obj *
drivers/accel/amdxdna/amdxdna_gem.h +2 -0
index 4fc48a1189d2..957305ccb485 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				private_buffer;
 };
 
 #define to_gobj(obj)    (&(obj)->base.base)
drivers/accel/amdxdna/amdxdna_ubuf.c +0 -50
index 3769210c55cc..bb60fb80467e 100644
@@ -69,60 +69,10 @@ static void amdxdna_ubuf_release(struct dma_buf *dbuf)
 	kfree(ubuf);
 }
 
-static vm_fault_t amdxdna_ubuf_vm_fault(struct vm_fault *vmf)
-{
-	struct vm_area_struct *vma = vmf->vma;
-	struct amdxdna_ubuf_priv *ubuf;
-	unsigned long pfn;
-	pgoff_t pgoff;
-
-	ubuf = vma->vm_private_data;
-	pgoff = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
-
-	pfn = page_to_pfn(ubuf->pages[pgoff]);
-	return vmf_insert_pfn(vma, vmf->address, pfn);
-}
-
-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)
author maintainer Applied
#3 lore raw

Applied to drm-misc-fixes

Quoted 134 lines · Christian König
Quoted 8 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]>
Quoted 123 lines

---
v2:
Remove dead code amdxdna_ubuf_vm_ops structure and amdxdna_ubuf_vm_fault function.
Rename Non-exportable buffer flag from 'pri' to 'private_buffer'

  drivers/accel/amdxdna/amdxdna_gem.c  |  9 ++++-
  drivers/accel/amdxdna/amdxdna_gem.h  |  2 ++
  drivers/accel/amdxdna/amdxdna_ubuf.c | 50 ----------------------------
  3 files changed, 10 insertions(+), 51 deletions(-)
drivers/accel/amdxdna/amdxdna_gem.c +8 -1
index 319d2064fafa..6b9b556de555 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->private_buffer)
+		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->private_buffer = true;
+
+	return abo;
  }
 
  static struct amdxdna_gem_obj *
drivers/accel/amdxdna/amdxdna_gem.h +2 -0
index 4fc48a1189d2..957305ccb485 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				private_buffer;
  };
 
  #define to_gobj(obj)    (&(obj)->base.base)
drivers/accel/amdxdna/amdxdna_ubuf.c +0 -50
index 3769210c55cc..bb60fb80467e 100644
@@ -69,60 +69,10 @@ static void amdxdna_ubuf_release(struct dma_buf *dbuf)
  	kfree(ubuf);
  }
 
-static vm_fault_t amdxdna_ubuf_vm_fault(struct vm_fault *vmf)
-{
-	struct vm_area_struct *vma = vmf->vma;
-	struct amdxdna_ubuf_priv *ubuf;
-	unsigned long pfn;
-	pgoff_t pgoff;
-
-	ubuf = vma->vm_private_data;
-	pgoff = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
-
-	pfn = page_to_pfn(ubuf->pages[pgoff]);
-	return vmf_insert_pfn(vma, vmf->address, pfn);
-}
-
-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)