public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
* [Intel-gfx] [PATCH i-g-t] i915/gem_mmap_gtt: Race mmap offset generation against closure
@ 2019-08-26 15:20 Chris Wilson
  2019-08-26 15:29 ` Chris Wilson
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Chris Wilson @ 2019-08-26 15:20 UTC (permalink / raw)
  To: intel-gfx; +Cc: igt-dev

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Abdiel Janulgue <abdiel.janulgue@linux.intel.com>
---
 tests/i915/gem_mmap_gtt.c | 98 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)

diff --git a/tests/i915/gem_mmap_gtt.c b/tests/i915/gem_mmap_gtt.c
index 8eff91850..81068f7d1 100644
--- a/tests/i915/gem_mmap_gtt.c
+++ b/tests/i915/gem_mmap_gtt.c
@@ -26,6 +26,7 @@
  */
 
 #include <unistd.h>
+#include <stdatomic.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -360,6 +361,99 @@ test_isolation(int i915)
 	igt_assert(ptr == MAP_FAILED);
 }
 
+static void
+test_close_race(int i915)
+{
+	const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+	uint32_t *handles;
+
+	handles = mmap64(0, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
+	igt_assert(handles != MAP_FAILED);
+
+	igt_fork(child, ncpus) {
+		do {
+			struct drm_i915_gem_mmap_gtt mmap_arg = {};
+			int i = 1 + random() % ncpus;
+			uint32_t old;
+
+			mmap_arg.handle = gem_create(i915, 4096);
+			old = atomic_exchange(&handles[i], mmap_arg.handle);
+			ioctl(i915, DRM_IOCTL_GEM_CLOSE, &old);
+
+			if (ioctl(i915,
+				  DRM_IOCTL_I915_GEM_MMAP_GTT,
+				  &mmap_arg) != -1) {
+				void *ptr;
+
+				ptr = mmap64(0, 4096,
+					     PROT_READ, MAP_SHARED, i915,
+					     mmap_arg.offset);
+				if (ptr != MAP_FAILED)
+					munmap(ptr, 4096);
+			}
+		} while (!READ_ONCE(handles[0]));
+	}
+
+	sleep(20);
+	handles[0] = 1;
+	igt_waitchildren();
+
+	for (int i = 1; i <= ncpus; i++)
+		ioctl(i915, DRM_IOCTL_GEM_CLOSE, handles[i]);
+	munmap(handles, 4096);
+}
+
+static void
+test_flink_race(int i915)
+{
+	const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+	uint32_t *handles;
+
+	handles = mmap64(0, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
+	igt_assert(handles != MAP_FAILED);
+
+	igt_fork(child, ncpus) {
+		int fd = gem_reopen_driver(i915);
+
+		do {
+			struct drm_i915_gem_mmap_gtt mmap_arg = {};
+			uint32_t old;
+			int i = 1 + random() % ncpus;
+
+			old = atomic_exchange(&handles[i],
+					      gem_create(i915, 4096));
+			if (!old)
+				continue;
+
+			mmap_arg.handle =
+				gem_open(fd, gem_flink(i915, old));
+			ioctl(i915, DRM_IOCTL_GEM_CLOSE, &old);
+
+			if (ioctl(fd,
+				  DRM_IOCTL_I915_GEM_MMAP_GTT,
+				  &mmap_arg) != -1) {
+				void *ptr;
+
+				ptr = mmap64(0, 4096,
+					     PROT_READ, MAP_SHARED, fd,
+					     mmap_arg.offset);
+				if (ptr != MAP_FAILED)
+					munmap(ptr, 4096);
+			}
+
+			ioctl(fd, DRM_IOCTL_GEM_CLOSE, &mmap_arg.handle);
+		} while (!READ_ONCE(handles[0]));
+	}
+
+	sleep(20);
+	handles[0] = 1;
+	igt_waitchildren();
+
+	for (int i = 1; i <= ncpus; i++)
+		ioctl(i915, DRM_IOCTL_GEM_CLOSE, handles[i]);
+	munmap(handles, 4096);
+}
+
 static void
 test_write_gtt(int fd)
 {
@@ -985,6 +1079,10 @@ igt_main
 		test_wc(fd);
 	igt_subtest("isolation")
 		test_isolation(fd);
+	igt_subtest("close-race")
+		test_close_race(fd);
+	igt_subtest("flink-race")
+		test_flink_race(fd);
 	igt_subtest("pf-nonblock")
 		test_pf_nonblock(fd);
 
-- 
2.23.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-08-29  7:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-26 15:20 [Intel-gfx] [PATCH i-g-t] i915/gem_mmap_gtt: Race mmap offset generation against closure Chris Wilson
2019-08-26 15:29 ` Chris Wilson
2019-08-26 16:21 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2019-08-26 20:09 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2019-08-27  8:41 ` [igt-dev] [PATCH i-g-t] " Arkadiusz Hiler
2019-08-29  7:36 ` Abdiel Janulgue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox