From: David Howells <dhowells@redhat.com>
To: Andrea Arcangeli <andrea@suse.de>
Cc: Manfred Spraul <manfred@colorfullife.com>,
Linus Torvalds <torvalds@transmeta.com>,
dhowells@redhat.com, Ulrich.Weigand@de.ibm.com,
linux-kernel@vger.kernel.org
Subject: Re: Deadlock on the mm->mmap_sem
Date: Tue, 18 Sep 2001 10:32:03 +0100 [thread overview]
Message-ID: <4294.1000805523@warthog.cambridge.redhat.com> (raw)
In-Reply-To: Message from Andrea Arcangeli <andrea@suse.de> of "Tue, 18 Sep 2001 09:55:49 +0200." <20010918095549.T698@athlon.random>
Linus Torvalds <linux-kernel@vger.kernel.org> wrote:
> The mmap semaphore is a read-write semaphore, and it _is_ permissible to
> call "copy_to_user()" and friends while holding the read lock.
>
> The bug appears to be in the implementation of the write semaphore -
> down_write() doesn't undestand that blocked writes must not block new
> readers, exactly because of this situation.
>
> The situation wrt read-write spinlocks is exactly the same, btw, except
> there we have "readers can have interrupts enabled even if interrupts
> also take read locks" instead of having user-level faults.
>
> Why do we want to explicitly allow this behaviour wrt mmap_sem? Because
> some things are inherently racy without it (ie threaded processes that
> read or write the address space - coredumping, ptrace etc).
Hmmm... I don't think this is possible with XADD based semaphores as they
stand (my version or Andrea's).
With the current XADD based stuff, you can't distinguish between one
writer running and a queue of sleeping locks and one reader running and a
queue of sleeping locks without counting the sleepers
Sem(sleepers) Proc 1 Proc 2 Proc 3 Proc 4 Proc 5
======== ====== ====== ====== ====== ======
00000000(0)
-->down_read()
<--down_read()
00000001(0)
-->down_write()
-->down_write_failed()
[schedule]
FFFF0001(1)
-->down_write()
-->down_write_failed()
[schedule]
FFFE0001(2)
-->down_write()
-->down_write_failed()
[schedule]
FFFD0001(3)
-->down_read_unfair()
FFFC0002(3)
is the active proc
R or W?
Sem Proc 1 Proc 2 Proc 3 Proc 4
======== ====== ====== ====== ======
00000000(0)
-->down_write()
<--down_write()
FFFF0001(0)
-->down_write()
-->down_write_failed()
[schedule]
FFFE0001(1)
-->down_write()
-->down_write_failed()
[schedule]
FFFD0001(2)
-->down_read_unfair()
FFFC0002(2)
is the active proc R or W?
In fact, it's worse than that: you can't tell the difference between two
active readers and a queue of sleepers and one active writer, one failed
read or write attempt as yet unprocessed, and a queue of sleepers
Sem(sleepers) Proc 1 Proc 2 Proc 3 Proc 4 Proc 5
============== ====== ====== ====== ====== ======
00000000(0)
-->down_read()
<--down_read()
00000001(0)
-->down_read()
<--down_read()
00000002(0)
-->down_write()
FFFF0003(0)
-->down_write_failed()
[schedule]
FFFF0002(1)
-->down_write()
FFFE0003(1)
-->down_read_unfair()
FFFE0004(1)
since the LSW>2 does
this mean there are 2+
readers active?
Sem(sleepers) Proc 1 Proc 2 Proc 3 Proc 4 Proc 5
============== ====== ====== ====== ====== ======
00000000(0)
-->down_write()
<--down_write()
FFFF0001(0)
-->down_write()
FFFE0002(0)
-->down_write_failed()
[schedule]
FFFE0001(1)
-->down_read()
FFFE0002(1)
-->down_read()
FFFE0003(1)
-->down_read_unfair()
FFFE0004(1)
since the LSW>2 does
this mean there are 2+
readers active?
I think it might well be too hard to do unfair reads with the XADD based
stuff. The problem is that you can't compensate for the effect on the counter
of failed attempts to get read or write locks, even when you've got the
semaphore spinlock (the queue length is of no help).
I think that this problem can only be solved by going to the spinlock version,
and maintaining a flag to say what sort of lock is currently active.
David
next prev parent reply other threads:[~2001-09-18 9:32 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-09-17 21:50 Deadlock on the mm->mmap_sem Manfred Spraul
2001-09-17 23:39 ` Linus Torvalds
[not found] ` <200109172339.f8HNd5W13244@penguin.transmeta.com>
2001-09-18 0:01 ` Andrea Arcangeli
2001-09-18 7:31 ` Manfred Spraul
2001-09-18 7:55 ` Andrea Arcangeli
2001-09-18 8:18 ` David Howells
2001-09-18 9:32 ` David Howells [this message]
2001-09-18 9:37 ` Manfred Spraul
2001-09-18 9:49 ` Arjan van de Ven
2001-09-18 12:53 ` Manfred Spraul
2001-09-18 14:13 ` David Howells
2001-09-18 14:49 ` Alan Cox
2001-09-18 15:26 ` David Howells
2001-09-18 15:46 ` Alan Cox
2001-09-18 15:11 ` David Howells
2001-09-18 16:49 ` Linus Torvalds
2001-09-19 9:51 ` David Howells
2001-09-19 12:49 ` Andrea Arcangeli
2001-09-19 14:08 ` Manfred Spraul
2001-09-19 14:51 ` David Howells
2001-09-19 15:18 ` Manfred Spraul
2001-09-19 14:53 ` David Howells
2001-09-19 18:03 ` Andrea Arcangeli
2001-09-19 18:16 ` Benjamin LaHaise
2001-09-19 18:27 ` David Howells
2001-09-19 18:48 ` Andrea Arcangeli
2001-09-19 18:45 ` Andrea Arcangeli
2001-09-19 21:14 ` Benjamin LaHaise
2001-09-19 22:07 ` Andrea Arcangeli
2001-09-19 18:19 ` Manfred Spraul
2001-09-20 2:07 ` Andrea Arcangeli
2001-09-20 4:37 ` Andrea Arcangeli
2001-09-20 7:05 ` David Howells
2001-09-20 7:19 ` Andrea Arcangeli
2001-09-20 8:01 ` David Howells
2001-09-20 8:09 ` Andrea Arcangeli
2001-09-19 18:26 ` David Howells
2001-09-19 18:47 ` Andrea Arcangeli
2001-09-19 23:25 ` David Howells
2001-09-19 23:34 ` Andrea Arcangeli
2001-09-19 23:46 ` Andrea Arcangeli
2001-09-19 23:24 ` [PATCH] attempt #2 (Re: Deadlock on the mm->mmap_sem) David Howells
2001-09-19 14:58 ` Deadlock on the mm->mmap_sem David Howells
[not found] <masp0008@stud.uni-sb.de>
2001-09-20 10:57 ` Studierende der Universitaet des Saarlandes
2001-09-20 12:40 ` David Howells
2001-09-20 18:24 ` Andrea Arcangeli
2001-09-20 21:43 ` Manfred Spraul
2001-09-22 21:06 ` Manfred Spraul
-- strict thread matches above, loose matches on Subject: below --
2001-09-18 13:22 Ulrich Weigand
2001-09-17 20:57 Ulrich Weigand
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=4294.1000805523@warthog.cambridge.redhat.com \
--to=dhowells@redhat.com \
--cc=Ulrich.Weigand@de.ibm.com \
--cc=andrea@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=manfred@colorfullife.com \
--cc=torvalds@transmeta.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