From patchwork Fri Feb 21 11:17:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 11396285 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 54A6D14BC for ; Fri, 21 Feb 2020 11:17:38 +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 392C124650 for ; Fri, 21 Feb 2020 11:17:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 392C124650 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com 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 AD8446F419; Fri, 21 Feb 2020 11:17:37 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6A6496F406; Fri, 21 Feb 2020 11:17:33 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2020 03:17:33 -0800 X-IronPort-AV: E=Sophos;i="5.70,468,1574150400"; d="scan'208";a="225190773" Received: from jkrzyszt-desk.igk.intel.com ([172.22.244.17]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2020 03:17:31 -0800 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Date: Fri, 21 Feb 2020 12:17:00 +0100 Message-Id: <20200221111701.30006-2-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200221111701.30006-1-janusz.krzysztofik@linux.intel.com> References: <20200221111701.30006-1-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC PATCH i-g-t v2 1/2] lib/i915: Restrict mmap types to GTT if no MMAP_OFFSET support X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Commit b0da8bb705c0 ("lib/i915: for_each_mmap_offset_type()") introduced a macro that makes it easy to repeat a test body within a loop for each mmap-offset mapping type supported by v4 of i915 MMAP_GTT API. However, when run on an older version of the driver, those subtests are believed to be still repeated for each known mmap-offset mapping type while effectively exercising GTT mapping type only. As that may be confusing, fix it. It has been assumed that the modified macro is still suitable for use inside gem_mmap_offset test itself. Would that not be case, gem_mmap_offset could redefine the macro back to its initial form for internal use. v2: Move extra condition to a separate function and call it via for_each_if(), in case we need to fix it again in future (Chris) v3: Fix blind copy-paste Suggested-by: MichaƂ Winiarski Signed-off-by: Janusz Krzysztofik Cc: Chris Wilson Reviewed-by: Chris Wilson --- lib/i915/gem_mman.c | 5 +++++ lib/i915/gem_mman.h | 7 +++++-- tests/i915/gem_ctx_sseu.c | 2 +- tests/i915/gem_exec_params.c | 2 +- tests/i915/gem_madvise.c | 18 ++++++++++++++---- tests/i915/gem_mmap_offset.c | 10 +++++----- tests/i915/i915_pm_rpm.c | 2 +- 7 files changed, 32 insertions(+), 14 deletions(-) diff --git a/lib/i915/gem_mman.c b/lib/i915/gem_mman.c index 08ae67696..93bef2bfc 100644 --- a/lib/i915/gem_mman.c +++ b/lib/i915/gem_mman.c @@ -60,6 +60,11 @@ bool gem_has_mmap_offset(int fd) return gtt_version >= 4; } +bool gem_has_mmap_offset_type(int fd, const struct mmap_offset *t) +{ + return gem_has_mmap_offset(fd) || t->type == I915_MMAP_OFFSET_GTT; +} + /** * __gem_mmap__gtt: * @fd: open i915 drm file descriptor diff --git a/lib/i915/gem_mman.h b/lib/i915/gem_mman.h index 4fc6a0186..2c4a7a00b 100644 --- a/lib/i915/gem_mman.h +++ b/lib/i915/gem_mman.h @@ -101,10 +101,13 @@ extern const struct mmap_offset { unsigned int domain; } mmap_offset_types[]; -#define for_each_mmap_offset_type(__t) \ +bool gem_has_mmap_offset_type(int fd, const struct mmap_offset *t); + +#define for_each_mmap_offset_type(fd, __t) \ for (const struct mmap_offset *__t = mmap_offset_types; \ (__t)->name; \ - (__t)++) + (__t)++) \ + for_each_if(gem_has_mmap_offset_type((fd), (__t))) #endif /* GEM_MMAN_H */ diff --git a/tests/i915/gem_ctx_sseu.c b/tests/i915/gem_ctx_sseu.c index d558c8baa..3bef11b51 100644 --- a/tests/i915/gem_ctx_sseu.c +++ b/tests/i915/gem_ctx_sseu.c @@ -531,7 +531,7 @@ igt_main test_invalid_sseu(fd); igt_subtest_with_dynamic("mmap-args") { - for_each_mmap_offset_type(t) { + for_each_mmap_offset_type(fd, t) { igt_dynamic_f("%s", t->name) test_mmapped_args(fd, t); } diff --git a/tests/i915/gem_exec_params.c b/tests/i915/gem_exec_params.c index e2912685b..cf7ea3065 100644 --- a/tests/i915/gem_exec_params.c +++ b/tests/i915/gem_exec_params.c @@ -244,7 +244,7 @@ static void mmapped(int i915) buf = gem_create(i915, 4096); handle = batch_create(i915); - for_each_mmap_offset_type(t) { /* repetitive! */ + for_each_mmap_offset_type(i915, t) { /* repetitive! */ struct drm_i915_gem_execbuffer2 *execbuf; struct drm_i915_gem_exec_object2 *exec; diff --git a/tests/i915/gem_madvise.c b/tests/i915/gem_madvise.c index e8716a891..54c9befff 100644 --- a/tests/i915/gem_madvise.c +++ b/tests/i915/gem_madvise.c @@ -62,12 +62,13 @@ dontneed_before_mmap(void) char *ptr; int fd; - for_each_mmap_offset_type(t) { + fd = drm_open_driver(DRIVER_INTEL); + + for_each_mmap_offset_type(fd, t) { sighandler_t old_sigsegv, old_sigbus; igt_debug("Mapping mode: %s\n", t->name); - fd = drm_open_driver(DRIVER_INTEL); handle = gem_create(fd, OBJECT_SIZE); gem_madvise(fd, handle, I915_MADV_DONTNEED); @@ -93,7 +94,11 @@ dontneed_before_mmap(void) munmap(ptr, OBJECT_SIZE); signal(SIGBUS, old_sigsegv); signal(SIGSEGV, old_sigbus); + + fd = drm_open_driver(DRIVER_INTEL); } + + close(fd); } static void @@ -103,12 +108,13 @@ dontneed_after_mmap(void) char *ptr; int fd; - for_each_mmap_offset_type(t) { + fd = drm_open_driver(DRIVER_INTEL); + + for_each_mmap_offset_type(fd, t) { sighandler_t old_sigsegv, old_sigbus; igt_debug("Mapping mode: %s\n", t->name); - fd = drm_open_driver(DRIVER_INTEL); handle = gem_create(fd, OBJECT_SIZE); ptr = __gem_mmap_offset(fd, handle, 0, OBJECT_SIZE, @@ -134,7 +140,11 @@ dontneed_after_mmap(void) munmap(ptr, OBJECT_SIZE); signal(SIGBUS, old_sigbus); signal(SIGSEGV, old_sigsegv); + + fd = drm_open_driver(DRIVER_INTEL); } + + close(fd); } static void diff --git a/tests/i915/gem_mmap_offset.c b/tests/i915/gem_mmap_offset.c index f49d18e63..1ec963b25 100644 --- a/tests/i915/gem_mmap_offset.c +++ b/tests/i915/gem_mmap_offset.c @@ -128,7 +128,7 @@ static void basic_uaf(int i915) { const uint32_t obj_size = 4096; - for_each_mmap_offset_type(t) { + for_each_mmap_offset_type(i915, t) { uint32_t handle = gem_create(i915, obj_size); uint8_t *expected, *buf, *addr; @@ -176,7 +176,7 @@ static void basic_uaf(int i915) static void isolation(int i915) { - for_each_mmap_offset_type(t) { + for_each_mmap_offset_type(i915, t) { struct drm_i915_gem_mmap_offset mmap_arg = { .flags = t->type }; @@ -245,7 +245,7 @@ static void pf_nonblock(int i915) { igt_spin_t *spin = igt_spin_new(i915); - for_each_mmap_offset_type(t) { + for_each_mmap_offset_type(i915, t) { uint32_t *ptr; ptr = __mmap_offset(i915, spin->handle, 0, 4096, @@ -324,7 +324,7 @@ static void open_flood(int i915, int timeout) handle = gem_create(i915, 4096); dmabuf = prime_handle_to_fd(i915, handle); - for_each_mmap_offset_type(t) { + for_each_mmap_offset_type(i915, t) { struct drm_i915_gem_mmap_offset arg = { .handle = handle, .flags = t->type, @@ -351,7 +351,7 @@ static void open_flood(int i915, int timeout) tmp = gem_reopen_driver(i915); handle = prime_fd_to_handle(i915, dmabuf); - for_each_mmap_offset_type(t) { + for_each_mmap_offset_type(i915, t) { struct drm_i915_gem_mmap_offset arg = { .handle = handle, .flags = t->type, diff --git a/tests/i915/i915_pm_rpm.c b/tests/i915/i915_pm_rpm.c index 0c2821122..1bec80db7 100644 --- a/tests/i915/i915_pm_rpm.c +++ b/tests/i915/i915_pm_rpm.c @@ -2006,7 +2006,7 @@ igt_main_args("", long_options, help_str, opt_handler, NULL) /* GEM */ igt_subtest_with_dynamic("gem-mmap-type") { - for_each_mmap_offset_type(t) { + for_each_mmap_offset_type(drm_fd, t) { igt_dynamic_f("%s", t->name) gem_mmap_args(t); } From patchwork Fri Feb 21 11:17:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 11396283 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 C7A0814BC for ; Fri, 21 Feb 2020 11:17:36 +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 B02EC207FD for ; Fri, 21 Feb 2020 11:17:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B02EC207FD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com 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 2B2596F414; Fri, 21 Feb 2020 11:17:36 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id E3DD56F41C; Fri, 21 Feb 2020 11:17:34 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2020 03:17:34 -0800 X-IronPort-AV: E=Sophos;i="5.70,468,1574150400"; d="scan'208";a="225190780" Received: from jkrzyszt-desk.igk.intel.com ([172.22.244.17]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2020 03:17:33 -0800 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Date: Fri, 21 Feb 2020 12:17:01 +0100 Message-Id: <20200221111701.30006-3-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200221111701.30006-1-janusz.krzysztofik@linux.intel.com> References: <20200221111701.30006-1-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC PATCH i-g-t v2 2/2] tests/gem_userptr_blits: Exercise mmap-offset mapping to userptr X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org, Matthew Auld Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Currently unavoidable lockedp loop related to userptr MMU notifier exists in the i915 driver. For that reason, attempts to set up a mmap-offset (or mmap-gtt) mapping to a userptr object may be now preventively rejected by the driver. A test should exists which checks for that. Would a mapping attempt succeed, the test should trigger the MMU notifier in a way that is proven to result in the lockdep slpat. As that exercise is strictly userptr related, it has been decided to add it as a new subtest to gem_userptr_blits. The new subtest examines userptr interaction with every supported mmap-offset type mapping on top of it. v2: Move the subtest from gem_mmap_offset to gem_userptr_blits, - use dynamic subtests (Chris), - don't FAIL but SKIP on mmap-offset attempt failure (Chris), - on success, try to anger lockdep (Chris). Suggested-by: Chris Wilson Cc: Matthew Auld Reviewed-by: Chris Wilson --- In order to be able to prove the proposed method of angering lockdep actually works, I'm going to submit a kernel patch that reverts commit f6c26b555e14 ("drm/i915: Never allow userptr into the new mapping types") to be tested on Trybot together with this one, so at least non-GTT mmap-offset attempts succeed and the MMU notifier is triggered. Thanks, Janusz tests/i915/gem_userptr_blits.c | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/i915/gem_userptr_blits.c b/tests/i915/gem_userptr_blits.c index fcad374ef..5f716a3ea 100644 --- a/tests/i915/gem_userptr_blits.c +++ b/tests/i915/gem_userptr_blits.c @@ -797,6 +797,42 @@ static int test_map_fixed_invalidate(int fd, uint32_t flags) return 0; } +static void test_mmap_offset_invalidate(int fd, const struct mmap_offset *t) +{ + void *ptr, *map; + uint32_t handle; + + /* check if mmap_offset type is supported by hardware, skip if not */ + handle = gem_create(fd, PAGE_SIZE); + map = __gem_mmap_offset(fd, handle, 0, PAGE_SIZE, + PROT_READ | PROT_WRITE, t->type); + igt_require_f(map, + "HW & kernel support for mmap_offset(%s)\n", t->name); + munmap(map, PAGE_SIZE); + gem_close(fd, handle); + + /* create userptr object */ + igt_assert_eq(posix_memalign(&ptr, PAGE_SIZE, PAGE_SIZE), 0); + gem_userptr(fd, ptr, PAGE_SIZE, 0, userptr_flags, &handle); + + /* set up mmap-offset mapping on top of the object, skip if refused */ + map = __gem_mmap_offset(fd, handle, 0, PAGE_SIZE, + PROT_READ | PROT_WRITE, t->type); + igt_skip_on_f(!map && errno == -ENODEV, + "lockdep loop preventive failure possibly occurred\n"); + igt_assert(map); + + /* set object pages in order to activate MMU notifier for it */ + gem_set_domain(fd, handle, t->domain, t->domain); + + /* trigger the notifier */ + munmap(ptr, PAGE_SIZE); + + /* cleanup */ + munmap(map, PAGE_SIZE); + gem_close(fd, handle); +} + static int test_forbidden_ops(int fd) { struct drm_i915_gem_pread gem_pread; @@ -2170,6 +2206,12 @@ igt_main_args("c:", NULL, help_str, opt_handler, NULL) } } + igt_describe("Invalidate pages of userptr with mmap-offset on top"); + igt_subtest_with_dynamic("mmap-offset-invalidate") + for_each_mmap_offset_type(fd, t) + igt_dynamic_f("%s", t->name) + test_mmap_offset_invalidate(fd, t); + igt_subtest("coherency-sync") test_coherency(fd, count);