public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: "Michał Winiarski" <michal.winiarski@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t] tests/gem_create: Test unaligned BO size update
Date: Tue, 26 Mar 2019 17:32:56 +0100	[thread overview]
Message-ID: <20190326163256.5315-1-michal.winiarski@intel.com> (raw)

The driver is supposed to update the size when it's trying to outsmart
userspace. Let's test it, and tweak the __gem_create in order to control
its input.

Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Janusz Krzysztofik <janusz.krzysztofik@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
 lib/ioctl_wrappers.c           | 19 ++++++++----------
 lib/ioctl_wrappers.h           |  2 +-
 tests/i915/gem_create.c        | 35 +++++++++++++++++++++++++---------
 tests/i915/gem_fd_exhaustion.c | 11 ++++++-----
 4 files changed, 41 insertions(+), 26 deletions(-)

diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index a66eb4bc..bb387a27 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -541,21 +541,16 @@ uint32_t gem_create_stolen(int fd, uint64_t size)
 	return create.handle;
 }
 
-int __gem_create(int fd, uint64_t size, uint32_t *handle)
+int __gem_create(int fd, struct drm_i915_gem_create *create)
 {
-	struct drm_i915_gem_create create = {
-		.size = size,
-	};
 	int err = 0;
 
-	if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create) == 0) {
-		*handle = create.handle;
-	} else {
+	if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, create) != 0) {
 		err = -errno;
 		igt_assume(err != 0);
 	}
-
 	errno = 0;
+
 	return err;
 }
 
@@ -571,11 +566,13 @@ int __gem_create(int fd, uint64_t size, uint32_t *handle)
  */
 uint32_t gem_create(int fd, uint64_t size)
 {
-	uint32_t handle;
+	struct drm_i915_gem_create create = {
+		.size = size,
+	};
 
-	igt_assert_eq(__gem_create(fd, size, &handle), 0);
+	igt_assert_eq(__gem_create(fd, &create), 0);
 
-	return handle;
+	return create.handle;
 }
 
 /**
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index ad93daff..8202374f 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -77,7 +77,7 @@ void gem_sync(int fd, uint32_t handle);
 bool gem_create__has_stolen_support(int fd);
 uint32_t __gem_create_stolen(int fd, uint64_t size);
 uint32_t gem_create_stolen(int fd, uint64_t size);
-int __gem_create(int fd, uint64_t size, uint32_t *handle);
+int __gem_create(int fd, struct drm_i915_gem_create *create);
 uint32_t gem_create(int fd, uint64_t size);
 void gem_execbuf_wr(int fd, struct drm_i915_gem_execbuffer2 *execbuf);
 int __gem_execbuf_wr(int fd, struct drm_i915_gem_execbuffer2 *execbuf);
diff --git a/tests/i915/gem_create.c b/tests/i915/gem_create.c
index 2a861ca8..057816a5 100644
--- a/tests/i915/gem_create.c
+++ b/tests/i915/gem_create.c
@@ -71,7 +71,7 @@ struct local_i915_gem_create_v2 {
 	uint32_t pad;
 #define I915_CREATE_PLACEMENT_STOLEN (1<<0)
 	uint32_t flags;
-} create;
+} create_v2;
 
 #define LOCAL_IOCTL_I915_GEM_CREATE       DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_CREATE, struct local_i915_gem_create_v2)
 
@@ -81,24 +81,26 @@ static void invalid_flag_test(int fd)
 
 	gem_require_stolen_support(fd);
 
-	create.handle = 0;
-	create.size = PAGE_SIZE;
-	create.flags = ~I915_CREATE_PLACEMENT_STOLEN;
-	ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CREATE, &create);
+	create_v2.handle = 0;
+	create_v2.size = PAGE_SIZE;
+	create_v2.flags = ~I915_CREATE_PLACEMENT_STOLEN;
+	ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CREATE, &create_v2);
 
 	igt_assert(ret <= 0);
 
-	create.flags = ~0;
-	ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CREATE, &create);
+	create_v2.flags = ~0;
+	ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CREATE, &create_v2);
 
 	igt_assert(ret <= 0);
 }
 
 static void invalid_size_test(int fd)
 {
-	uint32_t handle;
+	struct drm_i915_gem_create create = {
+		.size = 0,
+	};
 
-	igt_assert_eq(__gem_create(fd, 0, &handle), -EINVAL);
+	igt_assert_eq(__gem_create(fd, &create), -EINVAL);
 }
 
 /*
@@ -209,6 +211,18 @@ static void always_clear(int i915, int timeout)
 		pthread_join(thread[i], NULL);
 }
 
+static void size_update(int fd)
+{
+	int size_initial_nonaligned = 16;
+
+	struct drm_i915_gem_create create = {
+		.size = size_initial_nonaligned,
+	};
+
+	igt_assert_eq(__gem_create(fd, &create), 0);
+	igt_assert_neq(create.size, size_initial_nonaligned);
+}
+
 igt_main
 {
 	int fd = -1;
@@ -233,4 +247,7 @@ igt_main
 
 	igt_subtest("create-clear")
 		always_clear(fd, 30);
+
+	igt_subtest("create-size-update")
+		size_update(fd);
 }
diff --git a/tests/i915/gem_fd_exhaustion.c b/tests/i915/gem_fd_exhaustion.c
index 559590b1..05800a5d 100644
--- a/tests/i915/gem_fd_exhaustion.c
+++ b/tests/i915/gem_fd_exhaustion.c
@@ -100,16 +100,17 @@ igt_simple_main
 		igt_drop_root();
 
 		for (int i = 0; ; i++) {
+			struct drm_i915_gem_create create = {
+				.size = 4096,
+			};
 			int leak = open("/dev/null", O_RDONLY);
-			uint32_t handle;
 
-			if (__gem_create(fd, 4096, &handle) == 0)
-				gem_close(fd, handle);
+			if (__gem_create(fd, &create) == 0)
+				gem_close(fd, create.handle);
 
 			if (leak < 0) {
 				igt_info("fd exhaustion after %i rounds.\n", i);
-				igt_assert(__gem_create(fd, 4096,
-							&handle) < 0);
+				igt_assert(__gem_create(fd, &create) < 0);
 				break;
 			}
 		}
-- 
2.20.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

             reply	other threads:[~2019-03-26 16:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-26 16:32 Michał Winiarski [this message]
2019-03-26 16:48 ` [igt-dev] [PATCH i-g-t] tests/gem_create: Test unaligned BO size update Chris Wilson
2019-03-26 17:13 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2019-03-26 17:39 ` [igt-dev] [PATCH i-g-t v2] " Michał Winiarski
2019-03-26 18:05   ` Chris Wilson
2019-03-26 18:21 ` [igt-dev] ✓ Fi.CI.BAT: success for tests/gem_create: Test unaligned BO size update (rev2) Patchwork
2019-03-27  0:31 ` [igt-dev] ✓ Fi.CI.IGT: success for tests/gem_create: Test unaligned BO size update Patchwork
2019-03-27  2:02 ` [igt-dev] ✓ Fi.CI.IGT: success for tests/gem_create: Test unaligned BO size update (rev2) Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190326163256.5315-1-michal.winiarski@intel.com \
    --to=michal.winiarski@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox