Skip to contentSkip to conversation

Allow num_binds/num_batch_buffer to be zero IOCTLs

PATCH Superseded Matthew Brost 5 participants 17 messages Nov 16, 2023 – Dec 5, 2023

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Matthew Brost

author maintainer
#0 lore raw

cover Allow num_binds/num_batch_buffer to be zero IOCTLs

Easy way to flush exec queues. A semantic that VK will likely use.

Matthew Brost (5):
drm/xe: Allow num_binds == 0 in VM bind IOCTL
drm/xe: Use a flags field instead of bools for VMA create drm/xe: Use a flags field instead of bools for sync parse rm/xe: Allow num_batch_buffer == 0 in exec IOCTL
drm/xe: Take in-syncs into account when num_execs or num_binds == 0

 drivers/gpu/drm/xe/xe_exec.c             |  32 ++++++-
 drivers/gpu/drm/xe/xe_exec_queue.c       |   5 +-
 drivers/gpu/drm/xe/xe_exec_queue_types.h |   5 +-
 drivers/gpu/drm/xe/xe_sync.c             |  86 ++++++++++++++++-
 drivers/gpu/drm/xe/xe_sync.h             |  11 ++-
 drivers/gpu/drm/xe/xe_vm.c               | 117 ++++++++++++++---------
 6 files changed, 199 insertions(+), 57 deletions(-)
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 1/5 drm/xe: Allow num_binds == 0 in VM bind IOCTL

The idea being out-syncs can signal indicating all previous operations on the bind queue are complete. An example use case of this would be support for implementing vkQueueWaitForIdle easily.

---
 drivers/gpu/drm/xe/xe_vm.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +18 -12
index d45f4f1d490f..cd8c2332a22e 100644
@@ -2850,7 +2850,6 @@ static int vm_bind_ioctl_check_args(struct xe_device *xe,
 	int i;
 
 	if (XE_IOCTL_DBG(xe, args->extensions) ||
-	    XE_IOCTL_DBG(xe, !args->num_binds) ||
 	    XE_IOCTL_DBG(xe, args->num_binds > MAX_BINDS))
 		return -EINVAL;
 
@@ -2977,7 +2976,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 			goto put_exec_queue;
 		}
 
-		if (XE_IOCTL_DBG(xe, async !=
+		if (XE_IOCTL_DBG(xe, args->num_binds && async !=
 				 !!(q->flags & EXEC_QUEUE_FLAG_VM_ASYNC))) {
 			err = -EINVAL;
 			goto put_exec_queue;
@@ -2991,7 +2990,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	}
 
 	if (!args->exec_queue_id) {
-		if (XE_IOCTL_DBG(xe, async !=
+		if (XE_IOCTL_DBG(xe, args->num_binds && async !=
 				 !!(vm->flags & XE_VM_FLAG_ASYNC_DEFAULT))) {
 			err = -EINVAL;
 			goto put_vm;
@@ -3028,16 +3027,18 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 		}
 	}
 
-	bos = kzalloc(sizeof(*bos) * args->num_binds, GFP_KERNEL);
-	if (!bos) {
-		err = -ENOMEM;
-		goto release_vm_lock;
-	}
+	if (args->num_binds) {
+		bos = kzalloc(sizeof(*bos) * args->num_binds, GFP_KERNEL);
+		if (!bos) {
+			err = -ENOMEM;
+			goto release_vm_lock;
+		}
 
-	ops = kzalloc(sizeof(*ops) * args->num_binds, GFP_KERNEL);
-	if (!ops) {
-		err = -ENOMEM;
-		goto release_vm_lock;
+		ops = kzalloc(sizeof(*ops) * args->num_binds, GFP_KERNEL);
+		if (!ops) {
+			err = -ENOMEM;
+			goto release_vm_lock;
+		}
 	}
 
 	for (i = 0; i < args->num_binds; ++i) {
@@ -3092,6 +3093,11 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 			goto free_syncs;
 	}
 
+	if (!args->num_binds) {
+		err = -ENODATA;
+		goto free_syncs;
+	}
+
 	for (i = 0; i < args->num_binds; ++i) {
 		u64 range = bind_ops[i].range;
 		u64 addr = bind_ops[i].addr;
Signature · 1 line
2.34.1
#2 lore raw

Re: [Intel-xe] [PATCH 1/5] drm/xe: Allow num_binds == 0 in VM bind IOCTL

Quoted 3 lines · Matthew Brost

The idea being out-syncs can signal indicating all previous operations on the bind queue are complete. An example use case of this would be support for implementing vkQueueWaitForIdle easily.

s/vkQueueWaitForIdle/vkQueueWaitIdle

So this is just for the bind queue.
Not sure if it is useful, Mesa will eventually move to async vm bind and we will use a single TIMELINE_SYNCOBJ to track what bind operations are completed.
Paulo do you see any use with sparse?

Quoted 77 lines
---
 drivers/gpu/drm/xe/xe_vm.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +18 -12
index d45f4f1d490f..cd8c2332a22e 100644
@@ -2850,7 +2850,6 @@ static int vm_bind_ioctl_check_args(struct xe_device *xe,
 	int i;
 
 	if (XE_IOCTL_DBG(xe, args->extensions) ||
-	    XE_IOCTL_DBG(xe, !args->num_binds) ||
 	    XE_IOCTL_DBG(xe, args->num_binds > MAX_BINDS))
 		return -EINVAL;
 
@@ -2977,7 +2976,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 			goto put_exec_queue;
 		}
 
-		if (XE_IOCTL_DBG(xe, async !=
+		if (XE_IOCTL_DBG(xe, args->num_binds && async !=
 				 !!(q->flags & EXEC_QUEUE_FLAG_VM_ASYNC))) {
 			err = -EINVAL;
 			goto put_exec_queue;
@@ -2991,7 +2990,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	}
 
 	if (!args->exec_queue_id) {
-		if (XE_IOCTL_DBG(xe, async !=
+		if (XE_IOCTL_DBG(xe, args->num_binds && async !=
 				 !!(vm->flags & XE_VM_FLAG_ASYNC_DEFAULT))) {
 			err = -EINVAL;
 			goto put_vm;
@@ -3028,16 +3027,18 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 		}
 	}
 
-	bos = kzalloc(sizeof(*bos) * args->num_binds, GFP_KERNEL);
-	if (!bos) {
-		err = -ENOMEM;
-		goto release_vm_lock;
-	}
+	if (args->num_binds) {
+		bos = kzalloc(sizeof(*bos) * args->num_binds, GFP_KERNEL);
+		if (!bos) {
+			err = -ENOMEM;
+			goto release_vm_lock;
+		}
 
-	ops = kzalloc(sizeof(*ops) * args->num_binds, GFP_KERNEL);
-	if (!ops) {
-		err = -ENOMEM;
-		goto release_vm_lock;
+		ops = kzalloc(sizeof(*ops) * args->num_binds, GFP_KERNEL);
+		if (!ops) {
+			err = -ENOMEM;
+			goto release_vm_lock;
+		}
 	}
 
 	for (i = 0; i < args->num_binds; ++i) {
@@ -3092,6 +3093,11 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 			goto free_syncs;
 	}
 
+	if (!args->num_binds) {
+		err = -ENODATA;
+		goto free_syncs;
+	}
+
 	for (i = 0; i < args->num_binds; ++i) {
 		u64 range = bind_ops[i].range;
 		u64 addr = bind_ops[i].addr;
#3 lore raw

Re: [Intel-xe] [PATCH 1/5] drm/xe: Allow num_binds == 0 in VM bind IOCTL

Quoted 11 lines · Jose
Quoted 3 lines · Matthew Brost

The idea being out-syncs can signal indicating all previous operations on the bind queue are complete. An example use case of this would be support for implementing vkQueueWaitForIdle easily.

s/vkQueueWaitForIdle/vkQueueWaitIdle

So this is just for the bind queue.
Not sure if it is useful, Mesa will eventually move to async vm bind and we will use a single TIMELINE_SYNCOBJ to track what bind operations are completed.
Paulo do you see any use with sparse?

We don't have plans to submit stuff to the Kernel with num_binds=0, but we do need the Kernel to support the case where we're trying to bind something that's already bound (so there's nothing for the Kernel to do, but num_binds > 0).

And yes to track operations that are already complete it's usually better to just check the syncobj (timeline or not) of the last thing you submitted.

Currently, due to the xe.ko bugs, our vm_bind code is completely synchronous, but the plan is to move it to async like we're doing with TR-TT.

I'm not discarding the possibility that we may have to do something extra for vkQueueWaitIdle, especially after we make it async, but I don't think submitting num_binds=0 will be the right choice.

Quoted 79 lines
Quoted 78 lines
---
 drivers/gpu/drm/xe/xe_vm.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +18 -12
index d45f4f1d490f..cd8c2332a22e 100644
@@ -2850,7 +2850,6 @@ static int vm_bind_ioctl_check_args(struct xe_device *xe,
 	int i;
 
 	if (XE_IOCTL_DBG(xe, args->extensions) ||
-	    XE_IOCTL_DBG(xe, !args->num_binds) ||
 	    XE_IOCTL_DBG(xe, args->num_binds > MAX_BINDS))
 		return -EINVAL;
 
@@ -2977,7 +2976,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 			goto put_exec_queue;
 		}
 
-		if (XE_IOCTL_DBG(xe, async !=
+		if (XE_IOCTL_DBG(xe, args->num_binds && async !=
 				 !!(q->flags & EXEC_QUEUE_FLAG_VM_ASYNC))) {
 			err = -EINVAL;
 			goto put_exec_queue;
@@ -2991,7 +2990,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	}
 
 	if (!args->exec_queue_id) {
-		if (XE_IOCTL_DBG(xe, async !=
+		if (XE_IOCTL_DBG(xe, args->num_binds && async !=
 				 !!(vm->flags & XE_VM_FLAG_ASYNC_DEFAULT))) {
 			err = -EINVAL;
 			goto put_vm;
@@ -3028,16 +3027,18 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 		}
 	}
 
-	bos = kzalloc(sizeof(*bos) * args->num_binds, GFP_KERNEL);
-	if (!bos) {
-		err = -ENOMEM;
-		goto release_vm_lock;
-	}
+	if (args->num_binds) {
+		bos = kzalloc(sizeof(*bos) * args->num_binds, GFP_KERNEL);
+		if (!bos) {
+			err = -ENOMEM;
+			goto release_vm_lock;
+		}
 
-	ops = kzalloc(sizeof(*ops) * args->num_binds, GFP_KERNEL);
-	if (!ops) {
-		err = -ENOMEM;
-		goto release_vm_lock;
+		ops = kzalloc(sizeof(*ops) * args->num_binds, GFP_KERNEL);
+		if (!ops) {
+			err = -ENOMEM;
+			goto release_vm_lock;
+		}
 	}
 
 	for (i = 0; i < args->num_binds; ++i) {
@@ -3092,6 +3093,11 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 			goto free_syncs;
 	}
 
+	if (!args->num_binds) {
+		err = -ENODATA;
+		goto free_syncs;
+	}
+
 	for (i = 0; i < args->num_binds; ++i) {
 		u64 range = bind_ops[i].range;
 		u64 addr = bind_ops[i].addr;
author maintainer
#4 lore raw

Re: [Intel-xe] [PATCH 1/5] drm/xe: Allow num_binds == 0 in VM bind IOCTL

Quoted 13 lines · Paulo R
Quoted 11 lines · Jose
Quoted 3 lines · Matthew Brost

The idea being out-syncs can signal indicating all previous operations on the bind queue are complete. An example use case of this would be support for implementing vkQueueWaitForIdle easily.

s/vkQueueWaitForIdle/vkQueueWaitIdle

So this is just for the bind queue.
Not sure if it is useful, Mesa will eventually move to async vm bind and we will use a single TIMELINE_SYNCOBJ to track what bind operations are completed.
Paulo do you see any use with sparse?

Quoted 5 lines

We don't have plans to submit stuff to the Kernel with num_binds=0, but we do need the Kernel to support the case where we're trying to bind something that's already bound (so there's nothing for the Kernel to do, but num_binds > 0).

This series fixes an issue with num_binds > 0 but nothing to bind too.

Quoted 4 lines

And yes to track operations that are already complete it's usually better to just check the syncobj (timeline or not) of the last thing you submitted.

Quoted 8 lines

Currently, due to the xe.ko bugs, our vm_bind code is completely synchronous, but the plan is to move it to async like we're doing with TR-TT.

I'm not discarding the possibility that we may have to do something extra for vkQueueWaitIdle, especially after we make it async, but I don't think submitting num_binds=0 will be the right choice.

I'd like leave this option in the kernel as it is pretty easy to implement and matches the behavior for execs with num batches == 0.

Matt

Quoted 80 lines
Quoted 79 lines
Quoted 78 lines
---
 drivers/gpu/drm/xe/xe_vm.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +18 -12
index d45f4f1d490f..cd8c2332a22e 100644
@@ -2850,7 +2850,6 @@ static int vm_bind_ioctl_check_args(struct xe_device *xe,
 	int i;
 
 	if (XE_IOCTL_DBG(xe, args->extensions) ||
-	    XE_IOCTL_DBG(xe, !args->num_binds) ||
 	    XE_IOCTL_DBG(xe, args->num_binds > MAX_BINDS))
 		return -EINVAL;
 
@@ -2977,7 +2976,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 			goto put_exec_queue;
 		}
 
-		if (XE_IOCTL_DBG(xe, async !=
+		if (XE_IOCTL_DBG(xe, args->num_binds && async !=
 				 !!(q->flags & EXEC_QUEUE_FLAG_VM_ASYNC))) {
 			err = -EINVAL;
 			goto put_exec_queue;
@@ -2991,7 +2990,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	}
 
 	if (!args->exec_queue_id) {
-		if (XE_IOCTL_DBG(xe, async !=
+		if (XE_IOCTL_DBG(xe, args->num_binds && async !=
 				 !!(vm->flags & XE_VM_FLAG_ASYNC_DEFAULT))) {
 			err = -EINVAL;
 			goto put_vm;
@@ -3028,16 +3027,18 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 		}
 	}
 
-	bos = kzalloc(sizeof(*bos) * args->num_binds, GFP_KERNEL);
-	if (!bos) {
-		err = -ENOMEM;
-		goto release_vm_lock;
-	}
+	if (args->num_binds) {
+		bos = kzalloc(sizeof(*bos) * args->num_binds, GFP_KERNEL);
+		if (!bos) {
+			err = -ENOMEM;
+			goto release_vm_lock;
+		}
 
-	ops = kzalloc(sizeof(*ops) * args->num_binds, GFP_KERNEL);
-	if (!ops) {
-		err = -ENOMEM;
-		goto release_vm_lock;
+		ops = kzalloc(sizeof(*ops) * args->num_binds, GFP_KERNEL);
+		if (!ops) {
+			err = -ENOMEM;
+			goto release_vm_lock;
+		}
 	}
 
 	for (i = 0; i < args->num_binds; ++i) {
@@ -3092,6 +3093,11 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 			goto free_syncs;
 	}
 
+	if (!args->num_binds) {
+		err = -ENODATA;
+		goto free_syncs;
+	}
+
 	for (i = 0; i < args->num_binds; ++i) {
 		u64 range = bind_ops[i].range;
 		u64 addr = bind_ops[i].addr;
author maintainer
#5 lore raw

PATCH 2/5 drm/xe: Use a flags field instead of bools for VMA create

In reply to Matthew Brost

Use a flags field instead of severval bools for VMA create as it is easier to read and less bug prone.

---
 drivers/gpu/drm/xe/xe_vm.c | 58 ++++++++++++++++++++------------------
 1 file changed, 30 insertions(+), 28 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +30 -28
index cd8c2332a22e..13c8a9c6117c 100644
@@ -858,17 +858,21 @@ struct dma_fence *xe_vm_rebind(struct xe_vm *vm, bool rebind_worker)
 	return fence;
 }
 
+#define VMA_CREATE_FLAG_READ_ONLY	BIT(0)
+#define VMA_CREATE_FLAG_IS_NULL		BIT(1)
+
 static struct xe_vma *xe_vma_create(struct xe_vm *vm,
 				    struct xe_bo *bo,
 				    u64 bo_offset_or_userptr,
 				    u64 start, u64 end,
-				    bool read_only,
-				    bool is_null,
-				    u8 tile_mask)
+				    u8 tile_mask,
+				    unsigned int flags)
 {
 	struct xe_vma *vma;
 	struct xe_tile *tile;
 	u8 id;
+	bool read_only = (flags & VMA_CREATE_FLAG_READ_ONLY);
+	bool is_null = (flags & VMA_CREATE_FLAG_IS_NULL);
 
 	xe_assert(vm->xe, start < end);
 	xe_assert(vm->xe, end < vm->size);
@@ -2263,7 +2267,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
 }
 
 static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
-			      u8 tile_mask, bool read_only, bool is_null)
+			      u8 tile_mask, unsigned int flags)
 {
 	struct xe_bo *bo = op->gem.obj ? gem_to_xe_bo(op->gem.obj) : NULL;
 	struct xe_vma *vma;
@@ -2278,8 +2282,7 @@ static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
 	}
 	vma = xe_vma_create(vm, bo, op->gem.offset,
 			    op->va.addr, op->va.addr +
-			    op->va.range - 1, read_only, is_null,
-			    tile_mask);
+			    op->va.range - 1, tile_mask, flags);
 	if (bo)
 		xe_bo_unlock(bo);
 
@@ -2405,7 +2408,9 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_exec_queue *q,
 
 	drm_gpuva_for_each_op(__op, ops) {
 		struct xe_vma_op *op = gpuva_op_to_vma_op(__op);
+		struct xe_vma *vma;
 		bool first = list_empty(ops_list);
+		unsigned int flags = 0;
 
 		INIT_LIST_HEAD(&op->link);
 		list_add_tail(&op->link, ops_list);
@@ -2421,11 +2426,13 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_exec_queue *q,
 		switch (op->base.op) {
 		case DRM_GPUVA_OP_MAP:
 		{
-			struct xe_vma *vma;
+			flags |= op->map.read_only ?
+				VMA_CREATE_FLAG_READ_ONLY : 0;
+			flags |= op->map.is_null ?
+				VMA_CREATE_FLAG_IS_NULL : 0;
 
 			vma = new_vma(vm, &op->base.map,
-				      op->tile_mask, op->map.read_only,
-				      op->map.is_null);
+				      op->tile_mask, flags);
 			if (IS_ERR(vma))
 				return PTR_ERR(vma);
 
@@ -2441,17 +2448,15 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_exec_queue *q,
 			op->remap.range = xe_vma_size(old);
 
 			if (op->base.remap.prev) {
-				struct xe_vma *vma;
-				bool read_only =
-					op->base.remap.unmap->va->flags &
-					XE_VMA_READ_ONLY;
-				bool is_null =
-					op->base.remap.unmap->va->flags &
-					DRM_GPUVA_SPARSE;
+				flags |= op->base.remap.unmap->va->flags &
+					XE_VMA_READ_ONLY ?
+					VMA_CREATE_FLAG_READ_ONLY : 0;
+				flags |= op->base.remap.unmap->va->flags &
+					DRM_GPUVA_SPARSE ?
+					VMA_CREATE_FLAG_IS_NULL : 0;
 
 				vma = new_vma(vm, op->base.remap.prev,
-					      op->tile_mask, read_only,
-					      is_null);
+					      op->tile_mask, flags);
 				if (IS_ERR(vma))
 					return PTR_ERR(vma);
 
@@ -2474,18 +2479,15 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_exec_queue *q,
 			}
 
 			if (op->base.remap.next) {
-				struct xe_vma *vma;
-				bool read_only =
-					op->base.remap.unmap->va->flags &
-					XE_VMA_READ_ONLY;
-
-				bool is_null =
-					op->base.remap.unmap->va->flags &
-					DRM_GPUVA_SPARSE;
+				flags |= op->base.remap.unmap->va->flags &
+					XE_VMA_READ_ONLY ?
+					VMA_CREATE_FLAG_READ_ONLY : 0;
+				flags |= op->base.remap.unmap->va->flags &
+					DRM_GPUVA_SPARSE ?
+					VMA_CREATE_FLAG_IS_NULL : 0;
 
 				vma = new_vma(vm, op->base.remap.next,
-					      op->tile_mask, read_only,
-					      is_null);
+					      op->tile_mask, flags);
 				if (IS_ERR(vma))
 					return PTR_ERR(vma);
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 2/5
#6 lore raw

Re: [Intel-xe] [PATCH 2/5] drm/xe: Use a flags field instead of bools for VMA create

Quoted 5 lines · Matthew Brost

Use a flags field instead of severval bools for VMA create as it is easier to read and less bug prone.

Hmm.

If you feel that this was not really an improvement feel free to disregard. Anyway,

Quoted 130 lines
---
  drivers/gpu/drm/xe/xe_vm.c | 58 ++++++++++++++++++++------------------
  1 file changed, 30 insertions(+), 28 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +30 -28
index cd8c2332a22e..13c8a9c6117c 100644
@@ -858,17 +858,21 @@ struct dma_fence *xe_vm_rebind(struct xe_vm *vm, bool rebind_worker)
  	return fence;
  }
 
+#define VMA_CREATE_FLAG_READ_ONLY	BIT(0)
+#define VMA_CREATE_FLAG_IS_NULL		BIT(1)
+
  static struct xe_vma *xe_vma_create(struct xe_vm *vm,
  				    struct xe_bo *bo,
  				    u64 bo_offset_or_userptr,
  				    u64 start, u64 end,
-				    bool read_only,
-				    bool is_null,
-				    u8 tile_mask)
+				    u8 tile_mask,
+				    unsigned int flags)
  {
  	struct xe_vma *vma;
  	struct xe_tile *tile;
  	u8 id;
+	bool read_only = (flags & VMA_CREATE_FLAG_READ_ONLY);
+	bool is_null = (flags & VMA_CREATE_FLAG_IS_NULL);
 
  	xe_assert(vm->xe, start < end);
  	xe_assert(vm->xe, end < vm->size);
@@ -2263,7 +2267,7 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,
  }
 
  static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
-			      u8 tile_mask, bool read_only, bool is_null)
+			      u8 tile_mask, unsigned int flags)
  {
  	struct xe_bo *bo = op->gem.obj ? gem_to_xe_bo(op->gem.obj) : NULL;
  	struct xe_vma *vma;
@@ -2278,8 +2282,7 @@ static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
  	}
  	vma = xe_vma_create(vm, bo, op->gem.offset,
  			    op->va.addr, op->va.addr +
-			    op->va.range - 1, read_only, is_null,
-			    tile_mask);
+			    op->va.range - 1, tile_mask, flags);
  	if (bo)
  		xe_bo_unlock(bo);
 
@@ -2405,7 +2408,9 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_exec_queue *q,
 
  	drm_gpuva_for_each_op(__op, ops) {
  		struct xe_vma_op *op = gpuva_op_to_vma_op(__op);
+		struct xe_vma *vma;
  		bool first = list_empty(ops_list);
+		unsigned int flags = 0;
 
  		INIT_LIST_HEAD(&op->link);
  		list_add_tail(&op->link, ops_list);
@@ -2421,11 +2426,13 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_exec_queue *q,
  		switch (op->base.op) {
  		case DRM_GPUVA_OP_MAP:
  		{
-			struct xe_vma *vma;
+			flags |= op->map.read_only ?
+				VMA_CREATE_FLAG_READ_ONLY : 0;
+			flags |= op->map.is_null ?
+				VMA_CREATE_FLAG_IS_NULL : 0;
 
  			vma = new_vma(vm, &op->base.map,
-				      op->tile_mask, op->map.read_only,
-				      op->map.is_null);
+				      op->tile_mask, flags);
  			if (IS_ERR(vma))
  				return PTR_ERR(vma);
 
@@ -2441,17 +2448,15 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_exec_queue *q,
  			op->remap.range = xe_vma_size(old);
 
  			if (op->base.remap.prev) {
-				struct xe_vma *vma;
-				bool read_only =
-					op->base.remap.unmap->va->flags &
-					XE_VMA_READ_ONLY;
-				bool is_null =
-					op->base.remap.unmap->va->flags &
-					DRM_GPUVA_SPARSE;
+				flags |= op->base.remap.unmap->va->flags &
+					XE_VMA_READ_ONLY ?
+					VMA_CREATE_FLAG_READ_ONLY : 0;
+				flags |= op->base.remap.unmap->va->flags &
+					DRM_GPUVA_SPARSE ?
+					VMA_CREATE_FLAG_IS_NULL : 0;
 
  				vma = new_vma(vm, op->base.remap.prev,
-					      op->tile_mask, read_only,
-					      is_null);
+					      op->tile_mask, flags);
  				if (IS_ERR(vma))
  					return PTR_ERR(vma);
 
@@ -2474,18 +2479,15 @@ static int vm_bind_ioctl_ops_parse(struct xe_vm *vm, struct xe_exec_queue *q,
  			}
 
  			if (op->base.remap.next) {
-				struct xe_vma *vma;
-				bool read_only =
-					op->base.remap.unmap->va->flags &
-					XE_VMA_READ_ONLY;
-
-				bool is_null =
-					op->base.remap.unmap->va->flags &
-					DRM_GPUVA_SPARSE;
+				flags |= op->base.remap.unmap->va->flags &
+					XE_VMA_READ_ONLY ?
+					VMA_CREATE_FLAG_READ_ONLY : 0;
+				flags |= op->base.remap.unmap->va->flags &
+					DRM_GPUVA_SPARSE ?
+					VMA_CREATE_FLAG_IS_NULL : 0;
 
  				vma = new_vma(vm, op->base.remap.next,
-					      op->tile_mask, read_only,
-					      is_null);
+					      op->tile_mask, flags);
  				if (IS_ERR(vma))
  					return PTR_ERR(vma);
 
author maintainer
#7 lore raw

PATCH 3/5 drm/xe: Use a flags field instead of bools for sync parse

In reply to Matthew Brost

Use a flags field instead of severval bools for sync parse as it is easier to read and less bug prone.

---
 drivers/gpu/drm/xe/xe_exec.c | 5 +++--
 drivers/gpu/drm/xe/xe_sync.c | 8 +++++---
 drivers/gpu/drm/xe/xe_vm.c   | 5 +++--
 3 files changed, 11 insertions(+), 7 deletions(-)
drivers/gpu/drm/xe/xe_exec.c +3 -2
index 28e84a0bbeb0..7d4d22c81a42 100644
@@ -181,8 +181,9 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 
 	for (i = 0; i < args->num_syncs; i++) {
 		err = xe_sync_entry_parse(xe, xef, &syncs[num_syncs++],
-					  &syncs_user[i], true,
-					  xe_vm_no_dma_fences(vm));
+					  &syncs_user[i], SYNC_PARSE_FLAG_EXEC |
+					  (xe_vm_no_dma_fences(vm) ?
+					   SYNC_PARSE_FLAG_LR_MODE : 0));
 		if (err)
 			goto err_syncs;
 	}
drivers/gpu/drm/xe/xe_sync.c +5 -3
index 73ef259aa387..016d0a2ea5bc 100644
@@ -100,10 +100,12 @@ static void user_fence_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
 int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 			struct xe_sync_entry *sync,
 			struct drm_xe_sync __user *sync_user,
-			bool exec, bool no_dma_fences)
+			unsigned int flags)
 {
 	struct drm_xe_sync sync_in;
 	int err;
+	bool exec = flags & SYNC_PARSE_FLAG_EXEC;
+	bool lr_mode = flags & SYNC_PARSE_FLAG_LR_MODE;
 	bool signal;
 
 	if (copy_from_user(&sync_in, sync_user, sizeof(*sync_user)))
@@ -118,7 +120,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 	signal = sync_in.flags & DRM_XE_SYNC_SIGNAL;
 	switch (sync_in.flags & SYNC_FLAGS_TYPE_MASK) {
 	case DRM_XE_SYNC_SYNCOBJ:
-		if (XE_IOCTL_DBG(xe, no_dma_fences && signal))
+		if (XE_IOCTL_DBG(xe, lr_mode && signal))
 			return -EOPNOTSUPP;
 
 		if (XE_IOCTL_DBG(xe, upper_32_bits(sync_in.addr)))
@@ -136,7 +138,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		break;
 
 	case DRM_XE_SYNC_TIMELINE_SYNCOBJ:
-		if (XE_IOCTL_DBG(xe, no_dma_fences && signal))
+		if (XE_IOCTL_DBG(xe, lr_mode && signal))
 			return -EOPNOTSUPP;
 
 		if (XE_IOCTL_DBG(xe, upper_32_bits(sync_in.addr)))
drivers/gpu/drm/xe/xe_vm.c +3 -2
index 13c8a9c6117c..1f3e5dcbef9e 100644
@@ -3089,8 +3089,9 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	syncs_user = u64_to_user_ptr(args->syncs);
 	for (num_syncs = 0; num_syncs < args->num_syncs; num_syncs++) {
 		err = xe_sync_entry_parse(xe, xef, &syncs[num_syncs],
-					  &syncs_user[num_syncs], false,
-					  xe_vm_no_dma_fences(vm));
+					  &syncs_user[num_syncs],
+					  xe_vm_no_dma_fences(vm) ?
+					  SYNC_PARSE_FLAG_LR_MODE : 0);
 		if (err)
 			goto free_syncs;
 	}
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 3/5
#8 lore raw

Re: [Intel-xe] [PATCH 3/5] drm/xe: Use a flags field instead of bools for sync parse

Quoted 5 lines · Matthew Brost

Use a flags field instead of severval bools for sync parse as it is easier to read and less bug prone.

Quoted 74 lines
---
  drivers/gpu/drm/xe/xe_exec.c | 5 +++--
  drivers/gpu/drm/xe/xe_sync.c | 8 +++++---
  drivers/gpu/drm/xe/xe_vm.c   | 5 +++--
  3 files changed, 11 insertions(+), 7 deletions(-)
drivers/gpu/drm/xe/xe_exec.c +3 -2
index 28e84a0bbeb0..7d4d22c81a42 100644
@@ -181,8 +181,9 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 
  	for (i = 0; i < args->num_syncs; i++) {
  		err = xe_sync_entry_parse(xe, xef, &syncs[num_syncs++],
-					  &syncs_user[i], true,
-					  xe_vm_no_dma_fences(vm));
+					  &syncs_user[i], SYNC_PARSE_FLAG_EXEC |
+					  (xe_vm_no_dma_fences(vm) ?
+					   SYNC_PARSE_FLAG_LR_MODE : 0));
  		if (err)
  			goto err_syncs;
  	}
drivers/gpu/drm/xe/xe_sync.c +5 -3
index 73ef259aa387..016d0a2ea5bc 100644
@@ -100,10 +100,12 @@ static void user_fence_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
  int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
  			struct xe_sync_entry *sync,
  			struct drm_xe_sync __user *sync_user,
-			bool exec, bool no_dma_fences)
+			unsigned int flags)
  {
  	struct drm_xe_sync sync_in;
  	int err;
+	bool exec = flags & SYNC_PARSE_FLAG_EXEC;
+	bool lr_mode = flags & SYNC_PARSE_FLAG_LR_MODE;
  	bool signal;
 
  	if (copy_from_user(&sync_in, sync_user, sizeof(*sync_user)))
@@ -118,7 +120,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
  	signal = sync_in.flags & DRM_XE_SYNC_SIGNAL;
  	switch (sync_in.flags & SYNC_FLAGS_TYPE_MASK) {
  	case DRM_XE_SYNC_SYNCOBJ:
-		if (XE_IOCTL_DBG(xe, no_dma_fences && signal))
+		if (XE_IOCTL_DBG(xe, lr_mode && signal))
  			return -EOPNOTSUPP;
 
  		if (XE_IOCTL_DBG(xe, upper_32_bits(sync_in.addr)))
@@ -136,7 +138,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
  		break;
 
  	case DRM_XE_SYNC_TIMELINE_SYNCOBJ:
-		if (XE_IOCTL_DBG(xe, no_dma_fences && signal))
+		if (XE_IOCTL_DBG(xe, lr_mode && signal))
  			return -EOPNOTSUPP;
 
  		if (XE_IOCTL_DBG(xe, upper_32_bits(sync_in.addr)))
drivers/gpu/drm/xe/xe_vm.c +3 -2
index 13c8a9c6117c..1f3e5dcbef9e 100644
@@ -3089,8 +3089,9 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  	syncs_user = u64_to_user_ptr(args->syncs);
  	for (num_syncs = 0; num_syncs < args->num_syncs; num_syncs++) {
  		err = xe_sync_entry_parse(xe, xef, &syncs[num_syncs],
-					  &syncs_user[num_syncs], false,
-					  xe_vm_no_dma_fences(vm));
+					  &syncs_user[num_syncs],
+					  xe_vm_no_dma_fences(vm) ?
+					  SYNC_PARSE_FLAG_LR_MODE : 0);
  		if (err)
  			goto free_syncs;
  	}
#9 lore raw

Re: [Intel-xe] [PATCH 3/5] drm/xe: Use a flags field instead of bools for sync parse

Quoted 10 lines · Thomas Hellström
Quoted 5 lines · Matthew Brost

Use a flags field instead of severval bools for sync parse as it is easier to read and less bug prone.

Hmm. It looks, though, that the header update slipped into the next patch.

/Thomas

Quoted 75 lines
Quoted 75 lines

---
  drivers/gpu/drm/xe/xe_exec.c | 5 +++--
  drivers/gpu/drm/xe/xe_sync.c | 8 +++++---
  drivers/gpu/drm/xe/xe_vm.c   | 5 +++--

  3 files changed, 11 insertions(+), 7 deletions(-)
drivers/gpu/drm/xe/xe_exec.c +3 -2
index 28e84a0bbeb0..7d4d22c81a42 100644
@@ -181,8 +181,9 @@ int xe_exec_ioctl(struct drm_device *dev, void 
 *data, struct drm_file *file)
         for (i = 0; i < args->num_syncs; i++) {
           err = xe_sync_entry_parse(xe, xef, &syncs[num_syncs++],
-                      &syncs_user[i], true,
-                      xe_vm_no_dma_fences(vm));
+                      &syncs_user[i], SYNC_PARSE_FLAG_EXEC |
+                      (xe_vm_no_dma_fences(vm) ?
+                       SYNC_PARSE_FLAG_LR_MODE : 0));
           if (err)
               goto err_syncs;
       }
drivers/gpu/drm/xe/xe_sync.c +3 -1
index 73ef259aa387..016d0a2ea5bc 100644
@@ -100,10 +100,12 @@ static void user_fence_cb(struct dma_fence 
 *fence, struct dma_fence_cb *cb)
   int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
               struct xe_sync_entry *sync,
               struct drm_xe_sync __user *sync_user,
-            bool exec, bool no_dma_fences)
+            unsigned int flags)
   {
       struct drm_xe_sync sync_in;
       int err;
+    bool exec = flags & SYNC_PARSE_FLAG_EXEC;
+    bool lr_mode = flags & SYNC_PARSE_FLAG_LR_MODE;
       bool signal;
         if (copy_from_user(&sync_in, sync_user, sizeof(*sync_user)))
@@ -118,7 +120,7 @@ int xe_sync_entry_parse(struct xe_device *xe, 
 struct xe_file *xef,
       signal = sync_in.flags & DRM_XE_SYNC_SIGNAL;
       switch (sync_in.flags & SYNC_FLAGS_TYPE_MASK) {

      case DRM_XE_SYNC_SYNCOBJ:
-        if (XE_IOCTL_DBG(xe, no_dma_fences && signal)) +        if (XE_IOCTL_DBG(xe, lr_mode && signal)) return -EOPNOTSUPP;
            if (XE_IOCTL_DBG(xe, upper_32_bits(sync_in.addr)))

drivers/gpu/drm/xe/xe_sync.c +0 -0
@@ -136,7 +138,7 @@ int xe_sync_entry_parse(struct xe_device *xe, 
 struct xe_file *xef,
           break;

        case DRM_XE_SYNC_TIMELINE_SYNCOBJ:
-        if (XE_IOCTL_DBG(xe, no_dma_fences && signal)) +        if (XE_IOCTL_DBG(xe, lr_mode && signal)) return -EOPNOTSUPP;
            if (XE_IOCTL_DBG(xe, upper_32_bits(sync_in.addr)))

drivers/gpu/drm/xe/xe_vm.c +3 -2
index 13c8a9c6117c..1f3e5dcbef9e 100644
@@ -3089,8 +3089,9 @@ int xe_vm_bind_ioctl(struct drm_device *dev, 
 void *data, struct drm_file *file)
       syncs_user = u64_to_user_ptr(args->syncs);
       for (num_syncs = 0; num_syncs < args->num_syncs; num_syncs++) {
           err = xe_sync_entry_parse(xe, xef, &syncs[num_syncs],
-                      &syncs_user[num_syncs], false,
-                      xe_vm_no_dma_fences(vm));
+                      &syncs_user[num_syncs],
+                      xe_vm_no_dma_fences(vm) ?
+                      SYNC_PARSE_FLAG_LR_MODE : 0);
           if (err)
               goto free_syncs;

      }

author maintainer
#10 lore raw

PATCH 4/5 rm/xe: Allow num_batch_buffer == 0 in exec IOCTL

In reply to Matthew Brost

The idea being out-syncs can signal indicating all previous operations on the exec queue are complete. An example use case of this would be support for implementing vkQueueWaitForIdle easily.

v2: Don't add last_fence for VM's that do not support dma fences
v3: Use a flags field instead of severval bools in sync parse (Thomas)

---
 drivers/gpu/drm/xe/xe_exec.c             | 23 ++++++++++++++++++++---
 drivers/gpu/drm/xe/xe_exec_queue.c       |  5 ++++-
 drivers/gpu/drm/xe/xe_exec_queue_types.h |  5 +++--
 drivers/gpu/drm/xe/xe_sync.c             |  4 ++++
 drivers/gpu/drm/xe/xe_sync.h             |  6 +++++-
 5 files changed, 36 insertions(+), 7 deletions(-)
drivers/gpu/drm/xe/xe_exec.c +20 -3
index 7d4d22c81a42..4989bc6038af 100644
@@ -161,7 +161,8 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	if (XE_IOCTL_DBG(xe, q->flags & EXEC_QUEUE_FLAG_VM))
 		return -EINVAL;
 
-	if (XE_IOCTL_DBG(xe, q->width != args->num_batch_buffer))
+	if (XE_IOCTL_DBG(xe, args->num_batch_buffer &&
+			 q->width != args->num_batch_buffer))
 		return -EINVAL;
 
 	if (XE_IOCTL_DBG(xe, q->flags & EXEC_QUEUE_FLAG_BANNED)) {
@@ -183,12 +184,14 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 		err = xe_sync_entry_parse(xe, xef, &syncs[num_syncs++],
 					  &syncs_user[i], SYNC_PARSE_FLAG_EXEC |
 					  (xe_vm_no_dma_fences(vm) ?
-					   SYNC_PARSE_FLAG_LR_MODE : 0));
+					   SYNC_PARSE_FLAG_LR_MODE : 0) |
+					  (!args->num_batch_buffer ?
+					   SYNC_PARSE_FLAG_DISALLOW_USER_FENCE : 0));
 		if (err)
 			goto err_syncs;
 	}
 
-	if (xe_exec_queue_is_parallel(q)) {
+	if (args->num_batch_buffer && xe_exec_queue_is_parallel(q)) {
 		err = __copy_from_user(addresses, addresses_user, sizeof(u64) *
 				       q->width);
 		if (err) {
@@ -235,6 +238,18 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 		goto err_exec;
 	}
 
+	if (!args->num_batch_buffer) {
+		if (!xe_vm_no_dma_fences(vm)) {
+			struct dma_fence *fence =
+				xe_exec_queue_last_fence_get(q, vm);
+
+			for (i = 0; i < num_syncs; i++)
+				xe_sync_entry_signal(&syncs[i], NULL, fence);
+		}
+
+		goto err_exec;
+	}
+
 	if (xe_exec_queue_is_lr(q) && xe_exec_queue_ring_full(q)) {
 		err = -EWOULDBLOCK;
 		goto err_exec;
@@ -328,6 +343,8 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 
 	if (xe_exec_queue_is_lr(q))
 		q->ring_ops->emit_job(job);
+	if (!xe_vm_no_dma_fences(vm))
+		xe_exec_queue_last_fence_set(q, vm, &job->drm.s_fence->finished);
 	xe_sched_job_push(job);
 	xe_vm_reactivate_rebind(vm);
 
drivers/gpu/drm/xe/xe_exec_queue.c +4 -1
index 4fd44a9203e4..35710b66e5de 100644
@@ -924,7 +924,10 @@ int xe_exec_queue_set_property_ioctl(struct drm_device *dev, void *data,
 static void xe_exec_queue_last_fence_lockdep_assert(struct xe_exec_queue *q,
 						    struct xe_vm *vm)
 {
-	lockdep_assert_held_write(&vm->lock);
+	if (q->flags & EXEC_QUEUE_FLAG_VM)
+		lockdep_assert_held_write(&vm->lock);
+	else
+		xe_vm_assert_held(vm);
 }
 
 /**
drivers/gpu/drm/xe/xe_exec_queue_types.h +3 -2
index 5ba47a5cfdbd..52f0927d0d9b 100644
@@ -56,8 +56,9 @@ struct xe_exec_queue {
 	struct xe_hw_fence_irq *fence_irq;
 
 	/**
-	 * @last_fence: last fence on engine, protected by vm->lock in write
-	 * mode if bind engine
+	 * @last_fence: last fence on exec queue, protected by vm->lock in write
+	 * mode if bind exec queue, protected by dma resv lock if non-bind exec
+	 * queue
 	 */
 	struct dma_fence *last_fence;
 
drivers/gpu/drm/xe/xe_sync.c +4 -0
index 016d0a2ea5bc..cfe8724ee954 100644
@@ -106,6 +106,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 	int err;
 	bool exec = flags & SYNC_PARSE_FLAG_EXEC;
 	bool lr_mode = flags & SYNC_PARSE_FLAG_LR_MODE;
+	bool disallow_user_fence = flags & SYNC_PARSE_FLAG_DISALLOW_USER_FENCE;
 	bool signal;
 
 	if (copy_from_user(&sync_in, sync_user, sizeof(*sync_user)))
@@ -173,6 +174,9 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		break;
 
 	case DRM_XE_SYNC_USER_FENCE:
+		if (XE_IOCTL_DBG(xe, disallow_user_fence))
+			return -EOPNOTSUPP;
+
 		if (XE_IOCTL_DBG(xe, !signal))
 			return -EOPNOTSUPP;
 
drivers/gpu/drm/xe/xe_sync.h +5 -1
index 30958ddc4cdc..45f4371e94b9 100644
@@ -12,10 +12,14 @@ struct xe_device;
 struct xe_file;
 struct xe_sched_job;
 
+#define SYNC_PARSE_FLAG_EXEC			BIT(0)
+#define SYNC_PARSE_FLAG_LR_MODE			BIT(1)
+#define SYNC_PARSE_FLAG_DISALLOW_USER_FENCE	BIT(2)
+
 int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 			struct xe_sync_entry *sync,
 			struct drm_xe_sync __user *sync_user,
-			bool exec, bool compute_mode);
+			unsigned int flags);
 int xe_sync_entry_wait(struct xe_sync_entry *sync);
 int xe_sync_entry_add_deps(struct xe_sync_entry *sync,
 			   struct xe_sched_job *job);
Signature · 1 line
2.34.1
#11 lore raw

Re: [Intel-xe] [PATCH 4/5] rm/xe: Allow num_batch_buffer == 0 in exec IOCTL

Quoted 3 lines · Matthew Brost

The idea being out-syncs can signal indicating all previous operations on the exec queue are complete. An example use case of this would be support for implementing vkQueueWaitForIdle easily.

vkQueueWaitIdle

That is useful for Mesa.

Quoted 146 lines

v2: Don't add last_fence for VM's that do not support dma fences
v3: Use a flags field instead of severval bools in sync parse (Thomas)

---
 drivers/gpu/drm/xe/xe_exec.c             | 23 ++++++++++++++++++++---
 drivers/gpu/drm/xe/xe_exec_queue.c       |  5 ++++-
 drivers/gpu/drm/xe/xe_exec_queue_types.h |  5 +++--
 drivers/gpu/drm/xe/xe_sync.c             |  4 ++++
 drivers/gpu/drm/xe/xe_sync.h             |  6 +++++-
 5 files changed, 36 insertions(+), 7 deletions(-)
drivers/gpu/drm/xe/xe_exec.c +20 -3
index 7d4d22c81a42..4989bc6038af 100644
@@ -161,7 +161,8 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 	if (XE_IOCTL_DBG(xe, q->flags & EXEC_QUEUE_FLAG_VM))
 		return -EINVAL;
 
-	if (XE_IOCTL_DBG(xe, q->width != args->num_batch_buffer))
+	if (XE_IOCTL_DBG(xe, args->num_batch_buffer &&
+			 q->width != args->num_batch_buffer))
 		return -EINVAL;
 
 	if (XE_IOCTL_DBG(xe, q->flags & EXEC_QUEUE_FLAG_BANNED)) {
@@ -183,12 +184,14 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 		err = xe_sync_entry_parse(xe, xef, &syncs[num_syncs++],
 					  &syncs_user[i], SYNC_PARSE_FLAG_EXEC |
 					  (xe_vm_no_dma_fences(vm) ?
-					   SYNC_PARSE_FLAG_LR_MODE : 0));
+					   SYNC_PARSE_FLAG_LR_MODE : 0) |
+					  (!args->num_batch_buffer ?
+					   SYNC_PARSE_FLAG_DISALLOW_USER_FENCE : 0));
 		if (err)
 			goto err_syncs;
 	}
 
-	if (xe_exec_queue_is_parallel(q)) {
+	if (args->num_batch_buffer && xe_exec_queue_is_parallel(q)) {
 		err = __copy_from_user(addresses, addresses_user, sizeof(u64) *
 				       q->width);
 		if (err) {
@@ -235,6 +238,18 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 		goto err_exec;
 	}
 
+	if (!args->num_batch_buffer) {
+		if (!xe_vm_no_dma_fences(vm)) {
+			struct dma_fence *fence =
+				xe_exec_queue_last_fence_get(q, vm);
+
+			for (i = 0; i < num_syncs; i++)
+				xe_sync_entry_signal(&syncs[i], NULL, fence);
+		}
+
+		goto err_exec;
+	}
+
 	if (xe_exec_queue_is_lr(q) && xe_exec_queue_ring_full(q)) {
 		err = -EWOULDBLOCK;
 		goto err_exec;
@@ -328,6 +343,8 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 
 	if (xe_exec_queue_is_lr(q))
 		q->ring_ops->emit_job(job);
+	if (!xe_vm_no_dma_fences(vm))
+		xe_exec_queue_last_fence_set(q, vm, &job->drm.s_fence->finished);
 	xe_sched_job_push(job);
 	xe_vm_reactivate_rebind(vm);
 
drivers/gpu/drm/xe/xe_exec_queue.c +4 -1
index 4fd44a9203e4..35710b66e5de 100644
@@ -924,7 +924,10 @@ int xe_exec_queue_set_property_ioctl(struct drm_device *dev, void *data,
 static void xe_exec_queue_last_fence_lockdep_assert(struct xe_exec_queue *q,
 						    struct xe_vm *vm)
 {
-	lockdep_assert_held_write(&vm->lock);
+	if (q->flags & EXEC_QUEUE_FLAG_VM)
+		lockdep_assert_held_write(&vm->lock);
+	else
+		xe_vm_assert_held(vm);
 }
 
 /**
drivers/gpu/drm/xe/xe_exec_queue_types.h +3 -2
index 5ba47a5cfdbd..52f0927d0d9b 100644
@@ -56,8 +56,9 @@ struct xe_exec_queue {
 	struct xe_hw_fence_irq *fence_irq;
 
 	/**
-	 * @last_fence: last fence on engine, protected by vm->lock in write
-	 * mode if bind engine
+	 * @last_fence: last fence on exec queue, protected by vm->lock in write
+	 * mode if bind exec queue, protected by dma resv lock if non-bind exec
+	 * queue
 	 */
 	struct dma_fence *last_fence;
 
drivers/gpu/drm/xe/xe_sync.c +4 -0
index 016d0a2ea5bc..cfe8724ee954 100644
@@ -106,6 +106,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 	int err;
 	bool exec = flags & SYNC_PARSE_FLAG_EXEC;
 	bool lr_mode = flags & SYNC_PARSE_FLAG_LR_MODE;
+	bool disallow_user_fence = flags & SYNC_PARSE_FLAG_DISALLOW_USER_FENCE;
 	bool signal;
 
 	if (copy_from_user(&sync_in, sync_user, sizeof(*sync_user)))
@@ -173,6 +174,9 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 		break;
 
 	case DRM_XE_SYNC_USER_FENCE:
+		if (XE_IOCTL_DBG(xe, disallow_user_fence))
+			return -EOPNOTSUPP;
+
 		if (XE_IOCTL_DBG(xe, !signal))
 			return -EOPNOTSUPP;
 
drivers/gpu/drm/xe/xe_sync.h +5 -1
index 30958ddc4cdc..45f4371e94b9 100644
@@ -12,10 +12,14 @@ struct xe_device;
 struct xe_file;
 struct xe_sched_job;
 
+#define SYNC_PARSE_FLAG_EXEC			BIT(0)
+#define SYNC_PARSE_FLAG_LR_MODE			BIT(1)
+#define SYNC_PARSE_FLAG_DISALLOW_USER_FENCE	BIT(2)
+
 int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
 			struct xe_sync_entry *sync,
 			struct drm_xe_sync __user *sync_user,
-			bool exec, bool compute_mode);
+			unsigned int flags);
 int xe_sync_entry_wait(struct xe_sync_entry *sync);
 int xe_sync_entry_add_deps(struct xe_sync_entry *sync,
 			   struct xe_sched_job *job);
#12 lore raw

Re: [Intel-xe] [PATCH 4/5] rm/xe: Allow num_batch_buffer == 0 in exec IOCTL

In reply to Matthew Brost
Quoted 31 lines · Matthew Brost

The idea being out-syncs can signal indicating all previous operations on the exec queue are complete. An example use case of this would be support for implementing vkQueueWaitForIdle easily.

v2: Don't add last_fence for VM's that do not support dma fences
v3: Use a flags field instead of severval bools in sync parse (Thomas)

---
  drivers/gpu/drm/xe/xe_exec.c             | 23 ++++++++++++++++++++---
  drivers/gpu/drm/xe/xe_exec_queue.c       |  5 ++++-
  drivers/gpu/drm/xe/xe_exec_queue_types.h |  5 +++--
  drivers/gpu/drm/xe/xe_sync.c             |  4 ++++
  drivers/gpu/drm/xe/xe_sync.h             |  6 +++++-
  5 files changed, 36 insertions(+), 7 deletions(-)
drivers/gpu/drm/xe/xe_exec.c +2 -1
index 7d4d22c81a42..4989bc6038af 100644
@@ -161,7 +161,8 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  	if (XE_IOCTL_DBG(xe, q->flags & EXEC_QUEUE_FLAG_VM))
  		return -EINVAL;
 
-	if (XE_IOCTL_DBG(xe, q->width != args->num_batch_buffer))
+	if (XE_IOCTL_DBG(xe, args->num_batch_buffer &&
+			 q->width != args->num_batch_buffer))
  		return -EINVAL;
 
  	if (XE_IOCTL_DBG(xe, q->flags & EXEC_QUEUE_FLAG_BANNED)) {

drivers/gpu/drm/xe/xe_exec.c int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file) · line 189

Quoted 7 lines
drivers/gpu/drm/xe/xe_exec.c +3 -1
@@ -183,12 +184,14 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  		err = xe_sync_entry_parse(xe, xef, &syncs[num_syncs++],
  					  &syncs_user[i], SYNC_PARSE_FLAG_EXEC |
  					  (xe_vm_no_dma_fences(vm) ?
-					   SYNC_PARSE_FLAG_LR_MODE : 0));
+					   SYNC_PARSE_FLAG_LR_MODE : 0) |
+					  (!args->num_batch_buffer ?
+					   SYNC_PARSE_FLAG_DISALLOW_USER_FENCE : 0));

Q: Why do we disallow user fences in this situation?

Quoted 98 lines
drivers/gpu/drm/xe/xe_exec.c +15 -1
  		if (err)
  			goto err_syncs;
  	}
 
-	if (xe_exec_queue_is_parallel(q)) {
+	if (args->num_batch_buffer && xe_exec_queue_is_parallel(q)) {
  		err = __copy_from_user(addresses, addresses_user, sizeof(u64) *
  				       q->width);
  		if (err) {
@@ -235,6 +238,18 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  		goto err_exec;
  	}
 
+	if (!args->num_batch_buffer) {
+		if (!xe_vm_no_dma_fences(vm)) {
+			struct dma_fence *fence =
+				xe_exec_queue_last_fence_get(q, vm);
+
+			for (i = 0; i < num_syncs; i++)
+				xe_sync_entry_signal(&syncs[i], NULL, fence);
+		}
+
+		goto err_exec;
+	}
+
  	if (xe_exec_queue_is_lr(q) && xe_exec_queue_ring_full(q)) {
  		err = -EWOULDBLOCK;
  		goto err_exec;
@@ -328,6 +343,8 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 
  	if (xe_exec_queue_is_lr(q))
  		q->ring_ops->emit_job(job);
+	if (!xe_vm_no_dma_fences(vm))
+		xe_exec_queue_last_fence_set(q, vm, &job->drm.s_fence->finished);
  	xe_sched_job_push(job);
  	xe_vm_reactivate_rebind(vm);
 
drivers/gpu/drm/xe/xe_exec_queue.c +4 -1
index 4fd44a9203e4..35710b66e5de 100644
@@ -924,7 +924,10 @@ int xe_exec_queue_set_property_ioctl(struct drm_device *dev, void *data,
  static void xe_exec_queue_last_fence_lockdep_assert(struct xe_exec_queue *q,
  						    struct xe_vm *vm)
  {
-	lockdep_assert_held_write(&vm->lock);
+	if (q->flags & EXEC_QUEUE_FLAG_VM)
+		lockdep_assert_held_write(&vm->lock);
+	else
+		xe_vm_assert_held(vm);
  }
 
  /**
drivers/gpu/drm/xe/xe_exec_queue_types.h +3 -2
index 5ba47a5cfdbd..52f0927d0d9b 100644
@@ -56,8 +56,9 @@ struct xe_exec_queue {
  	struct xe_hw_fence_irq *fence_irq;
 
  	/**
-	 * @last_fence: last fence on engine, protected by vm->lock in write
-	 * mode if bind engine
+	 * @last_fence: last fence on exec queue, protected by vm->lock in write
+	 * mode if bind exec queue, protected by dma resv lock if non-bind exec
+	 * queue
  	 */
  	struct dma_fence *last_fence;
 
drivers/gpu/drm/xe/xe_sync.c +4 -0
index 016d0a2ea5bc..cfe8724ee954 100644
@@ -106,6 +106,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
  	int err;
  	bool exec = flags & SYNC_PARSE_FLAG_EXEC;
  	bool lr_mode = flags & SYNC_PARSE_FLAG_LR_MODE;
+	bool disallow_user_fence = flags & SYNC_PARSE_FLAG_DISALLOW_USER_FENCE;
  	bool signal;
 
  	if (copy_from_user(&sync_in, sync_user, sizeof(*sync_user)))
@@ -173,6 +174,9 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
  		break;
 
  	case DRM_XE_SYNC_USER_FENCE:
+		if (XE_IOCTL_DBG(xe, disallow_user_fence))
+			return -EOPNOTSUPP;
+
  		if (XE_IOCTL_DBG(xe, !signal))
  			return -EOPNOTSUPP;
 
drivers/gpu/drm/xe/xe_sync.h +0 -0
index 30958ddc4cdc..45f4371e94b9 100644
@@ -12,10 +12,14 @@ struct xe_device;
  struct xe_file;
  struct xe_sched_job;

drivers/gpu/drm/xe/xe_sync.h struct xe_device; · line 22

Quoted 10 lines
drivers/gpu/drm/xe/xe_sync.h +5 -1
 
+#define SYNC_PARSE_FLAG_EXEC			BIT(0)
+#define SYNC_PARSE_FLAG_LR_MODE			BIT(1)
+#define SYNC_PARSE_FLAG_DISALLOW_USER_FENCE	BIT(2)
+
  int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
  			struct xe_sync_entry *sync,
  			struct drm_xe_sync __user *sync_user,
-			bool exec, bool compute_mode);
+			unsigned int flags);

Should this have been in the previous patch?

Thomas

Quoted 3 lines
drivers/gpu/drm/xe/xe_sync.h +0 -0
  int xe_sync_entry_wait(struct xe_sync_entry *sync);
  int xe_sync_entry_add_deps(struct xe_sync_entry *sync,
  			   struct xe_sched_job *job);
author maintainer
#13 lore raw

Re: [Intel-xe] [PATCH 4/5] rm/xe: Allow num_batch_buffer == 0 in exec IOCTL

Quoted 32 lines · Thomas Hellström
Quoted 30 lines · Matthew Brost

The idea being out-syncs can signal indicating all previous operations on the exec queue are complete. An example use case of this would be support for implementing vkQueueWaitForIdle easily.

v2: Don't add last_fence for VM's that do not support dma fences
v3: Use a flags field instead of severval bools in sync parse (Thomas)

---
  drivers/gpu/drm/xe/xe_exec.c             | 23 ++++++++++++++++++++---
  drivers/gpu/drm/xe/xe_exec_queue.c       |  5 ++++-
  drivers/gpu/drm/xe/xe_exec_queue_types.h |  5 +++--
  drivers/gpu/drm/xe/xe_sync.c             |  4 ++++
  drivers/gpu/drm/xe/xe_sync.h             |  6 +++++-
  5 files changed, 36 insertions(+), 7 deletions(-)
drivers/gpu/drm/xe/xe_exec.c +2 -1
index 7d4d22c81a42..4989bc6038af 100644
@@ -161,7 +161,8 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  	if (XE_IOCTL_DBG(xe, q->flags & EXEC_QUEUE_FLAG_VM))
  		return -EINVAL;
-	if (XE_IOCTL_DBG(xe, q->width != args->num_batch_buffer))
+	if (XE_IOCTL_DBG(xe, args->num_batch_buffer &&
+			 q->width != args->num_batch_buffer))
  		return -EINVAL;
  	if (XE_IOCTL_DBG(xe, q->flags & EXEC_QUEUE_FLAG_BANNED)) {
@@ -183,12 +184,14 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  		err = xe_sync_entry_parse(xe, xef, &syncs[num_syncs++],
Quoted 10 lines

drivers/gpu/drm/xe/xe_exec.c int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file) · line 189

Quoted 6 lines
drivers/gpu/drm/xe/xe_exec.c +3 -1
  					  &syncs_user[i], SYNC_PARSE_FLAG_EXEC |
  					  (xe_vm_no_dma_fences(vm) ?
-					   SYNC_PARSE_FLAG_LR_MODE : 0));
+					   SYNC_PARSE_FLAG_LR_MODE : 0) |
+					  (!args->num_batch_buffer ?
+					   SYNC_PARSE_FLAG_DISALLOW_USER_FENCE : 0));

Q: Why do we disallow user fences in this situation?

A user fence is inserted into the ring so unless we issue a NULL batch or something this is not easy to support. I don't think we have use case for this either. If this is blocker can fix change this. Also I think we can add support this later if needed too.

Quoted 91 lines
Quoted 91 lines
drivers/gpu/drm/xe/xe_exec.c +15 -1
  		if (err)
  			goto err_syncs;
  	}
-	if (xe_exec_queue_is_parallel(q)) {
+	if (args->num_batch_buffer && xe_exec_queue_is_parallel(q)) {
  		err = __copy_from_user(addresses, addresses_user, sizeof(u64) *
  				       q->width);
  		if (err) {
@@ -235,6 +238,18 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  		goto err_exec;
  	}
+	if (!args->num_batch_buffer) {
+		if (!xe_vm_no_dma_fences(vm)) {
+			struct dma_fence *fence =
+				xe_exec_queue_last_fence_get(q, vm);
+
+			for (i = 0; i < num_syncs; i++)
+				xe_sync_entry_signal(&syncs[i], NULL, fence);
+		}
+
+		goto err_exec;
+	}
+
  	if (xe_exec_queue_is_lr(q) && xe_exec_queue_ring_full(q)) {
  		err = -EWOULDBLOCK;
  		goto err_exec;
@@ -328,6 +343,8 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
  	if (xe_exec_queue_is_lr(q))
  		q->ring_ops->emit_job(job);
+	if (!xe_vm_no_dma_fences(vm))
+		xe_exec_queue_last_fence_set(q, vm, &job->drm.s_fence->finished);
  	xe_sched_job_push(job);
  	xe_vm_reactivate_rebind(vm);
drivers/gpu/drm/xe/xe_exec_queue.c +4 -1
index 4fd44a9203e4..35710b66e5de 100644
@@ -924,7 +924,10 @@ int xe_exec_queue_set_property_ioctl(struct drm_device *dev, void *data,
  static void xe_exec_queue_last_fence_lockdep_assert(struct xe_exec_queue *q,
  						    struct xe_vm *vm)
  {
-	lockdep_assert_held_write(&vm->lock);
+	if (q->flags & EXEC_QUEUE_FLAG_VM)
+		lockdep_assert_held_write(&vm->lock);
+	else
+		xe_vm_assert_held(vm);
  }
  /**
drivers/gpu/drm/xe/xe_exec_queue_types.h +3 -2
index 5ba47a5cfdbd..52f0927d0d9b 100644
@@ -56,8 +56,9 @@ struct xe_exec_queue {
  	struct xe_hw_fence_irq *fence_irq;
  	/**
-	 * @last_fence: last fence on engine, protected by vm->lock in write
-	 * mode if bind engine
+	 * @last_fence: last fence on exec queue, protected by vm->lock in write
+	 * mode if bind exec queue, protected by dma resv lock if non-bind exec
+	 * queue
  	 */
  	struct dma_fence *last_fence;
drivers/gpu/drm/xe/xe_sync.c +4 -0
index 016d0a2ea5bc..cfe8724ee954 100644
@@ -106,6 +106,7 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
  	int err;
  	bool exec = flags & SYNC_PARSE_FLAG_EXEC;
  	bool lr_mode = flags & SYNC_PARSE_FLAG_LR_MODE;
+	bool disallow_user_fence = flags & SYNC_PARSE_FLAG_DISALLOW_USER_FENCE;
  	bool signal;
  	if (copy_from_user(&sync_in, sync_user, sizeof(*sync_user)))
@@ -173,6 +174,9 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
  		break;
  	case DRM_XE_SYNC_USER_FENCE:
+		if (XE_IOCTL_DBG(xe, disallow_user_fence))
+			return -EOPNOTSUPP;
+
  		if (XE_IOCTL_DBG(xe, !signal))
  			return -EOPNOTSUPP;
drivers/gpu/drm/xe/xe_sync.h +3 -0
index 30958ddc4cdc..45f4371e94b9 100644
@@ -12,10 +12,14 @@ struct xe_device;
  struct xe_file;
  struct xe_sched_job;
+#define SYNC_PARSE_FLAG_EXEC			BIT(0)
+#define SYNC_PARSE_FLAG_LR_MODE			BIT(1)
+#define SYNC_PARSE_FLAG_DISALLOW_USER_FENCE	BIT(2)
Quoted 9 lines

drivers/gpu/drm/xe/xe_sync.h struct xe_device; · line 22

Quoted 6 lines
drivers/gpu/drm/xe/xe_sync.h +2 -1
+
  int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,
  			struct xe_sync_entry *sync,
  			struct drm_xe_sync __user *sync_user,
-			bool exec, bool compute_mode);
+			unsigned int flags);

Should this have been in the previous patch?

Yes, good catch. Will fix.

Matt

Quoted 6 lines

Thomas

Quoted 3 lines
drivers/gpu/drm/xe/xe_sync.h +0 -0
  int xe_sync_entry_wait(struct xe_sync_entry *sync);
  int xe_sync_entry_add_deps(struct xe_sync_entry *sync,
  			   struct xe_sched_job *job);
author maintainer
#14 lore raw

PATCH 5/5 drm/xe: Take in-syncs into account when num_execs or num_binds == 0

In reply to Matthew Brost

Wait on in-syncs before signaling out-syncs if num_execs or num_binds == 0 in execbuf IOCTL or VM bind IOCTL respectfully.

v2: Wait on last fence in addition to in-fences (Thomas)

---
 drivers/gpu/drm/xe/xe_exec.c | 10 ++++-
 drivers/gpu/drm/xe/xe_sync.c | 74 ++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_sync.h |  5 +++
 drivers/gpu/drm/xe/xe_vm.c   | 24 ++++++++++--
 4 files changed, 107 insertions(+), 6 deletions(-)
drivers/gpu/drm/xe/xe_exec.c +8 -2
index 4989bc6038af..b3a66d07d22b 100644
@@ -240,11 +240,17 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 
 	if (!args->num_batch_buffer) {
 		if (!xe_vm_no_dma_fences(vm)) {
-			struct dma_fence *fence =
-				xe_exec_queue_last_fence_get(q, vm);
+			struct dma_fence *fence;
 
+			fence = xe_sync_in_fence_get(syncs, num_syncs, q, vm);
+			if (IS_ERR(fence)) {
+				err = PTR_ERR(fence);
+				goto err_exec;
+			}
 			for (i = 0; i < num_syncs; i++)
 				xe_sync_entry_signal(&syncs[i], NULL, fence);
+			xe_exec_queue_last_fence_set(q, vm, fence);
+			dma_fence_put(fence);
 		}
 
 		goto err_exec;
drivers/gpu/drm/xe/xe_sync.c +74 -0

89 lines not on this page · raw message

drivers/gpu/drm/xe/xe_sync.h +5 -0
index 45f4371e94b9..d284afbe917c 100644
@@ -9,8 +9,10 @@
 #include "xe_sync_types.h"
 
 struct xe_device;
+struct xe_exec_queue;
 struct xe_file;
 struct xe_sched_job;
+struct xe_vm;
 
 #define SYNC_PARSE_FLAG_EXEC			BIT(0)
 #define SYNC_PARSE_FLAG_LR_MODE			BIT(1)
@@ -27,5 +29,8 @@ void xe_sync_entry_signal(struct xe_sync_entry *sync,
 			  struct xe_sched_job *job,
 			  struct dma_fence *fence);
 void xe_sync_entry_cleanup(struct xe_sync_entry *sync);
+struct dma_fence *
+xe_sync_in_fence_get(struct xe_sync_entry *sync, int num_sync,
+		     struct xe_exec_queue *q, struct xe_vm *vm);
 
 #endif
drivers/gpu/drm/xe/xe_vm.c +20 -4
index 1f3e5dcbef9e..99e97b3519ee 100644
@@ -3158,12 +3158,28 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 unwind_ops:
 	vm_bind_ioctl_ops_unwind(vm, ops, args->num_binds);
 free_syncs:
-	for (i = 0; err == -ENODATA && i < num_syncs; i++) {
-		struct dma_fence *fence =
-			xe_exec_queue_last_fence_get(to_wait_exec_queue(vm, q), vm);
+	if (err == -ENODATA) {
+		struct dma_fence *fence;
+
+		fence = xe_sync_in_fence_get(syncs, num_syncs,
+					     to_wait_exec_queue(vm, q), vm);
+		if (IS_ERR(fence)) {
+			err = PTR_ERR(fence);
+			goto cleanup_syncs;
+		}
+		for (i = 0; i < num_syncs; i++)
+			xe_sync_entry_signal(&syncs[i], NULL, fence);
+		if (!async) {
+			long timeout = dma_fence_wait(fence, true);
 
-		xe_sync_entry_signal(&syncs[i], NULL, fence);
+			if (timeout < 0)
+				err = -EINTR;
+		}
+		xe_exec_queue_last_fence_set(to_wait_exec_queue(vm, q), vm,
+					     fence);
+		dma_fence_put(fence);
 	}
+cleanup_syncs:
 	while (num_syncs--)
 		xe_sync_entry_cleanup(&syncs[num_syncs]);
 
Signature · 1 line
2.34.1
#15 lore raw

[Intel-xe] ✗ CI.Patch_applied: failure for Allow num_binds/num_batch_buffer to be zero IOCTLs

In reply to Matthew Brost
== Series Details ==

== Series Details ==

Series: Allow num_binds/num_batch_buffer to be zero IOCTLs
URL : https://patchwork.freedesktop.org/series/126546/
State : failure

== Summary ==

=== Applying kernel patches on branch 'drm-xe-next' with base: === Base commit: 6253cfa4c drm/xe/pmu: Drop interrupt pmu event
=== git am output follows ===
Applying: drm/xe: Allow num_binds == 0 in VM bind IOCTL
Applying: drm/xe: Use a flags field instead of bools for VMA create
Applying: drm/xe: Use a flags field instead of bools for sync parse
Applying: rm/xe: Allow num_batch_buffer == 0 in exec IOCTL
Applying: drm/xe: Take in-syncs into account when num_execs or num_binds == 0

#16 lore raw

[Intel-xe] ✗ CI.Patch_applied: failure for Allow num_binds/num_batch_buffer to be zero IOCTLs

In reply to Matthew Brost
== Series Details ==

== Series Details ==

Series: Allow num_binds/num_batch_buffer to be zero IOCTLs
URL : https://patchwork.freedesktop.org/series/126546/
State : failure

== Summary ==

=== Applying kernel patches on branch 'drm-xe-next' with base: === Base commit: cb9b702d4 drm/xe/dg2: Wa_18028616096 now applies to all DG2 === git am output follows ===
error: patch failed: drivers/gpu/drm/xe/xe_sync.c:118
error: drivers/gpu/drm/xe/xe_sync.c: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch
Applying: drm/xe: Allow num_binds == 0 in VM bind IOCTL
Applying: drm/xe: Use a flags field instead of bools for VMA create
Applying: drm/xe: Use a flags field instead of bools for sync parse Patch failed at 0003 drm/xe: Use a flags field instead of bools for sync parse When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".