From patchwork Wed Feb 12 12:43:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 11378475 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 F30341395 for ; Wed, 12 Feb 2020 12:43:50 +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 D1CC220873 for ; Wed, 12 Feb 2020 12:43:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D1CC220873 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 13E286EA59; Wed, 12 Feb 2020 12:43:49 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3D4836EA59; Wed, 12 Feb 2020 12:43:48 +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 fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Feb 2020 04:43:47 -0800 X-IronPort-AV: E=Sophos;i="5.70,428,1574150400"; d="scan'208";a="222276404" 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; 12 Feb 2020 04:43:45 -0800 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Date: Wed, 12 Feb 2020 13:43:17 +0100 Message-Id: <20200212124317.23017-1-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v3] tests/gem_userptr_blits: Enhance invalid mapping exercise 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" Working with a userptr GEM object backed by any type of mapping to another GEM object, not only GTT mapping currently examined bu the test, may cause a currently unavoidable lockdep splat inside the i915 driver. Then, for as long as that issue is not resolved in the driver, such operations are expected to fail in advance to prevent from that badness to happen. Extend the scope of the test by adding subtests which exercise other, non-GTT mapping types. Moreover, don't fail but skip should the driver refuse to create a userptr object on top of the invalid mapping. If it succeeds however, warn about possible lockdep loop risk. v2: For as long as the lockdep loop issue is not fixed, don't succeed if a preventive failure occurs but skip (Chris), - otherwise, warn about possible risk, - put a FIXME placeholder until we learn how to anger lockdep. v3: Use dynamic subtests, with skips handled at mmap-offset attempt performed by the test anyway (Chris), - for better clarity of the patch, drop cosmetic only changes, - use more concise wording in subtest description. Suggested-by: Chris Wilson Signed-off-by: Janusz Krzysztofik --- tests/i915/gem_userptr_blits.c | 43 +++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/tests/i915/gem_userptr_blits.c b/tests/i915/gem_userptr_blits.c index a8d3783fb..74d441a60 100644 --- a/tests/i915/gem_userptr_blits.c +++ b/tests/i915/gem_userptr_blits.c @@ -60,6 +60,7 @@ #include "drm.h" #include "i915_drm.h" +#include "i915/gem_mman.h" #include "intel_bufmgr.h" @@ -577,11 +578,11 @@ static int test_invalid_null_pointer(int fd) return 0; } -static int test_invalid_gtt_mapping(int fd) +static int test_invalid_mapping(int fd, const struct mmap_offset *t) { - struct drm_i915_gem_mmap_gtt arg; + struct drm_i915_gem_mmap_offset arg; uint32_t handle; - char *gtt, *map; + char *ptr, *map; /* Anonymous mapping to find a hole */ map = mmap(NULL, sizeof(linear) + 2 * PAGE_SIZE, @@ -602,28 +603,35 @@ static int test_invalid_gtt_mapping(int fd) igt_assert_eq(copy(fd, handle, handle), 0); gem_close(fd, handle); - /* GTT mapping */ + /* mmap-offset mapping */ memset(&arg, 0, sizeof(arg)); arg.handle = create_bo(fd, 0); - do_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &arg); - gtt = mmap(map + PAGE_SIZE, sizeof(linear), - PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_FIXED, - fd, arg.offset); - igt_assert(gtt == map + PAGE_SIZE); + arg.flags = t->type; + igt_skip_on_f(igt_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP_OFFSET, &arg), + "HW & kernel support for mmap_offset(%s)\n", t->name); + ptr = mmap(map + PAGE_SIZE, sizeof(linear), PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_FIXED, fd, arg.offset); + igt_assert(ptr == map + PAGE_SIZE); gem_close(fd, arg.handle); - igt_assert(((unsigned long)gtt & (PAGE_SIZE - 1)) == 0); + igt_assert(((unsigned long)ptr & (PAGE_SIZE - 1)) == 0); igt_assert((sizeof(linear) & (PAGE_SIZE - 1)) == 0); - gem_userptr(fd, gtt, sizeof(linear), 0, userptr_flags, &handle); + /* FIXME: revisit as soon as lockdep loop issue is resolved */ + igt_require_f(!__gem_userptr(fd, ptr, sizeof(linear), 0, userptr_flags, + &handle), + "lockdep loop preventive failure possibly occurred\n"); + igt_warn("userptr(mmap_offset(%s)) succeeded, risk of lockdep loop exists\n", + t->name); + /* FIXME: we should try harder to anger lockdep */ igt_assert_eq(copy(fd, handle, handle), -EFAULT); gem_close(fd, handle); - gem_userptr(fd, gtt, PAGE_SIZE, 0, userptr_flags, &handle); + gem_userptr(fd, ptr, PAGE_SIZE, 0, userptr_flags, &handle); igt_assert_eq(copy(fd, handle, handle), -EFAULT); gem_close(fd, handle); - gem_userptr(fd, gtt + sizeof(linear) - PAGE_SIZE, PAGE_SIZE, 0, userptr_flags, &handle); + gem_userptr(fd, ptr + sizeof(linear) - PAGE_SIZE, PAGE_SIZE, 0, + userptr_flags, &handle); igt_assert_eq(copy(fd, handle, handle), -EFAULT); gem_close(fd, handle); @@ -2009,8 +2017,11 @@ igt_main_args("c:", NULL, help_str, opt_handler, NULL) igt_subtest("invalid-null-pointer") test_invalid_null_pointer(fd); - igt_subtest("invalid-gtt-mapping") - test_invalid_gtt_mapping(fd); + igt_describe("Verify userptr on mmap-offset mappings fails"); + igt_subtest_with_dynamic("invalid-mmap-offset") + for_each_mmap_offset_type(t) + igt_dynamic_f("%s", t->name) + test_invalid_mapping(fd, t); igt_subtest("forked-access") test_forked_access(fd);