perf: Fix missing RCU reader protection in perf_event_clear_cpumask()
Subsystems (2)
PATCH 1/1 perf: Fix missing RCU reader protection in perf_event_clear_cpumask()
From: Kan Liang <[email protected]>
Running rcutorture scenario TREE05, the below warning is triggered.
[ 32.604594] WARNING: suspicious RCU usage
[ 32.605928] 6.11.0-rc5-00040-g4ba4f1afb6a9 #55238 Not tainted
[ 32.607812] -----------------------------
[ 32.609140] kernel/events/core.c:13946 RCU-list traversed in non-reader section!!
[ 32.611595] other info that might help us debug this:
[ 32.614247] rcu_scheduler_active = 2, debug_locks = 1
[ 32.616392] 3 locks held by cpuhp/4/35:
[ 32.617687] #0: ffffffffb666a650 (cpu_hotplug_lock){++++}-{0:0}, at: cpuhp_thread_fun+0x4e/0x200
[ 32.620563] #1: ffffffffb666cd20 (cpuhp_state-down){+.+.}-{0:0}, at: cpuhp_thread_fun+0x4e/0x200
[ 32.623412] #2: ffffffffb677c288 (pmus_lock){+.+.}-{3:3}, at: perf_event_exit_cpu_context+0x32/0x2f0In perf_event_clear_cpumask(), uses list_for_each_entry_rcu() without an obvious RCU read-side critical section.
Either pmus_srcu or pmus_lock is good enough to protect the pmus list. In the current context, pmus_lock is already held. The list_for_each_entry_rcu() is not required.
--- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
@@ -13912,7 +13912,7 @@ static void perf_event_clear_cpumask(unsigned int cpu) }/* migrate */ -list_for_each_entry_rcu (pmu, &pmus, entry,lockdep_is_held (&pmus_srcu)) { +list_for_each_entry (pmu, &pmus, entry) {if (pmu->scope ==PERF_PMU_SCOPE_NONE ||WARN_ON_ONCE (pmu->scope >=PERF_PMU_MAX_SCOPE ))continue ;
Signature · 1 line
2.38.1
Quoted 22 lines · On 2024-09-13 12:23 p.m., [email protected] wrote:
From: Kan Liang <[email protected]>
Running rcutorture scenario TREE05, the below warning is triggered.
[ 32.604594] WARNING: suspicious RCU usage [ 32.605928] 6.11.0-rc5-00040-g4ba4f1afb6a9 #55238 Not tainted [ 32.607812] ----------------------------- [ 32.609140] kernel/events/core.c:13946 RCU-list traversed in non-reader section!! [ 32.611595] other info that might help us debug this: [ 32.614247] rcu_scheduler_active = 2, debug_locks = 1 [ 32.616392] 3 locks held by cpuhp/4/35: [ 32.617687] #0: ffffffffb666a650 (cpu_hotplug_lock){++++}-{0:0}, at: cpuhp_thread_fun+0x4e/0x200 [ 32.620563] #1: ffffffffb666cd20 (cpuhp_state-down){+.+.}-{0:0}, at: cpuhp_thread_fun+0x4e/0x200 [ 32.623412] #2: ffffffffb677c288 (pmus_lock){+.+.}-{3:3}, at: perf_event_exit_cpu_context+0x32/0x2f0In
perf_event_clear_cpumask(), useslist_for_each_entry_rcu()without an obvious RCU read-side critical section.Either
pmus_srcuorpmus_lockis good enough to protect the pmus list. In the current context,pmus_lockis already held. Thelist_for_each_entry_rcu()is not required.
Quoted 6 lines
Fixes 4ba4f1afb6a9 ("perf: Generic hotplug support for a PMU with a scope")Reported-by Paul E. McKenney <[email protected]>Tested-by Paul E. McKenney <[email protected]>Reported-by kernel test robot <[email protected]>
Forgot to add the below tag, please fold it.
Thanks,
Kan
Quoted 18 lines
Signed-off-by Kan Liang <[email protected]>--- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/events/core.c +1
-1@@ -13912,7 +13912,7 @@ static void perf_event_clear_cpumask(unsigned int cpu) }/* migrate */ -list_for_each_entry_rcu (pmu, &pmus, entry,lockdep_is_held (&pmus_srcu)) { +list_for_each_entry (pmu, &pmus, entry) {if (pmu->scope ==PERF_PMU_SCOPE_NONE ||WARN_ON_ONCE (pmu->scope >=PERF_PMU_MAX_SCOPE ))continue ;
Paul E. McKenney
Tested-byQuoted 32 lines · Kan
Quoted 22 lines · On 2024-09-13 12:23 p.m., [email protected] wrote:
From: Kan Liang <[email protected]>
Running rcutorture scenario TREE05, the below warning is triggered.
[ 32.604594] WARNING: suspicious RCU usage [ 32.605928] 6.11.0-rc5-00040-g4ba4f1afb6a9 #55238 Not tainted [ 32.607812] ----------------------------- [ 32.609140] kernel/events/core.c:13946 RCU-list traversed in non-reader section!! [ 32.611595] other info that might help us debug this: [ 32.614247] rcu_scheduler_active = 2, debug_locks = 1 [ 32.616392] 3 locks held by cpuhp/4/35: [ 32.617687] #0: ffffffffb666a650 (cpu_hotplug_lock){++++}-{0:0}, at: cpuhp_thread_fun+0x4e/0x200 [ 32.620563] #1: ffffffffb666cd20 (cpuhp_state-down){+.+.}-{0:0}, at: cpuhp_thread_fun+0x4e/0x200 [ 32.623412] #2: ffffffffb677c288 (pmus_lock){+.+.}-{3:3}, at: perf_event_exit_cpu_context+0x32/0x2f0In
perf_event_clear_cpumask(), useslist_for_each_entry_rcu()without an obvious RCU read-side critical section.Either
pmus_srcuorpmus_lockis good enough to protect the pmus list. In the current context,pmus_lockis already held. Thelist_for_each_entry_rcu()is not required.Quoted 6 lines
Fixes 4ba4f1afb6a9 ("perf: Generic hotplug support for a PMU with a scope")Reported-by Paul E. McKenney <[email protected]>Tested-by Paul E. McKenney <[email protected]>Reported-by kernel test robot <[email protected]>
Quoted 3 lines
Forgot to add the below tag, please fold it.
Suggested-by Peter Zijlstra <[email protected]>
Have one of these to go along with it. ;-)
Quoted 20 lines
Thanks,
KanQuoted 18 lines
Signed-off-by Kan Liang <[email protected]>--- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/events/core.c +1
-1@@ -13912,7 +13912,7 @@ static void perf_event_clear_cpumask(unsigned int cpu) }/* migrate */ -list_for_each_entry_rcu (pmu, &pmus, entry,lockdep_is_held (&pmus_srcu)) { +list_for_each_entry (pmu, &pmus, entry) {if (pmu->scope ==PERF_PMU_SCOPE_NONE ||WARN_ON_ONCE (pmu->scope >=PERF_PMU_MAX_SCOPE ))continue ;
Quoted 33 lines · Paul E. McKenney
Quoted 32 lines · Kan
Quoted 28 lines · On 2024-09-13 12:23 p.m., [email protected] wrote:
From: Kan Liang <[email protected]>
Running rcutorture scenario TREE05, the below warning is triggered.
[ 32.604594] WARNING: suspicious RCU usage [ 32.605928] 6.11.0-rc5-00040-g4ba4f1afb6a9 #55238 Not tainted [ 32.607812] ----------------------------- [ 32.609140] kernel/events/core.c:13946 RCU-list traversed in non-reader section!! [ 32.611595] other info that might help us debug this: [ 32.614247] rcu_scheduler_active = 2, debug_locks = 1 [ 32.616392] 3 locks held by cpuhp/4/35: [ 32.617687] #0: ffffffffb666a650 (cpu_hotplug_lock){++++}-{0:0}, at: cpuhp_thread_fun+0x4e/0x200 [ 32.620563] #1: ffffffffb666cd20 (cpuhp_state-down){+.+.}-{0:0}, at: cpuhp_thread_fun+0x4e/0x200 [ 32.623412] #2: ffffffffb677c288 (pmus_lock){+.+.}-{3:3}, at: perf_event_exit_cpu_context+0x32/0x2f0In
perf_event_clear_cpumask(), useslist_for_each_entry_rcu()without an obvious RCU read-side critical section.Either
pmus_srcuorpmus_lockis good enough to protect the pmus list. In the current context,pmus_lockis already held. Thelist_for_each_entry_rcu()is not required.Fixes 4ba4f1afb6a9 ("perf: Generic hotplug support for a PMU with a scope")Reported-by Paul E. McKenney <[email protected]>Tested-by Paul E. McKenney <[email protected]>Reported-by kernel test robot <[email protected]>
Quoted 7 lines
Quoted 3 lines
Forgot to add the below tag, please fold it.
Suggested-by Peter Zijlstra <[email protected]>Have one of these to go along with it. ;-)
Tested-by Paul E. McKenney <[email protected]>
Just following up, seeing how this is not yet in -next.
Is this on its way upstream?
Thanx, Paul
Quoted 20 lines
Quoted 20 lines
Thanks,
KanQuoted 18 lines
Signed-off-by Kan Liang <[email protected]>--- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/events/core.c +1
-1@@ -13912,7 +13912,7 @@ static void perf_event_clear_cpumask(unsigned int cpu) }/* migrate */ -list_for_each_entry_rcu (pmu, &pmus, entry,lockdep_is_held (&pmus_srcu)) { +list_for_each_entry (pmu, &pmus, entry) {if (pmu->scope ==PERF_PMU_SCOPE_NONE ||WARN_ON_ONCE (pmu->scope >=PERF_PMU_MAX_SCOPE ))continue ;
The following commit has been merged into the perf/urgent branch of tip:
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: e3dfd64c1f344ebec9397719244c27b360255855 Gitweb: https://git.kernel.org/tip/e3dfd64c1f344ebec9397719244c27b360255855 Author: Kan Liang <[email protected]> AuthorDate: Fri, 13 Sep 2024 09:23:40 -07:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Wed, 23 Oct 2024 20:52:25 +02:00
perf: Fix missing RCU reader protection in perf_event_clear_cpumask()
Running rcutorture scenario TREE05, the below warning is triggered.
[ 32.604594] WARNING: suspicious RCU usage
[ 32.605928] 6.11.0-rc5-00040-g4ba4f1afb6a9 #55238 Not tainted
[ 32.607812] -----------------------------
[ 32.609140] kernel/events/core.c:13946 RCU-list traversed in non-reader section!!
[ 32.611595] other info that might help us debug this:
[ 32.614247] rcu_scheduler_active = 2, debug_locks = 1
[ 32.616392] 3 locks held by cpuhp/4/35:
[ 32.617687] #0: ffffffffb666a650 (cpu_hotplug_lock){++++}-{0:0}, at: cpuhp_thread_fun+0x4e/0x200
[ 32.620563] #1: ffffffffb666cd20 (cpuhp_state-down){+.+.}-{0:0}, at: cpuhp_thread_fun+0x4e/0x200
[ 32.623412] #2: ffffffffb677c288 (pmus_lock){+.+.}-{3:3}, at: perf_event_exit_cpu_context+0x32/0x2f0In perf_event_clear_cpumask(), uses list_for_each_entry_rcu() without an obvious RCU read-side critical section.
Either pmus_srcu or pmus_lock is good enough to protect the pmus list. In the current context, pmus_lock is already held. The list_for_each_entry_rcu() is not required.
--- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
@@ -13959,7 +13959,7 @@ static void perf_event_clear_cpumask(unsigned int cpu) }/* migrate */ -list_for_each_entry_rcu (pmu, &pmus, entry,lockdep_is_held (&pmus_srcu)) { +list_for_each_entry (pmu, &pmus, entry) {if (pmu->scope ==PERF_PMU_SCOPE_NONE ||WARN_ON_ONCE (pmu->scope >=PERF_PMU_MAX_SCOPE ))continue ;