linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Liang, Kan" <kan.liang@linux.intel.com>
To: Peter Zijlstra <peterz@infradead.org>,
	"Paul E. McKenney" <paulmck@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	mingo@redhat.com, acme@kernel.org, namhyung@kernel.org,
	mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
	jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com
Subject: Re: [BUG BISECTED] Missing RCU reader in perf_event_setup_cpumask()
Date: Fri, 13 Sep 2024 11:51:34 -0400	[thread overview]
Message-ID: <8a9dabcd-023a-4e8f-8570-3c69a9cf0c0a@linux.intel.com> (raw)
In-Reply-To: <20240913104752.GU4723@noisy.programming.kicks-ass.net>



On 2024-09-13 6:47 a.m., Peter Zijlstra wrote:
> On Fri, Sep 13, 2024 at 01:00:44AM -0700, Paul E. McKenney wrote:
>> Hello!
>>
>> On next-20240912 running rcutorture scenario TREE05, I see this
>> deterministically:
>>
>> [   32.603233] =============================
>> [   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]
>> [   32.611595] other info that might help us debug this:
>> [   32.611595]
>> [   32.614247]
>> [   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
>> [   32.626399]
>> [   32.626399] stack backtrace:
>> [   32.627848] CPU: 4 UID: 0 PID: 35 Comm: cpuhp/4 Not tainted 6.11.0-rc5-00040-g4ba4f1afb6a9 #55238
>> [   32.628832] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
>> [   32.628832] Call Trace:
>> [   32.628832]  <TASK>
>> [   32.628832]  dump_stack_lvl+0x83/0xa0
>> [   32.628832]  lockdep_rcu_suspicious+0x143/0x1a0
>> [   32.628832]  perf_event_exit_cpu_context+0x2e5/0x2f0
>> [   32.628832]  ? __pfx_perf_event_exit_cpu+0x10/0x10
>> [   32.628832]  perf_event_exit_cpu+0x9/0x10
>> [   32.628832]  cpuhp_invoke_callback+0x130/0x2a0
>> [   32.628832]  ? lock_release+0xc7/0x290
>> [   32.628832]  ? cpuhp_thread_fun+0x4e/0x200
>> [   32.628832]  cpuhp_thread_fun+0x183/0x200
>> [   32.628832]  smpboot_thread_fn+0xd8/0x1d0
>> [   32.628832]  ? __pfx_smpboot_thread_fn+0x10/0x10
>> [   32.628832]  kthread+0xd4/0x100
>> [   32.628832]  ? __pfx_kthread+0x10/0x10
>> [   32.628832]  ret_from_fork+0x2f/0x50
>> [   32.628832]  ? __pfx_kthread+0x10/0x10
>> [   32.628832]  ret_from_fork_asm+0x1a/0x30
>> [   32.628832]  </TASK>
>>
>> I bisected this to:
>>
>> 4ba4f1afb6a9 ("perf: Generic hotplug support for a PMU with a scope")
>>
>> This adds a perf_event_setup_cpumask() function that uses
>> list_for_each_entry_rcu() without an obvious RCU read-side critical
>> section, so the fix might be as simple as adding rcu_read_lock() and
>> rcu_read_unlock().  In the proper places, of course.  ;-)
> 
> IIRC that condition should be:
> 
>   lockdep_is_held(&pmus_srcu) || lockdep_is_held(&pmus_lock)
> 
> And at this pooint we actually do hold pmus_lock.
> 
> But that all begs the question why we're using RCU iteration here to
> begin with, as this code seems to be only called from this context.

I think I just copied and paste the PMU iterate code here, and forget to
add the srcu_read_lock(). Sorry for it.

> 
> Kan, is the simple fix to do:
> 
> -	list_for_each_entry_rcu(pmu, &pmus, entry, lockdep_is_held(&pmus_srcu)) {
> +	list_for_each_entry(pmu, &pmus, entry) {
> 
> ?
>   

Yes, the &pmus_lock protect is good enough. we don't need the rcu here.
I will post a patch with the suggested fix.

Thanks,
Kan


      parent reply	other threads:[~2024-09-13 15:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-13  8:00 [BUG BISECTED] Missing RCU reader in perf_event_setup_cpumask() Paul E. McKenney
2024-09-13 10:47 ` Peter Zijlstra
2024-09-13 12:09   ` Paul E. McKenney
2024-09-13 15:51   ` Liang, Kan [this message]

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=8a9dabcd-023a-4e8f-8570-3c69a9cf0c0a@linux.intel.com \
    --to=kan.liang@linux.intel.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).