From patchwork Mon Nov 7 19:49:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Bragg X-Patchwork-Id: 9415961 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 E7CCB60512 for ; Mon, 7 Nov 2016 19:50:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D899228AF5 for ; Mon, 7 Nov 2016 19:50:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD65C28D42; Mon, 7 Nov 2016 19:50:45 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 7613128AF5 for ; Mon, 7 Nov 2016 19:50:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A33676E41D; Mon, 7 Nov 2016 19:50:13 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5ED356E296; Mon, 7 Nov 2016 19:50:11 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id p190so18343590wmp.1; Mon, 07 Nov 2016 11:50:11 -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=jFKSGlFzhAcu5OAI0TJQ79+EHbUr5fgw6rgY18ih4x8=; b=fIa5KTs+8aGHrZBbyj6DFcxVdDrHr+FYowd2bS7ibSMUHb3DAP+I38wBJRcb/VeES5 AkDuJ2gUYddrXIxXTdRkihpTtsdjCwmT0JuBBPMEg7H57vRnuBtNA05iPQfachrP27Y2 hB+/xwTSnni/GgDzdr2cxQDJOOh78XoCWg3iScvaNQVkxcg+RtMot3+h4cqKQMVbuLtU zg44yx6RRyCZk19HafFS9OejZ4pfMx5j5Sxy/V/Ak+tA15ncdbrkmK0x3P6RWEzgiCTh F+U+cFzDHwlYJch9JdYPvDXF9NMkYVIMnOGOId0Ch0u1j7RlLFPsH2Pw8GcYbRfjewLL LzbQ== 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=jFKSGlFzhAcu5OAI0TJQ79+EHbUr5fgw6rgY18ih4x8=; b=fTlD0Jk7CdXtIR9LLifPL8lc88hNdVWJyNwhT0sSftoUKtgoR5cxG5FKL/O9WTECnT +e9dnIdamWESYfmquiXYg0U9kIJ73lBfDeCRkviNn/Rmv3xXnn2KeGV2t6ukn4qQZzyw BnddKUQFb+R+J+6BrGnQQtsg7txc2UAX9+tK40hLfDi9sbj1MAAQ1NaCXvlB1JnT72qn OUqlsLgGy8sIQtHaBn7n5GFbjnpKcf2hS8FZK6/6phE4oZyILnCJIoEgWjQxXnd2zBXa ut0mh6jcHzpCV7TDgB3efLaM+pF09MIAUwPsgBQYWidDdSBDd+ZZFIxsxeF/hQ/nu5Jr tvkA== X-Gm-Message-State: ABUngvfRn5zbiU0+E8PvoqfkuJuWNmY6kC9B+yCzKq+0cAS0FaWA6k1sCZqi2yOD/DVJgg== X-Received: by 10.28.107.21 with SMTP id g21mr9343245wmc.131.1478548209831; Mon, 07 Nov 2016 11:50:09 -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 130sm15377355wmf.0.2016.11.07.11.50.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Nov 2016 11:50:09 -0800 (PST) From: Robert Bragg To: intel-gfx@lists.freedesktop.org Subject: [PATCH v9 08/11] drm/i915: Add dev.i915.perf_stream_paranoid sysctl option Date: Mon, 7 Nov 2016 19:49:54 +0000 Message-Id: <20161107194957.3385-9-robert@sixbynine.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161107194957.3385-1-robert@sixbynine.org> References: <20161107194957.3385-1-robert@sixbynine.org> Cc: dri-devel@lists.freedesktop.org, Matthew Auld , 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-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 Reviewed-by: Matthew Auld Reviewed-by: Sourab Gupta --- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_perf.c | 50 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 15fba6b..8962bfd 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2188,6 +2188,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 c427cd8c..e51c1d8 100644 --- a/drivers/gpu/drm/i915/i915_perf.c +++ b/drivers/gpu/drm/i915/i915_perf.c @@ -64,6 +64,11 @@ #define POLL_FREQUENCY 200 #define POLL_PERIOD (NSEC_PER_SEC / POLL_FREQUENCY) +/* for sysctl proc_dointvec_minmax of dev.i915.perf_stream_paranoid */ +static int zero; +static int one = 1; +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. @@ -1207,7 +1212,13 @@ i915_perf_open_ioctl_locked(struct drm_i915_private *dev_priv, } } - 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; @@ -1460,6 +1471,39 @@ void i915_perf_unregister(struct drm_i915_private *dev_priv) dev_priv->perf.metrics_kobj = NULL; } +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_minmax, + .extra1 = &zero, + .extra2 = &one, + }, + {} +}; + +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_i915_private *dev_priv) { if (!IS_HASWELL(dev_priv)) @@ -1490,6 +1534,8 @@ void i915_perf_init(struct drm_i915_private *dev_priv) dev_priv->perf.oa.n_builtin_sets = i915_oa_n_builtin_metric_sets_hsw; + dev_priv->perf.sysctl_header = register_sysctl_table(dev_root); + dev_priv->perf.initialized = true; } @@ -1498,6 +1544,8 @@ void i915_perf_fini(struct drm_i915_private *dev_priv) if (!dev_priv->perf.initialized) return; + unregister_sysctl_table(dev_priv->perf.sysctl_header); + memset(&dev_priv->perf.oa.ops, 0, sizeof(dev_priv->perf.oa.ops)); dev_priv->perf.initialized = false; }