mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Bart Van Assche <bart.vanassche@gmail.com>
Cc: ego@in.ibm.com, linux-kernel@vger.kernel.org,
	Zdenek Kabelac <zdenek.kabelac@gmail.com>,
	Oleg Nesterov <oleg@tv-sign.ru>,
	Heiko Carstens <heiko.carstens@de.ibm.com>,
	"Rafael J. Wysocki" <rjw@sisk.pl>,
	Andrew Morton <akpm@linux-foundation.org>,
	Ingo Molnar <mingo@elte.hu>,
	Srivatsa Vaddagiri <vatsa@in.ibm.com>
Subject: Re: [PATCH 1/8] lockdep: fix recursive read lock validation
Date: Tue, 29 Apr 2008 18:15:39 +0200	[thread overview]
Message-ID: <1209485739.13978.96.camel@twins> (raw)
In-Reply-To: <e2e108260804290903x44ad1cb7x1278027ab51b0831@mail.gmail.com>

On Tue, 2008-04-29 at 18:03 +0200, Bart Van Assche wrote:
> On Tue, Apr 29, 2008 at 5:15 PM, Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:
> >
> > On Tue, 2008-04-29 at 17:03 +0200, Bart Van Assche wrote:
> >  > On Tue, Apr 29, 2008 at 4:57 PM, Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:
> >  > >
> >  > > On Tue, 2008-04-29 at 15:16 +0200, Bart Van Assche wrote:
> >  > >  > On Tue, Apr 29, 2008 at 2:57 PM, Gautham R Shenoy <ego@in.ibm.com> wrote:
> >  > >  > > Subject: lockdep: fix recursive read lock validation
> >  > >  > >  This means that the following sequence is now invalid, whereas previously
> >  > >  > >  it was considered valid:
> >  > >  > >
> >  > >  > >   rlock(a); rlock(b); runlock(b); runlock(a)
> >  > >  > >   rlock(b); rlock(a);
> >  > >  >
> >  > >  > Why are you marking this sequence as invalid ? Although it can be
> >  > >  > debated whether it is good programming practice to be inconsistent
> >  > >  > about the order of read-locking, the above sequence can't be involved
> >  > >  > in a deadlock.
> >  > >
> >  > >  Not for pure read locks, but when you add write locks to it, it does get
> >  > >  deadlocky. Lockdep does not keep separate chains for read and write
> >  > >  locks.
> >  >
> >  > Nesting writer locks inside reader locks is always a bad idea. So
> >  > please come up with an example of how varying the reader lock nesting
> >  > order can trigger a deadlock (when no writer locks are nested inside
> >  > reader locks and nested writer locks are always nested in the same
> >  > order).
> >
> >  It can't deadlock when only readers are involved, but lockdep will not
> >  be able to distinguish between the cases where only read locks are
> >  involved and a mix of readers and writers is involved.
> >
> >  Hence disallow both.
> >
> >  But hitting this requires you do a series of rather unfortunate things:
> >
> >   1) use recursive locking
> >   2) don't have strict lock order
> >   3) make it work by using read locks only
> >
> >  Seriously, any code that triggers this might want to have its locking
> >  re-throught.
> 
> You did not get my point.
> 
> My point is that if you follow the following locking discipline, a
> deadlock will never be triggered:
> * Always obtain writer locks in a consistent order.
> * Never nest writer locks inside reader locks.
> * Nesting reader locks inside writer locks is okay, and nesting reader
> locks inside other reader locks is also OK.
> 
> Again: if you do not agree with the above, please post an example that
> proves me wrong.

Using a lock that does not allow reader nesting would be cheating,
right?

> Or: whether or not to allow a sequence like "rlock(a); rlock(b);
> runlock(b); runlock(a); rlock(b); rlock(a);" is something we can
> choose. We do not have to forbid this sequence -- we can choose
> whether or not we allow this sequence.

I'm utterly confused now; I never argued that it would get deadlocks;
and I said I choose to not allow it from a lockdep pov. What else do you
want?




  reply	other threads:[~2008-04-29 16:15 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-29 12:56 [PATCH 0/8] CPU-Hotplug: Fix CPU-Hotplug <--> cpufreq locking dependency Gautham R Shenoy
2008-04-29 12:57 ` [PATCH 1/8] lockdep: fix recursive read lock validation Gautham R Shenoy
2008-04-29 13:16   ` Bart Van Assche
2008-04-29 14:57     ` Peter Zijlstra
2008-04-29 15:03       ` Bart Van Assche
2008-04-29 15:15         ` Peter Zijlstra
2008-04-29 16:03           ` Bart Van Assche
2008-04-29 16:15             ` Peter Zijlstra [this message]
2008-04-29 16:29               ` Bart Van Assche
2008-04-29 17:04                 ` Peter Zijlstra
2008-04-29 17:45                   ` Bart Van Assche
2008-04-29 17:58                     ` Peter Zijlstra
2008-04-29 12:58 ` [PATCH 2/8] lockdep: reader-in-writer recursion Gautham R Shenoy
2008-04-29 13:00 ` [PATCH 3/8] lockdep: fix fib_hash softirq inversion Gautham R Shenoy
2008-04-29 14:45   ` Peter Zijlstra
2008-04-29 13:01 ` [PATCH 4/8] net: af_netlink: deadlock Gautham R Shenoy
2008-04-29 13:19   ` Hans Reiser, reiserfs developer linux-os (Dick Johnson)
2008-04-29 13:02 ` [PATCH 5/8] cpu: cpu-hotplug deadlock Gautham R Shenoy
2008-04-29 14:33   ` Oleg Nesterov
2008-04-29 15:09     ` Peter Zijlstra
2008-04-29 16:45       ` Oleg Nesterov
2008-04-29 17:31         ` Peter Zijlstra
2008-04-30  5:37     ` Gautham R Shenoy
2008-04-30 11:43       ` Oleg Nesterov
2008-04-29 13:02 ` [PATCH 6/8] lockdep: annotate cpu_hotplug Gautham R Shenoy
2008-04-29 13:03 ` [PATCH 7/8] cpu_hotplug: Introduce try_get_online_cpus() Gautham R Shenoy
2008-04-29 13:05 ` [PATCH 8/8] cpufreq: Nest down_write/read(cpufreq_rwsem) within get_online_cpus()/put_online_cpus() 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=1209485739.13978.96.camel@twins \
    --to=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=bart.vanassche@gmail.com \
    --cc=ego@in.ibm.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=oleg@tv-sign.ru \
    --cc=rjw@sisk.pl \
    --cc=vatsa@in.ibm.com \
    --cc=zdenek.kabelac@gmail.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

all inboxes | Powered by JetHome®