Received: by 10.223.164.202 with SMTP id h10csp1022718wrb; Fri, 17 Nov 2017 12:32:32 -0800 (PST) X-Google-Smtp-Source: AGs4zMZWTurXPtXMgRBM0B1iyql92POlndoFzsXLOAO1NcUNkwuMe+0tQJj+CZXo9prJpKQ+tMqd X-Received: by 10.101.71.205 with SMTP id f13mr6286627pgs.112.1510950752284; Fri, 17 Nov 2017 12:32:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510950752; cv=none; d=google.com; s=arc-20160816; b=qDeaYMXMDgqVxLttF838THRQBiUBNKEwsPEyErx6wMnrghaQAkRdxEIjVI6oAOIf+r +W5LU5jc+sSf7oDEteFT52mB52oQJyb4EAS+Fukbl8h+FVCp8oxXCKr0mHAmcKN2oKD1 qjt9Il8GwtexxqEfZAKuTNUzKD4TWcB2FM3ooNQL+b77phae9gnu9qKYYPGbZxiJYn1k VChRkZMGijW4Fi5GtUR7LJnEgZTuovjBE2ZJAtJI9FEuA9TKToFzGN3X1QWQ3JJwt4O0 le9Jv8xKoimRhhRTjI5VXldV8tRzHJh9cQ+y1cDcd9PjAbvlL5hCJD9T5NAU355Yg/Pk LTPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=mFhAl/lRJATmkLHBkGDpeH9r9bwoMykUBXQ/NRyzeEI=; b=s4TZctsCOxV1pcvrJMso/pLwyBCYfksut0VjaLx3o4BbOsfiq6czauqQNY57EZqlWd XxcUvuEE2326tWZK8ScYfOgUBNHz0Yl9EJKKlrR8uVrLjnXyzodSe4mfwiKw9tox4/io 1dNfW+WIk+iPgOLYtxd18DTCK4kGDtNuAVs97fcCWIpWlkKPq2adrIUOfqt+ag3Jq36K ZFiO3qMNgxq5IAzMXfem6GVmrXf/BVCUxolr5CSKw8fosmPqSDodEyuBPoyFuqYNUBgp n4QsMRb++42SYhcj4k9kpz4z7pSKJhop+B3nz/kuTHy9RjZ/XFhCts07SqV+NSS7+DXN H36w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ursulin-net.20150623.gappssmtp.com header.s=20150623 header.b=BbHrsnZO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a25si3647257pff.55.2017.11.17.12.32.19; Fri, 17 Nov 2017 12:32:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ursulin-net.20150623.gappssmtp.com header.s=20150623 header.b=BbHrsnZO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934885AbdKQN5x (ORCPT + 92 others); Fri, 17 Nov 2017 08:57:53 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35063 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934838AbdKQN5e (ORCPT ); Fri, 17 Nov 2017 08:57:34 -0500 Received: by mail-wm0-f67.google.com with SMTP id y80so6624479wmd.0 for ; Fri, 17 Nov 2017 05:57:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mFhAl/lRJATmkLHBkGDpeH9r9bwoMykUBXQ/NRyzeEI=; b=BbHrsnZO6e2q8MzC3D/S9naydINcMheLoeamwsFkBSVSPZe/H4jvuPoLtZt4GEs6DJ hNXz42DLw6pwZoXBmvfuCaHMWqvYZgyGHqSRIOdLV4yMrawI3MtrR9hH/uz+/LxoMeyc qbMA9pk4wjZ9XG2L093Mpkk1RIQiC6PIW4TsAH25DrPGd5cFo057mFaazKx2V13hCjVI fHR5eGKmJSYRoHN6C78tZtQMo/x1REz6F1CcKTbWcamEGgD/UHplErZ61V9PylG3TWjA FHFBeLu/uUL9wb9h4FfhWRwdn95VwtsNDycQI0cFwJVH1EqQyx3T7xEl38ISK/Y5MWWQ ByqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mFhAl/lRJATmkLHBkGDpeH9r9bwoMykUBXQ/NRyzeEI=; b=ClksCNHs8TAZwXwpndO3SHRJLx+vkjc9bNmS8NSQcVBtHlIsYb7r/zAV6Kg0lytadu 25sn1TCQak3V5sO0Y/iTJKypy9msF+KZ83JOG7agmdFxoEEpLKvBNfUkFUqvJ6IQtGpS nEcSpqJYKB5rJ0O/c5aGkEPmo3X7G+dTzUmF8+Ai+DFOCtcsu9fCFwWH0oLGK7VOvFQs Sk/4ZL2BvAa6cdEca0liSUXtH7SokUFdkd/zMXcpHUm/0EITLUdi+/q/DpSGn7UdwAZP 9WAowGiczIgZ/22cLrx7ZC3xGrPBnuiGkj8YRVaZ7mWEJbXa2L+wpsdy4wgUafKXGBfo bZJQ== X-Gm-Message-State: AJaThX7ELvl0OpvGuxTxgmFZ5NsKTqUCpnWbSXGBdGLAoXhDHFiaLQ3f rJCRFj4I8uKCldLIajBKnZ3WZQ== X-Received: by 10.28.107.66 with SMTP id g63mr4048446wmc.38.1510927052995; Fri, 17 Nov 2017 05:57:32 -0800 (PST) Received: from localhost.localdomain ([95.146.151.224]) by smtp.gmail.com with ESMTPSA id f19sm1882455wmf.5.2017.11.17.05.57.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Nov 2017 05:57:32 -0800 (PST) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org, Tvrtko Ursulin , Dmitry Rogozhkin , Chris Wilson Subject: [RFC 2/2] drm/i915/pmu: Allow fine-grained PMU access control Date: Fri, 17 Nov 2017 13:57:23 +0000 Message-Id: <20171117135723.22235-2-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171117135723.22235-1-tvrtko.ursulin@linux.intel.com> References: <20171117135723.22235-1-tvrtko.ursulin@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tvrtko Ursulin We implement the new pmu->is_privileged callback and add our own sysctl as /proc/sys/dev/i915/pmu_stream_paranoid (defaulting to true), which enables system administrators to override the global /proc/sys/kernel/perf_event_paranoid setting for i915 PMU only. Signed-off-by: Tvrtko Ursulin Cc: Dmitry Rogozhkin Cc: Chris Wilson --- drivers/gpu/drm/i915/i915_pmu.c | 55 +++++++++++++++++++++++++++++++++++++++-- drivers/gpu/drm/i915/i915_pmu.h | 4 +++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pmu.c index baa663641bb7..a8eca7303b7e 100644 --- a/drivers/gpu/drm/i915/i915_pmu.c +++ b/drivers/gpu/drm/i915/i915_pmu.c @@ -43,6 +43,11 @@ static cpumask_t i915_pmu_cpumask = CPU_MASK_NONE; +/* for sysctl proc_dointvec_minmax of dev.i915.pmu_stream_paranoid */ +static int zero; +static int one = 1; +static u32 i915_pmu_stream_paranoid = true; + static u8 engine_config_sample(u64 config) { return config & I915_PMU_SAMPLE_MASK; @@ -647,6 +652,11 @@ static int i915_pmu_event_event_idx(struct perf_event *event) return 0; } +static bool i915_pmu_is_privileged(struct perf_event *event) +{ + return i915_pmu_stream_paranoid; +} + static ssize_t i915_pmu_format_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -834,11 +844,44 @@ static void i915_pmu_unregister_cpuhp_state(struct drm_i915_private *i915) #endif } +static struct ctl_table pmu_table[] = { + { + .procname = "pmu_stream_paranoid", + .data = &i915_pmu_stream_paranoid, + .maxlen = sizeof(i915_pmu_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 = pmu_table, + }, + {} +}; + +static struct ctl_table dev_root[] = { + { + .procname = "dev", + .maxlen = 0, + .mode = 0555, + .child = i915_root, + }, + {} +}; + void i915_pmu_register(struct drm_i915_private *i915) { struct intel_engine_cs *engine; enum intel_engine_id id; - int ret; + int ret = -EINVAL; if (INTEL_GEN(i915) <= 2) { DRM_INFO("PMU not supported for this GPU."); @@ -854,6 +897,7 @@ void i915_pmu_register(struct drm_i915_private *i915) i915->pmu.base.stop = i915_pmu_event_stop; i915->pmu.base.read = i915_pmu_event_read; i915->pmu.base.event_idx = i915_pmu_event_event_idx; + i915->pmu.base.is_privileged = i915_pmu_is_privileged; spin_lock_init(&i915->pmu.lock); hrtimer_init(&i915->pmu.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); @@ -863,9 +907,12 @@ void i915_pmu_register(struct drm_i915_private *i915) INIT_DELAYED_WORK(&engine->pmu.disable_busy_stats, __disable_busy_stats); + if (!(i915->pmu.sysctl_header = register_sysctl_table(dev_root))) + goto err; + ret = perf_pmu_register(&i915->pmu.base, "i915", -1); if (ret) - goto err; + goto err_pmu; ret = i915_pmu_register_cpuhp_state(i915); if (ret) @@ -875,6 +922,8 @@ void i915_pmu_register(struct drm_i915_private *i915) err_unreg: perf_pmu_unregister(&i915->pmu.base); +err_pmu: + unregister_sysctl_table(i915->pmu.sysctl_header); err: i915->pmu.base.event_init = NULL; DRM_NOTE("Failed to register PMU! (err=%d)\n", ret); @@ -899,6 +948,8 @@ void i915_pmu_unregister(struct drm_i915_private *i915) i915_pmu_unregister_cpuhp_state(i915); + unregister_sysctl_table(i915->pmu.sysctl_header); + perf_pmu_unregister(&i915->pmu.base); i915->pmu.base.event_init = NULL; } diff --git a/drivers/gpu/drm/i915/i915_pmu.h b/drivers/gpu/drm/i915/i915_pmu.h index e209783a4c5f..30e2192b4218 100644 --- a/drivers/gpu/drm/i915/i915_pmu.h +++ b/drivers/gpu/drm/i915/i915_pmu.h @@ -61,6 +61,10 @@ struct i915_pmu { * @timer: Timer for internal i915 PMU sampling. */ struct hrtimer timer; + /** + * @sysctl_header: Sysctl table header. + */ + struct ctl_table_header *sysctl_header; /** * @enable: Bitmask of all currently enabled events. * -- 2.14.1 From 1584545988524406776@xxx Mon Nov 20 01:20:12 +0000 2017 X-GM-THRID: 1584226221830067445 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread