[igt-dev] [RFT i-g-t] lib/i915: Assert mmap size alignment

Tvrtko Ursulin tvrtko.ursulin at linux.intel.com
Fri Mar 1 09:37:58 UTC 2019


From: Tvrtko Ursulin <tvrtko.ursulin at intel.com>

Fishing for fails...

/*
mmap(2) mandates size is page aligned so check this in our wrappers.
*/

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
---
 lib/i915/gem_mman.c | 4 ++++
 tests/kms_psr.c     | 8 ++++----
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/lib/i915/gem_mman.c b/lib/i915/gem_mman.c
index 3cf9a6bbdb31..084dbb3b3678 100644
--- a/lib/i915/gem_mman.c
+++ b/lib/i915/gem_mman.c
@@ -57,6 +57,8 @@ void *__gem_mmap__gtt(int fd, uint32_t handle, uint64_t size, unsigned prot)
 	struct drm_i915_gem_mmap_gtt mmap_arg;
 	void *ptr;
 
+	igt_assert(!(size & 4095));
+
 	memset(&mmap_arg, 0, sizeof(mmap_arg));
 	mmap_arg.handle = handle;
 	if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg))
@@ -162,6 +164,8 @@ static void
 {
 	struct drm_i915_gem_mmap arg;
 
+	igt_assert(!(size & 4095));
+
 	memset(&arg, 0, sizeof(arg));
 	arg.handle = handle;
 	arg.offset = offset;
diff --git a/tests/kms_psr.c b/tests/kms_psr.c
index 3e16a6bf4f37..5d3f0ed87eec 100644
--- a/tests/kms_psr.c
+++ b/tests/kms_psr.c
@@ -270,8 +270,8 @@ static void run_test(data_t *data)
 		expected = "GREEN";
 		break;
 	case MMAP_GTT:
-		ptr = gem_mmap__gtt(data->drm_fd, handle, data->mod_size,
-				    PROT_WRITE);
+		ptr = gem_mmap__gtt(data->drm_fd, handle,
+				    ALIGN(data->mod_size, 4096), PROT_WRITE);
 		gem_set_domain(data->drm_fd, handle,
 			       I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
 		memset(ptr, 0xcc, data->mod_size);
@@ -279,8 +279,8 @@ static void run_test(data_t *data)
 		expected = "BLACK or TRANSPARENT mark on top of plane in test";
 		break;
 	case MMAP_CPU:
-		ptr = gem_mmap__cpu(data->drm_fd, handle, 0, data->mod_size,
-				    PROT_WRITE);
+		ptr = gem_mmap__cpu(data->drm_fd, handle, 0,
+				    ALIGN(data->mod_size, 4096), PROT_WRITE);
 		gem_set_domain(data->drm_fd, handle,
 			       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
 		memset(ptr, 0, data->mod_size);
-- 
2.19.1



More information about the igt-dev mailing list