From patchwork Mon Dec 2 14:47:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Kuoppala X-Patchwork-Id: 3265821 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 5399DBEEAD for ; Mon, 2 Dec 2013 14:48:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 35F032026F for ; Mon, 2 Dec 2013 14:48:09 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 54ABE20279 for ; Mon, 2 Dec 2013 14:48:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E22EBF9DCD; Mon, 2 Dec 2013 06:47:58 -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 01118FA993 for ; Mon, 2 Dec 2013 06:47:56 -0800 (PST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 02 Dec 2013 06:47:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.93,811,1378882800"; d="scan'208";a="445340686" Received: from rosetta.fi.intel.com (HELO rosetta) ([10.237.72.65]) by orsmga002.jf.intel.com with ESMTP; 02 Dec 2013 06:47:50 -0800 Received: by rosetta (Postfix, from userid 1000) id 062538006F; Mon, 2 Dec 2013 16:47:48 +0200 (EET) From: Mika Kuoppala To: intel-gfx@lists.freedesktop.org Date: Mon, 2 Dec 2013 16:47:46 +0200 Message-Id: <1385995666-3541-1-git-send-email-mika.kuoppala@intel.com> X-Mailer: git-send-email 1.7.9.5 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 Fork and create another filedesc to wait access to already hung GPU and then kill it. This triggers use after free of the request->batch_obj. Signed-off-by: Mika Kuoppala --- tests/gem_reset_stats.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/gem_reset_stats.c b/tests/gem_reset_stats.c index 6c22bce..242300c 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,64 @@ static void test_close_pending(void) close(fd); } +static int __test_open_any(void) +{ + char *name; + int ret, fd; + + ret = asprintf(&name, "/dev/dri/card%d", drm_get_card()); + if (ret == -1) + return -1; + + fd = open(name, O_RDWR); + free(name); + + return fd; +} + +static void test_close_pending_fork(void) +{ + int pid; + int fd, fd2, h; + + fd = drm_open_any(); + igt_assert(fd >= 0); + + assert_reset_status(fd, 0, RS_NO_ERROR); + + igt_disable_exit_handler(); + + h = inject_hang(fd, 0); + igt_assert(h >= 0); + + sleep(1); + + pid = fork(); + if (pid == 0) { + fd2 = __test_open_any(); + igt_assert(fd2 >= 0); + gem_quiescent_gpu(fd2); + close(fd2); + } else { + igt_assert(pid > 0); + sleep(1); + kill(pid, SIGKILL); + } + + gem_close(fd, h); + close(fd); + + 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 +897,9 @@ igt_main igt_subtest("close-pending") test_close_pending(); + igt_subtest("close-pending-fork") + test_close_pending_fork(); + igt_subtest("params") test_params(); }