linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: John Stultz <john.stultz@linaro.org>,
	Josh Triplett <josh@joshtriplett.org>,
	lkml <linux-kernel@vger.kernel.org>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Saravana Kannan <saravanak@google.com>,
	Todd Kjos <tkjos@google.com>, Stephen Boyd <sboyd@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: On trace_*_rcuidle functions in modules
Date: Wed, 15 Apr 2020 15:04:59 -0700	[thread overview]
Message-ID: <20200415220459.GE17661@paulmck-ThinkPad-P72> (raw)
In-Reply-To: <20200415174918.154a86d0@gandalf.local.home>

On Wed, Apr 15, 2020 at 05:49:18PM -0400, Steven Rostedt wrote:
> On Wed, 15 Apr 2020 14:02:04 -0700
> John Stultz <john.stultz@linaro.org> wrote:
> 
> > 
> > So in my case your concerns may not be a problem, but I guess
> > generally it might. Though I'd hope the callback would be unregistered
> > (and whatever waiting for the grace period to complete be done) before
> > the module removal is complete. But maybe I'm still missing your
> > point?
> 
> Hmm, you may have just brought up a problem here...
> 
> You're saying that cpu_pm_register_notifier() callers are called from non
> RCU watching context? If that's the case, we have this:
> 
> int cpu_pm_unregister_notifier(struct notifier_block *nb)
> {
> 	return atomic_notifier_chain_unregister(&cpu_pm_notifier_chain, nb);
> }
> 
> And this:
> 
> int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh,
> 		struct notifier_block *n)
> {
> 	unsigned long flags;
> 	int ret;
> 
> 	spin_lock_irqsave(&nh->lock, flags);
> 	ret = notifier_chain_unregister(&nh->head, n);
> 	spin_unlock_irqrestore(&nh->lock, flags);
> 	synchronize_rcu();
> 	return ret;
> }
> 
> Which means that if something registered a cpu_pm notifier, then
> unregistered it, and freed whatever the notifier accesses, then there's a
> chance that the synchronize_rcu() can return before the called notifier
> finishes, and anything that notifier accesses could have been freed.
> 
> I believe that module code should not be able to be run in RCU non watching
> context, and neither should notifiers. I think we just stumbled on a bug.
> 
> Paul?

Or we say that such modules cannot be unloaded.  Or that such modules'
exit handlers, after disentangling themselves from the idle loop, must
invoke synchronize_rcu_rude() or similar, just as modules that use
call_rcu() are currently required to invoke rcu_barrier().

Or is it possible to upgrade the protection that modules use?

My guess is that invoking rcu_irq_enter() and rcu_irq_exit() around every
potential call into module code out of the PM code is a non-starter,
but I cannot prove that either way.

							Thanx, Paul

  reply	other threads:[~2020-04-15 22:05 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-15  2:20 On trace_*_rcuidle functions in modules John Stultz
2020-04-15  2:57 ` Paul E. McKenney
2020-04-15  3:47   ` John Stultz
2020-04-15 13:12     ` Paul E. McKenney
2020-04-15 12:53 ` Steven Rostedt
2020-04-15 19:56   ` John Stultz
2020-04-15 20:14     ` Steven Rostedt
2020-04-15 20:17       ` John Stultz
2020-04-15 20:41         ` Steven Rostedt
2020-04-15 21:02           ` John Stultz
2020-04-15 21:49             ` Steven Rostedt
2020-04-15 22:04               ` Paul E. McKenney [this message]
2020-04-15 22:42                 ` Peter Zijlstra
2020-04-15 22:53                   ` Steven Rostedt
2020-04-15 22:53                   ` Paul E. McKenney
2020-04-15 22:51                 ` Steven Rostedt
2020-04-15 22:54                   ` Paul E. McKenney
2020-04-16  0:06                   ` John Stultz
2020-04-16  0:48                     ` Steven Rostedt
2020-04-16  1:02                       ` Bjorn Andersson
2020-04-16  1:24                         ` Steven Rostedt
2020-04-16  2:17                       ` John Stultz
2020-04-15 22:07               ` John Stultz
2020-04-15 22:40       ` Peter Zijlstra

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=20200415220459.GE17661@paulmck-ThinkPad-P72 \
    --to=paulmck@kernel.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=john.stultz@linaro.org \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=saravanak@google.com \
    --cc=sboyd@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tkjos@google.com \
    /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).