public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Mark Rutland <mark.rutland@arm.com>
Cc: Yang Jihong <yangjihong1@huawei.com>,
	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
Date: Tue, 16 Aug 2022 17:31:27 +0200	[thread overview]
Message-ID: <Yvu4TyFmeOd/rJ8t@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <Yvuvm7Onw3pmB9Z6@FVFF77S0Q05N>

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)
 

  reply	other threads:[~2022-08-16 15:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-16  9:11 [PATCH v3] perf/core: Fix reentry problem in perf_output_read_group Yang Jihong
2022-08-16 14:13 ` Peter Zijlstra
2022-08-16 14:54   ` Mark Rutland
2022-08-16 15:31     ` Peter Zijlstra [this message]
2022-08-16 16:39       ` Mark Rutland
2022-08-16 16:45         ` Mark Rutland
2022-08-17  7:23           ` Peter Zijlstra
2022-10-05 11:26         ` [tip: perf/core] perf: Fix lockdep_assert_event_ctx() tip-bot2 for Peter Zijlstra
2022-08-17  3:18   ` [PATCH v3] perf/core: Fix reentry problem in perf_output_read_group Yang Jihong
2022-08-18  2:23   ` Yang Jihong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yvu4TyFmeOd/rJ8t@worktop.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=yangjihong1@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox