[igt-dev] [PATCH i-g-t] i915/gem_userptr_blits: Check for allowed GTT mmaps
Chris Wilson
chris at chris-wilson.co.uk
Tue Oct 1 17:49:24 UTC 2019
Having decided to close the GTT mmap of userptr objects loophole in the
kernel, we need to adjust the test suite to avoid tripping over GTT
mmaps when required.
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
---
tests/i915/gem_userptr_blits.c | 32 ++++++++++++++++++++++++++++----
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/tests/i915/gem_userptr_blits.c b/tests/i915/gem_userptr_blits.c
index 3fad7d1b3..3f5edaeab 100644
--- a/tests/i915/gem_userptr_blits.c
+++ b/tests/i915/gem_userptr_blits.c
@@ -69,11 +69,33 @@
static uint32_t userptr_flags = LOCAL_I915_USERPTR_UNSYNCHRONIZED;
+static bool can_gtt_mmap;
+
#define WIDTH 512
#define HEIGHT 512
static uint32_t linear[WIDTH*HEIGHT];
+static bool has_gtt_mmap(int i915)
+{
+ void *ptr, *map;
+ uint32_t handle;
+
+ igt_assert(posix_memalign(&ptr, PAGE_SIZE, PAGE_SIZE) == 0);
+
+ gem_userptr(i915, ptr, 4096, 0, 0, &handle);
+ igt_assert(handle != 0);
+
+ map = __gem_mmap__gtt(i915, handle, 4096, PROT_WRITE);
+ if (map)
+ munmap(map, 4096);
+
+ gem_close(i915, handle);
+ free(ptr);
+
+ return map != NULL;
+}
+
static void gem_userptr_test_unsynchronized(void)
{
userptr_flags = LOCAL_I915_USERPTR_UNSYNCHRONIZED;
@@ -853,7 +875,7 @@ static void *umap(int fd, uint32_t handle)
{
void *ptr;
- if (gem_has_llc(fd)) {
+ if (can_gtt_mmap) {
ptr = gem_mmap__gtt(fd, handle, sizeof(linear),
PROT_READ | PROT_WRITE);
} else {
@@ -884,7 +906,7 @@ check_bo(int fd1, uint32_t handle1, int is_userptr, int fd2, uint32_t handle2)
sigbus_start = (unsigned long)ptr2;
igt_assert(memcmp(ptr1, ptr2, sizeof(linear)) == 0);
- if (gem_has_llc(fd1)) {
+ if (can_gtt_mmap) {
counter++;
memset(ptr1, counter, size);
memset(ptr2, counter, size);
@@ -971,7 +993,7 @@ static int test_dmabuf(void)
free_userptr_bo(fd1, handle);
close(fd1);
- if (gem_has_llc(fd2)) {
+ if (can_gtt_mmap) {
struct sigaction sigact, orig_sigact;
memset(&sigact, 0, sizeof(sigact));
@@ -1225,7 +1247,7 @@ static void test_readonly_mmap(int i915)
original = g_compute_checksum_for_data(G_CHECKSUM_SHA1, pages, sz);
ptr = __gem_mmap__gtt(i915, handle, sz, PROT_WRITE);
- igt_assert(ptr == NULL);
+ igt_require(ptr != NULL);
ptr = gem_mmap__gtt(i915, handle, sz, PROT_READ);
gem_close(i915, handle);
@@ -1834,6 +1856,8 @@ igt_main_args("c:", NULL, help_str, opt_handler, NULL)
igt_require_gem(fd);
gem_require_blitter(fd);
+ can_gtt_mmap = has_gtt_mmap(fd) && gem_has_llc(fd);
+
size = sizeof(linear);
aperture_size = gem_aperture_size(fd);
--
2.23.0
More information about the igt-dev
mailing list