public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Andrew Morton <akpm@osdl.org>
Cc: Ingo Molnar <mingo@elte.hu>,
	vatsa@in.ibm.com, Bjorn Helgaas <bjorn.helgaas@hp.com>,
	linux-kernel@vger.kernel.org, Myron Stowe <myron.stowe@hp.com>,
	Jens Axboe <axboe@kernel.dk>, Dipankar <dipankar@in.ibm.com>,
	Gautham shenoy <ego@in.ibm.com>, Pavel Machek <pavel@ucw.cz>
Subject: Re: workqueue deadlock
Date: Sun, 10 Dec 2006 15:18:38 +0100	[thread overview]
Message-ID: <200612101518.39334.rjw@sisk.pl> (raw)
In-Reply-To: <20061210041600.56306676.akpm@osdl.org>

On Sunday, 10 December 2006 13:16, Andrew Morton wrote:
> On Sun, 10 Dec 2006 12:49:43 +0100
> Ingo Molnar <mingo@elte.hu> wrote:
> 
> > > > 	void cpu_hotplug_lock(void)
> 
> This is actually not cpu-hotplug safe ;)  
> 
> > > > 	{
> > > > 		int cpu = raw_smp_processor_id();
> > > > 		/*
> > > > 		 * Interrupts/softirqs are hotplug-safe:
> > > > 		 */
> > > > 		if (in_interrupt())
> > > > 			return;
> > > > 		if (current->hotplug_depth++)
> > > > 			return;
> 
> <preempt, cpu hot-unplug, resume on different CPU>
> 
> > > > 		current->hotplug_lock = &per_cpu(hotplug_lock, cpu);
> 
> <use-after-free>
> 
> > > > 		mutex_lock(current->hotplug_lock);
> 
> And it sleeps, so we can't use preempt_disable().
> 
> > > > 	}
> 
> It's worth noting that this very common sequence:
> 
> 	preempt_disable();
> 	cpu = smp_processor_id();
> 	...
> 	preempt_enable();
> 
> also provides cpu-hotunplug protection against scenarios such as the above.
> 
> > > That's functionally equivalent to what we have now, and it isn't 
> > > working too well.
> > 
> > hm, i thought the main reason of not using cpu_hotplug_lock() in a 
> > widespread manner was not related to its functionality but to its 
> > scalability - but i could be wrong.
> 
> It hasn't been noticed yet.
> 
> I suspect a large part of the reason for that is that we only really care
> about hot-unplug when this CPU reaches across to some other CPU's data.  Often
> _all_ other CPU's data.  And that's a super-inefficient thing, so it's rare.
> 
> Most of the problems we've had are due to borkage in cpufreq.  And that's
> simply cruddy code - it's not due to the complexity of CPU hotplug per-se.
> 
> > The one above is scalable and we 
> > could use it as /the/ method to control CPU hotplug. All the flux i 
> > remember related to cpu_hotplug_lock() use from the fork path and from 
> > other scheduler hotpaths related to its scalability bottleneck, not to 
> > its locking efficiency.
> 
> One quite different way of addressing all of this is to stop using
> stop_machine_run() for hotplug synchronisation and switch to the swsusp
> freezer infrastructure: all kernel threads and user processes need to stop
> and park themselves in a known state before we allow the CPU to be removed.
> lock_cpu_hotplug() becomes a no-op.
> 
> Dunno if it'll work - I only just thought of it.  It sure would simplify
> things.

Hm, currently we're using the CPU hotplug to disable the nonboot CPUs before
the freezer is called. ;-)

However, we're now trying to make the freezer SMP-safe, so that we can disable
the nonboot CPUs after devices have been suspended (we want to do this for
some ACPI-related reasons).  In fact we're almost there, I'm only waiting for
the confirmation from Pavel to post the patches.

When this is done, we won't need the CPU hotplug that much and I think the CPU
hotplug code will be able to do something like:

freeze_processes
suspend_cpufreq (or even suspend_all_devices)
remove_the_CPU_in_question
resume_cpufreq
thaw_processes

Greetings,
Rafael


-- 
If you don't have the time to read,
you don't have the time or the tools to write.
		- Stephen King

  parent reply	other threads:[~2006-12-10 14:16 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-07  0:26 workqueue deadlock Bjorn Helgaas
2006-12-07  6:17 ` Srivatsa Vaddagiri
2006-12-07  6:45   ` Srivatsa Vaddagiri
2006-12-07 18:51 ` Andrew Morton
2006-12-07 19:37   ` Andrew Morton
2006-12-08  2:53     ` Srivatsa Vaddagiri
2006-12-08  4:54       ` Andrew Morton
2006-12-08  7:58         ` Srivatsa Vaddagiri
2006-12-09 10:26         ` Ingo Molnar
2006-12-09 19:47           ` Andrew Morton
2006-12-10  8:26             ` Ingo Molnar
2006-12-10  8:43               ` Andrew Morton
2006-12-10 11:49                 ` Ingo Molnar
2006-12-10 12:16                   ` Andrew Morton
2006-12-10 12:19                     ` Ingo Molnar
2006-12-10 12:34                       ` Andrew Morton
2006-12-11  6:09                         ` Ingo Molnar
2006-12-10 14:18                     ` Rafael J. Wysocki [this message]
2006-12-11  6:52                       ` Dipankar Sarma
2006-12-11 16:34                         ` Rafael J. Wysocki
2006-12-11  5:45                     ` Srivatsa Vaddagiri
2006-12-11  6:03                       ` Andrew Morton
2006-12-11  4:58               ` Srivatsa Vaddagiri

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=200612101518.39334.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=akpm@osdl.org \
    --cc=axboe@kernel.dk \
    --cc=bjorn.helgaas@hp.com \
    --cc=dipankar@in.ibm.com \
    --cc=ego@in.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=myron.stowe@hp.com \
    --cc=pavel@ucw.cz \
    --cc=vatsa@in.ibm.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