From patchwork Wed Dec 4 14:39:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Kuoppala X-Patchwork-Id: 3282851 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 70ACB9F37A for ; Wed, 4 Dec 2013 14:39:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C4F61204AF for ; Wed, 4 Dec 2013 14:39:19 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id DB04720379 for ; Wed, 4 Dec 2013 14:39:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D586EFADE1; Wed, 4 Dec 2013 06:39:13 -0800 (PST) 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 5EB8FFADE1 for ; Wed, 4 Dec 2013 06:39:12 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 04 Dec 2013 06:39:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.93,824,1378882800"; d="scan'208";a="419266752" Received: from rosetta.fi.intel.com (HELO rosetta) ([10.237.72.65]) by orsmga001.jf.intel.com with ESMTP; 04 Dec 2013 06:39:10 -0800 Received: by rosetta (Postfix, from userid 1000) id EE8FD81656; Wed, 4 Dec 2013 16:39:09 +0200 (EET) From: Mika Kuoppala To: intel-gfx@lists.freedesktop.org Date: Wed, 4 Dec 2013 16:39:09 +0200 Message-Id: <1386167949-10162-1-git-send-email-mika.kuoppala@intel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <20131203170343.GM27344@phenom.ffwll.local> References: <20131203170343.GM27344@phenom.ffwll.local> Subject: [Intel-gfx] [PATCH] tests/gem_reset_stats: add close-pending-fork X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org 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 From: Mika Kuoppala This triggers use after free oops on request->batch_obj when going through the rings and setting reset status on requests, after a gpu hang. v2: Streamlined the test and added comments (Daniel) Signed-off-by: Mika Kuoppala --- tests/gem_reset_stats.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/gem_reset_stats.c b/tests/gem_reset_stats.c index 6c22bce..095b14b 100644 --- a/tests/gem_reset_stats.c +++ b/tests/gem_reset_stats.c @@ -25,6 +25,7 @@ * */ +#define _GNU_SOURCE #include #include #include @@ -36,6 +37,7 @@ #include #include #include +#include #include "i915_drm.h" #include "intel_bufmgr.h" @@ -637,6 +639,63 @@ static void test_close_pending(void) close(fd); } +static void test_close_pending_fork(void) +{ + int pid; + int fd, h; + + fd = drm_open_any(); + igt_assert(fd >= 0); + + assert_reset_status(fd, 0, RS_NO_ERROR); + + h = inject_hang(fd, 0); + igt_assert(h >= 0); + + sleep(1); + + /* Avoid helpers as we need to kill the child + * without any extra signal handling on behalf of + * lib/drmtest.c + */ + pid = fork(); + if (pid == 0) { + /* Not first drm_open_any() so we need to do + * gem_quiescent_gpu() explicitly, as it is the + * key component to trigger the oops + */ + const int fd2 = drm_open_any(); + igt_assert(fd2 >= 0); + + /* This adds same batch on each ring */ + gem_quiescent_gpu(fd2); + + close(fd2); + return; + } else { + igt_assert(pid > 0); + sleep(1); + + /* Kill the child to reduce refcounts on + batch_objs */ + kill(pid, SIGKILL); + } + + gem_close(fd, h); + close(fd); + + /* Then we just wait on hang to happen */ + fd = drm_open_any(); + igt_assert(fd >= 0); + + h = exec_valid(fd, 0); + igt_assert(h >= 0); + + gem_sync(fd, h); + gem_close(fd, h); + close(fd); +} + static void drop_root(void) { igt_assert(getuid() == 0); @@ -837,6 +896,9 @@ igt_main igt_subtest("close-pending") test_close_pending(); + igt_subtest("close-pending-fork") + test_close_pending_fork(); + igt_subtest("params") test_params(); }