From patchwork Tue Dec 9 16:04:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Kuoppala X-Patchwork-Id: 5463821 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 8F37BBEEA8 for ; Tue, 9 Dec 2014 16:11:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B6C162015E for ; Tue, 9 Dec 2014 16:11:45 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id B762D20114 for ; Tue, 9 Dec 2014 16:11:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 976156EEB1; Tue, 9 Dec 2014 08:11:43 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTP id 4E89C6EEB1 for ; Tue, 9 Dec 2014 08:11:42 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 09 Dec 2014 08:00:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,545,1413270000"; d="scan'208";a="635045973" Received: from rosetta.fi.intel.com (HELO rosetta) ([10.237.72.102]) by fmsmga001.fm.intel.com with ESMTP; 09 Dec 2014 08:00:34 -0800 Received: by rosetta (Postfix, from userid 1000) id 8610480055; Tue, 9 Dec 2014 18:04:38 +0200 (EET) From: Mika Kuoppala To: intel-gfx@lists.freedesktop.org Date: Tue, 9 Dec 2014 18:04:33 +0200 Message-Id: <1418141074-10214-3-git-send-email-mika.kuoppala@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1418141074-10214-1-git-send-email-mika.kuoppala@intel.com> References: <1418141074-10214-1-git-send-email-mika.kuoppala@intel.com> Cc: miku@iki.fi Subject: [Intel-gfx] [PATCH 3/4] drm/i915: Add i915_gpu_state_unsafe debugfs entry 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_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 This is a similar to 'i915_gpu_state' but more dangerous as it doesn't try to lock nor idle the gpu before grabbing the state. But the obvious advantages are that one can inspect the current running gpu state and also get a state dump even if mutex is hold. As we don't want a unsuspecting user to trip into this by accident, there needs to be write into the debugfs node before any unsafe capturing can take place. Signed-off-by: Mika Kuoppala --- drivers/gpu/drm/i915/i915_debugfs.c | 55 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_drv.h | 4 +++ 2 files changed, 59 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c index 30f56f3..5480cf5 100644 --- a/drivers/gpu/drm/i915/i915_debugfs.c +++ b/drivers/gpu/drm/i915/i915_debugfs.c @@ -970,6 +970,60 @@ static const struct file_operations i915_gpu_state_fops = { .release = i915_gpu_state_release, }; +static int i915_gpu_state_open_unsafe(struct inode *inode, struct file *file) +{ + struct drm_device *dev = inode->i_private; + struct i915_error_state_file_priv *state_priv; + struct drm_i915_private *dev_priv = dev->dev_private; + + state_priv = kzalloc(sizeof(*state_priv), GFP_KERNEL); + if (!state_priv) + return -ENOMEM; + + state_priv->dev = dev; + + if (dev_priv->gpu_error.allow_unsafe_state_capture) { + state_priv->error = i915_gpu_state_capture(dev); + if (state_priv->error == NULL) { + kfree(state_priv); + return -ENOMEM; + } + } + + file->private_data = state_priv; + return 0; +} + +static ssize_t +i915_gpu_state_write_unsafe(struct file *filp, + const char __user *ubuf, + size_t cnt, + loff_t *ppos) +{ + struct i915_error_state_file_priv *error_priv = filp->private_data; + struct drm_device *dev = error_priv->dev; + struct drm_i915_private *dev_priv = dev->dev_private; + + dev_priv->gpu_error.allow_unsafe_state_capture = ! + dev_priv->gpu_error.allow_unsafe_state_capture; + + if (dev_priv->gpu_error.allow_unsafe_state_capture) + DRM_DEBUG_DRIVER("allowing unsafe, non locked gpu state dumps\n"); + else + DRM_DEBUG_DRIVER("denying unsafe, non locked gpu state dumps\n"); + + return cnt; +} + +static const struct file_operations i915_gpu_state_unsafe_fops = { + .owner = THIS_MODULE, + .open = i915_gpu_state_open_unsafe, + .read = i915_gpu_state_read, + .write = i915_gpu_state_write_unsafe, + .llseek = default_llseek, + .release = i915_gpu_state_release, +}; + static int i915_error_state_open(struct inode *inode, struct file *file) { struct drm_device *dev = inode->i_private; @@ -4410,6 +4464,7 @@ static const struct i915_debugfs_files { {"i915_gem_drop_caches", &i915_drop_caches_fops}, {"i915_error_state", &i915_error_state_fops}, {"i915_gpu_state", &i915_gpu_state_fops}, + {"i915_gpu_state_unsafe", &i915_gpu_state_unsafe_fops}, {"i915_next_seqno", &i915_next_seqno_fops}, {"i915_display_crc_ctl", &i915_display_crc_ctl_fops}, {"i915_pri_wm_latency", &i915_pri_wm_latency_fops}, diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index ca487b4..452f93f 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -1278,6 +1278,10 @@ struct i915_gpu_error { /* Used to prevent gem_check_wedged returning -EAGAIN during gpu reset */ bool reload_in_reset; + + /* Safety mechanism to prevent unsuspecting user to obtain nonlocked + * capture by accident */ + bool allow_unsafe_state_capture; }; enum modeset_restore {