From patchwork Thu Apr 7 18:39:48 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: 8775941 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 6CAAD9FBEA for ; Thu, 7 Apr 2016 18:40:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 76CCF20263 for ; Thu, 7 Apr 2016 18:40:34 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 6F7272025A for ; Thu, 7 Apr 2016 18:40:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0F0C06EA1D; Thu, 7 Apr 2016 18:40:33 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTP id B05836EA1D for ; Thu, 7 Apr 2016 18:40:31 +0000 (UTC) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP; 07 Apr 2016 11:40:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,449,1455004800"; d="scan'208";a="927747324" Received: from irsmsx102.ger.corp.intel.com ([163.33.3.155]) by orsmga001.jf.intel.com with ESMTP; 07 Apr 2016 11:40:30 -0700 Received: from mwiniars-desk1.ger.corp.intel.com (172.28.173.39) by IRSMSX102.ger.corp.intel.com (163.33.3.155) with Microsoft SMTP Server id 14.3.248.2; Thu, 7 Apr 2016 19:40:29 +0100 From: =?UTF-8?q?Micha=C5=82=20Winiarski?= To: Date: Thu, 7 Apr 2016 20:39:48 +0200 Message-ID: <1460054389-25554-2-git-send-email-michal.winiarski@intel.com> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1460054389-25554-1-git-send-email-michal.winiarski@intel.com> References: <1460054389-25554-1-git-send-email-michal.winiarski@intel.com> MIME-Version: 1.0 X-Originating-IP: [172.28.173.39] Subject: [Intel-gfx] [PATCH i-g-t 2/3] igt/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=-5.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 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 d154657..e88a9e4 100644 --- a/tests/gem_userptr_blits.c +++ b/tests/gem_userptr_blits.c @@ -571,6 +571,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