From patchwork Wed Nov 13 13:55:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 11241949 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9BEE016B1 for ; Wed, 13 Nov 2019 13:55:56 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 847F5222CD for ; Wed, 13 Nov 2019 13:55:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 847F5222CD Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=chris-wilson.co.uk Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D57F56ED17; Wed, 13 Nov 2019 13:55:55 +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 6DCBA6ED15; Wed, 13 Nov 2019 13:55:53 +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 19187912-1500050 for multiple; Wed, 13 Nov 2019 13:55:06 +0000 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Wed, 13 Nov 2019 13:55:05 +0000 Message-Id: <20191113135505.11426-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t] i915/gem_create: Check for cache bypass around zeroed pages 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, Matthew Auld Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Check that even if userspace tries to sneak around the CPU caches of its zeroed pages, it sees nothing but zeroes. Suggested-by: Joonas Lahtinen Signed-off-by: Chris Wilson Cc: Joonas Lahtinen Cc: Matthew Auld --- tests/i915/gem_create.c | 45 +++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/tests/i915/gem_create.c b/tests/i915/gem_create.c index aed7d1cec..9f7a45025 100644 --- a/tests/i915/gem_create.c +++ b/tests/i915/gem_create.c @@ -55,8 +55,10 @@ #include "intel_io.h" #include "intel_chipset.h" #include "igt_aux.h" +#include "igt_x86.h" #include "drmtest.h" #include "drm.h" +#include "i915/gem_mman.h" #include "i915_drm.h" IGT_TEST_DESCRIPTION("This is a test for the extended & old gem_create ioctl," @@ -188,11 +190,13 @@ static void *thread_clear(void *data) { struct thread_clear *arg = data; unsigned long checked = 0; + enum { PRW, GTT, WC, STREAM, __LAST__ } mode = PRW; int i915 = arg->i915; igt_until_timeout(arg->timeout) { struct drm_i915_gem_create create = {}; uint64_t npages; + void *ptr = NULL; npages = random(); npages <<= 32; @@ -201,18 +205,47 @@ static void *thread_clear(void *data) create.size = npages << 12; create_ioctl(i915, &create); - for (uint64_t page = 0; page < npages; page++) { - uint64_t x; + switch (mode) { + case __LAST__: + case PRW: + break; + case WC: + case STREAM: + ptr = __gem_mmap__wc(i915, create.handle, + 0, create.size, PROT_READ); + break; + case GTT: + ptr = __gem_mmap__gtt(i915, create.handle, + create.size, PROT_READ); + break; + } + /* No set-domains as we are being as naughty as possible */ - gem_read(i915, create.handle, - page * 4096 + (page % (4096 - sizeof(x))), - &x, sizeof(x)); - igt_assert_eq_u64(x, 0); + for (uint64_t page = 0; page < npages; page++) { + uint64_t x[8] = { + page * 4096 + + sizeof(x) * ((page % (4096 - sizeof(x)) / sizeof(x))) + }; + + if (!ptr) + gem_read(i915, create.handle, x[0], x, sizeof(x)); + else if (mode == STREAM) + igt_memcpy_from_wc(x, ptr + x[0], sizeof(x)); + else + memcpy(x, ptr + x[0], sizeof(x)); + + for (int i = 0; i < ARRAY_SIZE(x); i++) + igt_assert_eq_u64(x[i], 0); } + if (ptr) + munmap(ptr, create.size); gem_close(i915, create.handle); checked += npages; atomic_fetch_add(&arg->max, npages); + + if (++mode == __LAST__) + mode = PRW; } return (void *)(uintptr_t)checked;