From patchwork Tue Jun 30 15:01:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 6696971 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E9087C05AC for ; Tue, 30 Jun 2015 15:10:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0172520626 for ; Tue, 30 Jun 2015 15:10:35 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id D7DEF20621 for ; Tue, 30 Jun 2015 15:10:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5A33C6E97F; Tue, 30 Jun 2015 08:10:33 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTP id 9B9866E97F for ; Tue, 30 Jun 2015 08:10:31 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP; 30 Jun 2015 08:09:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,378,1432623600"; d="scan'208";a="720368491" Received: from irsmsx103.ger.corp.intel.com ([163.33.3.157]) by orsmga001.jf.intel.com with ESMTP; 30 Jun 2015 08:09:55 -0700 Received: from mwiniars-desk1.igk.intel.com (172.28.173.140) by IRSMSX103.ger.corp.intel.com (163.33.3.157) with Microsoft SMTP Server id 14.3.224.2; Tue, 30 Jun 2015 16:04:53 +0100 From: =?UTF-8?q?Micha=C5=82=20Winiarski?= To: Date: Tue, 30 Jun 2015 17:01:10 +0200 Message-ID: <1435676470-18125-1-git-send-email-michal.winiarski@intel.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1435575591-3510-1-git-send-email-michal.winiarski@intel.com> References: <1435575591-3510-1-git-send-email-michal.winiarski@intel.com> MIME-Version: 1.0 X-Originating-IP: [172.28.173.140] Subject: [Intel-gfx] [PATCH v2] tests/gem_userptr_blits: subtests for MAP_FIXED mappings of regular BO X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When the memory backing the userptr object is freed by the user, but the BO itself is not closed, it's possible to trigger recursive deadlock caused by operations done on different BO mapped in that region. Testcases are simulating such behaviour by using MAP_FIXED mmap flag. v2: Grammar/naming fixes, s/posix_memalign/mmap (Tvrtko), merge tests into single function, call set_tiling after get_pages, comments, GUP slowpath Signed-off-by: Micha? Winiarski Cc: Chris Wilson Cc: Tvrtko Ursulin --- tests/gem_userptr_blits.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/tests/gem_userptr_blits.c b/tests/gem_userptr_blits.c index 1f2cc96..04f6fa9 100644 --- a/tests/gem_userptr_blits.c +++ b/tests/gem_userptr_blits.c @@ -640,6 +640,93 @@ static void test_forked_access(int fd) free(ptr2); } +#define MAP_FIXED_INVALIDATE_OVERLAP (1<<0) +#define MAP_FIXED_INVALIDATE_BUSY (1<<1) +#define MAP_FIXED_INVALIDATE_GET_PAGES (1<<2) +#define MAP_FIXED_INVALIDATE_FILE_BACKED (1<<3) +#define ALL_MAP_FIXED_INVALIDATE (MAP_FIXED_INVALIDATE_OVERLAP | \ + MAP_FIXED_INVALIDATE_BUSY | \ + MAP_FIXED_INVALIDATE_GET_PAGES | \ + MAP_FIXED_INVALIDATE_FILE_BACKED) + +static void map_fixed_invalidate_drop_caches(int fd) +{ + if (fd != -1) { + igt_assert(fsync(fd) == 0); + intel_purge_vm_caches(); + } +} + +static int test_map_fixed_invalidate(int fd, uint32_t flags) +{ + void *ptr; + size_t ptr_size = sizeof(linear); + void *map; + int i; + int num_handles = (flags & MAP_FIXED_INVALIDATE_OVERLAP) ? 2 : 1; + int userptr_fd = -1; + char userptr_fd_name[32]; + uint32_t handle[num_handles]; + uint32_t mmap_handle; + struct drm_i915_gem_mmap_gtt mmap_arg; + struct drm_i915_gem_set_domain set_domain; + + //We can excercise mmap with fd to trigger slowpath on GUP + if (flags & MAP_FIXED_INVALIDATE_FILE_BACKED) { + snprintf(userptr_fd_name, 32, "igt.XXXXXX"); + userptr_fd = mkstemp(userptr_fd_name); + igt_assert(userptr_fd != -1); + igt_assert(unlink(userptr_fd_name) == 0); + igt_assert(ftruncate(userptr_fd, ptr_size) == 0); + ptr = mmap(NULL, ptr_size, PROT_READ | PROT_WRITE, MAP_SHARED, + userptr_fd, 0); + } + else + ptr = mmap(NULL, ptr_size, PROT_READ | PROT_WRITE, MAP_SHARED | + MAP_ANONYMOUS, -1, 0); + igt_assert(ptr != MAP_FAILED); + + for (i=0; i