Received: by 10.223.164.202 with SMTP id h10csp1021723wrb; Fri, 17 Nov 2017 12:31:31 -0800 (PST) X-Google-Smtp-Source: AGs4zMb/hzSyqZi8fbOm+73Uid1I2pAbKHbM0gGni8fK1ROWhHkSXXRMoKqMTxfFNtRlFbx2bLGd X-Received: by 10.84.131.161 with SMTP id d30mr6523792pld.270.1510950691297; Fri, 17 Nov 2017 12:31:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510950691; cv=none; d=google.com; s=arc-20160816; b=nHtGPG8Oys2lV7dX1c701Jgrcfh9F38TOS/ehu5XKFxUe+/S8vrYE3CCfqdtShHz+A eo81gSWzNBZh/D8LVEfJNjZEyIy30zpGtUsKr0an/l2NK4JuXK8Fp0AqA9DA0gumIG/8 MtTKkZmIIjwDmMUtvAUUY0Arl9rexQEpjDk9ObTSGJBufZhyVBznHasgYgjqYCy2j6Gu NNvgcpcFu5bo84vSOovQirZiadmPD/h9sgrNYSB+w0+YAE/OdciRvtJYl9MmussKdWAk TkmHGedpyjVdJK3VSDeiC1Mnf3GCDfgmFpqYo2B0aYi0MjOFWKncHkhtBWKOPXnW2P75 hQ0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=gN+nNHAFAps4YI5y9DoG5bNkHzUpmi8Gfyp+hW3ZwCo=; b=M812lkSnTbgfu2ZzPaEqTEyFxQgwfNXDqOKwTxtHlCEg5qClG1/rAdx6sv1CkTJokE wdxNwbgcYVAVKoDLk2ikwFmPYFQ5Mg35NHT+E01Gj8ZPaooCx0JKQeo1RoCGu9zXd9bY ZGMYQr07k2Cfve4Ewlcb/nOebizigEwH7KFovaedpXRV2Gg+bcoDzx+l2EECtdKfJf07 fqzDzUlXvOR2YceMp4LOrIDiUGd+gATYqqRMsMnzPigUeOowlaHg8aiKaQXP/ZdD6T+0 D1RslyKK7/Gbbj44U2okw3dDaNa69Ltcy2aZeBOjt/axI2C+0t4/8qnQM4jfgUyEU9SY 3mzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ursulin-net.20150623.gappssmtp.com header.s=20150623 header.b=Wl+tlTyn; 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 w12si3270513pgp.482.2017.11.17.12.31.18; Fri, 17 Nov 2017 12:31:31 -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=Wl+tlTyn; 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 S934849AbdKQN5n (ORCPT + 92 others); Fri, 17 Nov 2017 08:57:43 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:41576 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933420AbdKQN5e (ORCPT ); Fri, 17 Nov 2017 08:57:34 -0500 Received: by mail-wm0-f66.google.com with SMTP id b189so6665035wmd.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; bh=gN+nNHAFAps4YI5y9DoG5bNkHzUpmi8Gfyp+hW3ZwCo=; b=Wl+tlTyngwC+83SEZgOX2jrMkPKGIAUnA8xf5vdHkGTYngU08m030DpGX7Gx4QJFux jmDhdVMajavrhroMszVnM5GB9+sjLBhk36OBv12cWk598YPqcnJdI015XKfw6uu9Gyvw 0n4bx+0lP9iwsD8Ev6CN+Rjgx0PYgHtSs8HoGVmVDmE2Tg/LHT59Sum7sgGHNKSB5p9b nmkjv5JVRVyVS92nxsp2u9v0RdO6MAgrXCYJVXVjH8KGsitxuF7jgLbYVkqh7KrvLaDg PkqUswade89d7LFXN4+669xJPAt7dzmb+Jsyh6c60a/RqCe+3iG4tEeS23epOiD80vbA Q3hg== 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; bh=gN+nNHAFAps4YI5y9DoG5bNkHzUpmi8Gfyp+hW3ZwCo=; b=CjQyD9CdQ1O0NtxcoG6bdiEHpq6JBZn8Nd5NXVkfGE/ErQfWgFp8Uz/HwRpvS1QQ8Y vxyIsza0/aJj9AZky6lhMjgHf+GGt3ptTbsOe3JJfWoySw+S7CHFBpXlK0Rsii2Lthny F2Pqou2KMrmKcpAb41+ct4eZdm2tS2CfEoJyN06PzWyjTS5X5TbRVR22Gy6LHP/vYPTE 2nZiSQk4xSqS6/OZ3SI5b83BBf87Tok5li24J15HXaWH5qIS5FxvLY/WImhhmW6G9k+t GEqavbGgBAzpEcNvjMs47N9ZYynBJvqi51u+WnA7jeX/If5YpsjU3q32RGNLux7rXIrE O7Pg== X-Gm-Message-State: AJaThX60O8YzH/d/zGVzNczjrUpIdQHFM0+c3r++Hedsfa6/mmPW5qBG UYoj3Ufpw2EELIRrBjToTNGGPw== X-Received: by 10.28.152.74 with SMTP id a71mr4064964wme.22.1510927052248; 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.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Nov 2017 05:57:31 -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 , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Dmitry Rogozhkin , Chris Wilson Subject: [RFC 1/2] perf/pmu: Allow PMU providers to override system-wide security settings Date: Fri, 17 Nov 2017 13:57:22 +0000 Message-Id: <20171117135723.22235-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tvrtko Ursulin To allow system administrators finer-grained control over security settings, we add an optional pmu->is_privileged(pmu, event) callback which is consulted when unprivileged system-wide uncore event collection is disabled. Signed-off-by: Tvrtko Ursulin Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim Cc: linux-kernel@vger.kernel.org Cc: Dmitry Rogozhkin Cc: Chris Wilson --- include/linux/perf_event.h | 6 ++++++ kernel/events/core.c | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 8e22f24ded6a..a93630cad6b9 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -446,6 +446,12 @@ struct pmu { * Filter events for PMU-specific reasons. */ int (*filter_match) (struct perf_event *event); /* optional */ + + /* + * Returns true if the event needs CAP_SYS_ADMIN privilege in system- + * wide mode. + */ + bool (*is_privileged) (struct perf_event *event); /* optional */ }; /** diff --git a/kernel/events/core.c b/kernel/events/core.c index 1811dd5aa2e2..adec28c879e8 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3847,6 +3847,16 @@ find_lively_task_by_vpid(pid_t vpid) return task; } +static bool cpu_is_privileged(struct pmu *pmu, struct perf_event *event) +{ + bool privileged = perf_paranoid_cpu(); + + if (privileged && pmu->is_privileged) + privileged = pmu->is_privileged(event); + + return privileged; +} + /* * Returns a matching context with refcount and pincount. */ @@ -3863,7 +3873,7 @@ find_get_context(struct pmu *pmu, struct task_struct *task, if (!task) { /* Must be root to operate on a CPU event: */ - if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN)) + if (cpu_is_privileged(pmu, event) && !capable(CAP_SYS_ADMIN)) return ERR_PTR(-EACCES); cpuctx = per_cpu_ptr(pmu->pmu_cpu_context, cpu); -- 2.14.1 From 1584391640708314532@xxx Sat Nov 18 08:26:54 +0000 2017 X-GM-THRID: 1584391640708314532 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread