perf/core: remove a meaningless pair of rcu_read_{,un}lock()
PATCH 1/1 perf/core: remove a meaningless pair of rcu_read_{,un}lock()
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.
--- kernel/events/core.c | 2 -- 1 file changed, 2 deletions(-)
kernel/events/core.c +0 -2
@@ -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 ))
Signature · 1 line
2.32.0
Peter Zijlstra
maintainerQuoted 17 lines · Yanfei Xu
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" andperf_pmu_unregister()delete it after callingsynchronize_srcu.Signed-off-by Yanfei Xu <[email protected]>--- kernel/events/core.c | 2 -- 1 file changed, 2 deletions(-)kernel/events/core.c +0
-0
kernel/events/core.c static struct pmu *perf_init_event(struct perf_event *event) · line 11301
Quoted 6 lines
kernel/events/core.c +0
-2@@ -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.
Quoted 33 lines
-----Original Message-----
From: Peter Zijlstra <[email protected]>
Sent: Wednesday, June 8, 2022 5:43 PM
To: Xu, Yanfei <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] perf/core: remove a meaningless pair of rcu_read_{,un}lock()kernel/events/core.c static struct pmu *perf_init_event(struct
Quoted 17 lines · Yanfei Xu
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" andperf_pmu_unregister()delete it after callingsynchronize_srcu.Signed-off-by Yanfei Xu <[email protected]>--- kernel/events/core.c | 2 -- 1 file changed, 2 deletions(-)kernel/events/core.c index renamed from kernel/events/core.c +0
-0
950b25c3f210..36b0df6feab4100644kernel/events/core.c +0
-0@@ -11296,9 +11296,7 @@ static struct pmu *perf_init_event(struct
perf_event*event)Quoted 2 lines
kernel/events/core.c +0
-0}
Quoted 8 lines
kernel/events/core.c static struct pmu *perf_init_event(struct perf_event *event) · line 11301
Quoted 4 lines
kernel/events/core.c +0
-2again: -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