Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4113859rwb; Tue, 6 Sep 2022 02:46:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR5hav55Jfvrc7TxZTAqvFynX9to0OMAZea+cWgWlWQdquICUqhfrjjGovCB7k+k30WRRqFJ X-Received: by 2002:a17:907:2bf7:b0:730:996d:5e8d with SMTP id gv55-20020a1709072bf700b00730996d5e8dmr39949625ejc.382.1662457565760; Tue, 06 Sep 2022 02:46:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662457565; cv=none; d=google.com; s=arc-20160816; b=qFjbztjcNxiBXqWxGOA5EAD+2ubxy2K04dKIsb8NdEnnj1hAQp3zKl2RsyVBSOhmq3 ED08igbZjV+T3JVIFyz1RHqVAMR+zyVs5txgCn7yyeUm9XeM6qQzVgxu+iL3ccXFE6nk aeubKEQS4GeMaY7YsA/CDYx5wkqJkhJW8sQ3CAIGWVZG0VRGHa3tr3JitAXZ7TA/3ABH OOByS4MGZyE5unjUgnBNhaLFtuxtJMadertX1hu2xu9mWPgFreLt+GFhLXIOY0/nN3K5 nwzmVezzVlVbsPIgav/0yrE0dJLjqhy575+E38klKvoQLW8vGH8rD3fYr1PibSw9op/T Utbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=yk/M/Btz3UQ+D2dDlDmoWwKldQ/Q384INUORtAdcm10=; b=XGUCls+ceNyP3UX2hWdjrRF/AAm8u3fG/3VY67dKzDHF2aDWXUR0ydq9Ei2/f8oXNB 2wwFBfYuRFcN5PmXjGom8qmwt+kwAW2IjdSVKj4EJt2+EEkmLzZHuDmfl5JFwUgEDKW5 ptSNa7HD0LhK1bNsC1NQ9CZ+bNTzVxLqrzg+bte3drioV9LkGU8u8Mrlav6SbYzGsvxs qmIrPrP7gwV2AD4EcGskSO6P5DGu9scljW818KLvc8YCKpJVtvinkq1BaZcLXicsw8En LyXeCuVB26zdA4cAXV7rBKaD1sdet2jQEpPR+R4ZrBqGDeW9ksTmStGNg874vWuUQSCE L+qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=rS3oSWJG; dkim=neutral (no key) header.i=@linutronix.de; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nc6-20020a1709071c0600b0073d95653bccsi10778474ejc.641.2022.09.06.02.45.39; Tue, 06 Sep 2022 02:46:05 -0700 (PDT) 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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=rS3oSWJG; dkim=neutral (no key) header.i=@linutronix.de; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239465AbiIFJmH (ORCPT + 99 others); Tue, 6 Sep 2022 05:42:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239357AbiIFJlj (ORCPT ); Tue, 6 Sep 2022 05:41:39 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B3B47548F; Tue, 6 Sep 2022 02:41:38 -0700 (PDT) Date: Tue, 06 Sep 2022 09:41:35 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1662457296; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yk/M/Btz3UQ+D2dDlDmoWwKldQ/Q384INUORtAdcm10=; b=rS3oSWJG4A+hvFYJt+7De1/DH0VuIQPCskHtTPhabpXQ9YcU0BJNybbDh1pAxLAdgEKUnB oHKxgDeXv9o829GgibzjVzBZgoVm8qBZ7sbTwk6tYmNtTzsZWbSINYTf06Zdv3qn6kad99 XXlM6LmSPTXa7ONVSU6TMfFHLYEaE3op1CmW70d5rUogf3cmAb7/0RmhNA6Y40GfQlzpSN WQuApL6YGHyWTWeqeoj+2G9vgh4GqqWBI+2vpnJv9qVdvhD3c9XdUrLdWTecdOPbqhSxRb XJbpOAtUk+jYQhlUJMOjXCL0/FaNJ8QNmobeb384EgdLCCTk2jUXRKTeChFfGw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1662457296; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yk/M/Btz3UQ+D2dDlDmoWwKldQ/Q384INUORtAdcm10=; b=+RTQU6VB/fNDCUHScCx/qs0jS2OMGG4fuP9wp7cAUIBe0jAxs3zA5o7cQPrTSCem4le7Zo ce4JKt7ckeUvBBBw== From: "tip-bot2 for Yang Jihong" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/urgent] perf/core: Fix reentry problem in perf_output_read_group() Cc: Yang Jihong , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220902082918.179248-1-yangjihong1@huawei.com> References: <20220902082918.179248-1-yangjihong1@huawei.com> MIME-Version: 1.0 Message-ID: <166245729557.401.10270808744010825515.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 The following commit has been merged into the perf/urgent branch of tip: Commit-ID: 6b959ba22d34ca793ffdb15b5715457c78e38b1a Gitweb: https://git.kernel.org/tip/6b959ba22d34ca793ffdb15b5715457c78e38b1a Author: Yang Jihong AuthorDate: Fri, 02 Sep 2022 16:29:18 +08:00 Committer: Peter Zijlstra CommitterDate: Tue, 06 Sep 2022 11:33:00 +02:00 perf/core: Fix reentry problem in perf_output_read_group() perf_output_read_group may respond to IPI request of other cores and invoke __perf_install_in_context function. As a result, hwc configuration is modified. causing inconsistency and unexpected consequences. Interrupts are not disabled when perf_output_read_group reads PMU counter. In this case, IPI request may be received from other cores. As a result, PMU configuration is modified and an error occurs when reading PMU counter: CPU0 CPU1 __se_sys_perf_event_open perf_install_in_context perf_output_read_group smp_call_function_single for_each_sibling_event(sub, leader) { generic_exec_single if ((sub != event) && remote_function (sub->state == PERF_EVENT_STATE_ACTIVE)) | <----RAISE IPI-----+ __perf_install_in_context ctx_resched event_sched_out armpmu_del ... hwc->idx = -1; // event->hwc.idx is set to -1 ... sub->pmu->read(sub); armpmu_read armv8pmu_read_counter armv8pmu_read_hw_counter int idx = event->hw.idx; // idx = -1 u64 val = armv8pmu_read_evcntr(idx); u32 counter = ARMV8_IDX_TO_COUNTER(idx); // invalid counter = 30 read_pmevcntrn(counter) // undefined instruction Signed-off-by: Yang Jihong Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20220902082918.179248-1-yangjihong1@huawei.com --- kernel/events/core.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/events/core.c b/kernel/events/core.c index 2621fd2..ff4bffc 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6893,9 +6893,16 @@ static void perf_output_read_group(struct perf_output_handle *handle, { struct perf_event *leader = event->group_leader, *sub; u64 read_format = event->attr.read_format; + unsigned long flags; u64 values[6]; int n = 0; + /* + * Disabling interrupts avoids all counter scheduling + * (context switches, timer based rotation and IPIs). + */ + local_irq_save(flags); + values[n++] = 1 + leader->nr_siblings; if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) @@ -6931,6 +6938,8 @@ static void perf_output_read_group(struct perf_output_handle *handle, __output_copy(handle, values, n * sizeof(u64)); } + + local_irq_restore(flags); } #define PERF_FORMAT_TOTAL_TIMES (PERF_FORMAT_TOTAL_TIME_ENABLED|\