From: Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxx> Fishing for fails... /* mmap(2) mandates size is page aligned so check this in our wrappers. */ Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxx> --- lib/i915/gem_mman.c | 4 ++++ lib/igt_fb.c | 14 ++++++++------ tests/kms_ccs.c | 14 ++++++++------ tests/kms_psr.c | 8 ++++---- 4 files changed, 24 insertions(+), 16 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..82f0a41631c1 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); @@ -1604,6 +1605,7 @@ static void destroy_cairo_surface__gtt(void *arg) static void *map_bo(int fd, struct igt_fb *fb) { + size_t size = ALIGN(fb->size, 4096); void *ptr; if (is_i915_device(fd)) @@ -1611,13 +1613,13 @@ static void *map_bo(int fd, struct igt_fb *fb) I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); if (fb->is_dumb) - ptr = kmstest_dumb_map_buffer(fd, fb->gem_handle, fb->size, + ptr = kmstest_dumb_map_buffer(fd, fb->gem_handle, 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, size, PROT_READ | PROT_WRITE); else if (is_vc4_device(fd)) - ptr = igt_vc4_mmap_bo(fd, fb->gem_handle, fb->size, + ptr = igt_vc4_mmap_bo(fd, fb->gem_handle, size, PROT_READ | PROT_WRITE); else igt_assert(false); diff --git a/tests/kms_ccs.c b/tests/kms_ccs.c index 1ed2b4a08c5d..1b92527ee50d 100644 --- a/tests/kms_ccs.c +++ b/tests/kms_ccs.c @@ -196,15 +196,16 @@ static void render_fb(data_t *data, uint32_t gem_handle, unsigned int size, enum test_fb_flags fb_flags, int height, unsigned int stride) { - uint32_t *ptr; - unsigned int half_height, half_size; uint32_t uncompressed_color = data->plane ? GREEN : RED; uint32_t compressed_color = data->plane ? COMPRESSED_GREEN : COMPRESSED_RED; + size_t mmap_size = ALIGN(size, 4096); uint32_t bad_color = RED; + unsigned int half_height, half_size; + uint32_t *ptr; int i; - ptr = gem_mmap__cpu(data->drm_fd, gem_handle, 0, size, + ptr = gem_mmap__cpu(data->drm_fd, gem_handle, 0, mmap_size, PROT_READ | PROT_WRITE); if (fb_flags & FB_COMPRESSED) { @@ -243,7 +244,7 @@ static void render_fb(data_t *data, uint32_t gem_handle, unsigned int size, } } - munmap(ptr, size); + munmap(ptr, mmap_size); } static unsigned int @@ -259,6 +260,7 @@ static void render_ccs(data_t *data, uint32_t gem_handle, uint32_t offset, uint32_t size, int height, unsigned int ccs_stride) { + size_t mmap_size = ALIGN(size, 4096); unsigned int half_height, ccs_half_height; uint8_t *ptr; int i; @@ -266,7 +268,7 @@ static void render_ccs(data_t *data, uint32_t gem_handle, half_height = ALIGN(height, 128) / 2; ccs_half_height = half_height / 16; - ptr = gem_mmap__cpu(data->drm_fd, gem_handle, offset, size, + ptr = gem_mmap__cpu(data->drm_fd, gem_handle, offset, mmap_size, PROT_READ | PROT_WRITE); for (i = 0; i < size; i++) { @@ -276,7 +278,7 @@ static void render_ccs(data_t *data, uint32_t gem_handle, ptr[i] = CCS_COMPRESSED; } - munmap(ptr, size); + munmap(ptr, mmap_size); } static void generate_fb(data_t *data, struct igt_fb *fb, 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 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/intel-gfx