All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gautham R Shenoy <ego@in.ibm.com>
To: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Miles Lane <miles.lane@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	"Rafael J. Wysocki" <rjw@sisk.pl>, Ingo Molnar <mingo@elte.hu>
Subject: Re: 2.6.25-rc9 -- INFO: possible circular locking dependency detected
Date: Tue, 15 Apr 2008 19:22:10 +0530	[thread overview]
Message-ID: <20080415135210.GA17765@in.ibm.com> (raw)
In-Reply-To: <20080414193539.GA4438@osiris.boeblingen.de.ibm.com>

On Mon, Apr 14, 2008 at 09:35:39PM +0200, Heiko Carstens wrote:
> On Mon, Apr 14, 2008 at 09:16:42PM +0530, Gautham R Shenoy wrote:
> > On Mon, Apr 14, 2008 at 05:19:46PM +0200, Heiko Carstens wrote:
> > > On Mon, Apr 14, 2008 at 08:18:01PM +0530, Gautham R Shenoy wrote:
> > > > On Mon, Apr 14, 2008 at 02:42:27PM +0200, Peter Zijlstra wrote:
> > > 
> > > While you're fixing the cpu hotplug stuff anyway, there's still a bug
> > > present in a few modules init code:
> > > 
> > > Usually they do something like:
> > > 
> > > 	register_hotcpu_notifier(...);
> > > 	for_each_online_cpu(i)
> > > 		...
> > > 
> > > A module's init functions gets called from sys_init_module and there is nothing
> > > that would protect from cpu hotplug.
> > > Therefore the sequence of for_each_online_cpu() and register_hotcpu_notifier()
> > > better should be protected by a surrounding get/put_online_cpus() like this:
> > > 
> > > 	get_online_cpus();
> > > 	register_hotcpu_notifier(...);
> > > 	for_each_online_cpu(i)
> > > 		...
> > > 	put_online_cpus();
> > 
> > But shouldn't this be:
> > 	register_hotcpu_notifier(...);
> > 	get_online_cpus();
> > 	for_each_online_cpus()
> > 		...
> > 	put_online_cpus();
> > 
> > What's the problem with this ordering?
> 
> The problem here is that between register_hotcpu_notifier() and
> get_online_cpus() a cpu might have been hotplugged.
> So on cpu down the registered function might try to undo something that
> wasn't prepared in the first place.
> On cpu up however it will do things twice. Once for the cpus that got
> added between register_hotcpu_notifier() and for_each_online_cpus()
> and then again in the for_each_online_cpus() loop.
> 
> Of course all of these scenarios could be fixed in each driver, but that
> would be a lot of duplicated work. Making sure the combination of
> get_online_cpus() and register_hotcpu_notifier() cannot deadlock would
> make things much easier.

Ah, okay. Thanks for the explanation.
So how about having a new API,
something along the lines of:

kernel/cpu.c
------------------------------------------------------
register_hot_cpu_notifier_init(notifier_name, driver_hotcpu_init_function)
{
	mutex_lock(&cpu_add_remove_lock);
	get_online_cpus();
	__register_hot_cpu_notifier(notifier_name);
	driver_hotcpu_init_function();
	put_online_cpus();
	mutex_unlock(&cpu_add_remove_lock);
}

drivers/mydriver.c
--------------------------------------------------------------
driver_hotcpu_init_function()
{
	for_each_online_cpus()
		perform_subsystem_hotcpu_initialization();
}


driver_init()
{
	register_hotcpu_notifier_init(notifier_name,
			driver_hotcpu_init_function);
}



-- 
Thanks and Regards
gautham

  reply	other threads:[~2008-04-15 13:52 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-14  3:04 2.6.25-rc9 -- INFO: possible circular locking dependency detected Miles Lane
2008-04-14  3:29 ` Miles Lane
2008-04-14  6:54 ` Peter Zijlstra
2008-04-14  7:02   ` Heiko Carstens
2008-04-14  7:18     ` Ingo Molnar
2008-04-14 12:06   ` Peter Zijlstra
2008-04-14 12:27     ` Gautham R Shenoy
2008-04-14 12:42       ` Peter Zijlstra
2008-04-14 13:28         ` Gautham R Shenoy
2008-04-14 14:48         ` Gautham R Shenoy
2008-04-14 15:19           ` Heiko Carstens
2008-04-14 15:46             ` Gautham R Shenoy
2008-04-14 19:35               ` Heiko Carstens
2008-04-15 13:52                 ` Gautham R Shenoy [this message]
2008-04-15 14:37                   ` Heiko Carstens
     [not found]         ` <20080422123304.GA777@osiris.boeblingen.de.ibm.com>
     [not found]           ` <1208868236.7115.249.camel@twins>
     [not found]             ` <20080423035802.GA8895@in.ibm.com>
     [not found]               ` <20080424150714.GA8273@osiris.boeblingen.de.ibm.com>
     [not found]                 ` <1209052984.7115.369.camel@twins>
     [not found]                   ` <20080424155946.GA11160@tv-sign.ru>
     [not found]                     ` <20080424194810.GA4821@osiris.boeblingen.de.ibm.com>
     [not found]                       ` <20080424192706.GA165@tv-sign.ru>
     [not found]                         ` <20080425064044.GA10817@osiris.boeblingen.de.ibm.com>
2008-04-26 14:43                           ` get_online_cpus() && workqueues Oleg Nesterov
2008-04-27 12:22                             ` Heiko Carstens
2008-04-27 14:25                               ` Oleg Nesterov
2008-04-28  7:02                             ` Gautham R Shenoy
2008-04-28 10:56                               ` Oleg Nesterov
2008-04-28 12:03                                 ` Gautham R Shenoy
2008-04-28 12:40                                   ` Oleg Nesterov
2008-04-28 11:57                             ` Gautham R Shenoy

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=20080415135210.GA17765@in.ibm.com \
    --to=ego@in.ibm.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miles.lane@gmail.com \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=rjw@sisk.pl \
    /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.