[Intel-gfx] [RFT i-g-t] lib/i915: Assert mmap size alignment

Tvrtko Ursulin tvrtko.ursulin at linux.intel.com
Mon Mar 4 07:11:00 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 ++++
 lib/igt_fb.c        | 9 +++++----
 tests/kms_psr.c     | 8 ++++----
 3 files changed, 13 insertions(+), 8 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/lib/igt_fb.c b/lib/igt_fb.c
index 9dca2a4603ce..a160db38ff3a 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -1494,7 +1494,7 @@ static void free_linear_mapping(struct fb_blit_upload *blit)
 	struct igt_fb *fb = blit->fb;
 	struct fb_blit_linear *linear = &blit->linear;
 
-	gem_munmap(linear->map, linear->fb.size);
+	gem_munmap(linear->map, ALIGN(linear->fb.size, 4096));
 	gem_set_domain(fd, linear->fb.gem_handle,
 		       I915_GEM_DOMAIN_GTT, 0);
 
@@ -1544,7 +1544,8 @@ static void setup_linear_mapping(int fd, struct igt_fb *fb, struct fb_blit_linea
 
 	/* Setup cairo context */
 	linear->map = gem_mmap__cpu(fd, linear->fb.gem_handle,
-				    0, linear->fb.size, PROT_READ | PROT_WRITE);
+				    0, ALIGN(linear->fb.size, 4096),
+				    PROT_READ | PROT_WRITE);
 }
 
 static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
@@ -1588,7 +1589,7 @@ int igt_dirty_fb(int fd, struct igt_fb *fb)
 
 static void unmap_bo(struct igt_fb *fb, void *ptr)
 {
-	gem_munmap(ptr, fb->size);
+	gem_munmap(ptr, ALIGN(fb->size, 4096));
 
 	if (fb->is_dumb)
 		igt_dirty_fb(fb->fd, fb);
@@ -1614,7 +1615,7 @@ static void *map_bo(int fd, struct igt_fb *fb)
 		ptr = kmstest_dumb_map_buffer(fd, fb->gem_handle, fb->size,
 					      PROT_READ | PROT_WRITE);
 	else if (is_i915_device(fd))
-		ptr = gem_mmap__gtt(fd, fb->gem_handle, fb->size,
+		ptr = gem_mmap__gtt(fd, fb->gem_handle, ALIGN(fb->size, 4096),
 				    PROT_READ | PROT_WRITE);
 	else if (is_vc4_device(fd))
 		ptr = igt_vc4_mmap_bo(fd, fb->gem_handle, fb->size,
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 Intel-gfx mailing list