Skip to contentSkip to conversation

tests/gem_ppgtt: Check for vm leaks with flink and ppgtt

PATCH In review Tvrtko Ursulin 4 participants 15 messages Apr 20, 2015 – Apr 23, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/gem_ppgtt: Check for vm leaks with flink and ppgtt

From: Tvrtko Ursulin <[email protected]>

Using imported objects should not leak i915 vmas (and vms).

In practice this simulates Xorg importing fbcon and leaking (or not) one vma per Xorg startup cycle.

---
 tests/gem_ppgtt.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 100 insertions(+)
tests/gem_ppgtt.c +100 -0
index 5bf773c..9b5b3ee 100644
@@ -200,6 +200,103 @@ static void surfaces_check(dri_bo **bo, int count, uint32_t expected)
 	}
 }
 
+static void flink_and_contexts(void)
+{
+	drm_intel_bufmgr *bufmgr;
+	int fd, fd2;
+	dri_bo *bo;
+	uint32_t flink_name;
+	unsigned int max_line = 0, num_lines = 0, cnt = 0;
+	int ret;
+
+	/*
+	 * Export a bo via flink and access it from a child process via a
+	 * different ppggtt context. Make sure when child exists that the vma
+	 * (and hence the vm), associated with its ppgtt context, is torn down.
+	 */
+
+	fd = drm_open_any();
+
+	bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
+	igt_assert(bufmgr);
+
+	bo = create_bo(bufmgr, 0);
+	igt_assert(bo);
+
+	ret = drm_intel_bo_flink(bo, &flink_name);
+	igt_assert(ret == 0);
+
+	igt_fork(child, 20) {
+		int devid;
+		drm_intel_bufmgr *bufmgr;
+		int fd;
+		dri_bo *bo, *import;
+		struct intel_batchbuffer *batch;
+
+		fd = drm_open_any();
+		devid = intel_get_drm_devid(fd);
+
+		bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
+		igt_assert(bufmgr);
+
+		bo = create_bo(bufmgr, 0);
+		import = drm_intel_bo_gem_create_from_name(bufmgr,
+							   "flink_and_contexts",
+							   flink_name);
+		igt_assert(bo && import);
+
+		batch = intel_batchbuffer_alloc(bufmgr, devid);
+		igt_assert(batch);
+
+		intel_copy_bo(batch, bo, import, SIZE);
+
+		intel_batchbuffer_free(batch);
+
+		dri_bo_unreference(import);
+		dri_bo_unreference(bo);
+
+		drm_intel_bufmgr_destroy(bufmgr);
+		close(fd);
+
+		exit(0);
+	}
+
+	igt_waitchildren();
+
+	/*
+	 * Count the longest line in the file which lists the vmas per object.
+	 * This might be a bit fragile so maybe there is a better way.
+	 */
+	fd2 = open("/sys/kernel/debug/dri/0/i915_gem_gtt", O_RDONLY);
+	igt_assert(fd2 >= 0);
+
+	do {
+		char ch;
+
+		ret = read(fd2, &ch, 1);
+		if (ret == 0)
+			break;
+		igt_assert(ret == 1);
+		if (ch == '\n') {
+			if (cnt > max_line)
+				max_line = cnt;
+			num_lines++;
+			cnt = 0;
+		} else {
+			cnt++;
+		}
+	} while (true);
+
+	close(fd2);
+
+	dri_bo_unreference(bo);
+	drm_intel_bufmgr_destroy(bufmgr);
+	close(fd);
+
+	igt_assert(num_lines >= 1);
+	igt_assert(max_line < 1000);
+}
+
 #define N_CHILD 8
 int main(int argc, char **argv)
 {
@@ -229,5 +326,8 @@ int main(int argc, char **argv)
 		surfaces_check(rcs, N_CHILD, 0x8000 / N_CHILD);
 	}
 
+	igt_subtest("flink-vs-ctx-vm-leak")
+		flink_and_contexts();
+
 	igt_exit();
 }
Signature · 6 lines
2.3.5

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw
Quoted 60 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Using imported objects should not leak i915 vmas (and vms).

In practice this simulates Xorg importing fbcon and leaking (or not) one vma per Xorg startup cycle.

---
 tests/gem_ppgtt.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 100 insertions(+)
tests/gem_ppgtt.c +39 -0
index 5bf773c..9b5b3ee 100644
@@ -200,6 +200,103 @@ static void surfaces_check(dri_bo **bo, int count, uint32_t expected)
 	}
 }
 
+static void flink_and_contexts(void)
+{
+	drm_intel_bufmgr *bufmgr;
+	int fd, fd2;
+	dri_bo *bo;
+	uint32_t flink_name;
+	unsigned int max_line = 0, num_lines = 0, cnt = 0;
+	int ret;
+
+	/*
+	 * Export a bo via flink and access it from a child process via a
+	 * different ppggtt context. Make sure when child exists that the vma
+	 * (and hence the vm), associated with its ppgtt context, is torn down.
+	 */
+
+	fd = drm_open_any();
+
+	bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
+	igt_assert(bufmgr);
+
+	bo = create_bo(bufmgr, 0);
+	igt_assert(bo);
+
+	ret = drm_intel_bo_flink(bo, &flink_name);
+	igt_assert(ret == 0);
+
+	igt_fork(child, 20) {
+		int devid;
+		drm_intel_bufmgr *bufmgr;
+		int fd;
+		dri_bo *bo, *import;
+		struct intel_batchbuffer *batch;
+
+		fd = drm_open_any();
+		devid = intel_get_drm_devid(fd);
+
+		bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
+		igt_assert(bufmgr);
+

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 251

Quoted 10 lines
tests/gem_ppgtt.c +10 -0
+		bo = create_bo(bufmgr, 0);
+		import = drm_intel_bo_gem_create_from_name(bufmgr,
+							   "flink_and_contexts",
+							   flink_name);
+		igt_assert(bo && import);
+
+		batch = intel_batchbuffer_alloc(bufmgr, devid);
+		igt_assert(batch);
+
+		intel_copy_bo(batch, bo, import, SIZE);

Do we care about any differentiation between the default per-file context and explicitly created contexts?

Quoted 7 lines
tests/gem_ppgtt.c +7 -0
+		intel_batchbuffer_free(batch);
+
+		dri_bo_unreference(import);
+		dri_bo_unreference(bo);
+
+		drm_intel_bufmgr_destroy(bufmgr);
+		close(fd);

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 269

Quoted 10 lines
tests/gem_ppgtt.c +10 -0
+
+		exit(0);
+	}
+
+	igt_waitchildren();
+
+	/*
+	 * Count the longest line in the file which lists the vmas per object.
+	 * This might be a bit fragile so maybe there is a better way.
+	 */

So what I was thinking was something along the lines of:

/* record the return value from exec[0].offset */
intel_copy_bo(&leaked_vma_offset);

gem_close(exec[0].handle);

/* flush execbuffer and the vma should be gone */
gem_sync();

intel_copy_bo(&new_vma_offset);
igt_assert(new_vma_offset == leaked_vma_offset);

Will take a bit of judicious planning (like doing a self-copy on the dst first to make sure it bound ahead of the leak and not reallocating the batch handle)

Or alternatively, we know the name of the flinked object, so we can do an explicit search! Ok, that seems more robust, but you do some sync point in there (either gem_sync() every child before exit or gem_quiescent_gpu()).
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw
Quoted 66 lines · Chris Wilson
Quoted 65 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Using imported objects should not leak i915 vmas (and vms).

In practice this simulates Xorg importing fbcon and leaking (or not) one vma per Xorg startup cycle.

---
  tests/gem_ppgtt.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 100 insertions(+)
tests/gem_ppgtt.c +44 -0
index 5bf773c..9b5b3ee 100644
@@ -200,6 +200,103 @@ static void surfaces_check(dri_bo **bo, int count, uint32_t expected)
  	}
  }
 
+static void flink_and_contexts(void)
+{
+	drm_intel_bufmgr *bufmgr;
+	int fd, fd2;
+	dri_bo *bo;
+	uint32_t flink_name;
+	unsigned int max_line = 0, num_lines = 0, cnt = 0;
+	int ret;
+
+	/*
+	 * Export a bo via flink and access it from a child process via a
+	 * different ppggtt context. Make sure when child exists that the vma
+	 * (and hence the vm), associated with its ppgtt context, is torn down.
+	 */
+
+	fd = drm_open_any();
+
+	bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
+	igt_assert(bufmgr);
+
+	bo = create_bo(bufmgr, 0);
+	igt_assert(bo);
+
+	ret = drm_intel_bo_flink(bo, &flink_name);
+	igt_assert(ret == 0);
+
+	igt_fork(child, 20) {
+		int devid;
+		drm_intel_bufmgr *bufmgr;
+		int fd;
+		dri_bo *bo, *import;
+		struct intel_batchbuffer *batch;
+
+		fd = drm_open_any();
+		devid = intel_get_drm_devid(fd);
+
+		bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
+		igt_assert(bufmgr);
+
+		bo = create_bo(bufmgr, 0);
+		import = drm_intel_bo_gem_create_from_name(bufmgr,
+							   "flink_and_contexts",
+							   flink_name);
+		igt_assert(bo && import);
Quoted 8 lines

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 251

Quoted 5 lines
tests/gem_ppgtt.c +5 -0
+
+		batch = intel_batchbuffer_alloc(bufmgr, devid);
+		igt_assert(batch);
+
+		intel_copy_bo(batch, bo, import, SIZE);

Do we care about any differentiation between the default per-file context and explicitly created contexts?

Don't know - would expect so - but I am new in this area.

Quoted 28 lines
Quoted 7 lines
tests/gem_ppgtt.c +7 -0
+		intel_batchbuffer_free(batch);
+
+		dri_bo_unreference(import);
+		dri_bo_unreference(bo);
+
+		drm_intel_bufmgr_destroy(bufmgr);
+		close(fd);

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 269

Quoted 10 lines
tests/gem_ppgtt.c +10 -0
+
+		exit(0);
+	}
+
+	igt_waitchildren();
+
+	/*
+	 * Count the longest line in the file which lists the vmas per object.
+	 * This might be a bit fragile so maybe there is a better way.
+	 */

So what I was thinking was something along the lines of:

/* record the return value from exec[0].offset */
intel_copy_bo(&leaked_vma_offset);

gem_close(exec[0].handle);

/* flush execbuffer and the vma should be gone */
gem_sync();

Quoted 6 lines

intel_copy_bo(&new_vma_offset);
igt_assert(new_vma_offset == leaked_vma_offset);

Will take a bit of judicious planning (like doing a self-copy on the dst first to make sure it bound ahead of the leak and not reallocating the batch handle)

Hm.. not bad!

Quoted 4 lines

Or alternatively, we know the name of the flinked object, so we can do an explicit search! Ok, that seems more robust, but you do some sync point in there (either gem_sync() every child before exit or gem_quiescent_gpu()).

Anything to avoid debugfs parsing I think. Well not anything, if exec[].offset is not retrievable from intel_batchbuffer helpers I'll reconsider it. Definitely need to at least count ppgtt sections since the IGT already failed (to fail) on one older kernel with the poor character counting approach.

Thanks for the ideas!

Regards,

Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw
Quoted 11 lines · Tvrtko Ursulin
Quoted 3 lines

Will take a bit of judicious planning (like doing a self-copy on the dst first to make sure it bound ahead of the leak and not reallocating the batch handle)

Hm.. not bad!

Quoted 4 lines

Or alternatively, we know the name of the flinked object, so we can do an explicit search! Ok, that seems more robust, but you do some sync point in there (either gem_sync() every child before exit or gem_quiescent_gpu()).

Quoted 5 lines

Anything to avoid debugfs parsing I think. Well not anything, if exec[].offset is not retrievable from intel_batchbuffer helpers I'll reconsider it. Definitely need to at least count ppgtt sections since the IGT already failed (to fail) on one older kernel with the poor character counting approach.

With the libdrm interface, drm_intel_bo->offset will be kept up to date with the post-execbuffer value. I'd suggest just using the rawer ioctl wrappers for fine control, especially when allocating objects and offsets.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw
In reply to Chris Wilson
Quoted 106 lines · Chris Wilson
Quoted 60 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Using imported objects should not leak i915 vmas (and vms).

In practice this simulates Xorg importing fbcon and leaking (or not) one vma per Xorg startup cycle.

---
 tests/gem_ppgtt.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 100 insertions(+)
tests/gem_ppgtt.c +39 -0
index 5bf773c..9b5b3ee 100644
@@ -200,6 +200,103 @@ static void surfaces_check(dri_bo **bo, int count, uint32_t expected)
 	}
 }
 
+static void flink_and_contexts(void)
+{
+	drm_intel_bufmgr *bufmgr;
+	int fd, fd2;
+	dri_bo *bo;
+	uint32_t flink_name;
+	unsigned int max_line = 0, num_lines = 0, cnt = 0;
+	int ret;
+
+	/*
+	 * Export a bo via flink and access it from a child process via a
+	 * different ppggtt context. Make sure when child exists that the vma
+	 * (and hence the vm), associated with its ppgtt context, is torn down.
+	 */
+
+	fd = drm_open_any();
+
+	bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
+	igt_assert(bufmgr);
+
+	bo = create_bo(bufmgr, 0);
+	igt_assert(bo);
+
+	ret = drm_intel_bo_flink(bo, &flink_name);
+	igt_assert(ret == 0);
+
+	igt_fork(child, 20) {
+		int devid;
+		drm_intel_bufmgr *bufmgr;
+		int fd;
+		dri_bo *bo, *import;
+		struct intel_batchbuffer *batch;
+
+		fd = drm_open_any();
+		devid = intel_get_drm_devid(fd);
+
+		bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
+		igt_assert(bufmgr);
+

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 251

Quoted 10 lines
tests/gem_ppgtt.c +10 -0
+		bo = create_bo(bufmgr, 0);
+		import = drm_intel_bo_gem_create_from_name(bufmgr,
+							   "flink_and_contexts",
+							   flink_name);
+		igt_assert(bo && import);
+
+		batch = intel_batchbuffer_alloc(bufmgr, devid);
+		igt_assert(batch);
+
+		intel_copy_bo(batch, bo, import, SIZE);

Do we care about any differentiation between the default per-file context and explicitly created contexts?

Quoted 7 lines
tests/gem_ppgtt.c +7 -0
+		intel_batchbuffer_free(batch);
+
+		dri_bo_unreference(import);
+		dri_bo_unreference(bo);
+
+		drm_intel_bufmgr_destroy(bufmgr);
+		close(fd);

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 269

Quoted 10 lines
tests/gem_ppgtt.c +10 -0
+
+		exit(0);
+	}
+
+	igt_waitchildren();
+
+	/*
+	 * Count the longest line in the file which lists the vmas per object.
+	 * This might be a bit fragile so maybe there is a better way.
+	 */

So what I was thinking was something along the lines of:

/* record the return value from exec[0].offset */
intel_copy_bo(&leaked_vma_offset);

gem_close(exec[0].handle);

/* flush execbuffer and the vma should be gone */
gem_sync();

intel_copy_bo(&new_vma_offset);
igt_assert(new_vma_offset == leaked_vma_offset);

Quoted 8 lines

Will take a bit of judicious planning (like doing a self-copy on the dst first to make sure it bound ahead of the leak and not reallocating the batch handle)

Or alternatively, we know the name of the flinked object, so we can do an explicit search! Ok, that seems more robust, but you do some sync point in there (either gem_sync() every child before exit or gem_quiescent_gpu()).

Another option for making the leak check more robust is to allocate a few test objects and double-check that the count we deduce incremented/decremented by the correct amount. But checking the offsets the kernel hands out from execbuf should work well too, we have a few other tests relying upon that.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw

PATCH v2 1/1 tests/gem_ppgtt: Check for vm leaks with flink and ppgtt

In reply to Tvrtko Ursulin

From: Daniele Ceraolo Spurio <[email protected]>

From: Tvrtko Ursulin <[email protected]>

Using imported objects should not leak i915 vmas (and vms).

In practice this simulates Xorg importing fbcon and leaking (or not) one vma per Xorg startup cycle.

v2: use low-level ioctl wrappers and bo offset to check the leak (Chris)

---
 tests/gem_ppgtt.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 99 insertions(+)
tests/gem_ppgtt.c +99 -0
index 5bf773c..b865af3 100644
@@ -48,6 +48,22 @@
 #define HEIGHT 512
 #define SIZE (HEIGHT*STRIDE)
 
+static bool uses_full_ppgtt(int fd)
+{
+	struct drm_i915_getparam gp;
+	int val = 0;
+
+	memset(&gp, 0, sizeof(gp));
+	gp.param = 18; /* HAS_ALIASING_PPGTT */
+	gp.value = &val;
+
+	if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp))
+		return 0;
+
+	errno = 0;
+	return val > 1;
+}
+
 static drm_intel_bo *create_bo(drm_intel_bufmgr *bufmgr,
 			       uint32_t pixel)
 {
@@ -200,6 +216,86 @@ static void surfaces_check(dri_bo **bo, int count, uint32_t expected)
 	}
 }
 
+
+static uint64_t exec_and_get_offset(int fd, uint32_t batch, uint32_t bo)
+{
+	struct drm_i915_gem_execbuffer2 execbuf;
+	struct drm_i915_gem_exec_object2 exec[2];
+	struct drm_i915_gem_relocation_entry reloc[1];
+	uint32_t buf[6], i = 0;
+
+	/* use a simple MI_STORE_DWORD_IMM to write something on the bo.
+	 * We just want to get a VMA
+	 */
+	buf[i++] = MI_STORE_DWORD_IMM | 2;
+	buf[i++] = 0;
+	buf[i++] = 0;
+	buf[i++] = 0xdeadbeef;
+
+	reloc->offset = 1 * sizeof(uint32_t);
+	reloc->delta = 0;
+	reloc->target_handle = bo;
+	reloc->read_domains = I915_GEM_DOMAIN_INSTRUCTION;
+	reloc->write_domain = I915_GEM_DOMAIN_INSTRUCTION;
+	reloc->presumed_offset = 0;
+
+	buf[i++] = 0;
+	buf[i++] = MI_BATCH_BUFFER_END;
+
+	gem_write(fd, batch, 0, buf, i * sizeof(uint32_t));
+
+	memset(exec, 0, sizeof(exec));
+	exec[0].handle = bo;
+	exec[1].handle = batch;
+	exec[1].relocation_count = 1;
+	exec[1].relocs_ptr = (uintptr_t)reloc;
+
+	memset(&execbuf, 0, sizeof(execbuf));
+	execbuf.buffers_ptr = (uintptr_t)exec;
+	execbuf.buffer_count = 2;
+	execbuf.batch_len = i * sizeof(uint32_t);
+	execbuf.flags = 0;
+
+	gem_execbuf(fd, &execbuf);
+
+	return exec[0].offset;
+}
+
+static void flink_and_close(void)
+{
+	uint32_t fd, fd2;
+	uint32_t batch, bo, flinked_bo, new_bo, name;
+	uint64_t offset, offset_new;
+
+	fd = drm_open_any();
+	igt_require(uses_full_ppgtt(fd));
+
+	bo = gem_create(fd, 4096);
+	name = gem_flink(fd, bo);
+
+	fd2 = drm_open_any();
+	batch = gem_create(fd2, 4096);
+
+	flinked_bo = gem_open(fd2, name);
+	offset = exec_and_get_offset(fd2, batch, flinked_bo);
+	gem_close(fd2, flinked_bo);
+	gem_sync(fd2, batch);
+
+	/* the flinked bo VMA should have been cleared now, so a new bo of the
+	 * same size should get the same offset
+	 */
+	new_bo = gem_create(fd2, 4096);
+	offset_new = exec_and_get_offset(fd2, batch, new_bo);
+	gem_close(fd2, new_bo);
+
+	igt_assert(offset == offset_new);
+
+	gem_close(fd2, batch);
+	gem_close(fd, bo);
+	close(fd);
+	close(fd2);
+}
+
 #define N_CHILD 8
 int main(int argc, char **argv)
 {
@@ -229,5 +325,8 @@ int main(int argc, char **argv)
 		surfaces_check(rcs, N_CHILD, 0x8000 / N_CHILD);
 	}
 
+	igt_subtest("flink-and-close-vma-leak")
+		flink_and_close();
+
 	igt_exit();
 }
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#6 lore raw
Quoted 62 lines · On Thu, Apr 23, 2015 at 10:30:01AM +0100, [email protected] wrote:

From: Daniele Ceraolo Spurio <[email protected]>

From: Tvrtko Ursulin <[email protected]>

Using imported objects should not leak i915 vmas (and vms).

In practice this simulates Xorg importing fbcon and leaking (or not) one vma per Xorg startup cycle.

v2: use low-level ioctl wrappers and bo offset to check the leak (Chris)

---
 tests/gem_ppgtt.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 99 insertions(+)
tests/gem_ppgtt.c +28 -0
index 5bf773c..b865af3 100644
@@ -48,6 +48,22 @@
 #define HEIGHT 512
 #define SIZE (HEIGHT*STRIDE)
 
+static bool uses_full_ppgtt(int fd)
+{
+	struct drm_i915_getparam gp;
+	int val = 0;
+
+	memset(&gp, 0, sizeof(gp));
+	gp.param = 18; /* HAS_ALIASING_PPGTT */
+	gp.value = &val;
+
+	if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp))
+		return 0;
+
+	errno = 0;
+	return val > 1;
+}
+
 static drm_intel_bo *create_bo(drm_intel_bufmgr *bufmgr,
 			       uint32_t pixel)
 {
@@ -200,6 +216,86 @@ static void surfaces_check(dri_bo **bo, int count, uint32_t expected)
 	}
 }
 
+
+static uint64_t exec_and_get_offset(int fd, uint32_t batch, uint32_t bo)
+{
+	struct drm_i915_gem_execbuffer2 execbuf;
+	struct drm_i915_gem_exec_object2 exec[2];
+	struct drm_i915_gem_relocation_entry reloc[1];
+	uint32_t buf[6], i = 0;
+
+	/* use a simple MI_STORE_DWORD_IMM to write something on the bo.
+	 * We just want to get a VMA
+	 */
+	buf[i++] = MI_STORE_DWORD_IMM | 2;

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 240

Quoted 10 lines
tests/gem_ppgtt.c +10 -0
+	buf[i++] = 0;
+	buf[i++] = 0;
+	buf[i++] = 0xdeadbeef;
+
+	reloc->offset = 1 * sizeof(uint32_t);
+	reloc->delta = 0;
+	reloc->target_handle = bo;
+	reloc->read_domains = I915_GEM_DOMAIN_INSTRUCTION;
+	reloc->write_domain = I915_GEM_DOMAIN_INSTRUCTION;
+	reloc->presumed_offset = 0;

A relocation (and the STORE) is not required. The kernel will do all reservations (of exec_object[]) before doing relocations. Not relocating makes life more predictable (fewer error conditions may strike).

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 271

Quoted 8 lines
tests/gem_ppgtt.c +8 -0
+static void flink_and_close(void)
+{
+	uint32_t fd, fd2;
+	uint32_t batch, bo, flinked_bo, new_bo, name;
+	uint64_t offset, offset_new;
+
+	fd = drm_open_any();
+	igt_require(uses_full_ppgtt(fd));

The test equally applies to !full-ppgtt. The bug we saw isn't possible, but the interface expectations are the same.

Quoted 9 lines
tests/gem_ppgtt.c +9 -0
+	bo = gem_create(fd, 4096);
+	name = gem_flink(fd, bo);
+
+	fd2 = drm_open_any();
+	batch = gem_create(fd2, 4096);
+
+	flinked_bo = gem_open(fd2, name);
+	offset = exec_and_get_offset(fd2, batch, flinked_bo);
+	gem_close(fd2, flinked_bo);

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 291

Quoted 10 lines
tests/gem_ppgtt.c +10 -0
+	gem_sync(fd2, batch);
+
+	/* the flinked bo VMA should have been cleared now, so a new bo of the
+	 * same size should get the same offset
+	 */
+	new_bo = gem_create(fd2, 4096);
+	offset_new = exec_and_get_offset(fd2, batch, new_bo);
+	gem_close(fd2, new_bo);
+
+	igt_assert(offset == offset_new);

igt_assert_eq

Nice test.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw
Quoted 78 lines · Chris Wilson
Quoted 62 lines · On Thu, Apr 23, 2015 at 10:30:01AM +0100, [email protected] wrote:

From: Daniele Ceraolo Spurio <[email protected]>

From: Tvrtko Ursulin <[email protected]>

Using imported objects should not leak i915 vmas (and vms).

In practice this simulates Xorg importing fbcon and leaking (or not) one vma per Xorg startup cycle.

v2: use low-level ioctl wrappers and bo offset to check the leak (Chris)

---
  tests/gem_ppgtt.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 99 insertions(+)
tests/gem_ppgtt.c +28 -0
index 5bf773c..b865af3 100644
@@ -48,6 +48,22 @@
  #define HEIGHT 512
  #define SIZE (HEIGHT*STRIDE)
 
+static bool uses_full_ppgtt(int fd)
+{
+	struct drm_i915_getparam gp;
+	int val = 0;
+
+	memset(&gp, 0, sizeof(gp));
+	gp.param = 18; /* HAS_ALIASING_PPGTT */
+	gp.value = &val;
+
+	if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp))
+		return 0;
+
+	errno = 0;
+	return val > 1;
+}
+
  static drm_intel_bo *create_bo(drm_intel_bufmgr *bufmgr,
  			       uint32_t pixel)
  {
@@ -200,6 +216,86 @@ static void surfaces_check(dri_bo **bo, int count, uint32_t expected)
  	}
  }
 
+
+static uint64_t exec_and_get_offset(int fd, uint32_t batch, uint32_t bo)
+{
+	struct drm_i915_gem_execbuffer2 execbuf;
+	struct drm_i915_gem_exec_object2 exec[2];
+	struct drm_i915_gem_relocation_entry reloc[1];
+	uint32_t buf[6], i = 0;
+
+	/* use a simple MI_STORE_DWORD_IMM to write something on the bo.
+	 * We just want to get a VMA
+	 */
+	buf[i++] = MI_STORE_DWORD_IMM | 2;

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 240

Quoted 10 lines
tests/gem_ppgtt.c +10 -0
+	buf[i++] = 0;
+	buf[i++] = 0;
+	buf[i++] = 0xdeadbeef;
+
+	reloc->offset = 1 * sizeof(uint32_t);
+	reloc->delta = 0;
+	reloc->target_handle = bo;
+	reloc->read_domains = I915_GEM_DOMAIN_INSTRUCTION;
+	reloc->write_domain = I915_GEM_DOMAIN_INSTRUCTION;
+	reloc->presumed_offset = 0;

A relocation (and the STORE) is not required. The kernel will do all reservations (of exec_object[]) before doing relocations. Not relocating makes life more predictable (fewer error conditions may strike).

Quoted 11 lines

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 271

Quoted 8 lines
tests/gem_ppgtt.c +8 -0
+static void flink_and_close(void)
+{
+	uint32_t fd, fd2;
+	uint32_t batch, bo, flinked_bo, new_bo, name;
+	uint64_t offset, offset_new;
+
+	fd = drm_open_any();
+	igt_require(uses_full_ppgtt(fd));

The test equally applies to !full-ppgtt. The bug we saw isn't possible, but the interface expectations are the same.

I've tried the test with aliasing ppgtt, but the flinked buffer gets the same offset as the original one, so the new_bo will get a different offset indipendently from the vma leak and the assert will always fail. Are there any other ways to check the vma leak in !full-ppgtt mode?

Thanks,
Daniele

Quoted 23 lines
Quoted 10 lines
tests/gem_ppgtt.c +9 -0
+	bo = gem_create(fd, 4096);
+	name = gem_flink(fd, bo);
+
+	fd2 = drm_open_any();
+	batch = gem_create(fd2, 4096);
+
+	flinked_bo = gem_open(fd2, name);
+	offset = exec_and_get_offset(fd2, batch, flinked_bo);
+	gem_close(fd2, flinked_bo);

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 291

Quoted 10 lines
tests/gem_ppgtt.c +10 -0
+	gem_sync(fd2, batch);
+
+	/* the flinked bo VMA should have been cleared now, so a new bo of the
+	 * same size should get the same offset
+	 */
+	new_bo = gem_create(fd2, 4096);
+	offset_new = exec_and_get_offset(fd2, batch, new_bo);
+	gem_close(fd2, new_bo);
+
+	igt_assert(offset == offset_new);

igt_assert_eq

Quoted 3 lines

Nice test.
-Chris

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#8 lore raw
Quoted 70 lines · Daniele
Quoted 69 lines · Chris Wilson
Quoted 68 lines · On Thu, Apr 23, 2015 at 10:30:01AM +0100, [email protected] wrote:

From: Daniele Ceraolo Spurio <[email protected]>

From: Tvrtko Ursulin <[email protected]>

Using imported objects should not leak i915 vmas (and vms).

In practice this simulates Xorg importing fbcon and leaking (or not) one vma per Xorg startup cycle.

v2: use low-level ioctl wrappers and bo offset to check the leak (Chris)

---
 tests/gem_ppgtt.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 99 insertions(+)
tests/gem_ppgtt.c +34 -0
index 5bf773c..b865af3 100644
@@ -48,6 +48,22 @@
 #define HEIGHT 512
 #define SIZE (HEIGHT*STRIDE)
 
+static bool uses_full_ppgtt(int fd)
+{
+	struct drm_i915_getparam gp;
+	int val = 0;
+
+	memset(&gp, 0, sizeof(gp));
+	gp.param = 18; /* HAS_ALIASING_PPGTT */
+	gp.value = &val;
+
+	if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp))
+		return 0;
+
+	errno = 0;
+	return val > 1;
+}
+
 static drm_intel_bo *create_bo(drm_intel_bufmgr *bufmgr,
 			       uint32_t pixel)
 {
@@ -200,6 +216,86 @@ static void surfaces_check(dri_bo **bo, int count, uint32_t expected)
 	}
 }
 
+
+static uint64_t exec_and_get_offset(int fd, uint32_t batch, uint32_t bo)
+{
+	struct drm_i915_gem_execbuffer2 execbuf;
+	struct drm_i915_gem_exec_object2 exec[2];
+	struct drm_i915_gem_relocation_entry reloc[1];
+	uint32_t buf[6], i = 0;
+
+	/* use a simple MI_STORE_DWORD_IMM to write something on the bo.
+	 * We just want to get a VMA
+	 */
+	buf[i++] = MI_STORE_DWORD_IMM | 2;
+	buf[i++] = 0;
+	buf[i++] = 0;
+	buf[i++] = 0xdeadbeef;
+
+	reloc->offset = 1 * sizeof(uint32_t);
+	reloc->delta = 0;
Quoted 8 lines
Quoted 8 lines

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 240

Quoted 4 lines
tests/gem_ppgtt.c +4 -0
+	reloc->target_handle = bo;
+	reloc->read_domains = I915_GEM_DOMAIN_INSTRUCTION;
+	reloc->write_domain = I915_GEM_DOMAIN_INSTRUCTION;
+	reloc->presumed_offset = 0;

A relocation (and the STORE) is not required. The kernel will do all reservations (of exec_object[]) before doing relocations. Not relocating makes life more predictable (fewer error conditions may strike).

Actually thought of another potential issue. The kernel will reserve space in the GTT for an execbuffer in an arbitrary order. So kill the separate batch entirely, and just use flinked objects (as the batch buffer).

Quoted 12 lines
Quoted 11 lines

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 271

Quoted 8 lines
tests/gem_ppgtt.c +8 -0
+static void flink_and_close(void)
+{
+	uint32_t fd, fd2;
+	uint32_t batch, bo, flinked_bo, new_bo, name;
+	uint64_t offset, offset_new;
+
+	fd = drm_open_any();
+	igt_require(uses_full_ppgtt(fd));

The test equally applies to !full-ppgtt. The bug we saw isn't possible, but the interface expectations are the same.

Quoted 5 lines

I've tried the test with aliasing ppgtt, but the flinked buffer gets the same offset as the original one, so the new_bo will get a different offset indipendently from the vma leak and the assert will always fail.
Are there any other ways to check the vma leak in !full-ppgtt mode?

Oh right. Because we lazy-unbind and the object still exists within the aliasing vm so the eviction is not forced.

I give in, I can't think of a way to test this on !full-ppgtt without explicitly unbinding the vma, thereby breaking the neat test. -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#9 lore raw

PATCH v3 1/1 tests/gem_ppgtt: Check for vm leaks with flink and ppgtt

In reply to [email protected]

From: Tvrtko Ursulin <[email protected]>

Using imported objects should not leak i915 vmas (and vms).

In practice this simulates Xorg importing fbcon and leaking (or not) one vma per Xorg startup cycle.

v2: use low-level ioctl wrappers and bo offset to check the leak (Chris)
v3: use the flinked bo as batch (Chris)

---
 tests/gem_ppgtt.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)
tests/gem_ppgtt.c +76 -0
index 5bf773c..882a884 100644
@@ -48,6 +48,22 @@
 #define HEIGHT 512
 #define SIZE (HEIGHT*STRIDE)
 
+static bool uses_full_ppgtt(int fd)
+{
+	struct drm_i915_getparam gp;
+	int val = 0;
+
+	memset(&gp, 0, sizeof(gp));
+	gp.param = 18; /* HAS_ALIASING_PPGTT */
+	gp.value = &val;
+
+	if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp))
+		return 0;
+
+	errno = 0;
+	return val > 1;
+}
+
 static drm_intel_bo *create_bo(drm_intel_bufmgr *bufmgr,
 			       uint32_t pixel)
 {
@@ -200,6 +216,63 @@ static void surfaces_check(dri_bo **bo, int count, uint32_t expected)
 	}
 }
 
+static uint64_t exec_and_get_offset(int fd, uint32_t batch)
+{
+	struct drm_i915_gem_execbuffer2 execbuf;
+	struct drm_i915_gem_exec_object2 exec[1];
+	uint32_t batch_data[2] = { MI_NOOP, MI_BATCH_BUFFER_END };
+
+	gem_write(fd, batch, 0, batch_data, sizeof(batch_data));
+
+	memset(exec, 0, sizeof(exec));
+	exec[0].handle = batch;
+	exec[0].relocation_count = 0;
+	exec[0].relocs_ptr = 0;
+
+	memset(&execbuf, 0, sizeof(execbuf));
+	execbuf.buffers_ptr = (uintptr_t)exec;
+	execbuf.buffer_count = 1;
+	execbuf.batch_len = sizeof(batch_data);
+	execbuf.flags = 0;
+
+	gem_execbuf(fd, &execbuf);
+
+	return exec[0].offset;
+}
+
+static void flink_and_close(void)
+{
+	uint32_t fd, fd2;
+	uint32_t bo, flinked_bo, new_bo, name;
+	uint64_t offset, offset_new;
+
+	fd = drm_open_any();
+	igt_require(uses_full_ppgtt(fd));
+
+	bo = gem_create(fd, 4096);
+	name = gem_flink(fd, bo);
+
+	fd2 = drm_open_any();
+
+	flinked_bo = gem_open(fd2, name);
+	offset = exec_and_get_offset(fd2, flinked_bo);
+	gem_sync(fd2, flinked_bo);
+	gem_close(fd2, flinked_bo);
+
+	/* the flinked bo VMA should have been cleared now, so a new bo of the
+	 * same size should get the same offset
+	 */
+	new_bo = gem_create(fd2, 4096);
+	offset_new = exec_and_get_offset(fd2, new_bo);
+	gem_close(fd2, new_bo);
+
+	igt_assert_eq(offset, offset_new);
+
+	gem_close(fd, bo);
+	close(fd);
+	close(fd2);
+}
+
 #define N_CHILD 8
 int main(int argc, char **argv)
 {
@@ -229,5 +302,8 @@ int main(int argc, char **argv)
 		surfaces_check(rcs, N_CHILD, 0x8000 / N_CHILD);
 	}
 
+	igt_subtest("flink-and-close-vma-leak")
+		flink_and_close();
+
 	igt_exit();
 }
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v3 1/1
#10 lore raw
Quoted 7 lines · On Thu, Apr 23, 2015 at 12:23:17PM +0100, [email protected] wrote:

From: Tvrtko Ursulin <[email protected]>

Using imported objects should not leak i915 vmas (and vms).

In practice this simulates Xorg importing fbcon and leaking (or not) one vma per Xorg startup cycle.

Quoted 7 lines

v2: use low-level ioctl wrappers and bo offset to check the leak (Chris)
v3: use the flinked bo as batch (Chris)

Bikeshedding for fun aside,

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 223

Quoted 5 lines
tests/gem_ppgtt.c +5 -0
+static uint64_t exec_and_get_offset(int fd, uint32_t batch)
+{
+	struct drm_i915_gem_execbuffer2 execbuf;
+	struct drm_i915_gem_exec_object2 exec[1];
+	uint32_t batch_data[2] = { MI_NOOP, MI_BATCH_BUFFER_END };

uint32_t buf[2] = { MI_BATCH_BUFFER_END };

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 230

Quoted 7 lines
tests/gem_ppgtt.c +7 -0
+
+	gem_write(fd, batch, 0, batch_data, sizeof(batch_data));
+
+	memset(exec, 0, sizeof(exec));
+	exec[0].handle = batch;
+	exec[0].relocation_count = 0;
+	exec[0].relocs_ptr = 0;

We just memset(0) these two, so we don't need to clear them again.

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 236

Quoted 5 lines
tests/gem_ppgtt.c +5 -0
+	memset(&execbuf, 0, sizeof(execbuf));
+	execbuf.buffers_ptr = (uintptr_t)exec;
+	execbuf.buffer_count = 1;
+	execbuf.batch_len = sizeof(batch_data);
+	execbuf.flags = 0;

These two can also happily disappear.

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 238

Quoted 1 line
tests/gem_ppgtt.c +1 -0
+	gem_execbuf(fd, &execbuf);

igt_assert_neq(exec[0].offset, -1)
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#11 lore raw
Quoted 37 lines · Chris Wilson
Quoted 7 lines · On Thu, Apr 23, 2015 at 12:23:17PM +0100, [email protected] wrote:

From: Tvrtko Ursulin <[email protected]>

Using imported objects should not leak i915 vmas (and vms).

In practice this simulates Xorg importing fbcon and leaking (or not) one vma per Xorg startup cycle.

Quoted 7 lines

v2: use low-level ioctl wrappers and bo offset to check the leak (Chris)
v3: use the flinked bo as batch (Chris)

Bikeshedding for fun aside,

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 223

Quoted 5 lines
tests/gem_ppgtt.c +5 -0
+static uint64_t exec_and_get_offset(int fd, uint32_t batch)
+{
+	struct drm_i915_gem_execbuffer2 execbuf;
+	struct drm_i915_gem_exec_object2 exec[1];
+	uint32_t batch_data[2] = { MI_NOOP, MI_BATCH_BUFFER_END };

uint32_t buf[2] = { MI_BATCH_BUFFER_END };

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 230

Quoted 7 lines
tests/gem_ppgtt.c +7 -0
+
+	gem_write(fd, batch, 0, batch_data, sizeof(batch_data));
+
+	memset(exec, 0, sizeof(exec));
+	exec[0].handle = batch;
+	exec[0].relocation_count = 0;
+	exec[0].relocs_ptr = 0;

We just memset(0) these two, so we don't need to clear them again.

Quoted 6 lines

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 236

Quoted 5 lines
tests/gem_ppgtt.c +5 -0
+	memset(&execbuf, 0, sizeof(execbuf));
+	execbuf.buffers_ptr = (uintptr_t)exec;
+	execbuf.buffer_count = 1;
+	execbuf.batch_len = sizeof(batch_data);
+	execbuf.flags = 0;

These two can also happily disappear.

Ok for the execbuf.flags and for the other fixes, but why remove also execbuf.batch_len?

Thanks,
Daniele

Quoted 6 lines

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 238

Quoted 2 lines
tests/gem_ppgtt.c +1 -0
+	gem_execbuf(fd, &execbuf);

igt_assert_neq(exec[0].offset, -1)
-Chris

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#12 lore raw
Quoted 10 lines · Daniele
Quoted 6 lines · Chris Wilson

tests/gem_ppgtt.c static void surfaces_check(dri_bo **bo, int count, uint32_t expected) · line 236

Quoted 5 lines
tests/gem_ppgtt.c +5 -0
+	memset(&execbuf, 0, sizeof(execbuf));
+	execbuf.buffers_ptr = (uintptr_t)exec;
+	execbuf.buffer_count = 1;
+	execbuf.batch_len = sizeof(batch_data);
+	execbuf.flags = 0;

These two can also happily disappear.

Ok for the execbuf.flags and for the other fixes, but why remove also execbuf.batch_len?

Then we get flagged as a no-op batch. It's just a piece of sleight-of-hand.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#14 lore raw

PATCH v4 1/1 tests/gem_ppgtt: Check for vm leaks with flink and ppgtt

In reply to [email protected]

From: Daniele Ceraolo Spurio <[email protected]>

Using imported objects should not leak i915 vmas (and vms).

In practice this simulates Xorg importing fbcon and leaking (or not) one vma per Xorg startup cycle.

v2: use low-level ioctl wrappers and bo offset to check the leak (Chris)
v3: use the flinked bo as batch (Chris)
v4: add check on offset, remove unneeded assignments (Chris)

---
 tests/gem_ppgtt.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
tests/gem_ppgtt.c +73 -0
index 5bf773c..d1e484a 100644
@@ -48,6 +48,22 @@
 #define HEIGHT 512
 #define SIZE (HEIGHT*STRIDE)
 
+static bool uses_full_ppgtt(int fd)
+{
+	struct drm_i915_getparam gp;
+	int val = 0;
+
+	memset(&gp, 0, sizeof(gp));
+	gp.param = 18; /* HAS_ALIASING_PPGTT */
+	gp.value = &val;
+
+	if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp))
+		return 0;
+
+	errno = 0;
+	return val > 1;
+}
+
 static drm_intel_bo *create_bo(drm_intel_bufmgr *bufmgr,
 			       uint32_t pixel)
 {
@@ -200,6 +216,60 @@ static void surfaces_check(dri_bo **bo, int count, uint32_t expected)
 	}
 }
 
+static uint64_t exec_and_get_offset(int fd, uint32_t batch)
+{
+	struct drm_i915_gem_execbuffer2 execbuf;
+	struct drm_i915_gem_exec_object2 exec[1];
+	uint32_t batch_data[2] = { MI_BATCH_BUFFER_END };
+
+	gem_write(fd, batch, 0, batch_data, sizeof(batch_data));
+
+	memset(exec, 0, sizeof(exec));
+	exec[0].handle = batch;
+
+	memset(&execbuf, 0, sizeof(execbuf));
+	execbuf.buffers_ptr = (uintptr_t)exec;
+	execbuf.buffer_count = 1;
+
+	gem_execbuf(fd, &execbuf);
+	igt_assert_neq(exec[0].offset, -1);
+
+	return exec[0].offset;
+}
+
+static void flink_and_close(void)
+{
+	uint32_t fd, fd2;
+	uint32_t bo, flinked_bo, new_bo, name;
+	uint64_t offset, offset_new;
+
+	fd = drm_open_any();
+	igt_require(uses_full_ppgtt(fd));
+
+	bo = gem_create(fd, 4096);
+	name = gem_flink(fd, bo);
+
+	fd2 = drm_open_any();
+
+	flinked_bo = gem_open(fd2, name);
+	offset = exec_and_get_offset(fd2, flinked_bo);
+	gem_sync(fd2, flinked_bo);
+	gem_close(fd2, flinked_bo);
+
+	/* the flinked bo VMA should have been cleared now, so a new bo of the
+	 * same size should get the same offset
+	 */
+	new_bo = gem_create(fd2, 4096);
+	offset_new = exec_and_get_offset(fd2, new_bo);
+	gem_close(fd2, new_bo);
+
+	igt_assert_eq(offset, offset_new);
+
+	gem_close(fd, bo);
+	close(fd);
+	close(fd2);
+}
+
 #define N_CHILD 8
 int main(int argc, char **argv)
 {
@@ -229,5 +299,8 @@ int main(int argc, char **argv)
 		surfaces_check(rcs, N_CHILD, 0x8000 / N_CHILD);
 	}
 
+	igt_subtest("flink-and-close-vma-leak")
+		flink_and_close();
+
 	igt_exit();
 }
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx