All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf/core: remove a meaningless pair of rcu_read_{,un}lock()
@ 2022-06-08  9:09 Yanfei Xu
  2022-06-08  9:43 ` Peter Zijlstra
  0 siblings, 1 reply; 3+ messages in thread
From: Yanfei Xu @ 2022-06-08  9:09 UTC (permalink / raw)
  To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa, namhyung
  Cc: linux-kernel, linux-perf-users

Per the codes, this pair of rcu_read_{,un}lock() protects nothing.
Let's remove it.

Further, the variable "pmu" is safe as it is in the SRCU read-side
critical scope of "pmus_srcu" and perf_pmu_unregister() delete it
after calling synchronize_srcu.

Signed-off-by: Yanfei Xu <yanfei.xu@intel.com>
---
 kernel/events/core.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 950b25c3f210..36b0df6feab4 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -11296,9 +11296,7 @@ static struct pmu *perf_init_event(struct perf_event *event)
 	}
 
 again:
-	rcu_read_lock();
 	pmu = idr_find(&pmu_idr, type);
-	rcu_read_unlock();
 	if (pmu) {
 		if (event->attr.type != type && type != PERF_TYPE_RAW &&
 		    !(pmu->capabilities & PERF_PMU_CAP_EXTENDED_HW_TYPE))
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf/core: remove a meaningless pair of rcu_read_{,un}lock()
  2022-06-08  9:09 [PATCH] perf/core: remove a meaningless pair of rcu_read_{,un}lock() Yanfei Xu
@ 2022-06-08  9:43 ` Peter Zijlstra
  2022-06-08 15:46   ` Xu, Yanfei
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2022-06-08  9:43 UTC (permalink / raw)
  To: Yanfei Xu
  Cc: mingo, acme, mark.rutland, alexander.shishkin, jolsa, namhyung,
	linux-kernel, linux-perf-users

On Wed, Jun 08, 2022 at 05:09:38PM +0800, Yanfei Xu wrote:
> Per the codes, this pair of rcu_read_{,un}lock() protects nothing.
> Let's remove it.
> 
> Further, the variable "pmu" is safe as it is in the SRCU read-side
> critical scope of "pmus_srcu" and perf_pmu_unregister() delete it
> after calling synchronize_srcu.
> 
> Signed-off-by: Yanfei Xu <yanfei.xu@intel.com>
> ---
>  kernel/events/core.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 950b25c3f210..36b0df6feab4 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -11296,9 +11296,7 @@ static struct pmu *perf_init_event(struct perf_event *event)
>  	}
>  
>  again:
> -	rcu_read_lock();
>  	pmu = idr_find(&pmu_idr, type);
> -	rcu_read_unlock();

You're mistaken, this is required for the radix tree internal nodes.
Without it we can't safely traverse the radix tree without full
serialization against the modifiers.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH] perf/core: remove a meaningless pair of rcu_read_{,un}lock()
  2022-06-08  9:43 ` Peter Zijlstra
@ 2022-06-08 15:46   ` Xu, Yanfei
  0 siblings, 0 replies; 3+ messages in thread
From: Xu, Yanfei @ 2022-06-08 15:46 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: mingo, acme, mark.rutland, alexander.shishkin, jolsa, namhyung,
	linux-kernel, linux-perf-users



> -----Original Message-----
> From: Peter Zijlstra <peterz@infradead.org>
> Sent: Wednesday, June 8, 2022 5:43 PM
> To: Xu, Yanfei <yanfei.xu@intel.com>
> Cc: mingo@redhat.com; acme@kernel.org; mark.rutland@arm.com;
> 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] perf/core: remove a meaningless pair of
> rcu_read_{,un}lock()
> 
> On Wed, Jun 08, 2022 at 05:09:38PM +0800, Yanfei Xu wrote:
> > Per the codes, this pair of rcu_read_{,un}lock() protects nothing.
> > Let's remove it.
> >
> > Further, the variable "pmu" is safe as it is in the SRCU read-side
> > critical scope of "pmus_srcu" and perf_pmu_unregister() delete it
> > after calling synchronize_srcu.
> >
> > Signed-off-by: Yanfei Xu <yanfei.xu@intel.com>
> > ---
> >  kernel/events/core.c | 2 --
> >  1 file changed, 2 deletions(-)
> >
> > diff --git a/kernel/events/core.c b/kernel/events/core.c index
> > 950b25c3f210..36b0df6feab4 100644
> > --- a/kernel/events/core.c
> > +++ b/kernel/events/core.c
> > @@ -11296,9 +11296,7 @@ static struct pmu *perf_init_event(struct
> perf_event *event)
> >  	}
> >
> >  again:
> > -	rcu_read_lock();
> >  	pmu = idr_find(&pmu_idr, type);
> > -	rcu_read_unlock();
> 
> You're mistaken, this is required for the radix tree internal nodes.
> Without it we can't safely traverse the radix tree without full serialization
> against the modifiers.
Thanks your reminder! And after digging and learning these commits: f9c46d6ea5ce ("idr: make idr_find rcu-safe ") and 452a68d0ef34("KVM: hyperv: idr_find needs RCU protection "). Now I understand it.

Thanks,
Yanfei


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-08 15:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08  9:09 [PATCH] perf/core: remove a meaningless pair of rcu_read_{,un}lock() Yanfei Xu
2022-06-08  9:43 ` Peter Zijlstra
2022-06-08 15:46   ` Xu, Yanfei

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.