[PATCH i-g-t] tests/xe/xe_fault_injection: add split/skip bind coverage

Matthew Auld <[email protected]>
Newsgroups org.freedesktop.lists.igt-dev
Message-ID <[email protected]>
We were missing something for having to unwind a vector of binds where
there is splitting, as well as skipping.

Should explode with a dmesg WARN without the required kernel fix.

Link: https://gitlab.freedesktop.org/drm/xe/kernel/-/work_items/7602
Link: https://gitlab.freedesktop.org/drm/xe/kernel/-/work_items/5443
Signed-off-by: Matthew Auld <[email protected]>
Cc: Vijayakumar Nallamothu <[email protected]>
Cc: Matthew Brost <[email protected]>
---
 tests/intel/xe_fault_injection.c | 87 ++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)

diff --git a/tests/intel/xe_fault_injection.c b/tests/intel/xe_fault_injection.c
index 4f4a7922c..c69303ba6 100644
--- a/tests/intel/xe_fault_injection.c
+++ b/tests/intel/xe_fault_injection.c
@@ -478,6 +478,89 @@ vm_bind_fail(int fd, const char pci_slot[], const char function_name[])
 	igt_assert_eq(simple_vm_bind(fd, vm), 0);
 }
 
+static int
+simple_vm_bind_null(int fd, uint32_t vm)
+{
+	struct drm_xe_sync syncobj = {
+		.type = DRM_XE_SYNC_TYPE_SYNCOBJ,
+		.flags = DRM_XE_SYNC_FLAG_SIGNAL,
+		.handle = syncobj_create(fd, 0),
+	};
+	struct drm_xe_vm_bind bind = {
+		.vm_id = vm,
+		.num_binds = 1,
+		.bind.range = SZ_2G,
+		.bind.addr = 0,
+		.bind.op = DRM_XE_VM_BIND_OP_MAP,
+		.bind.pat_index = intel_get_pat_idx_uc(fd),
+		.bind.flags = DRM_XE_VM_BIND_FLAG_NULL,
+		.num_syncs = 1,
+		.syncs = (uintptr_t)&syncobj,
+	};
+
+        return igt_ioctl(fd, DRM_IOCTL_XE_VM_BIND, &bind);
+}
+
+static int
+vm_unmap_map_split_vector_null(int fd, uint32_t vm)
+{
+	struct drm_xe_sync syncobj = {
+		.type = DRM_XE_SYNC_TYPE_SYNCOBJ,
+		.flags = DRM_XE_SYNC_FLAG_SIGNAL,
+		.handle = syncobj_create(fd, 0),
+	};
+        struct drm_xe_vm_bind_op ops[] = {
+            {
+                .range = SZ_2G,
+                .addr = 0,
+                .op = DRM_XE_VM_BIND_OP_MAP,
+                .pat_index = intel_get_pat_idx_wb(fd),
+                .flags = DRM_XE_VM_BIND_FLAG_NULL,
+            },
+            {
+                .range = SZ_2M,
+                .addr = SZ_1G - SZ_2M,
+                .op = DRM_XE_VM_BIND_OP_UNMAP,
+            },
+        };
+        struct drm_xe_vm_bind bind = {
+		.vm_id = vm,
+		.num_binds = sizeof(ops)/sizeof(struct drm_xe_vm_bind_op),
+		.vector_of_binds = (uintptr_t)&ops,
+		.num_syncs = 1,
+		.syncs = (uintptr_t)&syncobj,
+	};
+
+	return igt_ioctl(fd, DRM_IOCTL_XE_VM_BIND, &bind);
+}
+/**
+ * SUBTEST: vm-bind-split-unwind-fail-%s
+ * Description: inject an error in function %arg[1] used in vm bind IOCTL
+ *		to make it fail
+ * Functionality: fault
+ *
+ * arg[1]:
+ * @vm_bind_ioctl_ops_create:		vm_bind_ioctl_ops_create
+ * @vm_bind_ioctl_ops_execute:		vm_bind_ioctl_ops_execute
+ * @xe_pt_update_ops_prepare:		xe_pt_update_ops_prepare
+ * @xe_pt_update_ops_run:		xe_pt_update_ops_run
+ * @xe_vma_ops_alloc:			xe_vma_ops_alloc
+ * @xe_sync_entry_parse:		xe_sync_entry_parse
+ */
+static void
+vm_bind_split_unwind_fail(int fd, const char pci_slot[], const char function_name[])
+{
+	uint32_t vm = xe_vm_create(fd, 0, 0);
+
+	igt_assert_eq(simple_vm_bind_null(fd, vm), 0);
+
+	/* See: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/7602 */
+	injection_list_add(function_name);
+	set_retval(function_name, INJECT_ERRNO);
+	igt_assert(vm_unmap_map_split_vector_null(fd, vm) != 0);
+	injection_list_remove(function_name);
+}
+
 /**
  * SUBTEST: oa-add-config-fail-%s
  * Description: inject an error in function %arg[1] used in oa add config IOCTL to make it fail
@@ -644,6 +727,10 @@ int igt_main_args("I:", NULL, help_str, opt_handler, NULL)
 		igt_subtest_f("vm-bind-fail-%s", s->name)
 			vm_bind_fail(fd, pci_slot, s->name);
 
+	for (const struct section *s = vm_bind_fail_functions; s->name; s++)
+		igt_subtest_f("vm-bind-split-unwind-fail-%s", s->name)
+			vm_bind_split_unwind_fail(fd, pci_slot, s->name);
+
 	for (const struct section *s = exec_queue_create_fail_functions; s->name; s++)
 		igt_subtest_f("exec-queue-create-fail-%s", s->name)
 			xe_for_each_engine(fd, hwe)
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.