[i-g-t] lib/draw: Align mmap requests to page boundaries

Submitted by Chris Wilson on Jan. 7, 2019, 10:56 a.m.

Details

Message ID 20190107105636.15118-1-chris@chris-wilson.co.uk
State Accepted
Commit 85cf76182087c09604bcae2bbee9e58b33bcb4f2
Headers show
Series "lib/draw: Align mmap requests to page boundaries" ( rev: 1 ) in IGT

Not browsing as part of any series.

Commit Message

Chris Wilson Jan. 7, 2019, 10:56 a.m.
Since we trust fb->size as either calculated by calc_fb_size() or the
supplied by the user, it invariably isn't page aligned. The mmap
routines and ioctls only deal in pages...

Not sure if fb->size should be page aligned, but that may break
some other drawing tests, so opt to just fix up the mmap requests.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
 lib/igt_draw.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/lib/igt_draw.c b/lib/igt_draw.c
index a9a73cb89..4990d4a01 100644
--- a/lib/igt_draw.c
+++ b/lib/igt_draw.c
@@ -34,6 +34,13 @@ 
 #include "ioctl_wrappers.h"
 #include "i830_reg.h"
 
+#ifndef PAGE_ALIGN
+#ifndef PAGE_SIZE
+#define PAGE_SIZE 4096
+#endif
+#define PAGE_ALIGN(x) ALIGN(x, PAGE_SIZE)
+#endif
+
 /**
  * SECTION:igt_draw
  * @short_description: drawing helpers for tests
@@ -336,7 +343,7 @@  static void draw_rect_mmap_cpu(int fd, struct buf_data *buf, struct rect *rect,
 	if (tiling != I915_TILING_NONE)
 		igt_require(intel_gen(intel_get_drm_devid(fd)) >= 5);
 
-	ptr = gem_mmap__cpu(fd, buf->handle, 0, buf->size, 0);
+	ptr = gem_mmap__cpu(fd, buf->handle, 0, PAGE_ALIGN(buf->size), 0);
 
 	switch (tiling) {
 	case I915_TILING_NONE:
@@ -365,7 +372,8 @@  static void draw_rect_mmap_gtt(int fd, struct buf_data *buf, struct rect *rect,
 	gem_set_domain(fd, buf->handle, I915_GEM_DOMAIN_GTT,
 		       I915_GEM_DOMAIN_GTT);
 
-	ptr = gem_mmap__gtt(fd, buf->handle, buf->size, PROT_READ | PROT_WRITE);
+	ptr = gem_mmap__gtt(fd, buf->handle, PAGE_ALIGN(buf->size),
+			    PROT_READ | PROT_WRITE);
 
 	draw_rect_ptr_linear(ptr, buf->stride, rect, color, buf->bpp);
 
@@ -386,7 +394,7 @@  static void draw_rect_mmap_wc(int fd, struct buf_data *buf, struct rect *rect,
 	if (tiling != I915_TILING_NONE)
 		igt_require(intel_gen(intel_get_drm_devid(fd)) >= 5);
 
-	ptr = gem_mmap__wc(fd, buf->handle, 0, buf->size,
+	ptr = gem_mmap__wc(fd, buf->handle, 0, PAGE_ALIGN(buf->size),
 			   PROT_READ | PROT_WRITE);
 
 	switch (tiling) {

Comments

Quoting Chris Wilson (2019-01-07 12:56:36)
> Since we trust fb->size as either calculated by calc_fb_size() or the
> supplied by the user, it invariably isn't page aligned. The mmap
> routines and ioctls only deal in pages...
> 
> Not sure if fb->size should be page aligned, but that may break
> some other drawing tests, so opt to just fix up the mmap requests.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>

Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>

Regards, Joonas
Quoting Joonas Lahtinen (2019-01-23 14:22:54)
> Quoting Chris Wilson (2019-01-07 12:56:36)
> > Since we trust fb->size as either calculated by calc_fb_size() or the
> > supplied by the user, it invariably isn't page aligned. The mmap
> > routines and ioctls only deal in pages...
> > 
> > Not sure if fb->size should be page aligned, but that may break
> > some other drawing tests, so opt to just fix up the mmap requests.
> > 
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> 
> Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>

Pushed, so that should clear the board for your mmap-wc fix.
-Chris