Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3893680rwb; Tue, 16 Aug 2022 10:27:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR4JjeUXNw0aT8mQYSiCNacUa3J/4ehnsVx+Sm/pOCMOJoIBIAL9mOryB/fvTspFATrRxAlQ X-Received: by 2002:a63:fb4a:0:b0:429:8605:6ebf with SMTP id w10-20020a63fb4a000000b0042986056ebfmr6017818pgj.225.1660670862655; Tue, 16 Aug 2022 10:27:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660670862; cv=none; d=google.com; s=arc-20160816; b=GlDmEbbsFrk8HkXPl8zyDN1aBbeu0ri4pbT4BW/0ONVFSpehuUyDLWU8g047CUrgcn 9p5coSGIvhPU/65d5QDRCsrIFXqsQtvgyuO5AmnNqKknLb1mfzGruZrGI8ZdxG6iRBV7 I0Eau2Fd925VlxqBdce3mY5pxFhiIEZCy4tBMEnPGM5xV+pljtvNyn2sFhDLdEwZhN8v MTVbdsE2rG67yfVApbIEqslwmiN9IuShc51BFvvNQngmcpHpEBVkzBCtu5PqM58Oz6yQ jV8jk92SChG33HBjrUxBzf3rqz99vmUxmBQlKWNhnv4XDMilz0KJn7HvUK/UksEzm2fL IMRw== 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; bh=r7Vj4cFVVTfz4plIV9FhgrXDQ+x21/fRkObtjPP+7bY=; b=XZDkQ4L5eBWVgA0s07m3XPE0urzzxTIRjPbJEHf9l9ISfflT/B6+09xhvTpJRABu5X kWR5QsciP+S6aLI+BQumN6nj2wuwYGSd/d+88h9BotYlAH4sR5amgVZzvrFdjOFf0epT 6kNG2rXdKkbS07SSUGPoGk7XBDVeoqf5Ih7lj3fsgIoiH3pPv/Ear4BHxs5D/6okiTN6 LcUSfSq2vWm8XzS5PmVQ72DQTXBIVaCkPhdBVQZyJgYVfHeutJiYfxhSZJdGVXv89yUu Bl6vjEqsUOJ7nEQ1Pkw19v+dYnJnb14Pu2pWynSdbf03zMiQFRamwbJtjhlzRoUAlbva OzOA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e33-20020a631e21000000b0040d275d3fcesi14177516pge.661.2022.08.16.10.27.31; Tue, 16 Aug 2022 10:27:42 -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; 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 S236575AbiHPQkH (ORCPT + 99 others); Tue, 16 Aug 2022 12:40:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235798AbiHPQkB (ORCPT ); Tue, 16 Aug 2022 12:40:01 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EE6137F10E; Tue, 16 Aug 2022 09:39:59 -0700 (PDT) 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 4D446106F; Tue, 16 Aug 2022 09:40:00 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.44.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C99633F67D; Tue, 16 Aug 2022 09:39:57 -0700 (PDT) Date: Tue, 16 Aug 2022 17:39:54 +0100 From: Mark Rutland To: Peter Zijlstra 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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, 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 05:31:27PM +0200, Peter Zijlstra wrote: > 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)) Uh, should that `||` be `&&`, or am I missing the plot? This'll warn if IRQs are enabled regardless of whether the mutex is held. Thanks, Mark. > +#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) >