From patchwork Thu Feb 16 14:12:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 58098 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2388:b0:96:219d:e725 with SMTP id i8csp548652dyf; Thu, 16 Feb 2023 06:14:19 -0800 (PST) X-Google-Smtp-Source: AK7set9Q0Yin9RXLsQshTov+t9yjM1N/udxaf4wGGlj00zop3G+veVtbGoThMl5N1F7sY29bCsA8 X-Received: by 2002:a05:6a20:a020:b0:bd:ce7:22d2 with SMTP id p32-20020a056a20a02000b000bd0ce722d2mr5675810pzj.25.1676556859431; Thu, 16 Feb 2023 06:14:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676556859; cv=none; d=google.com; s=arc-20160816; b=SdPWQCA/eNPwzccnDVKNu4ZRW5NLQ0Kuo/j5VHz97cJBHpvdSpks40o7EQZwQepD+Y eQK/4fX4WNdcmbI3SIxUhG23aF3CH8N12AoUbxvgPiG9AMl3t7SHwWCWABfoTDdg/wuv 2O2FuZZdLm4ativhTTLfgfzd+9PTIqZNophaQV+yNGM0iOhO5RBeCkMaPWrbtekAQFBJ inQGKwmQ0pdcsoFrXkALwSAdRsdFlF+vcvlpsJL1/vuRhoaTaKmuB0J7OVpG39YFcM7U /AhoIoNZUVDtWRqU9QulGUlCkoOl6Ois4G5bZV9Oj5ntH59KYMNeVQTDR+xsJC9dKKfP x+qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=6AnbsUqvia9iqv6iQhEJcNWJ20MaMEePInKnN+DHcis=; b=mTb7LYFoJvPhkDYXMy00LooSxuBDRrggoGYPhRG9oDRjnD4LsbXRqL6fIraA6tmgox /dgl4TsER+k4A6C6WxJiBzpC2ne2l9piqzw1IBFFE/1aPoXehpES1H0pTMgoKNZzdox9 VT61hQ7Z7No4Ey4QWWCcSmFfMSvOIGHwiXGoRjw2+YQZi6OC2S+3/1TJ1CPeloDIogaB +iKJht9uaAazDpKZsjHAaN6yMRv1QkcswySbGPAhDgIofxiTJauhwncNg7+gvrsEDH6m eGyDPeTUDlx2q2HmlCAE2e1CmhtAU40eWyqZYVNql1RVsg0GHuBcFP2AsCo41drg9RkY Es4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h27-20020a63575b000000b004fbce695208si1568063pgm.619.2023.02.16.06.14.05; Thu, 16 Feb 2023 06:14:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229984AbjBPOND (ORCPT + 99 others); Thu, 16 Feb 2023 09:13:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229822AbjBPOMw (ORCPT ); Thu, 16 Feb 2023 09:12:52 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 19A77976D for ; Thu, 16 Feb 2023 06:12:50 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5D2AF1682; Thu, 16 Feb 2023 06:13:32 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 51DCA3F703; Thu, 16 Feb 2023 06:12:48 -0800 (PST) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: asahi@lists.linux.dev, ecurtin@redhat.com, j@jannau.net, lina@asahilina.net, linux-kernel@vger.kernel.org, mark.rutland@arm.com, peterz@infradead.org, ravi.bangoria@amd.com, will@kernel.org Subject: [PATCH 2/2] arm64: perf: reject CHAIN events at creation time Date: Thu, 16 Feb 2023 14:12:39 +0000 Message-Id: <20230216141240.3833272-3-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230216141240.3833272-1-mark.rutland@arm.com> References: <20230216141240.3833272-1-mark.rutland@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757997285792193928?= X-GMAIL-MSGID: =?utf-8?q?1757997285792193928?= Currently it's possible for a user to open CHAIN events arbitrarily, which we previously tried to rule out in commit: ca2b497253ad01c8 ("arm64: perf: Reject stand-alone CHAIN events for PMUv3") Which allowed the events to be opened, but prevented them from being scheduled by by using an arm_pmu::filter_match hook to reject the relevant events. The CHAIN event filtering in the arm_pmu::filter_match hook was silently removed in commit: bd27568117664b8b ("perf: Rewrite core context handling") As a result, it's now possible for users to open CHAIN events, and for these to be installed arbitrarily. Fix this by rejecting CHAIN events at creation time. This avoids the creation of events which will never count, and doesn't require using the dynamic filtering. Attempting to open a CHAIN event (0x1e) will now be rejected: | # ./perf stat -e armv8_pmuv3/config=0x1e/ ls | perf | | Performance counter stats for 'ls': | | armv8_pmuv3/config=0x1e/ | | 0.002197470 seconds time elapsed | | 0.000000000 seconds user | 0.002294000 seconds sys Other events (e.g. CPU_CYCLES / 0x11) will open as usual: | # ./perf stat -e armv8_pmuv3/config=0x11/ ls | perf | | Performance counter stats for 'ls': | | 2538761 armv8_pmuv3/config=0x11/ | | 0.002227330 seconds time elapsed | | 0.002369000 seconds user | 0.000000000 seconds sys Fixes: bd27568117664b8b ("perf: Rewrite core context handling") Signed-off-by: Mark Rutland Cc: Peter Zijlstra Cc: Ravi Bangoria Cc: Will Deacon --- arch/arm64/kernel/perf_event.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c index 3e43538f6b72..dde06c0f97f3 100644 --- a/arch/arm64/kernel/perf_event.c +++ b/arch/arm64/kernel/perf_event.c @@ -1063,6 +1063,14 @@ static int __armv8_pmuv3_map_event(struct perf_event *event, &armv8_pmuv3_perf_cache_map, ARMV8_PMU_EVTYPE_EVENT); + /* + * CHAIN events only work when paired with an adjacent counter, and it + * never makes sense for a user to open one in isolation, as they'll be + * rotated arbitrarily. + */ + if (hw_event_id == ARMV8_PMUV3_PERFCTR_CHAIN) + return -EINVAL; + if (armv8pmu_event_is_64bit(event)) event->hw.flags |= ARMPMU_EVT_64BIT;