From patchwork Mon Apr 1 12:20:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 10879827 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F1C0D922 for ; Mon, 1 Apr 2019 12:20:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9DA32857E for ; Mon, 1 Apr 2019 12:20:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAE0D287C5; Mon, 1 Apr 2019 12:20:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 23BF52857E for ; Mon, 1 Apr 2019 12:20:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 95D746E08A; Mon, 1 Apr 2019 12:20:20 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id 939676E08A; Mon, 1 Apr 2019 12:20:19 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 16091097-1500050 for multiple; Mon, 01 Apr 2019 13:20:13 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Mon, 1 Apr 2019 13:20:11 +0100 Message-Id: <20190401122011.3800-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t] i915/gem_pread, gem_pwrite: Exercise using ourselves as the buffer X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: igt-dev@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 #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 #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);