From patchwork Mon Jul 14 13:19:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 4546201 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D832CC0514 for ; Mon, 14 Jul 2014 13:19:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8FD572015E for ; Mon, 14 Jul 2014 13:19:24 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 5820320158 for ; Mon, 14 Jul 2014 13:19:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 922656E2D3; Mon, 14 Jul 2014 06:19:22 -0700 (PDT) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id 78F286E2D3 for ; Mon, 14 Jul 2014 06:19:21 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 14 Jul 2014 06:19:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,658,1400050800"; d="scan'208";a="572804998" Received: from tursulin-linux.iwi.intel.com ([172.28.253.62]) by orsmga002.jf.intel.com with ESMTP; 14 Jul 2014 06:19:19 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Mon, 14 Jul 2014 14:19:17 +0100 Message-Id: <1405343957-8718-1-git-send-email-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1405332206-6292-1-git-send-email-tvrtko.ursulin@linux.intel.com> References: <1405332206-6292-1-git-send-email-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [PATCH] tests/gem_userptr_blits: Race between object creation and multi-threaded mm ops X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,HK_RANDOM_FROM, 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 From: Tvrtko Ursulin Userptr v23 was not thread safe against memory map operations and object creation from separate threads. MMU notifier callback would get triggered on a partially constructed object causing a NULL pointer dereference. This test excercises that path a bit. In my testing it would trigger it every time and easily, but unfortunately a test pass here does not guarantee the absence of the race. v2: Added explicit cancellation point and removed the stop flag. Use only igt_assert(). Signed-off-by: Tvrtko Ursulin Cc: Chris Wilson --- tests/Makefile.am | 2 ++ tests/gem_userptr_blits.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/tests/Makefile.am b/tests/Makefile.am index 2878624..e207509 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -65,6 +65,8 @@ prime_self_import_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS) prime_self_import_LDADD = $(LDADD) -lpthread gen7_forcewake_mt_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS) gen7_forcewake_mt_LDADD = $(LDADD) -lpthread +gem_userptr_blits_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS) +gem_userptr_blits_LDADD = $(LDADD) -lpthread gem_wait_render_timeout_LDADD = $(LDADD) -lrt kms_flip_LDADD = $(LDADD) -lrt -lpthread diff --git a/tests/gem_userptr_blits.c b/tests/gem_userptr_blits.c index 2eb127f..f80b467 100644 --- a/tests/gem_userptr_blits.c +++ b/tests/gem_userptr_blits.c @@ -47,6 +47,7 @@ #include #include #include +#include #include "drm.h" #include "i915_drm.h" @@ -1107,6 +1108,53 @@ static int test_unmap_cycles(int fd, int expected) return 0; } +static void *mm_stress_thread(void *data) +{ + void *ptr; + int ret; + + for (;;) { + ptr = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + igt_assert(ptr != MAP_FAILED); + ret = munmap(ptr, PAGE_SIZE); + igt_assert(ret == 0); + pthread_testcancel(); + } + + return NULL; +} + +static int test_stress_mm(int fd) +{ + int ret; + pthread_t t; + unsigned int loops = 100000; + uint32_t handle; + void *ptr; + + igt_assert(posix_memalign(&ptr, PAGE_SIZE, PAGE_SIZE) == 0); + + ret = pthread_create(&t, NULL, mm_stress_thread, NULL); + igt_assert(ret == 0); + + while (loops--) { + ret = gem_userptr(fd, ptr, PAGE_SIZE, 0, &handle); + igt_assert(ret == 0); + + gem_close(fd, handle); + } + + free(ptr); + + ret = pthread_cancel(t); + igt_assert(ret == 0); + ret = pthread_join(t, NULL); + igt_assert(ret == 0); + + return 0; +} + unsigned int total_ram; uint64_t aperture_size; int fd, count; @@ -1261,6 +1309,9 @@ int main(int argc, char **argv) igt_subtest("sync-unmap-after-close") test_unmap_after_close(fd); + igt_subtest("stress-mm") + test_stress_mm(fd); + igt_subtest("coherency-sync") test_coherency(fd, count);