From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Intel-gfx@lists.freedesktop.org,
Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Subject: [igt-dev] [RFT i-g-t] lib/i915: Assert mmap size alignment
Date: Mon, 4 Mar 2019 07:11:00 +0000 [thread overview]
Message-ID: <20190304071100.23554-1-tvrtko.ursulin@linux.intel.com> (raw)
From: Tvrtko Ursulin <tvrtko.ursulin@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@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
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next reply other threads:[~2019-03-04 7:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-04 7:11 Tvrtko Ursulin [this message]
-- strict thread matches above, loose matches on Subject: below --
2019-03-04 14:11 [igt-dev] [RFT i-g-t] lib/i915: Assert mmap size alignment Tvrtko Ursulin
2019-03-04 14:45 ` Chris Wilson
2019-03-05 7:55 ` Tvrtko Ursulin
2019-03-05 8:38 ` Chris Wilson
2019-03-05 9:23 ` Tvrtko Ursulin
2019-03-05 9:30 ` Chris Wilson
2019-03-04 7:14 Tvrtko Ursulin
2019-03-01 9:37 Tvrtko Ursulin
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=20190304071100.23554-1-tvrtko.ursulin@linux.intel.com \
--to=tvrtko.ursulin@linux.intel.com \
--cc=Intel-gfx@lists.freedesktop.org \
--cc=igt-dev@lists.freedesktop.org \
--cc=tvrtko.ursulin@intel.com \
/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