linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [patch] splice mmap_sem deadlock
@ 2007-09-28 16:00 Nick Piggin
  2007-09-28 17:31 ` Jens Axboe
  0 siblings, 1 reply; 21+ messages in thread
From: Nick Piggin @ 2007-09-28 16:00 UTC (permalink / raw)
  To: Andrew Morton, Jens Axboe, Linux Memory Management List

I'm fairly sure this is the right patch... but the explicit comment has me
thinking I missed something? (there is also a down_write->fault deadlock
in the splice code in -mm, however when talking with Jens about that code,
we might have an idea for a different approach using preexisting vmas
rather than setting them up with splice -- so this patch is just for mainline)


mmap_sem cannot be taken recursively for read, due to the FIFO nature of the
rwsem, and the presence of possible write lockers.

process A			process B
down_read(mmap_sem); [1]
get_user();             	down_write(mmap_sem); [2]
-> page fault
   down_read(mmap_sem); [3]

[1] will never be released until [3] can be taken and released, however:
[2] blocks on [1]; [3] blocks on [2].

Signed-off-by: Nick Piggin <npiggin@suse.de>

---
Index: linux-2.6/fs/splice.c
===================================================================
--- linux-2.6.orig/fs/splice.c
+++ linux-2.6/fs/splice.c
@@ -1534,12 +1534,6 @@ static int get_iovec_page_array(const st
 {
 	int buffers = 0, error = 0;
 
-	/*
-	 * It's ok to take the mmap_sem for reading, even
-	 * across a "get_user()".
-	 */
-	down_read(&current->mm->mmap_sem);
-
 	while (nr_vecs) {
 		unsigned long off, npages;
 		void __user *base;
@@ -1583,9 +1577,11 @@ static int get_iovec_page_array(const st
 		if (npages > PIPE_BUFFERS - buffers)
 			npages = PIPE_BUFFERS - buffers;
 
+		down_read(&current->mm->mmap_sem);
 		error = get_user_pages(current, current->mm,
 				       (unsigned long) base, npages, 0, 0,
 				       &pages[buffers], NULL);
+		up_read(&current->mm->mmap_sem);
 
 		if (unlikely(error <= 0))
 			break;
@@ -1624,8 +1620,6 @@ static int get_iovec_page_array(const st
 		iov++;
 	}
 
-	up_read(&current->mm->mmap_sem);
-
 	if (buffers)
 		return buffers;
 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2007-10-01 18:20 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-28 16:00 [patch] splice mmap_sem deadlock Nick Piggin
2007-09-28 17:31 ` Jens Axboe
2007-09-28 18:10   ` Linus Torvalds
2007-09-28 18:15     ` Jens Axboe
2007-09-28 18:23       ` Linus Torvalds
2007-09-28 19:30         ` Jens Axboe
2007-09-28 20:02           ` Linus Torvalds
2007-09-28 20:08             ` Linus Torvalds
2007-09-29  6:37               ` Jens Axboe
2007-10-01 12:03               ` Jens Axboe
2007-10-01 15:11                 ` Linus Torvalds
2007-10-01 15:45                   ` Balbir Singh
2007-10-01 16:11                     ` Linus Torvalds
2007-10-01 18:19                       ` Balbir Singh
2007-10-01 17:33                   ` Jens Axboe
2007-09-29 13:10             ` Nick Piggin
2007-09-30  6:46               ` Jens Axboe
2007-09-30 12:07                 ` Nick Piggin
2007-09-30 20:05                   ` Jens Axboe
2007-09-30 20:12                     ` Nick Piggin
2007-09-29 13:08     ` Nick Piggin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox