Skip to contentSkip to conversation

accel/amdxdna: fix open_ref leak and stale client pointer on dma map failure

PATCH In review Lizhi Hou 2 participants 3 messages Jul 7

Subsystems (2)
lore
Share & tools
lore

Lizhi Hou

author maintainer
#0 lore raw

PATCH 1/1 accel/amdxdna: fix open_ref leak and stale client pointer on dma map failure

amdxdna_gem_obj_open() increments open_ref before attempting to set up the DMA address mapping. When amdxdna_dma_map_bo() fails, the function returned immediately without rolling back either change made on the first open (open_ref == 1 path).

Fix it by decrementing open_ref and clearing abo->client on the error path.

Fixes ece3e8980907 ("accel/amdxdna: Allow forcing IOVA-based DMA via module parameter")
---
 drivers/accel/amdxdna/amdxdna_gem.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/amdxdna_gem.c +4 -1
index a4bd9e86bc8d..3f03d2db1603 100644
@@ -663,8 +663,11 @@ static int amdxdna_gem_obj_open(struct drm_gem_object *gobj, struct drm_file *fi
 	/* No need to set up dma addr mapping in PASID mode. */
 	if (!amdxdna_pasid_on(abo->client)) {
 		ret = amdxdna_dma_map_bo(xdna, abo);
-		if (ret)
+		if (ret) {
+			abo->open_ref--;
+			abo->client = NULL;
 			return ret;
+		}
 	}
 
 	amdxdna_gem_add_bo_usage(abo);
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Lizhi Hou

amdxdna_gem_obj_open() increments open_ref before attempting to set up the DMA address mapping. When amdxdna_dma_map_bo() fails, the function returned immediately without rolling back either change made on the first open (open_ref == 1 path).

Fix it by decrementing open_ref and clearing abo->client on the error path.

Fixes ece3e8980907 ("accel/amdxdna: Allow forcing IOVA-based DMA via module parameter")
Quoted 21 lines
---
  drivers/accel/amdxdna/amdxdna_gem.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/amdxdna_gem.c +4 -1
index a4bd9e86bc8d..3f03d2db1603 100644
@@ -663,8 +663,11 @@ static int amdxdna_gem_obj_open(struct drm_gem_object *gobj, struct drm_file *fi
  	/* No need to set up dma addr mapping in PASID mode. */
  	if (!amdxdna_pasid_on(abo->client)) {
  		ret = amdxdna_dma_map_bo(xdna, abo);
-		if (ret)
+		if (ret) {
+			abo->open_ref--;
+			abo->client = NULL;
  			return ret;
+		}
  	}
 
  	amdxdna_gem_add_bo_usage(abo);
author maintainer Applied
#2 lore raw

Applied to drm-misc-fixes

Quoted 35 lines · Max Zhen
Quoted 9 lines · Lizhi Hou

amdxdna_gem_obj_open() increments open_ref before attempting to set up the DMA address mapping.  When amdxdna_dma_map_bo() fails, the function returned immediately without rolling back either change made on the first open (open_ref == 1 path).

Fix it by decrementing open_ref and clearing abo->client on the error path.

Fixes ece3e8980907 ("accel/amdxdna: Allow forcing IOVA-based DMA via module parameter")
Quoted 21 lines

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

  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/amdxdna_gem.c +0 -0
index a4bd9e86bc8d..3f03d2db1603 100644
@@ -663,8 +663,11 @@ static int amdxdna_gem_obj_open(struct 

drm_gem_object *gobj, struct drm_file *fi
      /* No need to set up dma addr mapping in PASID mode. */ if (!amdxdna_pasid_on(abo->client)) {
          ret = amdxdna_dma_map_bo(xdna, abo);
-        if (ret)
+        if (ret) {
+            abo->open_ref--;
+            abo->client = NULL;
              return ret;
+        }
      }
        amdxdna_gem_add_bo_usage(abo);