From patchwork Wed Feb 3 18:39:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Bragg X-Patchwork-Id: 8207021 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DDA619FBE9 for ; Wed, 3 Feb 2016 18:39:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 01B4E202EB for ; Wed, 3 Feb 2016 18:39:37 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 20F5A202F0 for ; Wed, 3 Feb 2016 18:39:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 790296E7FA; Wed, 3 Feb 2016 10:39:29 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id 484846E7E9; Wed, 3 Feb 2016 10:39:25 -0800 (PST) Received: by mail-wm0-f67.google.com with SMTP id p63so8649570wmp.1; Wed, 03 Feb 2016 10:39:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=j2H6mmWtb4Z27ubwE4nqU3Uh7pABgsPKrSavOKZAhWk=; b=DFJZ2ry+vA4H9SWpAk9jQh5nnpA7iLlQ3hK1QdGmClMjKF2YDxSGxRvV3IiTvx8JWX YnWNW2ITTorbs43lKqU0e7slKGbgUI2yxuI50araJvnqXL4lp8i2npj7Nr+s+55z/eiT fLJ16osZ4ht0bP6AQv9vgkPuqlthgpw1b816Msl+V6h7DEAvv880jvERruUMFuJWbnBA YlvQyNILHdkdnl/QycfeQLZmcHLwaGeWagTiMzjiNYeXgtkRh6tD03Gg01c6sQ+ueOfO 5c7AwUZqPi3nGKn0VRrhXr4NatkgV99rFPyAwxLtQBFbKWFgtXSJepEQ47JWbtQ47Uvr GHMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=j2H6mmWtb4Z27ubwE4nqU3Uh7pABgsPKrSavOKZAhWk=; b=cGxrz2SDtopVhJdB4aiVxHip4Qm8OeWnwRcYh3GQ5I0IwF0+hbgTP+Sp7WAoEp1HCT gEjrh3r5WbwXv5eeP1jJYXD3pCUk/tr5IhjP1wPIu/9b4LDphBOPw6yUUHsLdti3o3N/ reGPVmgVcumoCMitPvVDn0dBvO0sTZjVBSKSeHUuleiNIKs04/gXmNG8trHMftSI2rEy T14UxYzEeCw78xXA4ZpMOTowrbH+weADWrjlgz662tm/unFU388ZYzQ4/FbZb1iRUygc 1LjvHa+DqOJm3//PzfdheLISzif7xlZTGd0tGM61VJFj+zr/rL+itt+N1TXFifp5Cs9O tVEA== X-Gm-Message-State: AG10YOR9op4zd48W4ocAss2zCAYMqdlucXd7IG9C9mVVmGyBm4ClVQ40TLpNZsollwvk9g== X-Received: by 10.28.72.197 with SMTP id v188mr20846538wma.34.1454524764023; Wed, 03 Feb 2016 10:39:24 -0800 (PST) Received: from sixbynine.org ([83.217.123.106]) by smtp.gmail.com with ESMTPSA id ei9sm7721327wjd.40.2016.02.03.10.39.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Feb 2016 10:39:23 -0800 (PST) From: Robert Bragg To: intel-gfx@lists.freedesktop.org Subject: [PATCH 6/8] drm/i915: Add dev.i915.perf_event_paranoid sysctl option Date: Wed, 3 Feb 2016 18:39:11 +0000 Message-Id: <1454524753-13218-7-git-send-email-robert@sixbynine.org> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1454524753-13218-1-git-send-email-robert@sixbynine.org> References: <1454524753-13218-1-git-send-email-robert@sixbynine.org> Cc: dri-devel@lists.freedesktop.org, Sourab Gupta , Daniel Vetter , Robert Bragg X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,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 Consistent with the kernel.perf_event_paranoid sysctl option that can allow non-root users to access system wide cpu metrics, this can optionally allow non-root users to access system wide OA counter metrics from Gen graphics hardware. Signed-off-by: Robert Bragg --- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_perf.c | 46 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index b1c60bb..6776e18 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2087,6 +2087,7 @@ struct drm_i915_private { bool initialized; struct kobject *metrics_kobj; + struct ctl_table_header *sysctl_header; struct mutex lock; struct list_head streams; diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c index 5c08a16..7c27d93 100644 --- a/drivers/gpu/drm/i915/i915_perf.c +++ b/drivers/gpu/drm/i915/i915_perf.c @@ -37,6 +37,8 @@ #define POLL_FREQUENCY 200 #define POLL_PERIOD max_t(u64, 10000, NSEC_PER_SEC / POLL_FREQUENCY) +static u32 i915_perf_stream_paranoid = true; + #define OA_EXPONENT_MAX 0x3f static struct i915_oa_format hsw_oa_formats[I915_OA_FORMAT_MAX] = { @@ -956,7 +958,13 @@ int i915_perf_open_ioctl_locked(struct drm_device *dev, } } - if (!specific_ctx && !capable(CAP_SYS_ADMIN)) { + /* Similar to perf's kernel.perf_paranoid_cpu sysctl option + * we check a dev.i915.perf_stream_paranoid sysctl option + * to determine if it's ok to access system wide OA counters + * without CAP_SYS_ADMIN privileges. + */ + if (!specific_ctx && + i915_perf_stream_paranoid && !capable(CAP_SYS_ADMIN)) { DRM_ERROR("Insufficient privileges to open system-wide i915 perf stream\n"); ret = -EACCES; goto err_ctx; @@ -1157,6 +1165,38 @@ int i915_perf_open_ioctl(struct drm_device *dev, void *data, return ret; } + +static struct ctl_table oa_table[] = { + { + .procname = "perf_stream_paranoid", + .data = &i915_perf_stream_paranoid, + .maxlen = sizeof(i915_perf_stream_paranoid), + .mode = 0644, + .proc_handler = proc_dointvec, + }, + {} +}; + +static struct ctl_table i915_root[] = { + { + .procname = "i915", + .maxlen = 0, + .mode = 0555, + .child = oa_table, + }, + {} +}; + +static struct ctl_table dev_root[] = { + { + .procname = "dev", + .maxlen = 0, + .mode = 0555, + .child = i915_root, + }, + {} +}; + void i915_perf_init(struct drm_device *dev) { struct drm_i915_private *dev_priv = to_i915(dev); @@ -1198,6 +1238,8 @@ void i915_perf_init(struct drm_device *dev) return; } + dev_priv->perf.sysctl_header = register_sysctl_table(dev_root); + dev_priv->perf.initialized = true; return; @@ -1210,6 +1252,8 @@ void i915_perf_fini(struct drm_device *dev) if (!dev_priv->perf.initialized) return; + unregister_sysctl_table(dev_priv->perf.sysctl_header); + i915_perf_deinit_sysfs_hsw(dev_priv); kobject_put(dev_priv->perf.metrics_kobj);