Skip to contentSkip to conversation

accel/amdxdna: Call dma_buf_vmap_unlocked() for imported object

PATCH RESEND Superseded Lizhi Hou 2 participants 3 messages Sep 15, 2025 – Sep 16, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Lizhi Hou

author maintainer
#0 lore raw

PATCH RESEND 1/1 accel/amdxdna: Call dma_buf_vmap_unlocked() for imported object

In amdxdna_gem_obj_vmap(), calling dma_buf_vmap() triggers a kernel warning if LOCKDEP is enabled. So for imported object, use dma_buf_vmap_unlocked(). Then, use drm_gem_vmap() for other objects. The similar change applies to vunmap code.

Fixes bd72d4acda10 ("accel/amdxdna: Support user space allocated buffer")
---
 drivers/accel/amdxdna/amdxdna_gem.c | 38 +++++++++++------------------
 1 file changed, 14 insertions(+), 24 deletions(-)
drivers/accel/amdxdna/amdxdna_gem.c +14 -24
index d407a36eb412..50950be189ae 100644
@@ -392,35 +392,25 @@ static const struct dma_buf_ops amdxdna_dmabuf_ops = {
 	.vunmap = drm_gem_dmabuf_vunmap,
 };
 
-static int amdxdna_gem_obj_vmap(struct drm_gem_object *obj, struct iosys_map *map)
+static int amdxdna_gem_obj_vmap(struct amdxdna_gem_obj *abo, struct iosys_map *map)
 {
-	struct amdxdna_gem_obj *abo = to_xdna_obj(obj);
-
 	iosys_map_clear(map);
 
-	dma_resv_assert_held(obj->resv);
-
 	if (is_import_bo(abo))
-		dma_buf_vmap(abo->dma_buf, map);
-	else
-		drm_gem_shmem_object_vmap(obj, map);
-
-	if (!map->vaddr)
-		return -ENOMEM;
+		return dma_buf_vmap_unlocked(abo->dma_buf, map);
 
-	return 0;
+	return drm_gem_vmap(to_gobj(abo), map);
 }
 
-static void amdxdna_gem_obj_vunmap(struct drm_gem_object *obj, struct iosys_map *map)
+static void amdxdna_gem_obj_vunmap(struct amdxdna_gem_obj *abo, struct iosys_map *map)
 {
-	struct amdxdna_gem_obj *abo = to_xdna_obj(obj);
-
-	dma_resv_assert_held(obj->resv);
+	if (iosys_map_is_null(map))
+		return;
 
 	if (is_import_bo(abo))
-		dma_buf_vunmap(abo->dma_buf, map);
-	else
-		drm_gem_shmem_object_vunmap(obj, map);
+		return dma_buf_vunmap_unlocked(abo->dma_buf, map);
+
+	return drm_gem_vunmap(to_gobj(abo), map);
 }
 
 static struct dma_buf *amdxdna_gem_prime_export(struct drm_gem_object *gobj, int flags)
@@ -468,7 +458,7 @@ static void amdxdna_gem_obj_free(struct drm_gem_object *gobj)
 	if (abo->type == AMDXDNA_BO_DEV_HEAP)
 		drm_mm_takedown(&abo->mm);
 
-	drm_gem_vunmap(gobj, &map);
+	amdxdna_gem_obj_vunmap(abo, &map);
 	mutex_destroy(&abo->lock);
 
 	if (is_import_bo(abo)) {
@@ -489,8 +479,8 @@ static const struct drm_gem_object_funcs amdxdna_gem_shmem_funcs = {
 	.pin = drm_gem_shmem_object_pin,
 	.unpin = drm_gem_shmem_object_unpin,
 	.get_sg_table = drm_gem_shmem_object_get_sg_table,
-	.vmap = amdxdna_gem_obj_vmap,
-	.vunmap = amdxdna_gem_obj_vunmap,
+	.vmap = drm_gem_shmem_object_vmap,
+	.vunmap = drm_gem_shmem_object_vunmap,
 	.mmap = amdxdna_gem_obj_mmap,
 	.vm_ops = &drm_gem_shmem_vm_ops,
 	.export = amdxdna_gem_prime_export,
@@ -692,7 +682,7 @@ amdxdna_drm_create_dev_heap(struct drm_device *dev,
 	abo->mem.dev_addr = client->xdna->dev_info->dev_mem_base;
 	drm_mm_init(&abo->mm, abo->mem.dev_addr, abo->mem.size);
 
-	ret = drm_gem_vmap(to_gobj(abo), &map);
+	ret = amdxdna_gem_obj_vmap(abo, &map);
 	if (ret) {
 		XDNA_ERR(xdna, "Vmap heap bo failed, ret %d", ret);
 		goto release_obj;
@@ -770,7 +760,7 @@ amdxdna_drm_create_cmd_bo(struct drm_device *dev,
 	abo->type = AMDXDNA_BO_CMD;
 	abo->client = filp->driver_priv;
 
-	ret = drm_gem_vmap(to_gobj(abo), &map);
+	ret = amdxdna_gem_obj_vmap(abo, &map);
 	if (ret) {
 		XDNA_ERR(xdna, "Vmap cmd bo failed, ret %d", ret);
 		goto release_obj;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 26 lines · Lizhi Hou

In amdxdna_gem_obj_vmap(), calling dma_buf_vmap() triggers a kernel warning if LOCKDEP is enabled. So for imported object, use dma_buf_vmap_unlocked(). Then, use drm_gem_vmap() for other objects. The similar change applies to vunmap code.

Fixes bd72d4acda10 ("accel/amdxdna: Support user space allocated buffer")
---
  drivers/accel/amdxdna/amdxdna_gem.c | 38 +++++++++++------------------
  1 file changed, 14 insertions(+), 24 deletions(-)
drivers/accel/amdxdna/amdxdna_gem.c +1 -3
index d407a36eb412..50950be189ae 100644
@@ -392,35 +392,25 @@ static const struct dma_buf_ops amdxdna_dmabuf_ops = {
  	.vunmap = drm_gem_dmabuf_vunmap,
  };
 
-static int amdxdna_gem_obj_vmap(struct drm_gem_object *obj, struct iosys_map *map)
+static int amdxdna_gem_obj_vmap(struct amdxdna_gem_obj *abo, struct iosys_map *map)
  {
-	struct amdxdna_gem_obj *abo = to_xdna_obj(obj);
-
  	iosys_map_clear(map);
 

drivers/accel/amdxdna/amdxdna_gem.c static const struct dma_buf_ops amdxdna_dmabuf_ops = { · line 400

Quoted 10 lines
drivers/accel/amdxdna/amdxdna_gem.c +1 -8
-	dma_resv_assert_held(obj->resv);
-
  	if (is_import_bo(abo))
-		dma_buf_vmap(abo->dma_buf, map);
-	else
-		drm_gem_shmem_object_vmap(obj, map);
-
-	if (!map->vaddr)
-		return -ENOMEM;
+		return dma_buf_vmap_unlocked(abo->dma_buf, map);

Hi,

The dma_buf_vmap_unlocked() will call iosys_map_clear at its start so that in this case it will be called twice. Probably it will be optimize out, but maybe its something to better omit.

Quoted 9 lines
drivers/accel/amdxdna/amdxdna_gem.c +2 -3
-	return 0;
+	return drm_gem_vmap(to_gobj(abo), map);
  }
 
-static void amdxdna_gem_obj_vunmap(struct drm_gem_object *obj, struct iosys_map *map)
+static void amdxdna_gem_obj_vunmap(struct amdxdna_gem_obj *abo, struct iosys_map *map)
  {
-	struct amdxdna_gem_obj *abo = to_xdna_obj(obj);

drivers/accel/amdxdna/amdxdna_gem.c static const struct dma_buf_ops amdxdna_dmabuf_ops = { · line 411

Quoted 10 lines
drivers/accel/amdxdna/amdxdna_gem.c +3 -5
-
-	dma_resv_assert_held(obj->resv);
+	if (iosys_map_is_null(map))
+		return;
 
  	if (is_import_bo(abo))
-		dma_buf_vunmap(abo->dma_buf, map);
-	else
-		drm_gem_shmem_object_vunmap(obj, map);
+		return dma_buf_vunmap_unlocked(abo->dma_buf, map);

I do also wonder what is the convention here on clearing iosys_map when returning. The function drm_gem_vunmap will clear the map for callers while the other not. I think at least comment explaining the logic will be necessary.

Best regards,
Maciej

Quoted 43 lines
drivers/accel/amdxdna/amdxdna_gem.c +7 -5
+
+	return drm_gem_vunmap(to_gobj(abo), map);
  }
 
  static struct dma_buf *amdxdna_gem_prime_export(struct drm_gem_object *gobj, int flags)
@@ -468,7 +458,7 @@ static void amdxdna_gem_obj_free(struct drm_gem_object *gobj)
  	if (abo->type == AMDXDNA_BO_DEV_HEAP)
  		drm_mm_takedown(&abo->mm);
 
-	drm_gem_vunmap(gobj, &map);
+	amdxdna_gem_obj_vunmap(abo, &map);
  	mutex_destroy(&abo->lock);
 
  	if (is_import_bo(abo)) {
@@ -489,8 +479,8 @@ static const struct drm_gem_object_funcs amdxdna_gem_shmem_funcs = {
  	.pin = drm_gem_shmem_object_pin,
  	.unpin = drm_gem_shmem_object_unpin,
  	.get_sg_table = drm_gem_shmem_object_get_sg_table,
-	.vmap = amdxdna_gem_obj_vmap,
-	.vunmap = amdxdna_gem_obj_vunmap,
+	.vmap = drm_gem_shmem_object_vmap,
+	.vunmap = drm_gem_shmem_object_vunmap,
  	.mmap = amdxdna_gem_obj_mmap,
  	.vm_ops = &drm_gem_shmem_vm_ops,
  	.export = amdxdna_gem_prime_export,
@@ -692,7 +682,7 @@ amdxdna_drm_create_dev_heap(struct drm_device *dev,
  	abo->mem.dev_addr = client->xdna->dev_info->dev_mem_base;
  	drm_mm_init(&abo->mm, abo->mem.dev_addr, abo->mem.size);
 
-	ret = drm_gem_vmap(to_gobj(abo), &map);
+	ret = amdxdna_gem_obj_vmap(abo, &map);
  	if (ret) {
  		XDNA_ERR(xdna, "Vmap heap bo failed, ret %d", ret);
  		goto release_obj;
@@ -770,7 +760,7 @@ amdxdna_drm_create_cmd_bo(struct drm_device *dev,
  	abo->type = AMDXDNA_BO_CMD;
  	abo->client = filp->driver_priv;
 
-	ret = drm_gem_vmap(to_gobj(abo), &map);
+	ret = amdxdna_gem_obj_vmap(abo, &map);
  	if (ret) {
  		XDNA_ERR(xdna, "Vmap cmd bo failed, ret %d", ret);
  		goto release_obj;
author maintainer
#2 lore raw
Quoted 40 lines · Maciej
Quoted 26 lines · Lizhi Hou

In amdxdna_gem_obj_vmap(), calling dma_buf_vmap() triggers a kernel warning if LOCKDEP is enabled. So for imported object, use dma_buf_vmap_unlocked(). Then, use drm_gem_vmap() for other objects. The similar change applies to vunmap code.

Fixes bd72d4acda10 ("accel/amdxdna: Support user space allocated buffer")

---
  drivers/accel/amdxdna/amdxdna_gem.c | 38 +++++++++++------------------

  1 file changed, 14 insertions(+), 24 deletions(-)
drivers/accel/amdxdna/amdxdna_gem.c +1 -2
index d407a36eb412..50950be189ae 100644
@@ -392,35 +392,25 @@ static const struct dma_buf_ops 
 amdxdna_dmabuf_ops = {
       .vunmap = drm_gem_dmabuf_vunmap,
   };
   -static int amdxdna_gem_obj_vmap(struct drm_gem_object *obj, struct iosys_map *map)
+static int amdxdna_gem_obj_vmap(struct amdxdna_gem_obj *abo, struct 
 iosys_map *map)
   {
-    struct amdxdna_gem_obj *abo = to_xdna_obj(obj);
-
       iosys_map_clear(map);

drivers/accel/amdxdna/amdxdna_gem.c static const struct dma_buf_ops · line 402

Quoted 10 lines
drivers/accel/amdxdna/amdxdna_gem.c +1 -7
   -    dma_resv_assert_held(obj->resv);
-
       if (is_import_bo(abo))
-        dma_buf_vmap(abo->dma_buf, map);
-    else
-        drm_gem_shmem_object_vmap(obj, map);
-
-    if (!map->vaddr)
-        return -ENOMEM;
+        return dma_buf_vmap_unlocked(abo->dma_buf, map);

Hi,

Quoted 3 lines

The dma_buf_vmap_unlocked() will call iosys_map_clear at its start so that in this case it will be called twice. Probably it will be optimize out, but maybe its something to better omit.

Ok. I will remove iosys_map_clear. The caller uses cleared map even drm_gem_vmap might not clear it.

Quoted 12 lines
Quoted 12 lines
drivers/accel/amdxdna/amdxdna_gem.c +4 -3
   -    return 0;
+    return drm_gem_vmap(to_gobj(abo), map);
   }
   -static void amdxdna_gem_obj_vunmap(struct drm_gem_object *obj, struct iosys_map *map)
+static void amdxdna_gem_obj_vunmap(struct amdxdna_gem_obj *abo, 
 struct iosys_map *map)
   {
-    struct amdxdna_gem_obj *abo = to_xdna_obj(obj);
-
-    dma_resv_assert_held(obj->resv);
+    if (iosys_map_is_null(map))
+        return;
Quoted 8 lines

drivers/accel/amdxdna/amdxdna_gem.c static const struct dma_buf_ops amdxdna_dmabuf_ops = { · line 411

Quoted 5 lines
drivers/accel/amdxdna/amdxdna_gem.c +1 -3
         if (is_import_bo(abo))
-        dma_buf_vunmap(abo->dma_buf, map);
-    else
-        drm_gem_shmem_object_vunmap(obj, map);
+        return dma_buf_vunmap_unlocked(abo->dma_buf, map);

I do also wonder what is the convention here on clearing iosys_map when returning. The function drm_gem_vunmap will clear the map for callers while the other not. I think at least comment explaining the logic will be necessary.

The input map will not be re-used, so it does not mater if it is cleared or not when returning. I will add a comment.

Thanks,

Lizhi

Quoted 44 lines

Best regards,
Maciej

Quoted 40 lines
drivers/accel/amdxdna/amdxdna_gem.c +2 -0
+
+    return drm_gem_vunmap(to_gobj(abo), map);
   }

    static struct dma_buf *amdxdna_gem_prime_export(struct drm_gem_object *gobj, int flags)

drivers/accel/amdxdna/amdxdna_gem.c +3 -2
@@ -468,7 +458,7 @@ static void amdxdna_gem_obj_free(struct 
 drm_gem_object *gobj)
       if (abo->type == AMDXDNA_BO_DEV_HEAP)
           drm_mm_takedown(&abo->mm);
   -    drm_gem_vunmap(gobj, &map);
+    amdxdna_gem_obj_vunmap(abo, &map);
       mutex_destroy(&abo->lock);
         if (is_import_bo(abo)) {
@@ -489,8 +479,8 @@ static const struct drm_gem_object_funcs 
 amdxdna_gem_shmem_funcs = {
       .pin = drm_gem_shmem_object_pin,
       .unpin = drm_gem_shmem_object_unpin,
       .get_sg_table = drm_gem_shmem_object_get_sg_table,
-    .vmap = amdxdna_gem_obj_vmap,
-    .vunmap = amdxdna_gem_obj_vunmap,
+    .vmap = drm_gem_shmem_object_vmap,
+    .vunmap = drm_gem_shmem_object_vunmap,
       .mmap = amdxdna_gem_obj_mmap,
       .vm_ops = &drm_gem_shmem_vm_ops,

      .export = amdxdna_gem_prime_export,

drivers/accel/amdxdna/amdxdna_gem.c +2 -0
@@ -692,7 +682,7 @@ amdxdna_drm_create_dev_heap(struct drm_device *dev,
       abo->mem.dev_addr = client->xdna->dev_info->dev_mem_base;
       drm_mm_init(&abo->mm, abo->mem.dev_addr, abo->mem.size);
   -    ret = drm_gem_vmap(to_gobj(abo), &map);
+    ret = amdxdna_gem_obj_vmap(abo, &map);
       if (ret) {
           XDNA_ERR(xdna, "Vmap heap bo failed, ret %d", ret);
           goto release_obj;
@@ -770,7 +760,7 @@ amdxdna_drm_create_cmd_bo(struct drm_device *dev,
       abo->type = AMDXDNA_BO_CMD;
       abo->client = filp->driver_priv;
   -    ret = drm_gem_vmap(to_gobj(abo), &map);
+    ret = amdxdna_gem_obj_vmap(abo, &map);
       if (ret) {
           XDNA_ERR(xdna, "Vmap cmd bo failed, ret %d", ret);
           goto release_obj;