[PATCH i-g-t] tests/intel/xe_vm: Test vm bind fails with invalid ufence
Nirmoy Das
nirmoy.das at intel.com
Mon Oct 14 14:18:39 UTC 2024
Bind ioctl accepts user addr for ufence which could be bogus.
Add a test to make sure such calls fails.
Cc: Matthew Auld <matthew.auld at intel.com>
Cc: Matthew Brost <matthew.brost at intel.com>
Cc: Kamil Konieczny <kamil.konieczny at linux.intel.com>
Signed-off-by: Nirmoy Das <nirmoy.das at intel.com>
---
tests/intel/xe_vm.c | 51 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/tests/intel/xe_vm.c b/tests/intel/xe_vm.c
index 7a8740b69..234b3f98a 100644
--- a/tests/intel/xe_vm.c
+++ b/tests/intel/xe_vm.c
@@ -336,6 +336,54 @@ static void unbind_all(int fd, int n_vmas)
}
#define MAP_ADDRESS 0x00007fadeadbe000
+#define USER_FENCE_VALUE 0xdeadbeefdeadbeefull
+
+/**
+ * SUBTEST: bind-invalid-ufence
+ * Description:
+ * Verifies that binding with invalid ufence addr is rejected.
+ * Functionality: userptr
+ * Test category: negative test
+ */
+static void invalid_ufence(int fd)
+{
+ size_t size = xe_get_default_alignment(fd);
+ uint32_t vm;
+ int64_t fence_timeout;
+ void *data, *unmapped_addr;
+ struct drm_xe_sync sync[1] = {
+ {
+ .type = DRM_XE_SYNC_TYPE_USER_FENCE,
+ .flags = DRM_XE_SYNC_FLAG_SIGNAL,
+ .timeline_value = USER_FENCE_VALUE
+ }
+ };
+ int ret;
+
+ fence_timeout = (igt_run_in_simulation() ? 100 : 1) * NSEC_PER_SEC;
+ data = mmap((void *)MAP_ADDRESS, size, PROT_READ |
+ PROT_WRITE, MAP_SHARED | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
+ igt_assert(data != MAP_FAILED);
+
+ vm = xe_vm_create(fd, 0, 0);
+
+ unmapped_addr = mmap(NULL, size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ igt_assert(unmapped_addr != MAP_FAILED);
+ munmap(unmapped_addr, size);
+
+ sync[0].addr = to_user_pointer(unmapped_addr);
+ ret = __xe_vm_bind(fd, vm, 0, 0, to_user_pointer(data), MAP_ADDRESS,
+ size, DRM_XE_VM_BIND_OP_MAP_USERPTR, 0, sync, 1, 0,
+ DEFAULT_PAT_INDEX, 0);
+ igt_assert(ret == -EFAULT);
+
+ sync[0].addr = to_user_pointer(data);
+ xe_vm_bind_userptr_async(fd, vm, 0, to_user_pointer(data), 0x40000, size, sync, 1);
+
+ xe_wait_ufence(fd, data, USER_FENCE_VALUE, 0, fence_timeout);
+
+ xe_vm_destroy(fd, vm);
+}
/**
* SUBTEST: userptr-invalid
@@ -2373,6 +2421,9 @@ igt_main
igt_subtest("userptr-invalid")
userptr_invalid(fd);
+ igt_subtest("bind-invalid-ufence")
+ invalid_ufence(fd);
+
igt_subtest("bind-flag-invalid")
bind_flag_invalid(fd);
--
2.46.0
More information about the igt-dev
mailing list