[PATCH igt] igt/gem_userptr: Exercise new PROBE | POPULATE flags

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Exercise new API to probe that the userptr range is valid (backed by
struct pages and not pfn) or to populate the userptr upon creation (by
calling get_user_pages() on the range).

Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
Cc: Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxx>
Cc: Michał Winiarski <michal.winiarski@xxxxxxxxx>
---
 tests/gem_userptr_blits.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/tests/gem_userptr_blits.c b/tests/gem_userptr_blits.c
index 849054ad..27f61f9c 100644
--- a/tests/gem_userptr_blits.c
+++ b/tests/gem_userptr_blits.c
@@ -549,6 +549,79 @@ static int test_invalid_gtt_mapping(int fd)
 	return 0;
 }
 
+#define LOCAL_USERPTR_PROBE 0x2
+#define LOCAL_USERPTR_POPULATE 0x4
+static void test_probe(int fd, unsigned int flags)
+{
+#define N_PAGES 5
+	struct drm_i915_gem_mmap_gtt mmap_gtt;
+	uint32_t handle;
+
+	igt_require(__gem_userptr(fd,
+				  (void *)-PAGE_SIZE, 2*PAGE_SIZE, 0,
+				  flags, &handle) == -EFAULT);
+
+	/*
+	 * We allocate 5 pages, and apply various combinations
+	 * of unmap, remap-gtt to the pages. Then we try to
+	 * create a userptr from the middle 3 pages and check
+	 * if unexpectedly succeeds or fails.
+	 */
+	memset(&mmap_gtt, 0, sizeof(mmap_gtt));
+	mmap_gtt.handle = gem_create(fd, PAGE_SIZE);
+	drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_gtt);
+
+	for (unsigned long pass = 0; pass < 4 * 4 * 4 * 4 *4; pass++) {
+		int expected = 0;
+		void *ptr;
+
+		ptr = mmap(NULL, N_PAGES * PAGE_SIZE,
+			   PROT_READ | PROT_WRITE,
+			   MAP_SHARED | MAP_ANONYMOUS,
+			   -1, 0);
+
+		for (int page = 0; page < N_PAGES; page++) {
+			int mode = (pass >> (2 * page)) & 3;
+			void *fixed = ptr + page * PAGE_SIZE;
+
+			switch (mode) {
+			default:
+			case 0:
+				break;
+
+			case 1:
+				munmap(fixed, PAGE_SIZE);
+				if (page >= 1 && page <= 3)
+					expected = -EFAULT;
+				break;
+
+			case 2:
+				fixed = mmap(fixed, PAGE_SIZE,
+					     PROT_READ | PROT_WRITE,
+					     MAP_SHARED | MAP_FIXED,
+					     fd, mmap_gtt.offset);
+				igt_assert(fixed != MAP_FAILED);
+				if (page >= 1 && page <= 3)
+					expected = -EFAULT;
+				break;
+			}
+		}
+
+		errno = 0;
+		handle = 0;
+		igt_assert_eq(__gem_userptr(fd, ptr + PAGE_SIZE, 3*PAGE_SIZE,
+					    0, flags, &handle),
+			      expected);
+		if (handle)
+			gem_close(fd, handle);
+
+		munmap(ptr, N_PAGES * PAGE_SIZE);
+	}
+
+	gem_close(fd, mmap_gtt.handle);
+#undef N_PAGES
+}
+
 #define PE_GTT_MAP 0x1
 #define PE_BUSY 0x2
 static void test_process_exit(int fd, int flags)
@@ -1456,6 +1529,12 @@ int main(int argc, char **argv)
 		igt_subtest("invalid-gtt-mapping")
 			test_invalid_gtt_mapping(fd);
 
+		igt_subtest("probe")
+			test_probe(fd, LOCAL_USERPTR_PROBE);
+
+		igt_subtest("populate")
+			test_probe(fd, LOCAL_USERPTR_POPULATE);
+
 		igt_subtest("forked-access")
 			test_forked_access(fd);
 
-- 
2.15.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux