Skip to contentSkip to conversation

drm/amdgpu/userq: Only look up for gem objects when count is non zero

PATCH In review Sunil Khatri 5 participants 8 messages Mar 10 – Mar 13

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu/userq: Only look up for gem objects when count is non zero

In function amdgpu_userq_wait_ioctl, call function drm_gem_objects_lookup only if the count is valid i.e non zero.

In case of object count is 0 set the pointer to NULL for proper clean up.

---
 .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   | 32 ++++++++++++-------
 1 file changed, 20 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +20 -12
index 76f32fd768fb..a4fff90b190a 100644
@@ -665,19 +665,27 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,
 		goto free_timeline_handles;
 	}
 
-	r = drm_gem_objects_lookup(filp,
-				   u64_to_user_ptr(wait_info->bo_read_handles),
-				   num_read_bo_handles,
-				   &gobj_read);
-	if (r)
-		goto free_timeline_points;
+	if (num_read_bo_handles) {
+		r = drm_gem_objects_lookup(filp,
+					   u64_to_user_ptr(wait_info->bo_read_handles),
+					   num_read_bo_handles,
+					   &gobj_read);
+		if (r)
+			goto free_timeline_points;
+	} else {
+		gobj_read = NULL;
+	}
 
-	r = drm_gem_objects_lookup(filp,
-				   u64_to_user_ptr(wait_info->bo_write_handles),
-				   num_write_bo_handles,
-				   &gobj_write);
-	if (r)
-		goto put_gobj_read;
+	if (num_write_bo_handles) {
+		r = drm_gem_objects_lookup(filp,
+					   u64_to_user_ptr(wait_info->bo_write_handles),
+					   num_write_bo_handles,
+					   &gobj_write);
+		if (r)
+			goto put_gobj_read;
+	} else {
+		gobj_write = NULL;
+	}
 
 	drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT,
 		      (num_read_bo_handles + num_write_bo_handles));
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 drm/amdgpu/userq: Only look up for gem objects when count is non zero

In function amdgpu_userq_signal_ioctl, call function drm_gem_objects_lookup only if the count is valid i.e non zero.

In case of object count is 0 set the pointer to NULL for proper clean up.

---
 .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   | 32 ++++++++++++-------
 1 file changed, 20 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +20 -12
index a4fff90b190a..f5069c7fff14 100644
@@ -505,19 +505,27 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
 		}
 	}
 
-	r = drm_gem_objects_lookup(filp,
-				   u64_to_user_ptr(args->bo_read_handles),
-				   num_read_bo_handles,
-				   &gobj_read);
-	if (r)
-		goto free_syncobj;
+	if (num_read_bo_handles) {
+		r = drm_gem_objects_lookup(filp,
+					   u64_to_user_ptr(args->bo_read_handles),
+					   num_read_bo_handles,
+					   &gobj_read);
+		if (r)
+			goto free_syncobj;
+	} else {
+		gobj_read = NULL;
+	}
 
-	r = drm_gem_objects_lookup(filp,
-				   u64_to_user_ptr(args->bo_write_handles),
-				   num_write_bo_handles,
-				   &gobj_write);
-	if (r)
-		goto put_gobj_read;
+	if (num_write_bo_handles) {
+		r = drm_gem_objects_lookup(filp,
+					   u64_to_user_ptr(args->bo_write_handles),
+					   num_write_bo_handles,
+					   &gobj_write);
+		if (r)
+			goto put_gobj_read;
+	} else {
+		gobj_write = NULL;
+	}
 
 	/* Retrieve the user queue */
 	queue = amdgpu_userq_get(userq_mgr, args->queue_id);
Signature · 1 line
2.34.1
#2 lore raw
In reply to Sunil Khatri

Ping

Quoted 55 lines · Sunil Khatri

In function amdgpu_userq_wait_ioctl, call function drm_gem_objects_lookup only if the count is valid i.e non zero.

In case of object count is 0 set the pointer to NULL for proper clean up.

---
  .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   | 32 ++++++++++++-------
  1 file changed, 20 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +20 -12
index 76f32fd768fb..a4fff90b190a 100644
@@ -665,19 +665,27 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,
  		goto free_timeline_handles;
  	}
 
-	r = drm_gem_objects_lookup(filp,
-				   u64_to_user_ptr(wait_info->bo_read_handles),
-				   num_read_bo_handles,
-				   &gobj_read);
-	if (r)
-		goto free_timeline_points;
+	if (num_read_bo_handles) {
+		r = drm_gem_objects_lookup(filp,
+					   u64_to_user_ptr(wait_info->bo_read_handles),
+					   num_read_bo_handles,
+					   &gobj_read);
+		if (r)
+			goto free_timeline_points;
+	} else {
+		gobj_read = NULL;
+	}
 
-	r = drm_gem_objects_lookup(filp,
-				   u64_to_user_ptr(wait_info->bo_write_handles),
-				   num_write_bo_handles,
-				   &gobj_write);
-	if (r)
-		goto put_gobj_read;
+	if (num_write_bo_handles) {
+		r = drm_gem_objects_lookup(filp,
+					   u64_to_user_ptr(wait_info->bo_write_handles),
+					   num_write_bo_handles,
+					   &gobj_write);
+		if (r)
+			goto put_gobj_read;
+	} else {
+		gobj_write = NULL;
+	}
 
  	drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT,
  		      (num_read_bo_handles + num_write_bo_handles));
#3 lore raw
In reply to Sunil Khatri
Quoted 5 lines · Sunil Khatri

In function amdgpu_userq_wait_ioctl, call function drm_gem_objects_lookup only if the count is valid i.e non zero.

In case of object count is 0 set the pointer to NULL for proper clean up.

Hasn't this been discussed already with the conclusion that nothing is broken? Or I am missing something? Regards,

Tvrtko

Quoted 49 lines
---
  .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   | 32 ++++++++++++-------
  1 file changed, 20 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +20 -12
index 76f32fd768fb..a4fff90b190a 100644
@@ -665,19 +665,27 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,
  		goto free_timeline_handles;
  	}
 
-	r = drm_gem_objects_lookup(filp,
-				   u64_to_user_ptr(wait_info->bo_read_handles),
-				   num_read_bo_handles,
-				   &gobj_read);
-	if (r)
-		goto free_timeline_points;
+	if (num_read_bo_handles) {
+		r = drm_gem_objects_lookup(filp,
+					   u64_to_user_ptr(wait_info->bo_read_handles),
+					   num_read_bo_handles,
+					   &gobj_read);
+		if (r)
+			goto free_timeline_points;
+	} else {
+		gobj_read = NULL;
+	}
 
-	r = drm_gem_objects_lookup(filp,
-				   u64_to_user_ptr(wait_info->bo_write_handles),
-				   num_write_bo_handles,
-				   &gobj_write);
-	if (r)
-		goto put_gobj_read;
+	if (num_write_bo_handles) {
+		r = drm_gem_objects_lookup(filp,
+					   u64_to_user_ptr(wait_info->bo_write_handles),
+					   num_write_bo_handles,
+					   &gobj_write);
+		if (r)
+			goto put_gobj_read;
+	} else {
+		gobj_write = NULL;
+	}
 
  	drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT,
  		      (num_read_bo_handles + num_write_bo_handles));
#4 lore raw
Quoted 5 lines · Tvrtko Ursulin
Quoted 3 lines · Sunil Khatri

In function amdgpu_userq_wait_ioctl, call function drm_gem_objects_lookup only if the count is valid i.e non zero.

Quoted 7 lines
Quoted 2 lines

In case of object count is 0 set the pointer to NULL for proper clean up.

Hasn't this been discussed already with the conclusion that nothing is broken? Or I am missing something? Regards,

Tvrtko

Issue was seen again since Alex pulled 6.19 fixes from DRM and the drm_gem_objects_lookup again got reverted to old and we started to see the issue. With that in mind Alex too suggested that nothing wrong if we explicitly check in driver too. Also i thought its only when handles are Zero case when the problem is actually seen and why not that have a check targeting that and not to invoke the function drm_gem_objects_lookup itself for that specific case.

Regards
Sunil Khatri

Quoted 49 lines
Quoted 48 lines

---
  .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   | 32 ++++++++++++-------

  1 file changed, 20 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +20 -10
index 76f32fd768fb..a4fff90b190a 100644
@@ -665,19 +665,27 @@ int amdgpu_userq_wait_ioctl(struct drm_device 
 *dev, void *data,
           goto free_timeline_handles;
       }
   -    r = drm_gem_objects_lookup(filp,
- u64_to_user_ptr(wait_info->bo_read_handles),
-                   num_read_bo_handles,
-                   &gobj_read);
-    if (r)
-        goto free_timeline_points;
+    if (num_read_bo_handles) {
+        r = drm_gem_objects_lookup(filp,
+ u64_to_user_ptr(wait_info->bo_read_handles),
+                       num_read_bo_handles,
+                       &gobj_read);
+        if (r)
+            goto free_timeline_points;
+    } else {
+        gobj_read = NULL;
+    }
   -    r = drm_gem_objects_lookup(filp,
- u64_to_user_ptr(wait_info->bo_write_handles),
-                   num_write_bo_handles,
-                   &gobj_write);
-    if (r)
-        goto put_gobj_read;
+    if (num_write_bo_handles) {
+        r = drm_gem_objects_lookup(filp,
+ u64_to_user_ptr(wait_info->bo_write_handles),
+                       num_write_bo_handles,
+                       &gobj_write);
+        if (r)
+            goto put_gobj_read;
+    } else {
+        gobj_write = NULL;
+    }
         drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT,
                 (num_read_bo_handles + num_write_bo_handles));
#5 lore raw
Quoted 7 lines · Sunil
Quoted 5 lines · Tvrtko Ursulin
Quoted 3 lines · Sunil Khatri

In function amdgpu_userq_wait_ioctl, call function drm_gem_objects_lookup only if the count is valid i.e non zero.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

In case of object count is 0 set the pointer to NULL for proper clean up.

Hasn't this been discussed already with the conclusion that nothing is broken? Or I am missing something? Regards,

Tvrtko

Issue was seen again since Alex pulled 6.19 fixes from DRM and the drm_gem_objects_lookup again got reverted to old and we started to see the issue. With that in mind Alex too suggested that nothing wrong if we explicitly check in driver too. Also i thought its only when handles are Zero case when the problem is actually seen and why not that have a check targeting that and not to invoke the function drm_gem_objects_lookup itself for that specific case.

Yes nothing wrong with checking, thanks for clarifying. I was just worried I again missed something in the code.

Regards,

Tvrtko

Quoted 48 lines
Quoted 48 lines
Quoted 47 lines

---
  .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   | 32 ++++++++++++-------

  1 file changed, 20 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +20 -10
index 76f32fd768fb..a4fff90b190a 100644
@@ -665,19 +665,27 @@ int amdgpu_userq_wait_ioctl(struct drm_device 
 *dev, void *data,
           goto free_timeline_handles;
       }
   -    r = drm_gem_objects_lookup(filp,
- u64_to_user_ptr(wait_info->bo_read_handles),
-                   num_read_bo_handles,
-                   &gobj_read);
-    if (r)
-        goto free_timeline_points;
+    if (num_read_bo_handles) {
+        r = drm_gem_objects_lookup(filp,
+ u64_to_user_ptr(wait_info->bo_read_handles),
+                       num_read_bo_handles,
+                       &gobj_read);
+        if (r)
+            goto free_timeline_points;
+    } else {
+        gobj_read = NULL;
+    }
   -    r = drm_gem_objects_lookup(filp,
- u64_to_user_ptr(wait_info->bo_write_handles),
-                   num_write_bo_handles,
-                   &gobj_write);
-    if (r)
-        goto put_gobj_read;
+    if (num_write_bo_handles) {
+        r = drm_gem_objects_lookup(filp,
+ u64_to_user_ptr(wait_info->bo_write_handles),
+                       num_write_bo_handles,
+                       &gobj_write);
+        if (r)
+            goto put_gobj_read;
+    } else {
+        gobj_write = NULL;
+    }
         drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT,
                 (num_read_bo_handles + num_write_bo_handles));
maintainer
#6 lore raw
Quoted 12 lines · Tvrtko Ursulin
Quoted 10 lines · Sunil
Quoted 8 lines · Tvrtko Ursulin
Quoted 5 lines · Sunil Khatri

In function amdgpu_userq_wait_ioctl, call function drm_gem_objects_lookup only if the count is valid i.e non zero.

In case of object count is 0 set the pointer to NULL for proper clean up.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

Hasn't this been discussed already with the conclusion that nothing is broken? Or I am missing something? Regards,

Tvrtko

Issue was seen again since Alex pulled 6.19 fixes from DRM and the drm_gem_objects_lookup again got reverted to old and we started to see the issue. With that in mind Alex too suggested that nothing wrong if we explicitly check in driver too. Also i thought its only when handles are Zero case when the problem is actually seen and why not that have a check targeting that and not to invoke the function drm_gem_objects_lookup itself for that specific case.

Yes nothing wrong with checking, thanks for clarifying. I was just worried I again missed something in the code.

I'm clearly against adding those checks. It adds additional complexity because of an issue somewhere else.

So we should probably just cherry pick the correct fix over into amd-staging-drm-next instead.

Regards,
Christian.

Quoted 53 lines

Regards,

Tvrtko

Quoted 47 lines
Quoted 47 lines
Quoted 46 lines

---
  .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   | 32 ++++++++++++-------

  1 file changed, 20 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +20 -10
index 76f32fd768fb..a4fff90b190a 100644
@@ -665,19 +665,27 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,
           goto free_timeline_handles;
       }
   -    r = drm_gem_objects_lookup(filp,
- u64_to_user_ptr(wait_info->bo_read_handles),
-                   num_read_bo_handles,
-                   &gobj_read);
-    if (r)
-        goto free_timeline_points;
+    if (num_read_bo_handles) {
+        r = drm_gem_objects_lookup(filp,
+ u64_to_user_ptr(wait_info->bo_read_handles),
+                       num_read_bo_handles,
+                       &gobj_read);
+        if (r)
+            goto free_timeline_points;
+    } else {
+        gobj_read = NULL;
+    }
   -    r = drm_gem_objects_lookup(filp,
- u64_to_user_ptr(wait_info->bo_write_handles),
-                   num_write_bo_handles,
-                   &gobj_write);
-    if (r)
-        goto put_gobj_read;
+    if (num_write_bo_handles) {
+        r = drm_gem_objects_lookup(filp,
+ u64_to_user_ptr(wait_info->bo_write_handles),
+                       num_write_bo_handles,
+                       &gobj_write);
+        if (r)
+            goto put_gobj_read;
+    } else {
+        gobj_write = NULL;
+    }
         drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT,
                 (num_read_bo_handles + num_write_bo_handles));
#7 lore raw
Quoted 19 lines · Christian König
Quoted 15 lines · Tvrtko Ursulin
Quoted 13 lines · Sunil
Quoted 11 lines · Tvrtko Ursulin
Quoted 5 lines · Sunil Khatri

In function amdgpu_userq_wait_ioctl, call function drm_gem_objects_lookup only if the count is valid i.e non zero.

In case of object count is 0 set the pointer to NULL for proper clean up.

Hasn't this been discussed already with the conclusion that nothing is broken? Or I am missing something? Regards,

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

Tvrtko

Issue was seen again since Alex pulled 6.19 fixes from DRM and the drm_gem_objects_lookup again got reverted to old and we started to see the issue. With that in mind Alex too suggested that nothing wrong if we explicitly check in driver too. Also i thought its only when handles are Zero case when the problem is actually seen and why not that have a check targeting that and not to invoke the function drm_gem_objects_lookup itself for that specific case.

Yes nothing wrong with checking, thanks for clarifying. I was just worried I again missed something in the code.

I'm clearly against adding those checks. It adds additional complexity because of an issue somewhere else.

So we should probably just cherry pick the correct fix over into amd-staging-drm-next instead.

My concern was if someone pulls these changes into some other distro or stable kernel and the drm fix is missing. Then they'll run into this issue again and someone will have to debug it again. We already ran into this twice in our trees, seems likely to repeat itself.

Alex

Quoted 58 lines

Regards,
Christian.

Quoted 53 lines

Regards,

Tvrtko

Quoted 47 lines
Quoted 47 lines
Quoted 46 lines
---
  .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   | 32 ++++++++++++-------
  1 file changed, 20 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +20 -10
index 76f32fd768fb..a4fff90b190a 100644
@@ -665,19 +665,27 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,
          goto free_timeline_handles;
      }
  -    r = drm_gem_objects_lookup(filp,
- u64_to_user_ptr(wait_info->bo_read_handles),
-                   num_read_bo_handles,
-                   &gobj_read);
-    if (r)
-        goto free_timeline_points;
+    if (num_read_bo_handles) {
+        r = drm_gem_objects_lookup(filp,
+ u64_to_user_ptr(wait_info->bo_read_handles),
+                       num_read_bo_handles,
+                       &gobj_read);
+        if (r)
+            goto free_timeline_points;
+    } else {
+        gobj_read = NULL;
+    }
  -    r = drm_gem_objects_lookup(filp,
- u64_to_user_ptr(wait_info->bo_write_handles),
-                   num_write_bo_handles,
-                   &gobj_write);
-    if (r)
-        goto put_gobj_read;
+    if (num_write_bo_handles) {
+        r = drm_gem_objects_lookup(filp,
+ u64_to_user_ptr(wait_info->bo_write_handles),
+                       num_write_bo_handles,
+                       &gobj_write);
+        if (r)
+            goto put_gobj_read;
+    } else {
+        gobj_write = NULL;
+    }
        drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT,
                (num_read_bo_handles + num_write_bo_handles));