From patchwork Tue Feb 2 21:30:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Bragg X-Patchwork-Id: 8195921 Return-Path: X-Original-To: patchwork-intel-gfx@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 E1A499F4DD for ; Tue, 2 Feb 2016 21:31:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 01108202D1 for ; Tue, 2 Feb 2016 21:31:15 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 0B8522027D for ; Tue, 2 Feb 2016 21:31:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 65CBA72090; Tue, 2 Feb 2016 13:31:08 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by gabe.freedesktop.org (Postfix) with ESMTPS id 44DDF7208C; Tue, 2 Feb 2016 13:31:07 -0800 (PST) Received: by mail-wm0-f68.google.com with SMTP id l66so4301105wml.2; Tue, 02 Feb 2016 13:31:07 -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=JuJSnKRl9q1gWx6mLMb4sf1SiwGK7nDwQwaPIP3zlzU=; b=U/No8+5SwiodxciFSmSwuECQ3kUufxyaWotLKNeUkKDRmWQqw2fFDNrkG2FnVNWLuF Sf6JsTGmbkEooa6iT/VDD701KYN6zIlL0Rfb/pz0tvcbiaoB0JT3oSoUcqZUiTK0gI8s 669jORRJclXXfD8jhJRUlWA9M0B/uvSRTfLJ+a9Dkkcs7ma3tpxnyd93W9jRuPDt2Fwf l7nwU5QhzcEmvzYaKUTJ5oHwTQ8eK02fnMvul2qtNyXfZhslxMaFIoGeRt0aQwd7m3xl VHxxD73oZxhDr/ZCZa6cuu5gUjPbGo6zGC4bBFhHserIpSmEslAJlXdYN8Q9Q/9x+ntq FoCQ== 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=JuJSnKRl9q1gWx6mLMb4sf1SiwGK7nDwQwaPIP3zlzU=; b=bjk8e0/hmjmqZ8eV3fp1TgR/Ndwej2r7vn30BThquxpDQGk8vnLTolM38QyAJYE/ai 4/4XC75rIlCp+jY8lCdke0n/M69J2qTngCK7gnacN+ScwrjdWSBYKeLj+n5ZFKKX1mqR +8eXpJAYCYXMLDTz5gBr6IqzX2HMsIXNErfYLLYULmJO5AVBARAvqwmLYKeiLkkCONvR zuh/07Nhc7ekBE30fTOBcPY6cxn3TsOI7A3SwuxdY4p1AE/GnnVeMqWOK/NX0jTw/HO/ tHprgi2sHccvcdbp+rPlDxb0Qk6zDsG7c7B5+QSqq9K58b+Hv4AREUeG0A6fCkAOkBx0 tuEg== X-Gm-Message-State: AG10YOS8n4XCJRgoKsJJJzE5YThE9W3o9kGiCCDzXXcR8HNJTNqRIYbYBoX9+4cYXWxEKw== X-Received: by 10.194.20.5 with SMTP id j5mr30611021wje.71.1454448666063; Tue, 02 Feb 2016 13:31:06 -0800 (PST) Received: from sixbynine.org (cpc26-heme10-2-0-cust305.9-1.cable.virginm.net. [86.3.57.50]) by smtp.gmail.com with ESMTPSA id u4sm3328285wjz.4.2016.02.02.13.31.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Feb 2016 13:31:05 -0800 (PST) From: Robert Bragg To: intel-gfx@lists.freedesktop.org Date: Tue, 2 Feb 2016 21:30:53 +0000 Message-Id: <1454448655-11178-7-git-send-email-robert@sixbynine.org> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1454448655-11178-1-git-send-email-robert@sixbynine.org> References: <1454448655-11178-1-git-send-email-robert@sixbynine.org> Cc: David Airlie , dri-devel@lists.freedesktop.org, Sourab Gupta , Daniel Vetter Subject: [Intel-gfx] [PATCH 6/8] 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=-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 d51460b..ed26605 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2045,6 +2045,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);