diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2019-04-01 13:16:57 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2019-04-02 15:12:54 +0100 |
commit | 995274436bcc9c14256027e0f136e16456b25ea3 (patch) | |
tree | caf434f50b613cf8f095f5db18433777404a0b63 /tests/i915/gem_pread.c | |
parent | dc36fa26305b832686616f3fadb1ef05f10f0f8f (diff) |
i915/gem_pread,gem_pwrite: Exercise using ourselves as the buffer
If we caused a fault on a GEM buffer while in the middle of trying to
write/read into that buffer, we could conceivably deadlock (e.g.
recursing on struct_mutex if we are not careful). Exercise these cases
by supplying a fresh mmap to pread/pwrite in both non-overlapping and
overlapping copies.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Diffstat (limited to 'tests/i915/gem_pread.c')
-rw-r--r-- | tests/i915/gem_pread.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/i915/gem_pread.c b/tests/i915/gem_pread.c index 00379580..83d878ee 100644 --- a/tests/i915/gem_pread.c +++ b/tests/i915/gem_pread.c @@ -39,6 +39,38 @@ #include <sys/time.h> #include "drm.h" +#define MiB(x) ((x) * 1024 * 1024) + +typedef void *(*mmap_fn_t)(int, uint32_t, uint64_t, uint64_t, unsigned int); + +static void *wrap_gem_mmap__gtt(int i915, uint32_t handle, + uint64_t offset, uint64_t length, + unsigned int prot) +{ + return gem_mmap__gtt(i915, handle, length, prot); +} + +static void pread_self(int i915) +{ + static const mmap_fn_t mmap_fn[] = { + wrap_gem_mmap__gtt, + gem_mmap__cpu, + gem_mmap__wc, + NULL + }; + for (const mmap_fn_t *fn = mmap_fn; *fn; fn++) { + uint32_t handle = gem_create(i915, MiB(4)); + void *ptr = (*fn)(i915, handle, 0, MiB(4), PROT_WRITE); + + gem_read(i915, handle, 0, ptr + MiB(3), MiB(1)); + gem_read(i915, handle, MiB(3), ptr, MiB(1)); + gem_read(i915, handle, MiB(1), ptr + MiB(1), MiB(2)); + + munmap(ptr, MiB(4)); + gem_close(i915, handle); + } +} + #define OBJECT_SIZE 16384 #define LARGE_OBJECT_SIZE 1024 * 1024 #define KGRN "\x1B[32m" @@ -131,6 +163,9 @@ int main(int argc, char **argv) } } + igt_subtest("self") + pread_self(fd); + for (c = cache; c->level != -1; c++) { igt_subtest(c->name) { gem_set_caching(fd, dst, c->level); |