Skip to contentSkip to conversation

Quick bat tests, please don't review.

PATCH New Zbigniew Kempczyński 2 participants 15 messages Sep 1, 2022 Library code

lore
Share & tools
lore
#0 lore raw

cover Quick bat tests, please don't review.

GEM_MMAP_OFFSET_FIXED missing subtests.

Chris Wilson (12):
lib: Fix off-by-one-page in 48b obj.flags
lib/i915: Mark gem_create as handling const memory regions lib/i915: Distinguish I915_MMAP_OFFSET_FIXED with an invalid domain i915/gem_create: Verify all regions return cleared objects i915/gem_create: Stress creation with busy engines i915/gem_mmap_offset: Verify all regions return clear mmaps on cration i915/gem_mmap_offset: Verify all regions with ptrace i915/gem_mmap_offset: Verify all regions remain in isolation i915/gem_mmap_offset: Verify all regions have nonblocking pagefaults i915/gem_mmap_offset: Check all mmap types reject invalid objects i915/gem_mmap_offset: Exercise close race against all types/regions i915/gem_mmap_offset: Crudely measure read/write to different mmaps

Zbigniew Kempczyński (1):
HAX: exercise subset of gem_create and gem_mmap_offset

 lib/i915/gem_mman.c                   |   2 +-
 lib/i915/intel_memory_region.c        |   4 +-
 lib/i915/intel_memory_region.h        |   4 +-
 lib/igt_dummyload.c                   |  63 ++--
 tests/i915/gem_create.c               | 141 ++++++--
 tests/i915/gem_mmap_offset.c          | 453 +++++++++++++++++---------
 tests/intel-ci/fast-feedback.testlist | 189 +----------
 7 files changed, 461 insertions(+), 395 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/13 lib: Fix off-by-one-page in 48b obj.flags

From: Chris Wilson <[email protected]>

The kernel checks that the last byte of the object will fit inside the 32b GTT window unless the object is marked as being suitable for use with 48b addressing. However, the spinner only checked the start of the object which depending on the mix of size/alignment, could allow the object to straddle the 32b boundary and not be marked as 48b capable.

Always set 48b for all the objects where ppGTT merites.

In the process, there was one location where we failed to write the upper 32b of the address into the instruction.

---
 lib/igt_dummyload.c | 63 ++++++++++++++++++++++-----------------------
 1 file changed, 31 insertions(+), 32 deletions(-)
lib/igt_dummyload.c +31 -32
index dc1bd51e08..17ae21f567 100644
@@ -100,12 +100,21 @@ emit_recursive_batch(igt_spin_t *spin,
 	struct drm_i915_gem_execbuffer2 *execbuf;
 	struct drm_i915_gem_exec_object2 *obj;
 	unsigned int flags[GEM_MAX_ENGINES];
+	unsigned int objflags = 0;
 	unsigned int nengine;
 	int fence_fd = -1;
-	uint64_t addr, addr_scratch, ahnd = opts->ahnd, objflags = 0;
+	uint64_t addr, addr_scratch, ahnd = opts->ahnd;
 	uint32_t *cs;
 	int i;
 
+	igt_assert(!(opts->ctx && opts->ctx_id));
+
+	r = memset(relocs, 0, sizeof(relocs));
+	execbuf = memset(&spin->execbuf, 0, sizeof(spin->execbuf));
+	execbuf->rsvd1 = opts->ctx ? opts->ctx->id : opts->ctx_id;
+	execbuf->flags = I915_EXEC_NO_RELOC;
+	obj = memset(spin->obj, 0, sizeof(spin->obj));
+
 	/*
 	 * Pick a random location for our spinner et al.
 	 *
@@ -121,8 +130,12 @@ emit_recursive_batch(igt_spin_t *spin,
 	 * that wrap.
 	 */
 
+	addr = gem_aperture_size(fd) / 2;
+	if (addr >> 32)
+		objflags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
+
 	if (!ahnd) {
-		addr = gem_aperture_size(fd) / 2;
+		addr /= 2;
 		if (addr >> 31)
 			addr = 1u << 31;
 		addr += random() % addr / 2;
@@ -131,8 +144,6 @@ emit_recursive_batch(igt_spin_t *spin,
 		objflags |= EXEC_OBJECT_PINNED;
 	}
 
-	igt_assert(!(opts->ctx && opts->ctx_id));
-
 	nengine = 0;
 	if (opts->engine == ALL_ENGINES) {
 		struct intel_execution_engine2 *engine;
@@ -150,11 +161,6 @@ emit_recursive_batch(igt_spin_t *spin,
 	}
 	igt_require(nengine);
 
-	memset(relocs, 0, sizeof(relocs));
-	execbuf = memset(&spin->execbuf, 0, sizeof(spin->execbuf));
-	execbuf->flags = I915_EXEC_NO_RELOC;
-	obj = memset(spin->obj, 0, sizeof(spin->obj));
-
 	obj[BATCH].handle =
 		handle_create(fd, BATCH_SIZE, opts->flags, &spin->batch);
 	if (!spin->batch) {
@@ -175,9 +181,7 @@ emit_recursive_batch(igt_spin_t *spin,
 							   BATCH_SIZE, 0,
 							   ALLOC_STRATEGY_LOW_TO_HIGH);
 	obj[BATCH].offset = CANONICAL(addr);
-	obj[BATCH].flags |= objflags;
-	if (obj[BATCH].offset >= (1ull << 32))
-		obj[BATCH].flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
+	obj[BATCH].flags = objflags;
 
 	addr += BATCH_SIZE;
 
@@ -192,27 +196,23 @@ emit_recursive_batch(igt_spin_t *spin,
 
 		obj[SCRATCH].handle = opts->dependency;
 		obj[SCRATCH].offset = CANONICAL(addr_scratch);
-		obj[SCRATCH].flags |= objflags;
-		if (obj[SCRATCH].offset >= (1ull << 32))
-			obj[SCRATCH].flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
+		obj[SCRATCH].flags = objflags;
 
 		if (!(opts->flags & IGT_SPIN_SOFTDEP)) {
 			obj[SCRATCH].flags |= EXEC_OBJECT_WRITE;
 
 			/* dummy write to dependency */
-			r = &relocs[obj[BATCH].relocation_count++];
 			r->presumed_offset = obj[SCRATCH].offset;
 			r->target_handle = obj[SCRATCH].handle;
 			r->offset = sizeof(uint32_t) * 1020;
 			r->delta = 0;
 			r->read_domains = I915_GEM_DOMAIN_RENDER;
 			r->write_domain = I915_GEM_DOMAIN_RENDER;
+			r++;
 		}
 
 		execbuf->buffer_count++;
 	} else if (opts->flags & IGT_SPIN_POLL_RUN) {
-		r = &relocs[obj[BATCH].relocation_count++];
-
 		igt_assert(!opts->dependency);
 
 		if (gen == 4 || gen == 5) {
@@ -244,6 +244,7 @@ emit_recursive_batch(igt_spin_t *spin,
 								   ALLOC_STRATEGY_LOW_TO_HIGH);
 		addr += 4096; /* guard page */
 		obj[SCRATCH].offset = CANONICAL(addr);
+		obj[SCRATCH].flags = objflags;
 		addr += 4096;
 
 		igt_assert_eq(spin->poll[SPIN_POLL_START_IDX], 0);
@@ -253,10 +254,6 @@ emit_recursive_batch(igt_spin_t *spin,
 		r->offset = sizeof(uint32_t) * 1;
 		r->delta = sizeof(uint32_t) * SPIN_POLL_START_IDX;
 
-		obj[SCRATCH].flags |= objflags;
-		if (obj[SCRATCH].offset >= (1ull << 32))
-			obj[SCRATCH].flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
-
 		*cs++ = MI_STORE_DWORD_IMM | (gen < 6 ? 1 << 22 : 0);
 
 		if (gen >= 8) {
@@ -274,6 +271,7 @@ emit_recursive_batch(igt_spin_t *spin,
 		*cs++ = 1;
 
 		execbuf->buffer_count++;
+		r++;
 	}
 
 	spin->handle = obj[BATCH].handle;
@@ -314,8 +312,6 @@ emit_recursive_batch(igt_spin_t *spin,
 	 * no matter how they modify it (from either the GPU or CPU).
 	 */
 	if (gen >= 8) { /* arbitrary cutoff between ring/execlists submission */
-		r = &relocs[obj[BATCH].relocation_count++];
-
 		/*
 		 * On Sandybridge+ the comparison is a strict greater-than:
 		 * if the value at spin->condition is greater than BB_END,
@@ -334,15 +330,17 @@ emit_recursive_batch(igt_spin_t *spin,
 		r->offset = (cs + 2 - spin->batch) * sizeof(*cs);
 		r->read_domains = I915_GEM_DOMAIN_COMMAND;
 		r->delta = (spin->condition - spin->batch) * sizeof(*cs);
+		igt_assert(r->delta < 4096);
 
 		*cs++ = MI_COND_BATCH_BUFFER_END | MI_DO_COMPARE | 2;
 		*cs++ = MI_BATCH_BUFFER_END;
 		*cs++ = r->presumed_offset + r->delta;
-		*cs++ = 0;
+		*cs++ = r->presumed_offset >> 32;
+
+		r++;
 	}
 
 	/* recurse */
-	r = &relocs[obj[BATCH].relocation_count++];
 	r->target_handle = obj[BATCH].handle;
 	r->presumed_offset = obj[BATCH].offset;
 	r->offset = (cs + 1 - spin->batch) * sizeof(*cs);
@@ -363,11 +361,10 @@ emit_recursive_batch(igt_spin_t *spin,
 		*cs = r->presumed_offset + r->delta;
 		cs++;
 	}
-	obj[BATCH].relocs_ptr = to_user_pointer(relocs);
+	r++;
 
 	execbuf->buffers_ptr =
 	       	to_user_pointer(obj + (2 - execbuf->buffer_count));
-	execbuf->rsvd1 = opts->ctx ? opts->ctx->id : opts->ctx_id;
 
 	if (opts->flags & IGT_SPIN_FENCE_OUT)
 		execbuf->flags |= I915_EXEC_FENCE_OUT;
@@ -382,14 +379,16 @@ emit_recursive_batch(igt_spin_t *spin,
 		execbuf->rsvd2 = opts->fence;
 	}
 
+	/* For allocator we have to rid of relocation_count */
+	if (!ahnd) {
+		obj[BATCH].relocs_ptr = to_user_pointer(relocs);
+		obj[BATCH].relocation_count = r - relocs;
+	}
+
 	for (i = 0; i < nengine; i++) {
 		execbuf->flags &= ~ENGINE_MASK;
 		execbuf->flags |= flags[i];
 
-		/* For allocator we have to rid of relocation_count */
-		for (int j = 0; j < ARRAY_SIZE(spin->obj) && ahnd; j++)
-			spin->obj[j].relocation_count = 0;
-
 		gem_execbuf_wr(fd, execbuf);
 
 		if (opts->flags & IGT_SPIN_FENCE_OUT) {
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/13 lib/i915: Mark gem_create as handling const memory regions

In reply to Zbigniew Kempczyński

From: Chris Wilson <[email protected]>

Make the memory regions passed to gem_crate_in_memory_region_list() as being const.

---
 lib/i915/intel_memory_region.c | 4 ++--
 lib/i915/intel_memory_region.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
lib/i915/intel_memory_region.c +2 -2
index 93a18982c1..568bace949 100644
@@ -198,7 +198,7 @@ bool gem_has_lmem(int fd)
 /* A version of gem_create_in_memory_region_list which can be allowed to
    fail so that the object creation can be retried */
 int __gem_create_in_memory_region_list(int fd, uint32_t *handle, uint64_t *size, uint32_t flags,
-				       struct drm_i915_gem_memory_class_instance *mem_regions,
+				       const struct drm_i915_gem_memory_class_instance *mem_regions,
 				       int num_regions)
 {
 	struct drm_i915_gem_create_ext_memory_regions ext_regions = {
@@ -234,7 +234,7 @@ int __gem_create_in_memory_region_list(int fd, uint32_t *handle, uint64_t *size,
  * @num_regions: @mem_regions length
  */
 uint32_t gem_create_in_memory_region_list(int fd, uint64_t size, uint32_t flags,
-					  struct drm_i915_gem_memory_class_instance *mem_regions,
+					  const struct drm_i915_gem_memory_class_instance *mem_regions,
 					  int num_regions)
 {
 	uint32_t handle;
lib/i915/intel_memory_region.h +2 -2
index e1bfe0ca65..fd04df83b5 100644
@@ -65,11 +65,11 @@ unsigned int gem_get_lmem_region_count(int fd);
 bool gem_has_lmem(int fd);
 
 int __gem_create_in_memory_region_list(int fd, uint32_t *handle, uint64_t *size, uint32_t flags,
-				       struct drm_i915_gem_memory_class_instance *mem_regions,
+				       const struct drm_i915_gem_memory_class_instance *mem_regions,
 				       int num_regions);
 
 uint32_t gem_create_in_memory_region_list(int fd, uint64_t size, uint32_t flags,
-					  struct drm_i915_gem_memory_class_instance *mem_regions,
+					  const struct drm_i915_gem_memory_class_instance *mem_regions,
 					  int num_regions);
 
 /*
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/13 lib/i915: Distinguish I915_MMAP_OFFSET_FIXED with an invalid domain

In reply to Zbigniew Kempczyński

From: Chris Wilson <[email protected]>

Don't treat OFFSET_FIXED as using DOMAIN_CPU [0], but give it an invalid domain so we can avoid using in tests.

---
 lib/i915/gem_mman.c          |  2 +-
 tests/i915/gem_mmap_offset.c | 12 ++++++++----
 2 files changed, 9 insertions(+), 5 deletions(-)
lib/i915/gem_mman.c +1 -1
index aa9ac6f3d7..48e3f8c991 100644
@@ -678,7 +678,7 @@ const struct mmap_offset mmap_offset_types[] = {
 	{ "wb", I915_MMAP_OFFSET_WB, I915_GEM_DOMAIN_CPU },
 	{ "wc", I915_MMAP_OFFSET_WC, I915_GEM_DOMAIN_WC },
 	{ "uc", I915_MMAP_OFFSET_UC, I915_GEM_DOMAIN_WC },
-	{ "fixed", I915_MMAP_OFFSET_FIXED, 0},
+	{ "fixed", I915_MMAP_OFFSET_FIXED, -1 },
 	{},
 };
 
tests/i915/gem_mmap_offset.c +8 -4
index 5e6b19eb34..d1075c32eb 100644
@@ -148,7 +148,8 @@ static void basic_uaf(int i915)
 		}
 
 		expected = calloc(obj_size, sizeof(*expected));
-		gem_set_domain(i915, handle, t->domain, 0);
+		if (t->domain != -1)
+			gem_set_domain(i915, handle, t->domain, 0);
 		igt_assert_f(memcmp(addr, expected, obj_size) == 0,
 			     "mmap(%s) not clear on gem_create()\n",
 			     t->name);
@@ -157,15 +158,18 @@ static void basic_uaf(int i915)
 		buf = calloc(obj_size, sizeof(*buf));
 		memset(buf + 1024, 0x01, 1024);
 		gem_write(i915, handle, 0, buf, obj_size);
-		gem_set_domain(i915, handle, t->domain, 0);
+		if (t->domain != -1)
+			gem_set_domain(i915, handle, t->domain, 0);
 		igt_assert_f(memcmp(buf, addr, obj_size) == 0,
 			     "mmap(%s) not coherent with gem_write()\n",
 			     t->name);
 
-		gem_set_domain(i915, handle, t->domain, t->domain);
+		if (t->domain != -1)
+			gem_set_domain(i915, handle, t->domain, t->domain);
 		memset(addr + 2048, 0xff, 1024);
 		gem_read(i915, handle, 0, buf, obj_size);
-		gem_set_domain(i915, handle, t->domain, 0);
+		if (t->domain != -1)
+			gem_set_domain(i915, handle, t->domain, 0);
 		igt_assert_f(memcmp(buf, addr, obj_size) == 0,
 			     "mmap(%s) not coherent with gem_read()\n",
 			     t->name);
Signature · 1 line
2.34.1
#4 lore raw

PATCH 4/13 i915/gem_create: Verify all regions return cleared objects

In reply to Zbigniew Kempczyński

From: Chris Wilson <[email protected]>

We do not tolerate leaking stale information in newly created objects, so make sure the test covers all memory regions.

---
 tests/i915/gem_create.c | 97 +++++++++++++++++++++++++++++++----------
 1 file changed, 74 insertions(+), 23 deletions(-)
tests/i915/gem_create.c +74 -23
index d7d2a01722..3c2251556f 100644
@@ -59,6 +59,7 @@
 #include "i915/gem_create.h"
 #include "i915/gem_engine_topology.h"
 #include "i915/gem_mman.h"
+#include "i915/intel_memory_region.h"
 #include "i915_drm.h"
 
 IGT_TEST_DESCRIPTION("Ensure that basic gem_create and gem_create_ext works"
@@ -145,45 +146,85 @@ static uint64_t get_npages(_Atomic(uint64_t) *global, uint64_t npages)
 
 struct thread_clear {
 	_Atomic(uint64_t) max;
+	struct drm_i915_gem_memory_class_instance region;
 	int timeout;
 	int i915;
 };
 
+static uint32_t batch_create(int i915)
+{
+	const uint32_t bbe = MI_BATCH_BUFFER_END;
+	uint32_t handle = gem_create(i915, sizeof(bbe));
+
+	gem_write(i915, handle, 0, &bbe, sizeof(bbe));
+	return handle;
+}
+
+static void make_resident(int i915, uint32_t batch, uint32_t handle)
+{
+	struct drm_i915_gem_exec_object2 obj[2] = {
+		[0] = {
+			.handle = handle,
+			.flags = EXEC_OBJECT_SUPPORTS_48B_ADDRESS,
+
+		},
+		[1] = {
+			.handle = batch ?: batch_create(i915),
+			.flags = EXEC_OBJECT_SUPPORTS_48B_ADDRESS,
+		},
+	};
+	struct drm_i915_gem_execbuffer2 eb = {
+		.buffers_ptr = to_user_pointer(obj),
+		.buffer_count = ARRAY_SIZE(obj),
+	};
+
+	gem_execbuf(i915, &eb);
+	if (obj[1].handle != batch)
+		gem_close(i915, obj[1].handle);
+}
+
 static void *thread_clear(void *data)
 {
 	struct thread_clear *arg = data;
 	unsigned long checked = 0, total = 0;
-	enum { PRW, GTT, WC, WB, __LAST__ } mode = PRW;
+	enum { PRW, GTT, WC, WB, __LAST__, FIXED } mode = PRW;
 	int i915 = arg->i915;
+	uint32_t batch = batch_create(i915);
+
+	if (__gem_write(i915, 0, 0, 0, 0) == -EOPNOTSUPP)
+		mode = FIXED;
 
 	igt_until_timeout(arg->timeout) {
-		struct drm_i915_gem_create create = {};
-		uint64_t npages;
+		uint64_t npages, size;
+		uint32_t handle;
 		void *ptr;
 
 		npages = random();
 		npages <<= 32;
 		npages |= random();
 		npages = get_npages(&arg->max, npages);
-		create.size = npages << 12;
+		size = npages << 12;
+
+		igt_assert_eq(__gem_create_in_memory_region_list(i915, &handle, &size, 0, &arg->region, 1), 0);
+		if (random() & 1)
+			make_resident(i915, batch, handle);
 
-		create_ioctl(i915, &create);
 		switch (mode) {
+		case FIXED:
+			ptr = __gem_mmap_offset__fixed(i915, handle, 0, size, PROT_READ);
+			break;
 		case __LAST__:
 		case PRW:
 			ptr = NULL;
 			break;
 		case WB:
-			ptr = __gem_mmap__cpu(i915, create.handle,
-					      0, create.size, PROT_READ);
+			ptr = __gem_mmap__cpu(i915, handle, 0, size, PROT_READ);
 			break;
 		case WC:
-			ptr = __gem_mmap__wc(i915, create.handle,
-					     0, create.size, PROT_READ);
+			ptr = __gem_mmap__wc(i915, handle, 0, size, PROT_READ);
 			break;
 		case GTT:
-			ptr = __gem_mmap__gtt(i915, create.handle,
-					      create.size, PROT_READ);
+			ptr = __gem_mmap__gtt(i915, handle, size, PROT_READ);
 			break;
 		}
 		/* No set-domains as we are being as naughty as possible */
@@ -195,7 +236,7 @@ static void *thread_clear(void *data)
 			};
 
 			if (!ptr)
-				gem_read(i915, create.handle, x[0], x, sizeof(x));
+				gem_read(i915, handle, x[0], x, sizeof(x));
 			else if (page & 1)
 				igt_memcpy_from_wc(x, ptr + x[0], sizeof(x));
 			else
@@ -207,26 +248,28 @@ static void *thread_clear(void *data)
 			checked++;
 		}
 		if (ptr)
-			munmap(ptr, create.size);
-		gem_close(i915, create.handle);
+			munmap(ptr, size);
+		gem_close(i915, handle);
 
 		total += npages;
 		atomic_fetch_add(&arg->max, npages);
 
-		if (++mode == __LAST__)
+		if (mode < __LAST__ && ++mode == __LAST__)
 			mode = PRW;
 	}
+	gem_close(i915, batch);
 
 	igt_info("Checked %'lu / %'lu pages\n", checked, total);
 	return (void *)(uintptr_t)checked;
 }
 
-static void always_clear(int i915, int timeout)
+static void always_clear(int i915, const struct gem_memory_region *r, int timeout)
 {
 	struct thread_clear arg = {
 		.i915 = i915,
+		.region = r->ci,
+		.max = r->size / 2 >> 12, /* in pages */
 		.timeout = timeout,
-		.max = igt_get_avail_ram_mb() << (20 - 12), /* in pages */
 	};
 	const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
 	unsigned long checked;
@@ -244,7 +287,7 @@ static void always_clear(int i915, int timeout)
 	igt_info("Checked %'lu page allocations\n", checked);
 }
 
-static void busy_create(int i915, int timeout)
+static void busy_create(int i915, const struct gem_memory_region *r, int timeout)
 {
 	struct intel_execution_engine2 *e;
 	const intel_ctx_t *ctx;
@@ -267,7 +310,7 @@ static void busy_create(int i915, int timeout)
 			uint32_t handle;
 			igt_spin_t *next;
 
-			handle = gem_create(i915, 4096);
+			handle = gem_create_in_memory_region_list(i915, 4096, 0, &r->ci, 1);
 			next = igt_spin_new(i915,
 					    .ahnd = ahnd,
 					    .ctx = ctx,
@@ -808,12 +851,20 @@ igt_main
 		size_update(fd);
 
 	igt_describe("Verify that all new objects are clear.");
-	igt_subtest("create-clear")
-		always_clear(fd, 30);
+	igt_subtest_with_dynamic("create-clear") {
+		for_each_memory_region(r, fd) {
+			igt_dynamic_f("%s", r->name)
+				always_clear(fd, r, 30);
+		}
+	}
 
 	igt_describe("Create buffer objects while GPU is busy.");
-	igt_subtest("busy-create")
-		busy_create(fd, 30);
+	igt_subtest_with_dynamic("busy-create") {
+		for_each_memory_region(r, fd) {
+			igt_dynamic_f("%s", r->name)
+				busy_create(fd, r, 30);
+		}
+	}
 
 	igt_describe("Exercise create_ext placements extension.");
 	igt_subtest("create-ext-placement-sanity-check")
Signature · 1 line
2.34.1
#5 lore raw

PATCH 5/13 i915/gem_create: Stress creation with busy engines

In reply to Zbigniew Kempczyński

From: Chris Wilson <[email protected]>

Use shortlived non-preemptible batches to demonstrate an issue with waiting on user controlled resources.

---
 tests/i915/gem_create.c | 54 +++++++++++++++++++++++++++--------------
 1 file changed, 36 insertions(+), 18 deletions(-)
tests/i915/gem_create.c +36 -18
index 3c2251556f..13fba35bae 100644
@@ -287,7 +287,8 @@ static void always_clear(int i915, const struct gem_memory_region *r, int timeou
 	igt_info("Checked %'lu page allocations\n", checked);
 }
 
-static void busy_create(int i915, const struct gem_memory_region *r, int timeout)
+static void busy_create(int i915, const struct gem_memory_region *r, int timeout, unsigned int flags)
+#define BUSY_HOG 0x1
 {
 	struct intel_execution_engine2 *e;
 	const intel_ctx_t *ctx;
@@ -298,12 +299,14 @@ static void busy_create(int i915, const struct gem_memory_region *r, int timeout
 	ctx = intel_ctx_create_all_physical(i915);
 	ahnd = get_reloc_ahnd(i915, ctx->id);
 
-	igt_fork_hang_detector(i915);
-	for_each_ctx_engine(i915, ctx, e)
-		spin[e->flags] = igt_spin_new(i915,
-					      .ahnd = ahnd,
-					      .ctx = ctx,
-					      .engine = e->flags);
+	for_each_ctx_engine(i915, ctx, e) {
+		spin[e->flags] =
+			igt_spin_new(i915,
+				     .ahnd = ahnd,
+				     .ctx = ctx,
+				     .engine = e->flags,
+				     .flags = flags & BUSY_HOG ? IGT_SPIN_NO_PREEMPTION : 0);
+	}
 
 	igt_until_timeout(timeout) {
 		for_each_ctx_engine(i915, ctx, e) {
@@ -311,12 +314,13 @@ static void busy_create(int i915, const struct gem_memory_region *r, int timeout
 			igt_spin_t *next;
 
 			handle = gem_create_in_memory_region_list(i915, 4096, 0, &r->ci, 1);
-			next = igt_spin_new(i915,
-					    .ahnd = ahnd,
-					    .ctx = ctx,
-					    .engine = e->flags,
-					    .dependency = handle,
-					    .flags = IGT_SPIN_SOFTDEP);
+			next = __igt_spin_new(i915,
+					      .ahnd = ahnd,
+					      .ctx = ctx,
+					      .engine = e->flags,
+					      .dependency = handle,
+					      .flags = ((flags & BUSY_HOG ? IGT_SPIN_NO_PREEMPTION : 0) |
+							IGT_SPIN_SOFTDEP));
 			gem_close(i915, handle);
 
 			igt_spin_free(i915, spin[e->flags]);
@@ -332,7 +336,6 @@ static void busy_create(int i915, const struct gem_memory_region *r, int timeout
 	igt_info("Created %ld objects while busy\n", count);
 
 	gem_quiescent_gpu(i915);
-	igt_stop_hang_detector();
 }
 
 static void size_update(int fd)
@@ -859,11 +862,26 @@ igt_main
 	}
 
 	igt_describe("Create buffer objects while GPU is busy.");
-	igt_subtest_with_dynamic("busy-create") {
-		for_each_memory_region(r, fd) {
-			igt_dynamic_f("%s", r->name)
-				busy_create(fd, r, 30);
+	igt_subtest_group {
+		igt_fixture
+			igt_fork_hang_detector(fd);
+
+		igt_subtest_with_dynamic("busy-create") {
+			for_each_memory_region(r, fd) {
+				igt_dynamic_f("%s", r->name)
+					busy_create(fd, r, 30, 0);
+			}
 		}
+
+		igt_subtest_with_dynamic("hog-create") {
+			for_each_memory_region(r, fd) {
+				igt_dynamic_f("%s", r->name)
+					busy_create(fd, r, 30, BUSY_HOG);
+			}
+		}
+
+		igt_fixture
+			igt_stop_hang_detector();
 	}
 
 	igt_describe("Exercise create_ext placements extension.");
Signature · 1 line
2.34.1
#6 lore raw

PATCH 6/13 i915/gem_mmap_offset: Verify all regions return clear mmaps on cration

In reply to Zbigniew Kempczyński

From: Chris Wilson <[email protected]>

We do not tolerate leaking stale information in newly created objects, so make sure the test covers all memory regions.

---
 tests/i915/gem_mmap_offset.c | 87 +++++++++++++++++++++++++-----------
 1 file changed, 60 insertions(+), 27 deletions(-)
tests/i915/gem_mmap_offset.c +60 -27
index d1075c32eb..faadbd4ee6 100644
@@ -35,6 +35,7 @@
 
 #include "i915/gem.h"
 #include "i915/gem_create.h"
+#include "i915/intel_memory_region.h"
 #include "igt.h"
 #include "igt_x86.h"
 
@@ -75,6 +76,37 @@ __mmap_offset(int i915, uint32_t handle, uint64_t offset, uint64_t size,
 	return ptr;
 }
 
+static uint32_t batch_create(int i915)
+{
+	const uint32_t bbe = MI_BATCH_BUFFER_END;
+	uint32_t handle = gem_create(i915, sizeof(bbe));
+
+	gem_write(i915, handle, 0, &bbe, sizeof(bbe));
+	return handle;
+}
+
+static void make_resident(int i915, uint32_t batch, uint32_t handle)
+{
+	struct drm_i915_gem_exec_object2 obj[2] = {
+		[0] = {
+			.handle = handle,
+			.flags = EXEC_OBJECT_SUPPORTS_48B_ADDRESS,
+		},
+		[1] = {
+			.handle = batch ?: batch_create(i915),
+			.flags = EXEC_OBJECT_SUPPORTS_48B_ADDRESS,
+		},
+	};
+	struct drm_i915_gem_execbuffer2 eb = {
+		.buffers_ptr = to_user_pointer(obj),
+		.buffer_count = ARRAY_SIZE(obj),
+	};
+
+	gem_execbuf(i915, &eb);
+	if (obj[1].handle != batch)
+		gem_close(i915, obj[1].handle);
+}
+
 static void bad_object(int i915)
 {
 	uint32_t real_handle;
@@ -529,44 +561,35 @@ static uint64_t get_npages(_Atomic(uint64_t) *global, uint64_t npages)
 
 struct thread_clear {
 	_Atomic(uint64_t) max;
+	struct drm_i915_gem_memory_class_instance region;
 	int timeout;
 	int i915;
 };
 
-static int create_ioctl(int i915, struct drm_i915_gem_create *create)
-{
-	int err = 0;
-
-	if (igt_ioctl(i915, DRM_IOCTL_I915_GEM_CREATE, create)) {
-		err = -errno;
-		igt_assume(err != 0);
-	}
-
-	errno = 0;
-	return err;
-}
-
 static void *thread_clear(void *data)
 {
 	struct thread_clear *arg = data;
 	const struct mmap_offset *t;
-	unsigned long checked = 0;
+	unsigned long checked = 0, total = 0;
 	int i915 = arg->i915;
+	uint32_t batch = batch_create(i915);
 
 	t = mmap_offset_types;
 	igt_until_timeout(arg->timeout) {
-		struct drm_i915_gem_create create = {};
-		uint64_t npages;
+		uint64_t npages, size;
+		uint32_t handle;
 		void *ptr;
 
 		npages = random();
 		npages <<= 32;
 		npages |= random();
 		npages = get_npages(&arg->max, npages);
-		create.size = npages << 12;
+		size = npages << 12;
 
-		create_ioctl(i915, &create);
-		ptr = __mmap_offset(i915, create.handle, 0, create.size,
+		igt_assert_eq(__gem_create_in_memory_region_list(i915, &handle, &size, 0, &arg->region, 1), 0);
+		make_resident(i915, batch, handle);
+
+		ptr = __mmap_offset(i915, handle, 0, size,
 				    PROT_READ | PROT_WRITE,
 				    t->type);
 		/* No set-domains as we are being as naughty as possible */
@@ -584,26 +607,32 @@ static void *thread_clear(void *data)
 			for (int i = 0; i < ARRAY_SIZE(x); i++)
 				igt_assert_eq_u64(x[i], 0);
 		}
-		if (ptr)
-			munmap(ptr, create.size);
-		gem_close(i915, create.handle);
-		checked += npages;
+		if (ptr) {
+			munmap(ptr, size);
+			checked += npages;
+		}
+		gem_close(i915, handle);
 
+		total += npages;
 		atomic_fetch_add(&arg->max, npages);
 
 		if (!(++t)->name)
 			t = mmap_offset_types;
 	}
 
+	gem_close(i915, batch);
+
+	igt_info("Checked %'lu / %'lu pages\n", checked, total);
 	return (void *)(uintptr_t)checked;
 }
 
-static void always_clear(int i915, int timeout)
+static void always_clear(int i915, const struct gem_memory_region *r, int timeout)
 {
 	struct thread_clear arg = {
 		.i915 = i915,
+		.region = r->ci,
+		.max = r->size / 2 >> 12, /* in pages */
 		.timeout = timeout,
-		.max = igt_get_avail_ram_mb() << (20 - 12), /* in pages */
 	};
 	const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
 	unsigned long checked;
@@ -750,8 +779,12 @@ igt_main
 	igt_subtest_f("open-flood")
 		open_flood(i915, 20);
 
-	igt_subtest_f("clear")
-		always_clear(i915, 20);
+	igt_subtest_with_dynamic("clear") {
+		for_each_memory_region(r, i915) {
+			igt_dynamic_f("%s", r->name)
+				always_clear(i915, r, 20);
+		}
+	}
 
 	igt_subtest_f("blt-coherency")
 		blt_coherency(i915);
Signature · 1 line
2.34.1
#7 lore raw

PATCH 7/13 i915/gem_mmap_offset: Verify all regions with ptrace

In reply to Zbigniew Kempczyński

From: Chris Wilson <[email protected]>

Check we can use ptrace to query *ptr of each mmap for each region.

---
 tests/i915/gem_mmap_offset.c | 84 ++++++++++++++++++++----------------
 1 file changed, 46 insertions(+), 38 deletions(-)
tests/i915/gem_mmap_offset.c +46 -38
index faadbd4ee6..806a9d68f4 100644
@@ -370,64 +370,72 @@ static void test_ptrace(int i915)
 	const unsigned int SZ = 3 * 4096;
 	unsigned long *ptr, *cpy;
 	unsigned long AA, CC;
-	uint32_t bo;
 
 	memset(&AA, 0xaa, sizeof(AA));
 	memset(&CC, 0x55, sizeof(CC));
 
 	cpy = malloc(SZ);
-	bo = gem_create(i915, SZ);
+	igt_assert(cpy);
 
-	for_each_mmap_offset_type(i915, t) {
-		ptr = __mmap_offset(i915, bo, 0, SZ,
-				    PROT_READ | PROT_WRITE,
-				    t->type);
-		if (!ptr)
-			continue;
+	for_each_memory_region(r, i915) {
+		uint64_t size = SZ;
+		uint32_t bo;
 
-		igt_dynamic_f("%s", t->name) {
-			pid_t pid;
+		igt_assert_eq(__gem_create_in_memory_region_list(i915, &bo, &size, 0, &r->ci, 1), 0);
+		make_resident(i915, 0, bo);
 
-			memset(cpy, AA, SZ);
-			memset(ptr, CC, SZ);
+		for_each_mmap_offset_type(i915, t) {
+			ptr = __mmap_offset(i915, bo, 0, size,
+					    PROT_READ | PROT_WRITE,
+					    t->type);
+			if (!ptr)
+				continue;
 
-			igt_assert(!memchr_inv(ptr, CC, SZ));
-			igt_assert(!memchr_inv(cpy, AA, SZ));
+			igt_dynamic_f("%s-%s", r->name, t->name) {
+				pid_t pid;
 
-			igt_fork(child, 1) {
-				ptrace(PTRACE_TRACEME, 0, NULL, NULL);
-				raise(SIGSTOP);
-			}
+				memset(cpy, AA, SZ);
+				memset(ptr, CC, SZ);
 
-			/* Wait for the child to ready themselves [SIGSTOP] */
-			pid = wait(NULL);
+				igt_assert(!memchr_inv(ptr, CC, SZ));
+				igt_assert(!memchr_inv(cpy, AA, SZ));
 
-			ptrace(PTRACE_ATTACH, pid, NULL, NULL);
-			for (int i = 0; i < SZ / sizeof(long); i++) {
-				long ret;
+				igt_fork(child, 1) {
+					ptrace(PTRACE_TRACEME, 0, NULL, NULL);
+					raise(SIGSTOP);
+				}
 
-				ret = ptrace(PTRACE_PEEKDATA, pid, ptr + i);
-				igt_assert_eq_u64(ret, CC);
-				cpy[i] = ret;
+				/* Wait for the child to ready themselves [SIGSTOP] */
+				pid = wait(NULL);
 
-				ret = ptrace(PTRACE_POKEDATA, pid, ptr + i, AA);
-				igt_assert_eq(ret, 0l);
-			}
-			ptrace(PTRACE_DETACH, pid, NULL, NULL);
+				ptrace(PTRACE_ATTACH, pid, NULL, NULL);
+				for (int i = 0; i < SZ / sizeof(long); i++) {
+					long ret;
+
+					ret = ptrace(PTRACE_PEEKDATA, pid, ptr + i);
+					igt_assert_eq_u64(ret, CC);
+					cpy[i] = ret;
+
+					ret = ptrace(PTRACE_POKEDATA, pid, ptr + i, AA);
+					igt_assert_eq(ret, 0l);
+				}
+				ptrace(PTRACE_DETACH, pid, NULL, NULL);
 
-			/* Wakeup the child for it to exit */
-			kill(SIGCONT, pid);
-			igt_waitchildren();
+				/* Wakeup the child for it to exit */
+				kill(SIGCONT, pid);
+				igt_waitchildren();
 
-			/* The two buffers should now be swapped */
-			igt_assert(!memchr_inv(ptr, AA, SZ));
-			igt_assert(!memchr_inv(cpy, CC, SZ));
+				/* The two buffers should now be swapped */
+				igt_assert(!memchr_inv(ptr, AA, SZ));
+				igt_assert(!memchr_inv(cpy, CC, SZ));
+			}
+
+			munmap(ptr, size);
 		}
 
-		munmap(ptr, SZ);
+		gem_close(i915, bo);
 	}
 
-	gem_close(i915, bo);
 	free(cpy);
 }
 
Signature · 1 line
2.34.1
#8 lore raw

PATCH 8/13 i915/gem_mmap_offset: Verify all regions remain in isolation

In reply to Zbigniew Kempczyński

From: Chris Wilson <[email protected]>

Check that we don't leak mmap pointers to different regions.

---
 tests/i915/gem_mmap_offset.c | 99 +++++++++++++++++++-----------------
 1 file changed, 51 insertions(+), 48 deletions(-)
tests/i915/gem_mmap_offset.c +51 -48
index 806a9d68f4..c392dc2092 100644
@@ -219,68 +219,71 @@ static void basic_uaf(int i915)
 
 static void isolation(int i915)
 {
-	for_each_mmap_offset_type(i915, t) {
-		struct drm_i915_gem_mmap_offset mmap_arg = {
-			.flags = t->type
-		};
-		int A = gem_reopen_driver(i915);
-		int B = gem_reopen_driver(i915);
-		uint64_t offset_a, offset_b;
-		uint32_t a, b;
-		void *ptr;
-
-		a = gem_create(A, 4096);
-		b = gem_open(B, gem_flink(A, a));
-
-		mmap_arg.handle = a;
-		if (mmap_offset_ioctl(A, &mmap_arg)) {
-			close(A);
-			close(B);
-			continue;
-		}
-		offset_a = mmap_arg.offset;
-
-		mmap_arg.handle = b;
-		igt_assert_eq(mmap_offset_ioctl(B, &mmap_arg), 0);
-		offset_b = mmap_arg.offset;
-
-		igt_info("A[%s]: {fd:%d, handle:%d, offset:%"PRIx64"}\n",
-			 t->name, A, a, offset_a);
-		igt_info("B[%s]: {fd:%d, handle:%d, offset:%"PRIx64"}\n",
-			 t->name, B, b, offset_b);
+	for_each_memory_region(r, i915) {
+		igt_info("%s\n", r->name);
+		for_each_mmap_offset_type(i915, t) {
+			struct drm_i915_gem_mmap_offset mmap_arg = {
+				.flags = t->type
+			};
+			int A = gem_reopen_driver(i915);
+			int B = gem_reopen_driver(i915);
+			uint64_t offset_a, offset_b;
+			uint32_t a, b;
+			void *ptr;
+
+			a = gem_create_in_memory_region_list(A, 4096, 0, &r->ci, 1);
+			b = gem_open(B, gem_flink(A, a));
+
+			mmap_arg.handle = a;
+			if (mmap_offset_ioctl(A, &mmap_arg)) {
+				close(A);
+				close(B);
+				continue;
+			}
+			offset_a = mmap_arg.offset;
 
-		errno = 0;
-		ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, i915, offset_a);
-		igt_assert(ptr == MAP_FAILED);
-		igt_assert_eq(errno, EACCES);
+			mmap_arg.handle = b;
+			igt_assert_eq(mmap_offset_ioctl(B, &mmap_arg), 0);
+			offset_b = mmap_arg.offset;
 
-		errno = 0;
-		ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, i915, offset_b);
-		igt_assert(ptr == MAP_FAILED);
-		igt_assert_eq(errno, EACCES);
+			igt_info("\tA[%s]: {fd:%d, handle:%d, offset:%"PRIx64"}\n",
+				 t->name, A, a, offset_a);
+			igt_info("\tB[%s]: {fd:%d, handle:%d, offset:%"PRIx64"}\n",
+				 t->name, B, b, offset_b);
 
-		if (offset_a != offset_b) {
 			errno = 0;
-			ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, B, offset_a);
+			ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, i915, offset_a);
 			igt_assert(ptr == MAP_FAILED);
 			igt_assert_eq(errno, EACCES);
 
 			errno = 0;
-			ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_b);
+			ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, i915, offset_b);
 			igt_assert(ptr == MAP_FAILED);
 			igt_assert_eq(errno, EACCES);
-		}
 
-		close(B);
+			if (offset_a != offset_b) {
+				errno = 0;
+				ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, B, offset_a);
+				igt_assert(ptr == MAP_FAILED);
+				igt_assert_eq(errno, EACCES);
 
-		ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
-		igt_assert(ptr != MAP_FAILED);
-		munmap(ptr, 4096);
+				errno = 0;
+				ptr = mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_b);
+				igt_assert(ptr == MAP_FAILED);
+				igt_assert_eq(errno, EACCES);
+			}
 
-		close(A);
+			close(B);
+
+			ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
+			igt_assert(ptr != MAP_FAILED);
+			munmap(ptr, 4096);
+
+			close(A);
 
-		ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
-		igt_assert(ptr == MAP_FAILED);
+			ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
+			igt_assert(ptr == MAP_FAILED);
+		}
 	}
 }
 
Signature · 1 line
2.34.1
#9 lore raw

PATCH 9/13 i915/gem_mmap_offset: Verify all regions have nonblocking pagefaults

In reply to Zbigniew Kempczyński

From: Chris Wilson <[email protected]>

Check that if we fault in a page that is active on the gpu, it doesn't wait for completion.

---
 tests/i915/gem_mmap_offset.c | 37 +++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)
tests/i915/gem_mmap_offset.c +36 -1
index c392dc2092..d82c19e946 100644
@@ -287,7 +287,7 @@ static void isolation(int i915)
 	}
 }
 
-static void pf_nonblock(int i915)
+static void pf_nonblock_batch(int i915)
 {
 	uint64_t ahnd = get_reloc_ahnd(i915, 0);
 	igt_spin_t *spin = igt_spin_new(i915, .ahnd = ahnd);
@@ -313,6 +313,41 @@ static void pf_nonblock(int i915)
 	put_ahnd(ahnd);
 }
 
+static void pf_nonblock(int i915)
+{
+	uint64_t ahnd = get_reloc_ahnd(i915, 0);
+
+	pf_nonblock_batch(i915);
+
+	for_each_memory_region(r, i915) {
+		igt_spin_t *spin;
+		uint32_t handle;
+
+		handle = gem_create_in_memory_region_list(i915, 4096, 0, &r->ci, 1);
+		spin = igt_spin_new(i915, .ahnd = ahnd, .dependency = handle);
+
+		for_each_mmap_offset_type(i915, t) {
+			uint32_t *ptr;
+
+			ptr = __mmap_offset(i915, handle, 0, 4096,
+					    PROT_READ | PROT_WRITE,
+					    t->type);
+			if (!ptr)
+				continue;
+
+			igt_set_timeout(1, t->name);
+			/* no set-domain as we want to verify the pagefault is async */
+			ptr[256] = 0;
+			igt_reset_timeout();
+
+			munmap(ptr, 4096);
+		}
+
+		igt_spin_free(i915, spin);
+		gem_close(i915, handle);
+	}
+}
+
 static void *memchr_inv(const void *s, int c, size_t n)
 {
 	const uint8_t *us = s;
Signature · 1 line
2.34.1
#10 lore raw

PATCH 10/13 i915/gem_mmap_offset: Check all mmap types reject invalid objects

In reply to Zbigniew Kempczyński

From: Chris Wilson <[email protected]>

Extend the bad_object negative subtest to cover all mmap types.

---
 tests/i915/gem_mmap_offset.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
tests/i915/gem_mmap_offset.c +10 -8
index d82c19e946..8f66b76138 100644
@@ -121,15 +121,17 @@ static void bad_object(int i915)
 	handles[i] = real_handle + 1;
 
 	for (; i >= 0; i--) {
-		struct drm_i915_gem_mmap_offset arg = {
-			.handle = handles[i],
-			.flags = I915_MMAP_OFFSET_WB,
-		};
+		for_each_mmap_offset_type(i915, t) {
+			struct drm_i915_gem_mmap_offset arg = {
+				.handle = handles[i],
+				.flags = t->type,
+			};
 
-		igt_debug("Trying MMAP IOCTL with handle %x\n",
-			  handles[i]);
-		igt_assert_eq(mmap_offset_ioctl(i915, &arg),
-			      -ENOENT);
+			igt_debug("Trying MMAP IOCTL[%s] with handle %x\n",
+				  t->name, handles[i]);
+			igt_assert_eq(mmap_offset_ioctl(i915, &arg),
+				      -ENOENT);
+		}
 	}
 
 	gem_close(i915, real_handle);
Signature · 1 line
2.34.1
#11 lore raw

PATCH 11/13 i915/gem_mmap_offset: Exercise close race against all types/regions

In reply to Zbigniew Kempczyński

From: Chris Wilson <[email protected]>

Iterate over all mmmap types and memory regions looking for races against closing the object.

---
 tests/i915/gem_mmap_offset.c | 42 +++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 20 deletions(-)
tests/i915/gem_mmap_offset.c +22 -20
index 8f66b76138..24da713589 100644
@@ -490,29 +490,31 @@ static void close_race(int i915, int timeout)
 
 	igt_fork(child, ncpus + 1) {
 		do {
-			struct drm_i915_gem_mmap_offset mmap_arg = {};
-			const int i = 1 + random() % ncpus;
-			uint32_t old;
-
-			mmap_arg.handle = gem_create(i915, 4096);
-			mmap_arg.flags = I915_MMAP_OFFSET_WB;
-			old = atomic_exchange(&handles[i], mmap_arg.handle);
-			ioctl(i915, DRM_IOCTL_GEM_CLOSE, &old);
-
-			if (ioctl(i915,
-				  DRM_IOCTL_I915_GEM_MMAP_OFFSET,
-				  &mmap_arg) != -1) {
-				void *ptr;
-
-				ptr = mmap64(0, 4096,
-					     PROT_WRITE, MAP_SHARED, i915,
-					     mmap_arg.offset);
-				if (ptr != MAP_FAILED) {
+			for_each_memory_region(r, i915) {
+				const int i = 1 + random() % ncpus;
+				uint64_t size = 4096;
+				uint32_t bo, old;
+
+				igt_assert_eq(__gem_create_in_memory_region_list(i915, &bo, &size, 0, &r->ci, 1), 0);
+				make_resident(i915, 0, bo);
+
+				old = atomic_exchange(&handles[i], bo);
+				ioctl(i915, DRM_IOCTL_GEM_CLOSE, &old);
+
+				for_each_mmap_offset_type(i915, t) {
+					void *ptr;
+
+					ptr = __mmap_offset(i915, bo, 0, size,
+							    PROT_READ | PROT_WRITE,
+							    t->type);
+					if (!ptr)
+						continue;
+
+
 					*(volatile uint32_t *)ptr = 0;
-					munmap(ptr, 4096);
+					munmap(ptr, size);
 				}
 			}
-
 		} while (!READ_ONCE(handles[0]));
 	}
 
Signature · 1 line
2.34.1
#12 lore raw

PATCH 12/13 i915/gem_mmap_offset: Crudely measure read/write to different mmaps

In reply to Zbigniew Kempczyński

From: Chris Wilson <[email protected]>

Compare the read/write performance of different mmap types to different memory regions.

---
 tests/i915/gem_mmap_offset.c | 74 ++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
tests/i915/gem_mmap_offset.c +74 -0
index 24da713589..106072cc06 100644
@@ -107,6 +107,73 @@ static void make_resident(int i915, uint32_t batch, uint32_t handle)
 		gem_close(i915, obj[1].handle);
 }
 
+static void perf(int i915, const struct gem_memory_region *r)
+{
+#define MiB (1024 * 1024)
+	const unsigned int rep = 1024;
+	const uint64_t sz = 4096;
+	struct timespec tv;
+	uint32_t handle;
+	char buf[4096];
+
+	/*
+	 * Time reading/writing through each mmap type into each
+	 * memory region to have a rough estimate of the memory
+	 * bandwidth exposed to userspace across each link.
+	 *
+	 * For example, we would expect that reading and writing to
+	 * lmem would utilise the full PCIe bandwidth (>3.2GiB/s),
+	 * and notably be symmetric, the same in both directions.
+	 */
+
+	handle = gem_create_in_memory_region_list(i915, 4096, 0, &r->ci, 1);
+	make_resident(i915, 0, handle);
+
+	for_each_mmap_offset_type(i915, t) {
+		double ns;
+		void *ptr;
+
+		ptr = __mmap_offset(i915, handle, 0, sz,
+				    PROT_READ | PROT_WRITE,
+				    t->type);
+		if (!ptr)
+			continue;
+
+		igt_nsec_elapsed(memset(&tv, 0, sizeof(tv)));
+		for (int i = 0; i < rep; i++)
+			memset(ptr, 0, sz);
+		ns = igt_nsec_elapsed(&tv);
+		igt_info("%s: Clear    %12.2fMiB/s\n",
+			 t->name, sz * rep * NSEC_PER_SEC / ns / MiB);
+
+		igt_nsec_elapsed(memset(&tv, 0, sizeof(tv)));
+		for (int i = 0; i < rep; i++)
+			memcpy(ptr, buf, sz);
+		ns = igt_nsec_elapsed(&tv);
+		igt_info("%s: Write    %12.2fMiB/s\n",
+			 t->name, sz * rep * NSEC_PER_SEC / ns / MiB);
+
+		igt_nsec_elapsed(memset(&tv, 0, sizeof(tv)));
+		for (int i = 0; i < rep; i++)
+			memcpy(buf, ptr, sz);
+		ns = igt_nsec_elapsed(&tv);
+		igt_info("%s: Read     %12.2fMiB/s\n",
+			 t->name, sz * rep * NSEC_PER_SEC / ns / MiB);
+
+		igt_nsec_elapsed(memset(&tv, 0, sizeof(tv)));
+		for (int i = 0; i < rep; i++)
+			igt_memcpy_from_wc(buf, ptr, sz);
+		ns = igt_nsec_elapsed(&tv);
+		igt_info("%s: movntqda %12.2fMiB/s\n",
+			 t->name, sz * rep * NSEC_PER_SEC / ns / MiB);
+
+		munmap(ptr, sz);
+	}
+
+	gem_close(i915, handle);
+#undef MiB
+}
+
 static void bad_object(int i915)
 {
 	uint32_t real_handle;
@@ -836,6 +903,13 @@ igt_main
 		}
 	}
 
+	igt_subtest_with_dynamic("perf") {
+		for_each_memory_region(r, i915) {
+			igt_dynamic_f("%s", r->name)
+				perf(i915, r);
+		}
+	}
+
 	igt_subtest_f("blt-coherency")
 		blt_coherency(i915);
 
Signature · 1 line
2.34.1
#13 lore raw

PATCH 13/13 HAX: exercise subset of gem_create and gem_mmap_offset

In reply to Zbigniew Kempczyński
---
 tests/intel-ci/fast-feedback.testlist | 189 ++------------------------
 1 file changed, 13 insertions(+), 176 deletions(-)
tests/intel-ci/fast-feedback.testlist +13 -176
index bd5538a035..feff6daa11 100644
@@ -1,177 +1,14 @@
-# Try to load the driver if it's not available yet.
-igt@i915_module_load@load
+igt@gem_create@busy-create
+igt@gem_create@create-clear
+igt@gem_create@hog-create
+igt@gem_mmap_offset@bad-object
+igt@gem_mmap_offset@basic-uaf
+igt@gem_mmap_offset@clear
+igt@gem_mmap_offset@close-race
+igt@gem_mmap_offset@isolation
+igt@gem_mmap_offset@perf
+igt@gem_mmap_offset@pf-nonblock
+igt@gem_mmap_offset@ptrace
+
+igt@meta_test@fail-result
 
-# Keep alphabetically sorted by default
-igt@core_auth@basic-auth
-igt@debugfs_test@read_all_entries
-igt@fbdev@eof
-igt@fbdev@info
-igt@fbdev@nullptr
-igt@fbdev@read
-igt@fbdev@write
-igt@gem_basic@bad-close
-igt@gem_basic@create-close
-igt@gem_basic@create-fd-close
-igt@gem_busy@busy@all
-igt@gem_close_race@basic-process
-igt@gem_close_race@basic-threads
-igt@gem_ctx_create@basic
-igt@gem_ctx_create@basic-files
-igt@gem_ctx_exec@basic
-igt@gem_exec_basic@basic
-igt@gem_exec_create@basic
-igt@gem_exec_fence@basic-busy
-igt@gem_exec_fence@basic-wait
-igt@gem_exec_fence@basic-await
-igt@gem_exec_fence@nb-await
-igt@gem_exec_gttfill@basic
-igt@gem_exec_parallel@engines
-igt@gem_exec_store@basic
-igt@gem_flink_basic@bad-flink
-igt@gem_flink_basic@bad-open
-igt@gem_flink_basic@basic
-igt@gem_flink_basic@double-flink
-igt@gem_flink_basic@flink-lifetime
-igt@gem_huc_copy@huc-copy
-igt@gem_linear_blits@basic
-igt@gem_mmap@basic
-igt@gem_mmap_gtt@basic
-igt@gem_render_linear_blits@basic
-igt@gem_render_tiled_blits@basic
-igt@gem_ringfill@basic-all
-igt@gem_softpin@allocator-basic
-igt@gem_softpin@allocator-basic-reserve
-igt@gem_softpin@safe-alignment
-igt@gem_sync@basic-all
-igt@gem_sync@basic-each
-igt@gem_tiled_blits@basic
-igt@gem_tiled_fence_blits@basic
-igt@gem_tiled_pread_basic
-igt@gem_wait@busy@all
-igt@gem_wait@wait@all
-igt@i915_getparams_basic@basic-eu-total
-igt@i915_getparams_basic@basic-subslice-total
-igt@i915_hangman@error-state-basic
-igt@i915_pciid
-igt@kms_addfb_basic@addfb25-bad-modifier
-igt@kms_addfb_basic@addfb25-framebuffer-vs-set-tiling
-igt@kms_addfb_basic@addfb25-modifier-no-flag
-igt@kms_addfb_basic@addfb25-x-tiled-legacy
-igt@kms_addfb_basic@addfb25-x-tiled-mismatch-legacy
-igt@kms_addfb_basic@addfb25-yf-tiled-legacy
-igt@kms_addfb_basic@addfb25-y-tiled-legacy
-igt@kms_addfb_basic@addfb25-y-tiled-small-legacy
-igt@kms_addfb_basic@bad-pitch-0
-igt@kms_addfb_basic@bad-pitch-1024
-igt@kms_addfb_basic@bad-pitch-128
-igt@kms_addfb_basic@bad-pitch-256
-igt@kms_addfb_basic@bad-pitch-32
-igt@kms_addfb_basic@bad-pitch-63
-igt@kms_addfb_basic@bad-pitch-65536
-igt@kms_addfb_basic@bad-pitch-999
-igt@kms_addfb_basic@basic
-igt@kms_addfb_basic@basic-x-tiled-legacy
-igt@kms_addfb_basic@basic-y-tiled-legacy
-igt@kms_addfb_basic@bo-too-small
-igt@kms_addfb_basic@bo-too-small-due-to-tiling
-igt@kms_addfb_basic@clobberred-modifier
-igt@kms_addfb_basic@framebuffer-vs-set-tiling
-igt@kms_addfb_basic@invalid-get-prop
-igt@kms_addfb_basic@invalid-get-prop-any
-igt@kms_addfb_basic@invalid-set-prop
-igt@kms_addfb_basic@invalid-set-prop-any
-igt@kms_addfb_basic@no-handle
-igt@kms_addfb_basic@size-max
-igt@kms_addfb_basic@small-bo
-igt@kms_addfb_basic@tile-pitch-mismatch
-igt@kms_addfb_basic@too-high
-igt@kms_addfb_basic@too-wide
-igt@kms_addfb_basic@unused-handle
-igt@kms_addfb_basic@unused-modifier
-igt@kms_addfb_basic@unused-offsets
-igt@kms_addfb_basic@unused-pitches
-igt@kms_busy@basic
-igt@kms_chamelium@dp-hpd-fast
-igt@kms_chamelium@dp-edid-read
-igt@kms_chamelium@dp-crc-fast
-igt@kms_chamelium@hdmi-hpd-fast
-igt@kms_chamelium@hdmi-edid-read
-igt@kms_chamelium@hdmi-crc-fast
-igt@kms_chamelium@vga-hpd-fast
-igt@kms_chamelium@vga-edid-read
-igt@kms_prop_blob@basic
-igt@kms_cursor_legacy@basic-busy-flip-before-cursor
-igt@kms_cursor_legacy@basic-flip-after-cursor
-igt@kms_cursor_legacy@basic-flip-before-cursor
-igt@kms_flip@basic-flip-vs-dpms
-igt@kms_flip@basic-flip-vs-modeset
-igt@kms_flip@basic-flip-vs-wf_vblank
-igt@kms_flip@basic-plain-flip
-igt@kms_force_connector_basic@force-connector-state
-igt@kms_force_connector_basic@force-edid
-igt@kms_force_connector_basic@force-load-detect
-igt@kms_force_connector_basic@prune-stale-modes
-igt@kms_frontbuffer_tracking@basic
-igt@kms_pipe_crc_basic@compare-crc-sanitycheck
-igt@kms_pipe_crc_basic@hang-read-crc
-igt@kms_pipe_crc_basic@nonblocking-crc
-igt@kms_pipe_crc_basic@nonblocking-crc-frame-sequence
-igt@kms_pipe_crc_basic@read-crc
-igt@kms_pipe_crc_basic@read-crc-frame-sequence
-igt@kms_psr@primary_page_flip
-igt@kms_psr@cursor_plane_move
-igt@kms_psr@sprite_plane_onoff
-igt@kms_psr@primary_mmap_gtt
-igt@kms_setmode@basic-clone-single-crtc
-igt@i915_pm_backlight@basic-brightness
-igt@i915_pm_rpm@basic-pci-d3-state
-igt@i915_pm_rpm@basic-rte
-igt@i915_pm_rps@basic-api
-igt@prime_self_import@basic-llseek-bad
-igt@prime_self_import@basic-llseek-size
-igt@prime_self_import@basic-with_fd_dup
-igt@prime_self_import@basic-with_one_bo
-igt@prime_self_import@basic-with_one_bo_two_files
-igt@prime_self_import@basic-with_two_bos
-igt@prime_vgem@basic-fence-flip
-igt@prime_vgem@basic-fence-mmap
-igt@prime_vgem@basic-fence-read
-igt@prime_vgem@basic-gtt
-igt@prime_vgem@basic-read
-igt@prime_vgem@basic-write
-igt@prime_vgem@basic-userptr
-igt@vgem_basic@setversion
-igt@vgem_basic@create
-igt@vgem_basic@debugfs
-igt@vgem_basic@dmabuf-export
-igt@vgem_basic@dmabuf-fence
-igt@vgem_basic@dmabuf-fence-before
-igt@vgem_basic@dmabuf-mmap
-igt@vgem_basic@mmap
-igt@vgem_basic@second-client
-igt@vgem_basic@sysfs
-
-# All tests that do module unloading and reloading are executed last.
-# They will sometimes reveal issues of earlier tests leaving the
-# driver in a broken state that is not otherwise noticed in that test.
-
-igt@core_hotunplug@unbind-rebind
-igt@vgem_basic@unload
-igt@i915_module_load@reload
-igt@gem_lmem_swapping@basic
-igt@gem_lmem_swapping@parallel-random-engines
-igt@gem_lmem_swapping@random-engines
-igt@gem_lmem_swapping@verify-random
-igt@i915_pm_rpm@module-reload
-
-# Kernel selftests
-igt@i915_selftest@live
-igt@dmabuf@all
-
-# System wide suspend tests
-igt@i915_suspend@basic-s2idle-without-i915
-igt@i915_suspend@basic-s3-without-i915
-igt@gem_exec_suspend@basic-s0
-igt@gem_exec_suspend@basic-s3
-igt@kms_chamelium@common-hpd-after-suspend
-igt@kms_pipe_crc_basic@suspend-read-crc
Signature · 1 line
2.34.1
#14 lore raw

[igt-dev] ✗ Fi.CI.BAT: failure for Quick bat tests, please don't review.

In reply to Zbigniew Kempczyński
== Series Details ==

== Series Details ==

Series: Quick bat tests, please don't review.
URL : https://patchwork.freedesktop.org/series/107996/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_12058 -> IGTPW_7714
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with IGTPW_7714 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes introduced in IGTPW_7714, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/index.html

Participating hosts (37 -> 34)
------------------------------

Missing (3): fi-adl-ddr5 fi-hsw-4770 fi-bdw-samus

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in IGTPW_7714:

### IGT changes ###

#### Possible regressions ####

* {igt@gem_mmap_offset@clear@smem0} (NEW):
- fi-hsw-g3258: NOTRUN -> [FAIL][1] +2 similar issues
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-hsw-g3258/igt@gem_mmap_offset@[email protected]

* igt@gem_mmap_offset@close-race:
- fi-elk-e7500: NOTRUN -> [FAIL][2] +1 similar issue
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-elk-e7500/igt@[email protected]

* {igt@gem_mmap_offset@ptrace@lmem0-fixed} (NEW):
- {bat-dg2-11}: NOTRUN -> [FAIL][3] +1 similar issue
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/bat-dg2-11/igt@gem_mmap_offset@[email protected]
- {bat-dg2-8}: NOTRUN -> [FAIL][4] +1 similar issue
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/bat-dg2-8/igt@gem_mmap_offset@[email protected]
- {bat-dg2-9}: NOTRUN -> [FAIL][5] +1 similar issue
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/bat-dg2-9/igt@gem_mmap_offset@[email protected]

* igt@meta_test@fail-result (NEW):
- {fi-jsl-1}: NOTRUN -> [FAIL][6]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-jsl-1/igt@[email protected]
- {bat-rpls-1}: NOTRUN -> [FAIL][7]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/bat-rpls-1/igt@[email protected]
- fi-skl-6600u: NOTRUN -> [FAIL][8]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-skl-6600u/igt@[email protected]
- {fi-ehl-2}: NOTRUN -> [FAIL][9]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-ehl-2/igt@[email protected]
- bat-dg1-5: NOTRUN -> [FAIL][10] +1 similar issue
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/bat-dg1-5/igt@[email protected]
- fi-pnv-d510: NOTRUN -> [FAIL][11] +1 similar issue
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-pnv-d510/igt@[email protected]
- fi-bdw-5557u: NOTRUN -> [FAIL][12]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-bdw-5557u/igt@[email protected]
- fi-snb-2520m: NOTRUN -> [FAIL][13]
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-snb-2520m/igt@[email protected]
- fi-glk-j4005: NOTRUN -> [FAIL][14]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-glk-j4005/igt@[email protected]
- fi-rkl-guc: NOTRUN -> [FAIL][15]
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-rkl-guc/igt@[email protected]
- fi-kbl-7567u: NOTRUN -> [FAIL][16]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-kbl-7567u/igt@[email protected]
- fi-cfl-8700k: NOTRUN -> [FAIL][17]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-cfl-8700k/igt@[email protected]
- {bat-rplp-1}: NOTRUN -> [FAIL][18]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/bat-rplp-1/igt@[email protected]
- fi-rkl-11600: NOTRUN -> [FAIL][19]
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-rkl-11600/igt@[email protected]
- fi-bdw-gvtdvm: NOTRUN -> [FAIL][20]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-bdw-gvtdvm/igt@[email protected]
- fi-bsw-kefka: NOTRUN -> [FAIL][21]
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-bsw-kefka/igt@[email protected]
- fi-cfl-guc: NOTRUN -> [FAIL][22]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-cfl-guc/igt@[email protected]
- {bat-jsl-3}: NOTRUN -> [FAIL][23]
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/bat-jsl-3/igt@[email protected]
- fi-skl-6700k2: NOTRUN -> [FAIL][24]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-skl-6700k2/igt@[email protected]
- fi-cfl-8109u: NOTRUN -> [FAIL][25]
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-cfl-8109u/igt@[email protected]
- bat-adlp-4: NOTRUN -> [FAIL][26]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/bat-adlp-4/igt@[email protected]
- {bat-adln-1}: NOTRUN -> [FAIL][27]
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/bat-adln-1/igt@[email protected]
- fi-ivb-3770: NOTRUN -> [FAIL][28]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/fi-ivb-3770/igt@[email protected]

New tests
---------

New tests have been introduced between CI_DRM_12058 and IGTPW_7714:

### New IGT tests (19) ###

* igt@gem_create@busy-create@lmem0:
- Statuses : 4 pass(s)
- Exec time: [32.28, 32.36] s

* igt@gem_create@busy-create@smem0:
- Statuses : 28 pass(s)
- Exec time: [32.23, 35.96] s

* igt@gem_create@create-clear@lmem0:
- Statuses : 4 pass(s)
- Exec time: [32.86, 38.41] s

* igt@gem_create@create-clear@smem0:
- Statuses : 1 fail(s) 27 pass(s)
- Exec time: [32.34, 37.34] s

* igt@gem_create@hog-create:
- Statuses :
- Exec time: [None] s

* igt@gem_create@hog-create@lmem0:
- Statuses : 4 pass(s)
- Exec time: [32.27, 32.34] s

* igt@gem_create@hog-create@smem0:
- Statuses : 28 pass(s)
- Exec time: [32.23, 33.49] s

* igt@gem_mmap_offset@clear@lmem0:
- Statuses : 4 pass(s)
- Exec time: [21.56, 27.00] s

* igt@gem_mmap_offset@clear@smem0:
- Statuses : 1 fail(s) 27 pass(s)
- Exec time: [2.25, 27.37] s

* igt@gem_mmap_offset@perf:
- Statuses :
- Exec time: [None] s

* igt@gem_mmap_offset@perf@lmem0:
- Statuses : 4 pass(s)
- Exec time: [0.14, 0.58] s

* igt@gem_mmap_offset@perf@smem0:
- Statuses : 28 pass(s)
- Exec time: [0.00, 0.47] s

* igt@gem_mmap_offset@ptrace@lmem0-fixed:
- Statuses : 4 fail(s)
- Exec time: [0.03, 0.04] s

* igt@gem_mmap_offset@ptrace@smem0-fixed:
- Statuses : 4 pass(s)
- Exec time: [0.01, 0.03] s

* igt@gem_mmap_offset@ptrace@smem0-gtt:
- Statuses : 24 pass(s)
- Exec time: [0.02, 0.20] s

* igt@gem_mmap_offset@ptrace@smem0-uc:
- Statuses : 24 pass(s)
- Exec time: [0.01, 0.20] s

* igt@gem_mmap_offset@ptrace@smem0-wb:
- Statuses : 24 pass(s)
- Exec time: [0.01, 0.20] s

* igt@gem_mmap_offset@ptrace@smem0-wc:
- Statuses : 24 pass(s)
- Exec time: [0.01, 0.20] s

* igt@meta_test@fail-result:
- Statuses : 28 fail(s)
- Exec time: [0.00, 0.12] s

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

Build changes
-------------

* CI: CI-20190529 -> None
* IGT: IGT_6639 -> IGTPW_7714

CI-20190529: 20190529
CI_DRM_12058: 2ef8278465adc6572e0d22dffbaa332d56b4b40c @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_7714: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/index.html
IGT_6639: ba61c48dba71d5597d7297a07dc3e307665f961b @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git

Testlist changes
----------------

+igt@gem_create@hog-create
+igt@gem_mmap_offset@perf

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7714/index.html