public inbox for linux-perf-users@vger.kernel.org
 help / color / mirror / Atom feed
From: "Liang, Kan" <kan.liang@linux.intel.com>
To: peterz@infradead.org, mingo@redhat.com,
	linux-kernel@vger.kernel.org, linux-next@vger.kernel.org,
	linux-perf-users@vger.kernel.org
Cc: "Paul E . McKenney" <paulmck@kernel.org>,
	kernel test robot <oliver.sang@intel.com>
Subject: Re: [PATCH] perf: Fix missing RCU reader protection in perf_event_clear_cpumask()
Date: Fri, 13 Sep 2024 12:25:59 -0400	[thread overview]
Message-ID: <39bb4c06-a8e8-4eef-8659-534939c9987f@linux.intel.com> (raw)
In-Reply-To: <20240913162340.2142976-1-kan.liang@linux.intel.com>



On 2024-09-13 12:23 p.m., kan.liang@linux.intel.com wrote:
> From: Kan Liang <kan.liang@linux.intel.com>
> 
> 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 <paulmck@kernel.org>
> Closes: https://lore.kernel.org/lkml/2b66dff8-b827-494b-b151-1ad8d56f13e6@paulmck-laptop/
> Tested-by: Paul E. McKenney <paulmck@kernel.org>
> Reported-by: kernel test robot <oliver.sang@intel.com>
> Closes: https://lore.kernel.org/oe-lkp/202409131559.545634cc-oliver.sang@intel.com

Forgot to add the below tag, please fold it.

Suggested-by: Peter Zijlstra <peterz@infradead.org>

Thanks,
Kan
> Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
> ---
>  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 20e97c1aa4d6..5ba9934b49df 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -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;

  reply	other threads:[~2024-09-13 16:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-13 16:23 [PATCH] perf: Fix missing RCU reader protection in perf_event_clear_cpumask() kan.liang
2024-09-13 16:25 ` Liang, Kan [this message]
2024-09-13 18:14   ` Paul E. McKenney
2024-10-16 18:23     ` Paul E. McKenney

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=39bb4c06-a8e8-4eef-8659-534939c9987f@linux.intel.com \
    --to=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=oliver.sang@intel.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    /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