Skip to contentSkip to conversation

gem_ppgtt: Test VMA leak on context destruction

PATCH Superseded Tvrtko Ursulin 2 participants 4 messages Sep 11, 2015 – Sep 23, 2015

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gem_ppgtt: Test VMA leak on context destruction

From: Tvrtko Ursulin <[email protected]>

Test that VMAs associated with a context are cleaned up when contexts are destroyed.

In practice this emulates the leak seen between fbcon and X server. Every time the X server exits we gain one VMA on the fbcon frame buffer object as externally visible via for example /sys/kernel/debug/dri/0/i915_gem_gtt.

---
 tests/gem_ppgtt.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)
tests/gem_ppgtt.c +80 -0
index 4f6df063214a..363f9d701585 100644
@@ -265,6 +265,83 @@ static void flink_and_close(void)
 	close(fd2);
 }
 
+static int grep_name(char *match, int to_match)
+{
+	int fdd, ret, matched;
+
+	fdd = open("/sys/kernel/debug/dri/0/i915_gem_gtt", O_RDONLY);
+	igt_assert(fdd >= 0);
+
+	matched = 0;
+	do {
+		char ch;
+
+		ret = read(fdd, &ch, 1);
+		if (ret == 0)
+			break;
+		igt_assert(ret == 1);
+
+		if (ch == match[matched])
+			matched++;
+		else
+			matched = 0;
+	} while (matched < to_match);
+
+	close(fdd);
+
+	return matched;
+}
+
+static void flink_and_exit(void)
+{
+	uint32_t fd, fd2;
+	uint32_t bo, flinked_bo, name;
+	char match[100];
+	int matched, to_match;
+	int retry = 0;
+	const int retries = 50;
+
+	fd = drm_open_any();
+	igt_require(uses_full_ppgtt(fd));
+
+	bo = gem_create(fd, 4096);
+	name = gem_flink(fd, bo);
+
+	to_match  = snprintf(match, sizeof(match), "(name: %u)", name);
+	igt_assert(to_match < sizeof(match));
+
+	fd2 = drm_open_any();
+
+	flinked_bo = gem_open(fd2, name);
+	exec_and_get_offset(fd2, flinked_bo);
+	gem_sync(fd2, flinked_bo);
+
+	/* Verify looking for string works OK. */
+	matched = grep_name(match, to_match);
+	igt_assert_eq(matched, to_match);
+
+	gem_close(fd2, flinked_bo);
+
+	/* Close the context. */
+	close(fd2);
+
+retry:
+	/* Give cleanup some time to run. */
+	usleep(100000);
+
+	/* The flinked bo VMA should have been cleared now, so list of VMAs
+	 * in debugfs should not contain the one for the imported object.
+	 */
+	matched = grep_name(match, to_match);
+	if (matched >= to_match && retry++ < retries)
+		goto retry;
+
+	igt_assert_lt(matched, to_match);
+
+	gem_close(fd, bo);
+	close(fd);
+}
+
 #define N_CHILD 8
 int main(int argc, char **argv)
 {
@@ -297,5 +374,8 @@ int main(int argc, char **argv)
 	igt_subtest("flink-and-close-vma-leak")
 		flink_and_close();
 
+	igt_subtest("flink-and-exit-vma-leak")
+		flink_and_exit();
+
 	igt_exit();
 }
Signature · 6 lines
2.5.1

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

From: Tvrtko Ursulin <[email protected]>

Test that VMAs associated with a context are cleaned up when contexts are destroyed.

In practice this emulates the leak seen between fbcon and X server. Every time the X server exits we gain one VMA on the fbcon frame buffer object as externally visible via for example /sys/kernel/debug/dri/0/i915_gem_gtt.

---
 tests/gem_ppgtt.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)
tests/gem_ppgtt.c +0 -0
index 4f6df063214a..363f9d701585 100644

tests/gem_ppgtt.c static void flink_and_close(void) · line 268

Quoted 4 lines
tests/gem_ppgtt.c +1 -0
@@ -265,6 +265,83 @@ static void flink_and_close(void)
        close(fd2);
 }
 
+static int grep_name(char *match, int to_match)

This could be added to igt_debugfs.c, as it might be useful for other tests.

tests/gem_ppgtt.c static void flink_and_close(void) · line 272

Quoted 4 lines
tests/gem_ppgtt.c +4 -0
+{
+       int fdd, ret, matched;
+
+       fdd = open("/sys/kernel/debug/dri/0/i915_gem_gtt", O_RDONLY);

igt_debugfs_open would be more robust here, as it checks various locations for the debugfs and also attempts to mount it if it can't be found.

Quoted 6 lines
tests/gem_ppgtt.c +6 -0
+       igt_assert(fdd >= 0);
+
+       matched = 0;
+       do {
+               char ch;
+

tests/gem_ppgtt.c static void flink_and_close(void) · line 288

Quoted 10 lines
tests/gem_ppgtt.c +10 -0
+               ret = read(fdd, &ch, 1);
+               if (ret == 0)
+                       break;
+               igt_assert(ret == 1);
+
+               if (ch == match[matched])
+                       matched++;
+               else
+                       matched = 0;
+       } while (matched < to_match);

igt_debugfs_fopen is also available, which would allow the use of getline and strstr here instead, as a slightly simpler implementation.

Quoted 71 lines
tests/gem_ppgtt.c +59 -1
+
+       close(fdd);
+
+       return matched;
+}
+
+static void flink_and_exit(void)
+{
+       uint32_t fd, fd2;
+       uint32_t bo, flinked_bo, name;
+       char match[100];
+       int matched, to_match;
+       int retry = 0;
+       const int retries = 50;
+
+       fd = drm_open_any();
+       igt_require(uses_full_ppgtt(fd));
+
+       bo = gem_create(fd, 4096);
+       name = gem_flink(fd, bo);
+
+       to_match  = snprintf(match, sizeof(match), "(name: %u)", name);
+       igt_assert(to_match < sizeof(match));
+
+       fd2 = drm_open_any();
+
+       flinked_bo = gem_open(fd2, name);
+       exec_and_get_offset(fd2, flinked_bo);
+       gem_sync(fd2, flinked_bo);
+
+       /* Verify looking for string works OK. */
+       matched = grep_name(match, to_match);
+       igt_assert_eq(matched, to_match);
+
+       gem_close(fd2, flinked_bo);
+
+       /* Close the context. */
+       close(fd2);
+
+retry:
+       /* Give cleanup some time to run. */
+       usleep(100000);
+
+       /* The flinked bo VMA should have been cleared now, so list of VMAs
+        * in debugfs should not contain the one for the imported object.
+        */
+       matched = grep_name(match, to_match);
+       if (matched >= to_match && retry++ < retries)
+               goto retry;
+
+       igt_assert_lt(matched, to_match);
+
+       gem_close(fd, bo);
+       close(fd);
+}
+
 #define N_CHILD 8
 int main(int argc, char **argv)
 {
@@ -297,5 +374,8 @@ int main(int argc, char **argv)
        igt_subtest("flink-and-close-vma-leak")
                flink_and_close();
 
+       igt_subtest("flink-and-exit-vma-leak")
+               flink_and_exit();
+
        igt_exit();
 }
--

2.5.1

Quoted 4 lines

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

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

#2 lore raw

Hi,

Quoted 25 lines · Thomas Wood
Quoted 23 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Test that VMAs associated with a context are cleaned up when contexts are destroyed.

In practice this emulates the leak seen between fbcon and X server. Every time the X server exits we gain one VMA on the fbcon frame buffer object as externally visible via for example /sys/kernel/debug/dri/0/i915_gem_gtt.

---
  tests/gem_ppgtt.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 80 insertions(+)
tests/gem_ppgtt.c +0 -0
index 4f6df063214a..363f9d701585 100644
@@ -265,6 +265,83 @@ static void flink_and_close(void)
         close(fd2);
  }
 
Quoted 3 lines

tests/gem_ppgtt.c static void flink_and_close(void) · line 268

Quoted 1 line
tests/gem_ppgtt.c +1 -0
+static int grep_name(char *match, int to_match)

This could be added to igt_debugfs.c, as it might be useful for other tests.

I couldn't force myself to do it.

Quoted 9 lines

tests/gem_ppgtt.c static void flink_and_close(void) · line 272

Quoted 5 lines
tests/gem_ppgtt.c +4 -0
+{
+       int fdd, ret, matched;
+
+       fdd = open("/sys/kernel/debug/dri/0/i915_gem_gtt", O_RDONLY);

igt_debugfs_open would be more robust here, as it checks various locations for the debugfs and also attempts to mount it if it can't be found.

Done.

Quoted 13 lines
Quoted 13 lines
tests/gem_ppgtt.c +11 -0
+       igt_assert(fdd >= 0);
+
+       matched = 0;
+       do {
+               char ch;
+
+               ret = read(fdd, &ch, 1);
+               if (ret == 0)
+                       break;
+               igt_assert(ret == 1);
+
Quoted 8 lines

tests/gem_ppgtt.c static void flink_and_close(void) · line 288

Quoted 5 lines
tests/gem_ppgtt.c +5 -0
+               if (ch == match[matched])
+                       matched++;
+               else
+                       matched = 0;
+       } while (matched < to_match);

igt_debugfs_fopen is also available, which would allow the use of getline and strstr here instead, as a slightly simpler implementation.

Also done. Ah not via fopen but open+fdopen... drat..

You want v3 or you can live with v2?

Regards,

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

#3 lore raw
Quoted 32 lines · Tvrtko Ursulin

Hi,

Quoted 28 lines · Thomas Wood
Quoted 25 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Test that VMAs associated with a context are cleaned up when contexts are destroyed.

In practice this emulates the leak seen between fbcon and X server. Every time the X server exits we gain one VMA on the fbcon frame buffer object as externally visible via for example /sys/kernel/debug/dri/0/i915_gem_gtt.

---
  tests/gem_ppgtt.c | 80
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 80 insertions(+)
tests/gem_ppgtt.c +0 -0
index 4f6df063214a..363f9d701585 100644
@@ -265,6 +265,83 @@ static void flink_and_close(void)
         close(fd2);
  }
 
Quoted 8 lines
Quoted 5 lines

tests/gem_ppgtt.c static void flink_and_close(void) · line 268

Quoted 1 line
tests/gem_ppgtt.c +1 -0
+static int grep_name(char *match, int to_match)

This could be added to igt_debugfs.c, as it might be useful for other tests.

I couldn't force myself to do it.

I've sent a follow up patch to move the function into the library and use it in gem_ppgtt and gem_tiled_swapping.

Quoted 39 lines
Quoted 11 lines

tests/gem_ppgtt.c static void flink_and_close(void) · line 272

Quoted 6 lines
tests/gem_ppgtt.c +4 -0
+{
+       int fdd, ret, matched;
+
+       fdd = open("/sys/kernel/debug/dri/0/i915_gem_gtt", O_RDONLY);

igt_debugfs_open would be more robust here, as it checks various locations for the debugfs and also attempts to mount it if it can't be found.

Done.

Quoted 14 lines
Quoted 14 lines
tests/gem_ppgtt.c +12 -0
+       igt_assert(fdd >= 0);
+
+       matched = 0;
+       do {
+               char ch;
+
+               ret = read(fdd, &ch, 1);
+               if (ret == 0)
+                       break;
+               igt_assert(ret == 1);
+
+               if (ch == match[matched])
Quoted 8 lines

tests/gem_ppgtt.c static void flink_and_close(void) · line 288

Quoted 4 lines
tests/gem_ppgtt.c +4 -0
+                       matched++;
+               else
+                       matched = 0;
+       } while (matched < to_match);

igt_debugfs_fopen is also available, which would allow the use of getline and strstr here instead, as a slightly simpler implementation.

Quoted 1 line

Also done. Ah not via fopen but open+fdopen... drat..

The follow up patch I've sent addresses this and a few other minor issues.

Quoted 2 lines

You want v3 or you can live with v2?

Unfortunately another version will be needed, as drm_open_any has been replaced by drm_open_driver.

Quoted 9 lines

Regards,

Tvrtko

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

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