public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: Arjan van de Ven <arjan@infradead.org>
Cc: David Howells <dhowells@redhat.com>,
	Ingo Molnar <mingo@redhat.com>,
	torvalds@osdl.org, akpm@osdl.org, linux-kernel@vger.kernel.org
Subject: Re: R/W semaphore changes
Date: Tue, 04 Jul 2006 14:05:39 +0100	[thread overview]
Message-ID: <15345.1152018339@warthog.cambridge.redhat.com> (raw)
In-Reply-To: <1152017562.3109.48.camel@laptopd505.fenrus.org>

Arjan van de Ven <arjan@infradead.org> wrote:

> > Please, please, please don't.  R/W semaphores are _not_ permitted to nest.
> 
> yet they do in places, there where there is a natural hierarchy..

Where?  I believe the mm used to but no longer does.

They still aren't allowed to.  Consider:

	CPU 1			CPU 2
	=======================	=======================
	-->down_read(&A);
	<--down_read(&A);
				-->down_write(&A);
				   --- SLEEPING ---
	-->down_read(&A);
	   --- DEADLOCKED ---

> > | # define down_read_nested(sem, subclass)		down_read(sem)
> > | # define down_write_nested(sem, subclass)	down_write(sem)
> > 
> > This is _not_ okay.
> 
> why not?

See above.

R/W semaphores are as completely fair as I can make them, and they do not keep
track of who's currently been granted what sort of lock.  This means they are
liable to fall foul of the above deadlock sequence.

Any viable down_read()/down_write() nesting must be handled outside of rwsems
themselves.

Also, assume down_write() nesting is permitted, what do you do in the
following situation:

	CPU 1			CPU 2
	=======================	=======================
	-->down_write(&A);
	<--down_write(&A);
				-->down_read(&A);
				   --- SLEEPING ---
	-->foo();
	   -->down_write(&A);
	   <--down_write(&A);
	   ...
	   -->downgrade_write(&A);
	   <--downgrade_write(&A);
				   --- ??? ---
	   -->up_read(&A);
	      --- ??? ---
	   <--up_read(&A);
	<--foo();
	-->up_write(&A);
	   --- ??? ---
	<--up_write(&A);

David


  reply	other threads:[~2006-07-04 13:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-04 12:47 R/W semaphore changes David Howells
2006-07-04 12:52 ` Arjan van de Ven
2006-07-04 13:05   ` David Howells [this message]
2006-07-04 13:17     ` Arjan van de Ven
2006-07-04 13:21     ` Ingo Molnar
2006-07-04 13:33       ` [patch] lockdep: add more rwsem.h documentation Ingo Molnar

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=15345.1152018339@warthog.cambridge.redhat.com \
    --to=dhowells@redhat.com \
    --cc=akpm@osdl.org \
    --cc=arjan@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=torvalds@osdl.org \
    /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