From 3a5d7e033047459b13c3855a4ef9b0c6e3abb911 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Thu, 24 Oct 2024 11:32:52 +0200 Subject: [PATCH 1/5] tg create t/perf-Fix-missing-RCU-reader-protection-in-perf_event_clear_cpumask base --- .topdeps | 1 - .topmsg | 14 -------------- 2 files changed, 15 deletions(-) delete mode 100644 .topdeps delete mode 100644 .topmsg diff --git a/.topdeps b/.topdeps deleted file mode 100644 index a5b7e920a840f7..00000000000000 --- a/.topdeps +++ /dev/null @@ -1 +0,0 @@ -net diff --git a/.topmsg b/.topmsg deleted file mode 100644 index ad5af831799c1a..00000000000000 --- a/.topmsg +++ /dev/null @@ -1,14 +0,0 @@ -From: Matthieu Baerts -Subject: [PATCH] DO-NOT-MERGE: git markup: net - -All commits older than this one are from Netdev's net repo: - - https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/ - -Following commits are fixes for other trees than the net ones or -imported from elsewhere. We should not send these commits to either -net -or net-next. - -This commit is useful to easily find the "bottom of the tree". - -Signed-off-by: Matthieu Baerts From 6c408f4bbf1d5224f0408040dcce6abccc4a4f98 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Thu, 24 Oct 2024 11:32:52 +0200 Subject: [PATCH 2/5] tg create t/perf-Fix-missing-RCU-reader-protection-in-perf_event_clear_cpumask --- .topdeps | 1 + .topmsg | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 .topdeps create mode 100644 .topmsg diff --git a/.topdeps b/.topdeps new file mode 100644 index 00000000000000..616ba42aaa0cd4 --- /dev/null +++ b/.topdeps @@ -0,0 +1 @@ +t/DO-NOT-MERGE-git-markup-net diff --git a/.topmsg b/.topmsg new file mode 100644 index 00000000000000..4d8c83d067edb0 --- /dev/null +++ b/.topmsg @@ -0,0 +1,4 @@ +From: Matthieu Baerts (NGI0) +Subject: [PATCH] t/perf-Fix-missing-RCU-reader-protection-in-perf_event_clear_cpumask + +Signed-off-by: Matthieu Baerts (NGI0) From 3021dee40633a7fb781d34379189c1ab0ac2fb05 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Thu, 24 Oct 2024 11:32:53 +0200 Subject: [PATCH 3/5] tg import create t/perf-Fix-missing-RCU-reader-protection-in-perf_event_clear_cpumask --- .topmsg | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/.topmsg b/.topmsg index 4d8c83d067edb0..d0681632f83f89 100644 --- a/.topmsg +++ b/.topmsg @@ -1,4 +1,31 @@ -From: Matthieu Baerts (NGI0) -Subject: [PATCH] t/perf-Fix-missing-RCU-reader-protection-in-perf_event_clear_cpumask +From: Kan Liang +Subject: [PATCH] perf: Fix missing RCU reader protection in perf_event_clear_cpumask() -Signed-off-by: Matthieu Baerts (NGI0) +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/0x2f0 + +In 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. + +Fixes: 4ba4f1afb6a9 ("perf: Generic hotplug support for a PMU with a scope") +Reported-by: Paul E. McKenney +Closes: https://lore.kernel.org/lkml/2b66dff8-b827-494b-b151-1ad8d56f13e6@paulmck-laptop/ +Tested-by: Paul E. McKenney +Reported-by: kernel test robot +Closes: https://lore.kernel.org/oe-lkp/202409131559.545634cc-oliver.sang@intel.com +Signed-off-by: Kan Liang +Suggested-by: Peter Zijlstra From 3614f20b2657c40eaf6da8f1b22ae5dbd7121b57 Mon Sep 17 00:00:00 2001 From: Kan Liang Date: Fri, 13 Sep 2024 09:23:40 -0700 Subject: [PATCH 4/5] 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/0x2f0 In 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. Fixes: 4ba4f1afb6a9 ("perf: Generic hotplug support for a PMU with a scope") Reported-by: Paul E. McKenney Closes: https://lore.kernel.org/lkml/2b66dff8-b827-494b-b151-1ad8d56f13e6@paulmck-laptop/ Tested-by: Paul E. McKenney Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202409131559.545634cc-oliver.sang@intel.com Signed-off-by: Kan Liang Suggested-by: Peter Zijlstra --- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index e3589c4287cb45..946221a69783ec 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -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; From 3bf1854e9ddc2e2ffdd274bfb8c7ab34fea53374 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Thu, 24 Oct 2024 11:32:54 +0200 Subject: [PATCH 5/5] tg: switch to t/perf-Fix-missing-RCU-reader-protection-in-perf_event_clear_cpumask Signed-off-by: Matthieu Baerts (NGI0) --- .topdeps | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.topdeps b/.topdeps index 616ba42aaa0cd4..acab4d5d0ba2b7 100644 --- a/.topdeps +++ b/.topdeps @@ -1 +1 @@ -t/DO-NOT-MERGE-git-markup-net +t/perf-Fix-missing-RCU-reader-protection-in-perf_event_clear_cpumask