Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3792983rwb; Tue, 16 Aug 2022 08:51:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR7OUaRiZNeQwpS7SnGCxT1zkCDDQRXOeqi5tl81cnkeKbKT8TDQrPMQiyvRtEYNfm2p75w+ X-Received: by 2002:a17:907:6e12:b0:730:bc12:82e3 with SMTP id sd18-20020a1709076e1200b00730bc1282e3mr14336477ejc.36.1660665108399; Tue, 16 Aug 2022 08:51:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660665108; cv=none; d=google.com; s=arc-20160816; b=eJIryJOPdVxtvX/RHO7z+6jH+DUHyk/NaTdk+YiAAfhJ/EYUXxmjfjXC0KLrwm5vt9 NYzOTfn3sLJBIO93JRIBHct/1YlIeB53CtJ1CbbyJ0Xxn4c/QhQMW2pXXC+H1jDwBBHd fXqMLp4TW3xABUXNQ+PGFeriTZ+WiCwmAB0/vKeFo7T0TEw/tDneyfbrx5pTNNyQt2r1 QhwN4BQI0NQ79USvDrZOM8Cp37SsQD6JWExuA/7xEFCa5DZARIjgJWgL303Y7dazNq0Q gmxekoWTHVTythOtdnWvFiuRrsNjunydq7retqXNcOqRb9z2ftztqNShvlPudZa/CeLW 7IJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=piB87MH4BnL8/sCpyrwH73dQ4LrdevKm9iNdDHRtn8Y=; b=oaTwP5vK8+7BGvPh8YDhtoHvBxjbjcfEHc8xbLF4MqXPOzhy5wQE9o7qsFTswqk7sO N0Tx1E5HMzxZf1Fetfk7HOyCsqFHz6XjLLB6hfu3zpR/Df0AqZZQ9T1c8cD2gt6NSP5T 7HIl5S0Gc3OF6Qfy4g+WWSyJQSoQRU3Ym3SjWG+wRljQ1ufS47RmWTLFKg+lvnpA2u5m IcCE8LHzLqQHcCR4JqqG1yAIDcdgXNJDjxgcTZdPxdVg54wcEQ9NOCZnpkRyjYbc09zH vTbfk/EVyumkOLbvbJBGJnJXS3DMgNEj/K3qyaxvHM6gehK1Z1/7/bJDvS7Vhk7a7NxC dSkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=bw0i6sQh; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw28-20020a1709066a1c00b00731417f551esi9737566ejc.283.2022.08.16.08.51.22; Tue, 16 Aug 2022 08:51:48 -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=@infradead.org header.s=casper.20170209 header.b=bw0i6sQh; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234420AbiHPPb4 (ORCPT + 99 others); Tue, 16 Aug 2022 11:31:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231589AbiHPPby (ORCPT ); Tue, 16 Aug 2022 11:31:54 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45E23DE5; Tue, 16 Aug 2022 08:31:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=piB87MH4BnL8/sCpyrwH73dQ4LrdevKm9iNdDHRtn8Y=; b=bw0i6sQhn+gqtiCOs5StixYStC CpXdFygGFVg81kotcMz0zpZfp1orva5SUyaaSpE/9SgPn/iMiE2RIqQDnb3218YiID1zFa1Asbcjd N99U2xyH3JkgeGDKK3jndKfTxtqQt6NFQcfZZldLdXYxSMTPp+6MdVLXi85kXUxV1xIQCAlIHPoa9 Uf8XGn8ayjr3g7bE9+tMRVvRzbmJ0/NygNTGj6DPo+SodWqXVALg5vct8el1pMe345NMCBYcogyFA gYS2f0mH/lsidFU/IlkEwqi0o8JBiv0PaC/dBipLFFM/NZLTveRIySXHqPQewh0ruP3OYm8/mXH3j KyqlAjnw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=worktop.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNyXR-00756X-AE; Tue, 16 Aug 2022 15:31:29 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 2E882980120; Tue, 16 Aug 2022 17:31:27 +0200 (CEST) Date: Tue, 16 Aug 2022 17:31:27 +0200 From: Peter Zijlstra To: Mark Rutland Cc: Yang Jihong , rostedt@goodmis.org, mingo@redhat.com, acme@kernel.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: Re: [PATCH v3] perf/core: Fix reentry problem in perf_output_read_group Message-ID: References: <20220816091103.257702-1-yangjihong1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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_NONE,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 On Tue, Aug 16, 2022 at 03:54:19PM +0100, Mark Rutland wrote: > > diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h > > index ee8b9ecdc03b..d4d53b9ba71e 100644 > > --- a/include/linux/perf_event.h > > +++ b/include/linux/perf_event.h > > @@ -631,7 +631,12 @@ struct pmu_event_list { > > struct list_head list; > > }; > > > > +/* > > + * Iterating the sibling list requires this list to be stable; by ensuring IRQs > > + * are disabled IPIs from perf_{install_in,remove_from}_context() are held off. > > + */ > > #define for_each_sibling_event(sibling, event) \ > > + lockdep_assert_irqs_disabled(); \ > > if ((event)->group_leader == (event)) \ > > list_for_each_entry((sibling), &(event)->sibling_list, sibling_list) > > > > I had a go with v6.0-rc1 and Vince's perf fuzzer immediately triggered a bunch > of cases (dump below). > > I had thought holding the context mutex protected some of these cases, even > with IRQs unmasked? Ah yes.. duh. How's this then? diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index ee8b9ecdc03b..4d9cf508c510 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -631,7 +631,21 @@ struct pmu_event_list { struct list_head list; }; +#ifdef CONFIG_LOCKDEP +#define LOCKDEP_ASSERT_EVENT_CTX(event) \ + WARN_ON_ONCE(__lockdep_enabled && \ + (this_cpu_read(hardirqs_enabled) || \ + lockdep_is_held(&(event)->ctx->mutex) != LOCK_STATE_HELD)) +#else +#define LOCKDEP_ASSERT_EVENT_CTX(event) +#endif + +/* + * Iterating the sibling list requires this list to be stable; by ensuring IRQs + * are disabled IPIs from perf_{install_in,remove_from}_context() are held off. + */ #define for_each_sibling_event(sibling, event) \ + LOCKDEP_ASSERT_EVENT_CTX(event); \ if ((event)->group_leader == (event)) \ list_for_each_entry((sibling), &(event)->sibling_list, sibling_list)