From patchwork Tue Feb 24 13:17:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 5872711 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8AC9CBF440 for ; Tue, 24 Feb 2015 13:22:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 92786201C8 for ; Tue, 24 Feb 2015 13:22:06 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E9F7D2018E for ; Tue, 24 Feb 2015 13:22:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YQFOY-0008H5-Nn; Tue, 24 Feb 2015 13:19:26 +0000 Received: from service87.mimecast.com ([91.220.42.44]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YQFNi-0007rE-6o for linux-arm-kernel@lists.infradead.org; Tue, 24 Feb 2015 13:18:36 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by service87.mimecast.com; Tue, 24 Feb 2015 13:18:08 +0000 Received: from e106634-lin.cambridge.arm.com ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 24 Feb 2015 13:18:06 +0000 From: "Suzuki K. Poulose" To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 4/4] arm-cci: Fix CCI PMU event validation Date: Tue, 24 Feb 2015 13:17:43 +0000 Message-Id: <1424783863-9894-5-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1424783863-9894-1-git-send-email-suzuki.poulose@arm.com> References: <1424783863-9894-1-git-send-email-suzuki.poulose@arm.com> X-OriginalArrivalTime: 24 Feb 2015 13:18:06.0803 (UTC) FILETIME=[53CA4230:01D05034] X-MC-Unique: 115022413180818401 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150224_051834_644320_2AA7B609 X-CRM114-Status: GOOD ( 10.43 ) X-Spam-Score: -2.3 (--) Cc: devicetree@vger.kernel.org, Lorenzo Pieralisi , Catalin Marinas , Pawel Moll , Arnd Bergmann , Bartlomiej Zolnierkiewicz , Will Deacon , Nicolas Pitre , Liviu Dudau , linux-kernel@vger.kernel.org, Olof Johansson , Kukjin Kim , Sudeep Holla , Abhilash Kesavan , "Suzuki K. Poulose" , Punit Agrawal X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 From: "Suzuki K. Poulose" We mask the event with the CCI_PMU_EVENT_MASK, before passing the config to pmu_validate_hw_event(), which causes extra bits to be ignored and qualifies an invalid event code as valid. e.g, $ perf stat -a -C 0 -e CCI_400/config=0x1ff,name=cycles/ sleep 1 Performance counter stats for 'system wide': 506951142 cycles 1.013879626 seconds time elapsed where, cycles has an event coding of 0xff. This patch also removes the unnecessary 'event' mask in pmu_write_register, since the config_base is set by the pmu code after the event is validated. Signed-off-by: Suzuki K. Poulose --- drivers/bus/arm-cci.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c index 7e330fe..b0ee582 100644 --- a/drivers/bus/arm-cci.c +++ b/drivers/bus/arm-cci.c @@ -191,11 +191,14 @@ static int pmu_is_valid_master_event(u8 ev_code) ev_code <= pmu->model->event_ranges[CCI_IF_MASTER].max; } -static int pmu_validate_hw_event(u8 hw_event) +static int pmu_validate_hw_event(u32 hw_event) { u8 ev_source = CCI_PMU_EVENT_SOURCE(hw_event); u8 ev_code = CCI_PMU_EVENT_CODE(hw_event); + if (hw_event & ~CCI_PMU_EVENT_MASK) + return -ENOENT; + switch (ev_source) { case CCI_PORT_S0: case CCI_PORT_S1: @@ -265,7 +268,6 @@ static void pmu_enable_counter(int idx) static void pmu_set_event(int idx, unsigned long event) { - event &= CCI_PMU_EVENT_MASK; pmu_write_register(event, idx, CCI_PMU_EVT_SEL); } @@ -282,7 +284,7 @@ static int pmu_get_event_idx(struct cci_pmu_hw_events *hw, struct perf_event *ev { struct cci_pmu *cci_pmu = to_cci_pmu(event->pmu); struct hw_perf_event *hw_event = &event->hw; - unsigned long cci_event = hw_event->config_base & CCI_PMU_EVENT_MASK; + unsigned long cci_event = hw_event->config_base; int idx; if (cci_event == CCI_PMU_CYCLES) { @@ -303,7 +305,7 @@ static int pmu_get_event_idx(struct cci_pmu_hw_events *hw, struct perf_event *ev static int pmu_map_event(struct perf_event *event) { int mapping; - u8 config = event->attr.config & CCI_PMU_EVENT_MASK; + u32 config = event->attr.config; if (event->attr.type < PERF_TYPE_MAX) return -ENOENT;