From patchwork Thu May 7 14:15:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Bragg X-Patchwork-Id: 6358481 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 7811C9F32B for ; Thu, 7 May 2015 14:16:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 87220203B6 for ; Thu, 7 May 2015 14:16:04 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 9D19220376 for ; Thu, 7 May 2015 14:16:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0F8B16E837; Thu, 7 May 2015 07:16:03 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) by gabe.freedesktop.org (Postfix) with ESMTP id 1B2836E817; Thu, 7 May 2015 07:15:59 -0700 (PDT) Received: by widdi4 with SMTP id di4so61680943wid.0; Thu, 07 May 2015 07:15:58 -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=U5XiVdqgBpcBOT1+zcV/xzuq3aBimSnppE5jmM4XSGM=; b=m8OGRAyuJRJnekl789ZzZ0/lgGL/4Jwu3YTD3+ITFlLrMcc3opeZYWbMG6NhKyA8LP vplL5Pn8QK6ATH2oemJIE1NDbBQks/aSYcM/dhkW1RfScUeOgOkJ1jF+639+bCfxeis1 EdUJMwJC/7cRdIHae8daYX1fI/K0XSFBPnM9g/KGgyK8Pb4ZJ5pFeHSIEe/WERcxCR7e k00yAW66pSErfhARMcIiFUem1eLkpETSQ/13hxTqEyZwBbknzzNK75wm0ksOSxTsiU2j XfVubPLOpSwzfPGm+tOEwNIlSAw42ruNqjqmoTmKRfa0P3vwr+OCcVpnzqItK08d/d9x w0Pw== X-Received: by 10.195.11.202 with SMTP id ek10mr7954333wjd.12.1431008158561; Thu, 07 May 2015 07:15:58 -0700 (PDT) Received: from sixbynine.org (cpc26-heme10-2-0-cust305.9-1.cable.virginm.net. [86.3.57.50]) by mx.google.com with ESMTPSA id n3sm3638214wix.1.2015.05.07.07.15.57 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 May 2015 07:15:57 -0700 (PDT) From: Robert Bragg To: intel-gfx@lists.freedesktop.org Date: Thu, 7 May 2015 15:15:45 +0100 Message-Id: <1431008154-6833-3-git-send-email-robert@sixbynine.org> X-Mailer: git-send-email 2.3.2 In-Reply-To: <1431008154-6833-1-git-send-email-robert@sixbynine.org> References: <1431008154-6833-1-git-send-email-robert@sixbynine.org> Cc: Peter Zijlstra , David Airlie , linux-api@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Ingo Molnar , Paul Mackerras , Arnaldo Carvalho de Melo , Daniel Vetter Subject: [Intel-gfx] [RFC PATCH 02/11] perf: Add PERF_PMU_CAP_IS_DEVICE flag 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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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 The PERF_PMU_CAP_IS_DEVICE flag provides pmu drivers a way to declare that they only monitor device specific metrics and since they don't monitor any cpu metrics then perf should bypass any cpu centric security checks, as well as disallow cpu centric attributes. Signed-off-by: Robert Bragg --- include/linux/perf_event.h | 1 + kernel/events/core.c | 39 +++++++++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 2b62198..1af35b4 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -166,6 +166,7 @@ struct perf_event; * pmu::capabilities flags */ #define PERF_PMU_CAP_NO_INTERRUPT 0x01 +#define PERF_PMU_CAP_IS_DEVICE 0x02 /** * struct pmu - generic performance monitoring unit diff --git a/kernel/events/core.c b/kernel/events/core.c index 38c240c..7218b01 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3330,7 +3330,8 @@ find_get_context(struct pmu *pmu, struct task_struct *task, int cpu) if (!task) { /* Must be root to operate on a CPU event: */ - if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN)) + if (!(pmu->capabilities & PERF_PMU_CAP_IS_DEVICE) && + perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN)) return ERR_PTR(-EACCES); /* @@ -7475,11 +7476,6 @@ SYSCALL_DEFINE5(perf_event_open, if (err) return err; - if (!attr.exclude_kernel) { - if (perf_paranoid_kernel() && !capable(CAP_SYS_ADMIN)) - return -EACCES; - } - if (attr.freq) { if (attr.sample_freq > sysctl_perf_event_sample_rate) return -EINVAL; @@ -7538,6 +7534,37 @@ SYSCALL_DEFINE5(perf_event_open, goto err_cpus; } + if (event->pmu->capabilities & PERF_PMU_CAP_IS_DEVICE) { + + /* Don't allow cpu centric attributes... */ + if (event->attr.exclude_user || + event->attr.exclude_callchain_user || + event->attr.exclude_kernel || + event->attr.exclude_callchain_kernel || + event->attr.exclude_hv || + event->attr.exclude_idle || + event->attr.exclude_host || + event->attr.exclude_guest || + event->attr.mmap || + event->attr.comm || + event->attr.task) + return -EINVAL; + + if (attr.sample_type & + (PERF_SAMPLE_IP | + PERF_SAMPLE_TID | + PERF_SAMPLE_ADDR | + PERF_SAMPLE_CALLCHAIN | + PERF_SAMPLE_CPU | + PERF_SAMPLE_BRANCH_STACK | + PERF_SAMPLE_REGS_USER | + PERF_SAMPLE_STACK_USER)) + return -EINVAL; + } else if (!attr.exclude_kernel) { + if (perf_paranoid_kernel() && !capable(CAP_SYS_ADMIN)) + return -EACCES; + } + if (flags & PERF_FLAG_PID_CGROUP) { err = perf_cgroup_connect(pid, event, &attr, group_leader); if (err) {