mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Borislav Petkov <bp@alien8.de>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Thomas Gleixner <tglx@linutronix.de>,
	lkml <linux-kernel@vger.kernel.org>
Subject: Re: WARNING: possible circular locking dependency detected
Date: Mon, 28 Aug 2017 17:06:17 +0200	[thread overview]
Message-ID: <20170828150617.wp6hh7flfjjjsu4m@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20170828145808.btuqpe2bvxymljyg@hirez.programming.kicks-ass.net>

On Mon, Aug 28, 2017 at 04:58:08PM +0200, Peter Zijlstra wrote:
> On Fri, Aug 25, 2017 at 12:03:04PM +0200, Borislav Petkov wrote:
> > Hey,
> > 
> > tglx says I have something for ya :-)
> > 
> > ======================================================
> > WARNING: possible circular locking dependency detected
> > 4.13.0-rc6+ #1 Not tainted
> > ------------------------------------------------------
> > watchdog/3/27 is trying to acquire lock:
> >  (cpu_hotplug_lock.rw_sem){++++}, at: [<ffffffff8100c489>] release_ds_buffers+0x29/0xd0
> > 
> > but now in release context of a crosslock acquired at the following:
> >  ((complete)&self->parked){+.+.}, at: [<ffffffff810895f6>] kthread_park+0x46/0x60
> 
> 
> So I'm thinking this one is an actual deadlock.
> 
> So, as far as I can tell this ends up being:
> 
> CPU0                    CPU1
> 
> (smpboot_regiser_percpu_thread_cpumask)
> 
> get_online_cpus()
> __smpboot_create_thread()
>   kthread_park();
>     wait_for_completion(&X)
> 
> 
>                         (smpboot_thread_fn)
> 
>                         ->park() := watchdog_disable()
>                           watchdog_nmi_disable()
>                             perf_event_release_kernel();
>                               put_event()
>                                 _free_event()
>                                   ->destroy() := hw_perf_event_destroy()
>                                     x86_release_hardware()
>                                       release_ds_buffers()
>                                         get_online_cpus()
> 
> 
>                         kthread_parkme()
>                           complete(&X)
> 
> 
> 
> So CPU0 holds cpus_hotplug_lock while wait_for_completion() and CPU1
> needs to acquire before complete().
> 
> So if, in between, CPU2 does down_write(), things will get unstuck.
> 
> What's worse, there's also:
> 
>   cpus_write_lock()
>     ...
>       takedown_cpu()
>         smpboot_park_threads()
> 	  smpboot_park_thread()
> 	    kthread_park()
> 	      ->park() := watchdog_disable()
> 		watchdog_nmi_disable()
> 		  perf_event_release_kernel();
> 		    put_event()
> 		      _free_event()
> 			->destroy() := hw_perf_event_destroy()
> 			  x86_release_hardware()
> 			    release_ds_buffers()
> 			      get_online_cpus()
> 
> which as far as I can tell, spells instant deadlock..

Aah, but that latter will never happen.. because each CPU will have a
&pmc_refcount and we can't unplug _all_ CPUs.

So the first one will only ever happen on boot, where we park() the very
first watchdog thread and is a potential deadlock, but won't happen
because nobody is around to do down_write() just yet.

argh!

  reply	other threads:[~2017-08-28 15:06 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-25 10:03 Borislav Petkov
2017-08-25 11:45 ` Borislav Petkov
2017-08-25 14:47 ` Sebastian Andrzej Siewior
2017-08-25 16:12   ` Byungchul Park
2017-08-25 16:21     ` Thomas Gleixner
2017-08-28  7:41   ` Peter Zijlstra
2017-08-28 14:11   ` Peter Zijlstra
2017-08-29 19:34   ` Peter Zijlstra
2017-08-25 16:42 ` Sebastian Andrzej Siewior
2017-08-28 14:58 ` Peter Zijlstra
2017-08-28 15:06   ` Peter Zijlstra [this message]
2017-08-28 16:32     ` Peter Zijlstra
2017-08-29 17:40   ` Thomas Gleixner
2017-08-29 19:49     ` Peter Zijlstra
2017-08-29 20:10       ` Thomas Gleixner
2017-08-30  5:47         ` Peter Zijlstra
2017-08-31  7:08           ` Thomas Gleixner
2017-08-31  7:37             ` Peter Zijlstra
2017-08-31  7:55               ` Thomas Gleixner
2017-08-31  8:09                 ` Peter Zijlstra
2017-08-31  8:15                   ` Thomas Gleixner
2017-08-31 21:24                     ` Thomas Gleixner
2017-09-01 20:32                       ` Peter Zijlstra
2018-11-14  2:41 Qian Cai

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=20170828150617.wp6hh7flfjjjsu4m@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=bigeasy@linutronix.de \
    --cc=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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

all inboxes | Powered by JetHome®