From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Cc: igt-dev@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH i-g-t] i915/gem_pread, gem_pwrite: Exercise using ourselves as the buffer
Date: Mon, 1 Apr 2019 13:20:11 +0100 [thread overview]
Message-ID: <20190401122011.3800-1-chris@chris-wilson.co.uk> (raw)
If we caused a fault on a GEM buffer while in the middle of trying to
write/read into that buffer, we could conceivably deadlock (e.g.
recursing on struct_mutex if we are not careful). Exercise these cases
by supplying a fresh mmap to pread/pwrite in both non-overlapping and
overlapping copies.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
tests/i915/gem_pread.c | 31 +++++++++++++++++++++++++++++++
tests/i915/gem_pwrite.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+)
diff --git a/tests/i915/gem_pread.c b/tests/i915/gem_pread.c
index 00379580c..60830c5c5 100644
--- a/tests/i915/gem_pread.c
+++ b/tests/i915/gem_pread.c
@@ -39,6 +39,34 @@
#include <sys/time.h>
#include "drm.h"
+#define MiB(x) ((x) * 1024 * 1024)
+
+static void pread_self(int i915)
+{
+ uint32_t handle = gem_create(i915, MiB(4));
+ void *ptr;
+
+ ptr = gem_mmap__gtt(i915, handle, MiB(4), PROT_WRITE);
+ gem_read(i915, handle, 0, ptr + MiB(3), MiB(1));
+ gem_read(i915, handle, MiB(3), ptr, MiB(1));
+ gem_read(i915, handle, MiB(1), ptr + MiB(1), MiB(2));
+ munmap(ptr, MiB(4));
+
+ ptr = gem_mmap__cpu(i915, handle, 0, MiB(4), PROT_WRITE);
+ gem_read(i915, handle, 0, ptr + MiB(3), MiB(1));
+ gem_read(i915, handle, MiB(3), ptr, MiB(1));
+ gem_read(i915, handle, MiB(1), ptr + MiB(1), MiB(2));
+ munmap(ptr, MiB(4));
+
+ ptr = gem_mmap__wc(i915, handle, 0, MiB(4), PROT_WRITE);
+ gem_read(i915, handle, 0, ptr + MiB(3), MiB(1));
+ gem_read(i915, handle, MiB(3), ptr, MiB(1));
+ gem_read(i915, handle, MiB(1), ptr + MiB(1), MiB(2));
+ munmap(ptr, MiB(4));
+
+ gem_close(i915, handle);
+}
+
#define OBJECT_SIZE 16384
#define LARGE_OBJECT_SIZE 1024 * 1024
#define KGRN "\x1B[32m"
@@ -131,6 +159,9 @@ int main(int argc, char **argv)
}
}
+ igt_subtest("self")
+ pread_self(fd);
+
for (c = cache; c->level != -1; c++) {
igt_subtest(c->name) {
gem_set_caching(fd, dst, c->level);
diff --git a/tests/i915/gem_pwrite.c b/tests/i915/gem_pwrite.c
index 696bd316a..684b4b216 100644
--- a/tests/i915/gem_pwrite.c
+++ b/tests/i915/gem_pwrite.c
@@ -39,6 +39,34 @@
#include <sys/time.h>
#include "drm.h"
+#define MiB(x) ((x) * 1024 * 1024)
+
+static void pwrite_self(int i915)
+{
+ uint32_t handle = gem_create(i915, MiB(4));
+ void *ptr;
+
+ ptr = gem_mmap__gtt(i915, handle, MiB(4), PROT_READ);
+ gem_write(i915, handle, 0, ptr + MiB(3), MiB(1));
+ gem_write(i915, handle, MiB(3), ptr, MiB(1));
+ gem_write(i915, handle, MiB(1), ptr + MiB(1), MiB(2));
+ munmap(ptr, MiB(4));
+
+ ptr = gem_mmap__cpu(i915, handle, 0, MiB(4), PROT_READ);
+ gem_write(i915, handle, 0, ptr + MiB(3), MiB(1));
+ gem_write(i915, handle, MiB(3), ptr, MiB(1));
+ gem_write(i915, handle, MiB(1), ptr + MiB(1), MiB(2));
+ munmap(ptr, MiB(4));
+
+ ptr = gem_mmap__wc(i915, handle, 0, MiB(4), PROT_READ);
+ gem_write(i915, handle, 0, ptr + MiB(3), MiB(1));
+ gem_write(i915, handle, MiB(3), ptr, MiB(1));
+ gem_write(i915, handle, MiB(1), ptr + MiB(1), MiB(2));
+ munmap(ptr, MiB(4));
+
+ gem_close(i915, handle);
+}
+
#define OBJECT_SIZE 16384
#define COPY_BLT_CMD (2<<29|0x53<<22|0x6)
@@ -258,6 +286,9 @@ int main(int argc, char **argv)
}
}
+ igt_subtest("self")
+ pwrite_self(fd);
+
for (c = cache; c->level != -1; c++) {
igt_subtest(c->name) {
gem_set_caching(fd, dst, c->level);
--
2.20.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next reply other threads:[~2019-04-01 12:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-01 12:20 Chris Wilson [this message]
2019-04-01 12:45 ` [igt-dev] [PATCH i-g-t v2] i915/gem_pread, gem_pwrite: Exercise using ourselves as the buffer Chris Wilson
2019-04-02 12:48 ` [Intel-gfx] " Matthew Auld
2019-04-01 13:02 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2019-04-01 14:44 ` [igt-dev] ✓ Fi.CI.BAT: success for i915/gem_pread, gem_pwrite: Exercise using ourselves as the buffer (rev2) Patchwork
2019-04-01 15:57 ` [igt-dev] ✓ Fi.CI.IGT: success for i915/gem_pread, gem_pwrite: Exercise using ourselves as the buffer Patchwork
2019-04-01 16:01 ` Chris Wilson
2019-04-01 17:19 ` [igt-dev] ✓ Fi.CI.IGT: success for i915/gem_pread, gem_pwrite: Exercise using ourselves as the buffer (rev2) Patchwork
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=20190401122011.3800-1-chris@chris-wilson.co.uk \
--to=chris@chris-wilson.co.uk \
--cc=igt-dev@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
/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