From patchwork Wed Jan 20 17:50:22 2016 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: 8073431 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 312359F440 for ; Wed, 20 Jan 2016 17:50:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 48193204D3 for ; Wed, 20 Jan 2016 17:50:41 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 38A9920398 for ; Wed, 20 Jan 2016 17:50:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 229606E99D; Wed, 20 Jan 2016 09:50:39 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTP id 65EF16E99E for ; Wed, 20 Jan 2016 09:50:35 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP; 20 Jan 2016 09:50:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,322,1449561600"; d="scan'208";a="897497461" Received: from irsmsx151.ger.corp.intel.com ([163.33.192.59]) by fmsmga002.fm.intel.com with ESMTP; 20 Jan 2016 09:50:34 -0800 Received: from mwiniars-desk1.ger.corp.intel.com (172.28.173.39) by IRSMSX151.ger.corp.intel.com (163.33.192.59) with Microsoft SMTP Server id 14.3.248.2; Wed, 20 Jan 2016 17:50:32 +0000 From: =?UTF-8?q?Micha=C5=82=20Winiarski?= To: Date: Wed, 20 Jan 2016 18:50:22 +0100 Message-ID: <1453312222-8305-1-git-send-email-michal.winiarski@intel.com> X-Mailer: git-send-email 2.5.0 MIME-Version: 1.0 X-Originating-IP: [172.28.173.39] Subject: [Intel-gfx] [PATCH i-g-t v3] 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.2 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 v3: Do not assert on EFAULT from get_pages Signed-off-by: Micha? Winiarski Cc: Chris Wilson Cc: Tvrtko Ursulin --- tests/gem_userptr_blits.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/tests/gem_userptr_blits.c b/tests/gem_userptr_blits.c index 6d38260..1868dd7 100644 --- a/tests/gem_userptr_blits.c +++ b/tests/gem_userptr_blits.c @@ -637,6 +637,92 @@ 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