From 3b1a55874d151c8044b0168de4b6d9351ced69d4 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 25 Nov 2015 10:46:53 +0000 Subject: igt/drm_read: Check handling of pagefault on destination buffer In theory, this should force i915_gem_fault() when we first use the buffer (and not at mmap time) and so prevent a __copy_to_user_inatomic() from writting to the buffer. Signed-off-by: Chris Wilson --- tests/drm_read.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/drm_read.c b/tests/drm_read.c index 8587aeeb..d18cb55e 100644 --- a/tests/drm_read.c +++ b/tests/drm_read.c @@ -119,6 +119,44 @@ static void test_invalid_buffer(int in) teardown(fd); } +static uint32_t dumb_create(int fd) +{ + struct drm_mode_create_dumb arg; + + arg.bpp = 32; + arg.width = 32; + arg.height = 32; + + do_ioctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &arg); + igt_assert(arg.size >= 4096); + + return arg.handle; +} + +static void test_fault_buffer(int in) +{ + int fd = setup(in, 0); + struct drm_mode_map_dumb arg; + char *buf; + + memset(&arg, 0, sizeof(arg)); + arg.handle = dumb_create(fd); + + do_ioctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &arg); + + buf = mmap(0, 4096, PROT_WRITE, MAP_SHARED, fd, arg.offset); + igt_assert(buf != MAP_FAILED); + + generate_event(fd); + + alarm(1); + + igt_assert(read(fd, buf, 4096) > 0); + + munmap(buf, 4096); + teardown(fd); +} + static void test_empty(int in, int nonblock, int expected) { char buffer[1024]; @@ -207,6 +245,9 @@ igt_main igt_subtest("invalid-buffer") test_invalid_buffer(fd); + igt_subtest("fault-buffer") + test_fault_buffer(fd); + igt_subtest("empty-block") test_empty(fd, 0, EINTR); -- cgit v1.2.3