From patchwork Tue Nov 21 15:55:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kim Phillips X-Patchwork-Id: 10068537 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 1ABE06038F for ; Tue, 21 Nov 2017 15:55:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B7DA297CF for ; Tue, 21 Nov 2017 15:55:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3409297D0; Tue, 21 Nov 2017 15:55:33 +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.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 638C6297A0 for ; Tue, 21 Nov 2017 15:55:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Mime-Version:Message-Id:Subject:To:From :Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=sENDWhTzpFhnohG43hxrbBKwZaltCnAWuDzExwF+idw=; b=SC194pwVHqjD8E dge0/s+3FltQVF5UABIpOAAmpfIB6mVIQjIJEx9inQSKZs9reKcF5i++1IMDpvXk6Wv0Iz+qhmRrB qOEBt9NabRdeb/fPjndFaCnqWWFtO3RVmPY5260EwK6w7N7byFyXHsVZ/cz5FLmPPRjEx2yS2827/ zA6vgL2V2Arr1C+OXwiaIrhQJD77Dk/AZXeQ0ukKTB9gEyRrFMdvJQ2LcpOkSjTjbPHByHtJzenKc MXOYPYaL544Hae/xh4ZUOkW4vCL4X1ev9sRTo2y/XIWiftoXbnO2oW+8SKZtHYw0gc0GcmdxE1hQX X9J7uHM62le8bwXDENww==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eHAtX-0003CW-Eu; Tue, 21 Nov 2017 15:55:31 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eHAtR-0002Xs-SX for linux-arm-kernel@lists.infradead.org; Tue, 21 Nov 2017 15:55:29 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A22C580D; Tue, 21 Nov 2017 07:55:05 -0800 (PST) Received: from dupont (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A2C583F246; Tue, 21 Nov 2017 07:55:04 -0800 (PST) Date: Tue, 21 Nov 2017 09:55:03 -0600 From: Kim Phillips To: Will Deacon , Mark Rutland , Arnaldo Carvalho de Melo Subject: [PATCH] perf: arm_spe: add user error messaging Message-Id: <20171121095503.965fba61d90fbf5fa1f81734@arm.com> Organization: Arm X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171121_075525_972814_C43C3EF3 X-CRM114-Status: GOOD ( 16.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robh@kernel.org, Andi Kleen , mathieu.poirier@linaro.org, pawel.moll@arm.com, suzuki.poulose@arm.com, marc.zyngier@arm.com, linux-kernel@vger.kernel.org, Adrian Hunter , alexander.shishkin@linux.intel.com, peterz@infradead.org, mingo@redhat.com, Jiri Olsa , tglx@linutronix.de, Wang Nan , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Make the SPE PMU driver easier to use by elaborating SPE-specific errors at perf record event initialization time. Example #1: Trouble setting the sampling period: BEFORE THIS PATCH: $ ./perf record -e arm_spe_0/ts_enable=1/ -F 30 true Error: The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (arm_spe_0/ts_enable=1/). /bin/dmesg may provide additional information. No CONFIG_PERF_EVENTS=y kernel support configured? with nothing in dmesg. AFTER: like BEFORE above, but this text is in dmesg: arm_spe_pmu spe-pmu@0: Sample period must be specified with --count The user takes the corrective action and specifies -c instead of -F, which succeeds. Example #2: Trouble specifying CPU vs. SPE domains: BEFORE: $ ./perf record -e arm_spe_0/ts_enable=1/ -C 3-7 true Error: The arm_spe_0/ts_enable=1/ event is not supported. AFTER: like BEFORE above, but this text is in dmesg: arm_spe_pmu spe-pmu@0: Target CPU list includes unsupported CPUs Example #3: Non-privileged user tries to obtain physical address (pa) data on a non-paranoid system: BEFORE: $ ./perf record -e arm_spe_0/ts_enable=1,pa_enable=1/ -C 0 true Error: You may not have permission to collect stats. Consider tweaking /proc/sys/kernel/perf_event_paranoid, which controls use of the performance events system by unprivileged users (without CAP_SYS_ADMIN). The current value is -1: -1: Allow use of (almost) all events by all users Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK >= 0: Disallow ftrace function tracepoint by users without CAP_SYS_ADMIN Disallow raw tracepoint access by users without CAP_SYS_ADMIN >= 1: Disallow CPU event access by users without CAP_SYS_ADMIN >= 2: Disallow kernel profiling by users without CAP_SYS_ADMIN To make this setting permanent, edit /etc/sysctl.conf too, e.g.: kernel.perf_event_paranoid = -1 AFTER: like BEFORE above, but this text is in dmesg: arm_spe_pmu spe-pmu@0: Admin privilege needed for physical addr, time and/or context capture Example #4: Trying to exclude idle profiling: BEFORE: $ sudo ./perf record -e arm_spe_0/ts_enable=1,pa_enable=1/I -c 1 true Error: PMU Hardware doesn't support sampling/overflow-interrupts. AFTER: like BEFORE above, but this text is in dmesg: arm_spe_pmu spe-pmu@0: Cannot exclude profiling when idle Signed-off-by: Kim Phillips --- I've tried to help solve the PMU error messaging problem various ways from userspace [1], but it hasn't been resolved [2] by the time the SPE driver was pushed upstream last week (now commit d5d9696b0380). For these reasons, please consider applying this patch for the interim. Thanks! [1] latest SPE incarnation: https://www.spinics.net/lists/arm-kernel/msg614362.html [2] -EINVAL when using CCN but not from the driver itself: https://www.spinics.net/lists/arm-kernel/msg614025.html drivers/perf/arm_spe_pmu.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c index 8ce262fc2561..6887eb45b401 100644 --- a/drivers/perf/arm_spe_pmu.c +++ b/drivers/perf/arm_spe_pmu.c @@ -659,20 +659,27 @@ static int arm_spe_pmu_event_init(struct perf_event *event) u64 reg; struct perf_event_attr *attr = &event->attr; struct arm_spe_pmu *spe_pmu = to_spe_pmu(event->pmu); + struct device *dev = &spe_pmu->pdev->dev; /* This is, of course, deeply driver-specific */ if (attr->type != event->pmu->type) return -ENOENT; if (event->cpu >= 0 && - !cpumask_test_cpu(event->cpu, &spe_pmu->supported_cpus)) + !cpumask_test_cpu(event->cpu, &spe_pmu->supported_cpus)) { + dev_err_ratelimited(dev, "Target CPU list includes unsupported CPUs\n"); return -ENOENT; + } - if (arm_spe_event_to_pmsevfr(event) & SYS_PMSEVFR_EL1_RES0) + if (arm_spe_event_to_pmsevfr(event) & SYS_PMSEVFR_EL1_RES0) { + dev_err_ratelimited(dev, "Specified event filter is not supported\n"); return -EOPNOTSUPP; + } - if (attr->exclude_idle) + if (attr->exclude_idle) { + dev_err_ratelimited(dev, "Cannot exclude profiling when idle\n"); return -EOPNOTSUPP; + } /* * Feedback-directed frequency throttling doesn't work when we @@ -681,28 +688,38 @@ static int arm_spe_pmu_event_init(struct perf_event *event) * count to reflect that. Instead, just force the user to specify * a sample period. */ - if (attr->freq) + if (attr->freq) { + dev_err_ratelimited(dev, "Sample period must be specified with --count\n"); return -EINVAL; + } reg = arm_spe_event_to_pmsfcr(event); if ((reg & BIT(SYS_PMSFCR_EL1_FE_SHIFT)) && - !(spe_pmu->features & SPE_PMU_FEAT_FILT_EVT)) + !(spe_pmu->features & SPE_PMU_FEAT_FILT_EVT)) { + dev_err_ratelimited(dev, "Unsupported EVT filter\n"); return -EOPNOTSUPP; + } if ((reg & BIT(SYS_PMSFCR_EL1_FT_SHIFT)) && - !(spe_pmu->features & SPE_PMU_FEAT_FILT_TYP)) + !(spe_pmu->features & SPE_PMU_FEAT_FILT_TYP)) { + dev_err_ratelimited(dev, "Unsupported TYP filter\n"); return -EOPNOTSUPP; + } if ((reg & BIT(SYS_PMSFCR_EL1_FL_SHIFT)) && - !(spe_pmu->features & SPE_PMU_FEAT_FILT_LAT)) + !(spe_pmu->features & SPE_PMU_FEAT_FILT_LAT)) { + dev_err_ratelimited(dev, "Unsupported LAT filter\n"); return -EOPNOTSUPP; + } reg = arm_spe_event_to_pmscr(event); if (!capable(CAP_SYS_ADMIN) && (reg & (BIT(SYS_PMSCR_EL1_PA_SHIFT) | BIT(SYS_PMSCR_EL1_CX_SHIFT) | - BIT(SYS_PMSCR_EL1_PCT_SHIFT)))) + BIT(SYS_PMSCR_EL1_PCT_SHIFT)))) { + dev_err_ratelimited(dev, "Admin privilege needed for physical addr, time and/or context capture\n"); return -EACCES; + } return 0; }