Skip to contentSkip to conversation

drm/amdgpu/userq: Add syncobj_points to signal ioctl

PATCH Superseded David Rosca 1 participant 3 messages Sep 15, 2025 – Sep 23, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu/userq: Add syncobj_points to signal ioctl

---
 .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   | 49 +++++++++++++++----
 include/uapi/drm/amdgpu_drm.h                 |  5 ++
 2 files changed, 45 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +40 -9
index 95e91d1dc58a..5b2cdc49a28c 100644
@@ -460,10 +460,11 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
 	struct drm_gem_object **gobj_read = NULL;
 	struct amdgpu_usermode_queue *queue;
 	struct amdgpu_userq_fence *userq_fence;
-	struct drm_syncobj **syncobj = NULL;
+	struct amdgpu_cs_post_dep *syncobj = NULL;
 	u32 *bo_handles_write, num_write_bo_handles;
 	u32 *syncobj_handles, num_syncobj_handles;
 	u32 *bo_handles_read, num_read_bo_handles;
+	u64 *syncobj_points = NULL;
 	int r, i, entry, rentry, wentry;
 	struct dma_fence *fence;
 	struct drm_exec exec;
@@ -475,19 +476,37 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
 	if (IS_ERR(syncobj_handles))
 		return PTR_ERR(syncobj_handles);
 
+	if (args->syncobj_points) {
+		syncobj_points = memdup_user(u64_to_user_ptr(args->syncobj_points),
+					     sizeof(u64) * num_syncobj_handles);
+		if (IS_ERR(syncobj_points)) {
+			r = PTR_ERR(syncobj_points);
+			goto free_syncobj_handles;
+		}
+	}
+
 	/* Array of pointers to the looked up syncobjs */
 	syncobj = kmalloc_array(num_syncobj_handles, sizeof(*syncobj), GFP_KERNEL);
 	if (!syncobj) {
 		r = -ENOMEM;
-		goto free_syncobj_handles;
+		goto free_syncobj_points;
 	}
 
 	for (entry = 0; entry < num_syncobj_handles; entry++) {
-		syncobj[entry] = drm_syncobj_find(filp, syncobj_handles[entry]);
-		if (!syncobj[entry]) {
+		syncobj[entry].chain = NULL;
+		syncobj[entry].syncobj = drm_syncobj_find(filp, syncobj_handles[entry]);
+		if (!syncobj[entry].syncobj) {
 			r = -ENOENT;
 			goto free_syncobj;
 		}
+		if (syncobj_points && syncobj_points[entry]) {
+			syncobj[entry].point = syncobj_points[entry];
+			syncobj[entry].chain = dma_fence_chain_alloc();
+			if (!syncobj[entry].chain) {
+				r = -ENOMEM;
+				goto free_syncobj;
+			}
+		}
 	}
 
 	num_read_bo_handles = args->num_bo_read_handles;
@@ -603,8 +622,15 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
 	}
 
 	/* Add the created fence to syncobj/BO's */
-	for (i = 0; i < num_syncobj_handles; i++)
-		drm_syncobj_replace_fence(syncobj[i], fence);
+	for (i = 0; i < num_syncobj_handles; i++) {
+		if (syncobj[i].chain) {
+			drm_syncobj_add_point(syncobj[i].syncobj, syncobj[i].chain,
+							      fence, syncobj[i].point);
+			syncobj[i].chain = NULL;
+		} else {
+			drm_syncobj_replace_fence(syncobj[i].syncobj, fence);
+		}
+	}
 
 	/* drop the reference acquired in fence creation function */
 	dma_fence_put(fence);
@@ -624,10 +650,15 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
 free_bo_handles_read:
 	kfree(bo_handles_read);
 free_syncobj:
-	while (entry-- > 0)
-		if (syncobj[entry])
-			drm_syncobj_put(syncobj[entry]);
+	while (entry-- > 0) {
+		if (syncobj[entry].syncobj)
+			drm_syncobj_put(syncobj[entry].syncobj);
+		if (syncobj[entry].chain)
+			dma_fence_chain_free(syncobj[entry].chain);
+	}
 	kfree(syncobj);
+free_syncobj_points:
+	kfree(syncobj_points);
 free_syncobj_handles:
 	kfree(syncobj_handles);
 
include/uapi/drm/amdgpu_drm.h +5 -0
index 85b3ca14f81e..197ea3bfb559 100644
@@ -504,6 +504,11 @@ struct drm_amdgpu_userq_signal {
 	 * @bo_write_handles.
 	 */
 	__u32	num_bo_write_handles;
+	/**
+	 * @syncobj_points: The list of syncobj points submitted by the user queue job
+	 * for the corresponding @syncobj_handles.
+	 */
+	__u64	syncobj_points;
 };
 
 struct drm_amdgpu_userq_fence_info {
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/2 drm/amdgpu/userq: Rename waitq_id to queue_id in wait ioctl

To make it consistent with signal ioctl.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 8 ++++----
 include/uapi/drm/amdgpu_drm.h                   | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +4 -4
index 5b2cdc49a28c..a9d51b38b7d3 100644
@@ -674,7 +674,7 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,
 	struct drm_amdgpu_userq_wait *wait_info = data;
 	struct amdgpu_fpriv *fpriv = filp->driver_priv;
 	struct amdgpu_userq_mgr *userq_mgr = &fpriv->userq_mgr;
-	struct amdgpu_usermode_queue *waitq;
+	struct amdgpu_usermode_queue *queue;
 	struct drm_gem_object **gobj_write;
 	struct drm_gem_object **gobj_read;
 	struct dma_fence **fences = NULL;
@@ -930,8 +930,8 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,
 		 */
 		num_fences = dma_fence_dedup_array(fences, num_fences);
 
-		waitq = idr_find(&userq_mgr->userq_idr, wait_info->waitq_id);
-		if (!waitq) {
+		queue = idr_find(&userq_mgr->userq_idr, wait_info->queue_id);
+		if (!queue) {
 			r = -EINVAL;
 			goto free_fences;
 		}
@@ -964,7 +964,7 @@ int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,
 			 * Otherwise, we would gather those references until we don't
 			 * have any more space left and crash.
 			 */
-			r = xa_alloc(&waitq->fence_drv_xa, &index, fence_drv,
+			r = xa_alloc(&queue->fence_drv_xa, &index, fence_drv,
 				     xa_limit_32b, GFP_KERNEL);
 			if (r)
 				goto free_fences;
include/uapi/drm/amdgpu_drm.h +1 -1
index 197ea3bfb559..6d4bf401f783 100644
@@ -530,7 +530,7 @@ struct drm_amdgpu_userq_wait {
 	 * @waitq_id: Queue handle used by the userq wait IOCTL to retrieve the
 	 * wait queue and maintain the fence driver references in it.
 	 */
-	__u32	waitq_id;
+	__u32	queue_id;
 	__u32	pad;
 	/**
 	 * @syncobj_handles: The list of syncobj handles submitted by the user queue
Signature · 1 line
2.43.0
#2 lore raw
In reply to David Rosca

Cc Christian

Mesa MR: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37335

Quoted 117 lines · David Rosca
---
  .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   | 49 +++++++++++++++----
  include/uapi/drm/amdgpu_drm.h                 |  5 ++
  2 files changed, 45 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +40 -9
index 95e91d1dc58a..5b2cdc49a28c 100644
@@ -460,10 +460,11 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
  	struct drm_gem_object **gobj_read = NULL;
  	struct amdgpu_usermode_queue *queue;
  	struct amdgpu_userq_fence *userq_fence;
-	struct drm_syncobj **syncobj = NULL;
+	struct amdgpu_cs_post_dep *syncobj = NULL;
  	u32 *bo_handles_write, num_write_bo_handles;
  	u32 *syncobj_handles, num_syncobj_handles;
  	u32 *bo_handles_read, num_read_bo_handles;
+	u64 *syncobj_points = NULL;
  	int r, i, entry, rentry, wentry;
  	struct dma_fence *fence;
  	struct drm_exec exec;
@@ -475,19 +476,37 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
  	if (IS_ERR(syncobj_handles))
  		return PTR_ERR(syncobj_handles);
 
+	if (args->syncobj_points) {
+		syncobj_points = memdup_user(u64_to_user_ptr(args->syncobj_points),
+					     sizeof(u64) * num_syncobj_handles);
+		if (IS_ERR(syncobj_points)) {
+			r = PTR_ERR(syncobj_points);
+			goto free_syncobj_handles;
+		}
+	}
+
  	/* Array of pointers to the looked up syncobjs */
  	syncobj = kmalloc_array(num_syncobj_handles, sizeof(*syncobj), GFP_KERNEL);
  	if (!syncobj) {
  		r = -ENOMEM;
-		goto free_syncobj_handles;
+		goto free_syncobj_points;
  	}
 
  	for (entry = 0; entry < num_syncobj_handles; entry++) {
-		syncobj[entry] = drm_syncobj_find(filp, syncobj_handles[entry]);
-		if (!syncobj[entry]) {
+		syncobj[entry].chain = NULL;
+		syncobj[entry].syncobj = drm_syncobj_find(filp, syncobj_handles[entry]);
+		if (!syncobj[entry].syncobj) {
  			r = -ENOENT;
  			goto free_syncobj;
  		}
+		if (syncobj_points && syncobj_points[entry]) {
+			syncobj[entry].point = syncobj_points[entry];
+			syncobj[entry].chain = dma_fence_chain_alloc();
+			if (!syncobj[entry].chain) {
+				r = -ENOMEM;
+				goto free_syncobj;
+			}
+		}
  	}
 
  	num_read_bo_handles = args->num_bo_read_handles;
@@ -603,8 +622,15 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
  	}
 
  	/* Add the created fence to syncobj/BO's */
-	for (i = 0; i < num_syncobj_handles; i++)
-		drm_syncobj_replace_fence(syncobj[i], fence);
+	for (i = 0; i < num_syncobj_handles; i++) {
+		if (syncobj[i].chain) {
+			drm_syncobj_add_point(syncobj[i].syncobj, syncobj[i].chain,
+							      fence, syncobj[i].point);
+			syncobj[i].chain = NULL;
+		} else {
+			drm_syncobj_replace_fence(syncobj[i].syncobj, fence);
+		}
+	}
 
  	/* drop the reference acquired in fence creation function */
  	dma_fence_put(fence);
@@ -624,10 +650,15 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
  free_bo_handles_read:
  	kfree(bo_handles_read);
  free_syncobj:
-	while (entry-- > 0)
-		if (syncobj[entry])
-			drm_syncobj_put(syncobj[entry]);
+	while (entry-- > 0) {
+		if (syncobj[entry].syncobj)
+			drm_syncobj_put(syncobj[entry].syncobj);
+		if (syncobj[entry].chain)
+			dma_fence_chain_free(syncobj[entry].chain);
+	}
  	kfree(syncobj);
+free_syncobj_points:
+	kfree(syncobj_points);
  free_syncobj_handles:
  	kfree(syncobj_handles);
 
include/uapi/drm/amdgpu_drm.h +5 -0
index 85b3ca14f81e..197ea3bfb559 100644
@@ -504,6 +504,11 @@ struct drm_amdgpu_userq_signal {
  	 * @bo_write_handles.
  	 */
  	__u32	num_bo_write_handles;
+	/**
+	 * @syncobj_points: The list of syncobj points submitted by the user queue job
+	 * for the corresponding @syncobj_handles.
+	 */
+	__u64	syncobj_points;
  };
 
  struct drm_amdgpu_userq_fence_info {