From patchwork Fri Oct 13 20:10:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jeff.mcgee@intel.com X-Patchwork-Id: 10005855 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ACBCE60325 for ; Fri, 13 Oct 2017 20:16:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EBA129165 for ; Fri, 13 Oct 2017 20:16:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93A1229167; Fri, 13 Oct 2017 20:16:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 37D0C29165 for ; Fri, 13 Oct 2017 20:16:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 899996E25B; Fri, 13 Oct 2017 20:16:30 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id A4E1B6E25B for ; Fri, 13 Oct 2017 20:16:29 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP; 13 Oct 2017 13:16:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.43,372,1503385200"; d="scan'208"; a="1205620432" Received: from jeffdesk.fm.intel.com ([10.1.27.96]) by fmsmga001.fm.intel.com with ESMTP; 13 Oct 2017 13:16:28 -0700 From: jeff.mcgee@intel.com To: intel-gfx@lists.freedesktop.org Date: Fri, 13 Oct 2017 13:10:32 -0700 Message-Id: <20171013201033.29092-1-jeff.mcgee@intel.com> X-Mailer: git-send-email 2.14.2 Subject: [Intel-gfx] [PATCH 1/2] drm/i915: Properly lock the engine timeline in debugfs i915_gem_request 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: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Jeff McGee We are racing with updates to the timeline. This can cause an inconsistent snapshot to be dumped, or even worse a NULL pointer dereference. Signed-off-by: Jeff McGee --- drivers/gpu/drm/i915/i915_debugfs.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c index 0bb6e01121fc..135828fb1904 100644 --- a/drivers/gpu/drm/i915/i915_debugfs.c +++ b/drivers/gpu/drm/i915/i915_debugfs.c @@ -657,33 +657,26 @@ static void print_request(struct seq_file *m, static int i915_gem_request_info(struct seq_file *m, void *data) { struct drm_i915_private *dev_priv = node_to_i915(m->private); - struct drm_device *dev = &dev_priv->drm; struct drm_i915_gem_request *req; struct intel_engine_cs *engine; enum intel_engine_id id; - int ret, any; - - ret = mutex_lock_interruptible(&dev->struct_mutex); - if (ret) - return ret; + int any = 0; - any = 0; for_each_engine(engine, dev_priv, id) { - int count; + int count = 0; - count = 0; + spin_lock_irq(&engine->timeline->lock); list_for_each_entry(req, &engine->timeline->requests, link) count++; - if (count == 0) - continue; - - seq_printf(m, "%s requests: %d\n", engine->name, count); - list_for_each_entry(req, &engine->timeline->requests, link) - print_request(m, req, " "); - any++; + if (count) { + seq_printf(m, "%s requests: %d\n", engine->name, count); + list_for_each_entry(req, &engine->timeline->requests, link) + print_request(m, req, " "); + any++; + } + spin_unlock_irq(&engine->timeline->lock); } - mutex_unlock(&dev->struct_mutex); if (any == 0) seq_puts(m, "No requests\n");