From patchwork Wed Apr 20 14:23:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Bragg X-Patchwork-Id: 8890341 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 076D4BF29F for ; Wed, 20 Apr 2016 14:24:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0823B20260 for ; Wed, 20 Apr 2016 14:24:38 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 2D1212024C for ; Wed, 20 Apr 2016 14:24:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7096C6EA0D; Wed, 20 Apr 2016 14:24:36 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 20AD26EA0D; Wed, 20 Apr 2016 14:24:35 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id l6so14215477wml.3; Wed, 20 Apr 2016 07:24:35 -0700 (PDT) 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=TPvA8MRYvz2JpVRvHK+hBkYd8b2Ma/uKuENkf/beGqY=; b=lE2yCwimimVeRQZYnfEdpS8XN9FlbM5C8OPytLARR9l7imAATkf2pSe/x08YGaDeRJ j+HnWnZmOw4qE8pIO2iRjB8oR79iPEk/2BjWjp+vcitVVIyf87q5mG0gxISawfF8X1uW dWysH86MOXSwUq7Vr8RvizCHBPv6hDflRp1gFe2yu0PspML+YAlTzpsTQOBmzT8utPDo Usu7GIP1CNfJ+hMFWfUKoL3vbWS/95zRNcJQOIpo706ZQ+KEBMATV9AojQljIj4SrDkK NqK2FmdKduXS9vpKcGPh456+lSV82ihhNySiXMOKI7XjqJkYYIZUdjb2BC5OlrWN7how 45TQ== 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=TPvA8MRYvz2JpVRvHK+hBkYd8b2Ma/uKuENkf/beGqY=; b=Jes7V5+atPZqT9oKDL5u5xWZ64ThCBj/BXL3coDpFshkWvg+9G50OxAxVtEh/9VPw3 67hcLQoPP8lCRKgNI9OL7Xv2TOVChAB+vDzaYyqEMoVr9oApqNZK3pzoPpBoKD0Ssi9m 9rxBNT9SWifHzmRcGajyFRLYWbBkUcXqT/D+d2772Cbg1AnN1o6JVVuLnpAqJCv88vBa DCK/Ie2ioLKjhB2P3XstyMKPn/c7XQyudi8vKj66msKUQcoy6af7kJ1tcTQ/YlHeezjq FcoAgFEdn/kJWO5TNus9j9NmS+Sce5PW14gSxIqXwSsULUOdQXU7n51OtTngyu+H31E4 r60Q== X-Gm-Message-State: AOPr4FVzo+wUYind9glL+daM2tP5cRhoQYVV41ljhNYyNJmHiUt+YESMNjHgWWPyEv5Kkg== X-Received: by 10.28.139.203 with SMTP id n194mr29791187wmd.40.1461162273426; Wed, 20 Apr 2016 07:24:33 -0700 (PDT) Received: from sixbynine.org (host-78-151-18-103.as13285.net. [78.151.18.103]) by smtp.gmail.com with ESMTPSA id u79sm9928839wmu.8.2016.04.20.07.24.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Apr 2016 07:24:32 -0700 (PDT) From: Robert Bragg To: intel-gfx@lists.freedesktop.org Date: Wed, 20 Apr 2016 15:23:12 +0100 Message-Id: <1461162194-1424-8-git-send-email-robert@sixbynine.org> X-Mailer: git-send-email 2.7.1 In-Reply-To: <1461162194-1424-1-git-send-email-robert@sixbynine.org> References: <1461162194-1424-1-git-send-email-robert@sixbynine.org> Cc: David Airlie , dri-devel@lists.freedesktop.org, Sourab Gupta , Deepak S , Daniel Vetter Subject: [Intel-gfx] [PATCH 7/9] drm/i915: Add dev.i915.perf_event_paranoid sysctl option 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=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham 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 1406b93..2ac32b2 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2081,6 +2081,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 f2db3de..c2ba16a 100644 --- a/drivers/gpu/drm/i915/i915_perf.c +++ b/drivers/gpu/drm/i915/i915_perf.c @@ -59,6 +59,8 @@ #define POLL_FREQUENCY 200 #define POLL_PERIOD (NSEC_PER_SEC / POLL_FREQUENCY) +static u32 i915_perf_stream_paranoid = true; + /* The maximum exponent the hardware accepts is 63 (essentially it selects one * of the 64bit timestamp bits to trigger reports from) but there's currently * no known use case for sampling as infrequently as once per 47 thousand years. @@ -1105,7 +1107,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; @@ -1309,6 +1317,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); @@ -1354,6 +1394,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; @@ -1366,6 +1408,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);