All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm00@gmail.com>
To: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>, Tejun Heo <htejun@gmail.com>,
	Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH RFC] stop_machine: make stop_machine safe and efficient to call early
Date: Fri, 30 Sep 2011 14:06:25 -0700	[thread overview]
Message-ID: <20110930140625.c7faad28.akpm00@gmail.com> (raw)
In-Reply-To: <4E85F596.4050704@goop.org>

On Fri, 30 Sep 2011 10:00:06 -0700
Jeremy Fitzhardinge <jeremy@goop.org> wrote:

> On 09/30/2011 09:34 AM, Steven Rostedt wrote:
> > Doesn't interrupts need to be disabled here too? As stop machine
> > functions also guarantee that they will not be interrupted by
> > interrupts. -- Steve
> 
> Good point.
> 
>     J
> 
> Make stop_machine() safe to call early in boot, before SMP has been
> set up, by simply calling the callback function directly if there's
> only one CPU online.

Being a trusting soul, I shall assume that you presently have or soon
will have some code which requires this change?

>
> ...
>
> --- a/kernel/stop_machine.c
> +++ b/kernel/stop_machine.c
> @@ -485,6 +485,17 @@ int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus)
>  					    .num_threads = num_online_cpus(),
>  					    .active_cpus = cpus };
>  
> +	if (smdata.num_threads == 1) {
> +		unsigned long flags;
> +		int ret;
> +
> +		local_save_flags(flags);
> +		ret = (*fn)(data);
> +		local_irq_restore(flags);
> +
> +		return ret;
> +	}

It is quite unobvious to readers why this code exists.  Therefore, we
should tell them.

Also, bug.  local_save_flags() is used to read the irq flags - it does
not actually disable interrupts.  We want local_irq_save() here.  None
of these interfaces are documented and their naming system is crappy. 
Cause, effect.


--- a/kernel/stop_machine.c~stop_machine-make-stop_machine-safe-and-efficient-to-call-early-fix
+++ a/kernel/stop_machine.c
@@ -486,10 +486,14 @@ int __stop_machine(int (*fn)(void *), vo
 					    .active_cpus = cpus };
 
 	if (smdata.num_threads == 1) {
+		/*
+		 * Handle the case where stop_machine() is called early in boot
+		 * before SMP startup.
+		 */
 		unsigned long flags;
 		int ret;
 
-		local_save_flags(flags);
+		local_irq_save(flags);
 		ret = (*fn)(data);
 		local_irq_restore(flags);
 
_



  reply	other threads:[~2011-09-30 21:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-30 16:28 [PATCH RFC] stop_machine: make stop_machine safe and efficient to call early Jeremy Fitzhardinge
2011-09-30 16:34 ` Steven Rostedt
2011-09-30 17:00   ` Jeremy Fitzhardinge
2011-09-30 21:06     ` Andrew Morton [this message]
2011-09-30 21:21       ` Steven Rostedt
2011-09-30 21:23   ` Andrew Morton
2011-09-30 23:06 ` Tejun Heo
2011-09-30 23:32   ` Jeremy Fitzhardinge
2011-09-30 23:39     ` Tejun Heo

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=20110930140625.c7faad28.akpm00@gmail.com \
    --to=akpm00@gmail.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=hpa@zytor.com \
    --cc=htejun@gmail.com \
    --cc=jeremy@goop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=rusty@rustcorp.com.au \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.