mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Hildenbrand <dahi@linux.vnet.ibm.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: linux-kernel@vger.kernel.org, heiko.carstens@de.ibm.com,
	borntraeger@de.ibm.com, rafael.j.wysocki@intel.com,
	paulmck@linux.vnet.ibm.com, peterz@infradead.org, bp@suse.de,
	jkosina@suse.cz
Subject: Re: [PATCH v3] CPU hotplug: active_writer not woken up in some cases - deadlock
Date: Wed, 10 Dec 2014 08:56:20 +0100	[thread overview]
Message-ID: <20141210085620.0c102fd9@thinkpad-w530> (raw)
In-Reply-To: <20141210001239.GA516@redhat.com>

> (sorry if this was already discussed, I ignored most of my emails
>  I got this week)
> 
> On 12/09, David Hildenbrand wrote:
> >
> > @@ -116,7 +118,13 @@ void put_online_cpus(void)
> >  	if (cpu_hotplug.active_writer == current)
> >  		return;
> >  	if (!mutex_trylock(&cpu_hotplug.lock)) {
> > +		/* inc before testing for active_writer to not lose wake ups */
> >  		atomic_inc(&cpu_hotplug.puts_pending);
> > +		spin_lock(&cpu_hotplug.awr_lock);
> > +		/* we might be the last one */
> > +		if (unlikely(cpu_hotplug.active_writer))
> > +			wake_up_process(cpu_hotplug.active_writer);
> > +		spin_unlock(&cpu_hotplug.awr_lock);
> 
> Not sure I understand. awr_lock can only ensure that active_writer
> can't go away.

This solution is not optimal but works without races ... I'll try to get
something with wait queues running and/or even change the way refcount is
accessed as suggested by you.

And yes, awr_lock will only ensure that active_writer won't go away.

> 
> Why active_writer should see .puts_pending != 0 if this is called
> right after cpu_hotplug_begin() takes cpu_hotplug.lock but before
> it sets TASK_UNINTERRUPTIBLE?

get_online_cpus() increased the refcount.
put_online_cpus() will increment puts_pending and trigger a wake up (if the
lock is alread taken - might be by cpu_hotplug_begin() or by some other
get_online_cpus()).

So refcount == 1, puts_pending == 1

cpu_hotplug_begin() gets the lock and sees refcount == 1 and puts_pending == 0
or puts_pending == 1 (race with put_online_cpus()).

If that answers your question :)

> 
> IOW,
> 
> >  void cpu_hotplug_begin(void)
> >  {
> > +	spin_lock(&cpu_hotplug.awr_lock);
> >  	cpu_hotplug.active_writer = current;
> > +	spin_unlock(&cpu_hotplug.awr_lock);
> >  
> >  	cpuhp_lock_acquire();
> >  	for (;;) {
> >  		mutex_lock(&cpu_hotplug.lock);
> > +		__set_current_state(TASK_UNINTERRUPTIBLE);
> 
> don't we need set_current_state() here ?

Hm, good question, this was only a move of existing code. But I thing the
checked variant would be better.

> 
> Oleg.
> 

Thanks!

David


  reply	other threads:[~2014-12-10  7:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-09 12:23 David Hildenbrand
2014-12-09 14:19 ` Paul E. McKenney
2014-12-09 16:24   ` David Hildenbrand
2014-12-09 17:01     ` Paul E. McKenney
2014-12-10  0:26   ` Oleg Nesterov
2014-12-10  3:18     ` Paul E. McKenney
2014-12-10  0:12 ` Oleg Nesterov
2014-12-10  7:56   ` David Hildenbrand [this message]
2014-12-10 18:59     ` Oleg Nesterov

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=20141210085620.0c102fd9@thinkpad-w530 \
    --to=dahi@linux.vnet.ibm.com \
    --cc=borntraeger@de.ibm.com \
    --cc=bp@suse.de \
    --cc=heiko.carstens@de.ibm.com \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rafael.j.wysocki@intel.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

Powered by JetHome