summaryrefslogtreecommitdiff
path: root/tests/drm_read.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2015-11-25 10:46:53 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2015-11-25 11:13:25 +0000
commit3b1a55874d151c8044b0168de4b6d9351ced69d4 (patch)
treed142f00d265870b309ee92cef1a95c4b26a5fe35 /tests/drm_read.c
parentd84e62478bf2c34d610467a98826d64c321b839b (diff)
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 <chris@chris-wilson.co.uk>
Diffstat (limited to 'tests/drm_read.c')
-rw-r--r--tests/drm_read.c41
1 files changed, 41 insertions, 0 deletions
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);