[Intel-gfx] [PATCH i-g-t] tests/gem_userptr_blits: Test object invalidation more thoroughly
Tvrtko Ursulin
tursulin at ursulin.net
Mon Oct 31 15:36:15 UTC 2016
From: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
Verify that the userspace will get told if it changes to what the userptr
object backing store points to, *after* having created the GEM object.
Two variants are tested:
1. One where the object is used after it has been invalidated but while
the address space for the backing store is still invalid.
2. Second one where the backing store becomes valid immediately after the
object has been invalidated.
In both cases we want the kernel to give us -EFAULT on the buffer object in
question since the userspace is acting strangely so the driver does not want
to take part in corrupting memory.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
---
tests/gem_userptr_blits.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/tests/gem_userptr_blits.c b/tests/gem_userptr_blits.c
index f30e14360727..11a29ff5fdde 100644
--- a/tests/gem_userptr_blits.c
+++ b/tests/gem_userptr_blits.c
@@ -1151,6 +1151,58 @@ static void test_unmap_cycles(int fd, int expected)
test_unmap(fd, expected);
}
+/*
+ * Verify that the userspace will get told if it changes to what the userptr
+ * object backing store points to, *after* having created the GEM object.
+ *
+ * Two variants are tested:
+ * 1. One where the object is used after it has been invalidated but while
+ * the address space for the backing store is still invalid.
+ * 2. Second one where the backing store becomes valid immediately after the
+ * object has been invalidated.
+ *
+ * In both cases we want the kernel to give us -EFAULT on the buffer object in
+ * question since the userspace is acting strangely so the driver does not want
+ * to take part in corrupting memory.
+ */
+static void test_remap(int fd, bool midaccess, int expected)
+{
+ char *ptr, *ptr2, *bo_ptr;
+ uint32_t bo[2];
+ size_t map_size = sizeof(linear) + (PAGE_SIZE - 1);
+ int ret;
+
+ ptr = mmap(NULL, map_size, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ igt_assert(ptr != MAP_FAILED);
+
+ bo_ptr = (char *)ALIGN((unsigned long)ptr, PAGE_SIZE);
+ gem_userptr(fd, bo_ptr, sizeof(linear), 0, userptr_flags, &bo[0]);
+
+ bo[1] = create_bo(fd, 0);
+
+ copy(fd, bo[1], bo[0], 0);
+
+ ret = munmap(ptr, map_size);
+ igt_assert_eq(ret, 0);
+
+ if (midaccess)
+ copy(fd, bo[1], bo[0], expected);
+
+ ptr2 = mmap(ptr, map_size, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
+ igt_assert(ptr2 != MAP_FAILED);
+ igt_assert(ptr2 == ptr);
+
+ copy(fd, bo[1], bo[0], expected);
+
+ gem_close(fd, bo[1]);
+ gem_close(fd, bo[0]);
+
+ ret = munmap(ptr, map_size);
+ igt_assert_eq(ret, 0);
+}
+
#define MM_STRESS_LOOPS 100000
struct stress_thread_data {
@@ -1354,6 +1406,12 @@ int main(int argc, char **argv)
igt_subtest("unsync-unmap-after-close")
test_unmap_after_close(fd);
+ igt_subtest("unsync-remap")
+ test_remap(fd, false, 0);
+
+ igt_subtest("unsync-remap-access")
+ test_remap(fd, true, 0);
+
igt_subtest("coherency-unsync")
test_coherency(fd, count);
@@ -1452,6 +1510,12 @@ int main(int argc, char **argv)
igt_subtest("sync-unmap-after-close")
test_unmap_after_close(fd);
+ igt_subtest("sync-remap")
+ test_remap(fd, false, EFAULT);
+
+ igt_subtest("sync-remap-access")
+ test_remap(fd, true, EFAULT);
+
igt_subtest("stress-mm")
test_stress_mm(fd);
--
2.7.4
More information about the Intel-gfx
mailing list