mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] anon_vma list locking bug
@ 2004-06-25 22:35 Hugh Dickins
  2004-06-25 22:37 ` [PATCH] mm lock ordering summary Hugh Dickins
  0 siblings, 1 reply; 7+ messages in thread
From: Hugh Dickins @ 2004-06-25 22:35 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Vladimir V. Saveliev, linux-kernel

Vladimir Saveliev reported anon_vma_unlink list_del BUG (LKML 24 June).
His testing is still in progress, but we believe it comes from a nasty
locking deficiency I introduced in 2.6.7's anon_vma_prepare.

Andrea's original anon_vma_prepare was fine, it needed no anon_vma lock
because it was always linking a freshly allocated structure; but my
find_mergeable enhancement let it adopt a neighbouring anon_vma, which
of course needs locking against a racing linkage from another mm -
which the earlier adjust_vma fix seems to have made more likely.

Does anon_vma->lock nest inside or outside page_table_lock?  Inside, but
that's not obvious without a lock ordering list: instead of listing the
order here, update the list in filemap.c; but a separate patch because
that's less urgent and more likely to get wrong or provoke controversy.

(Could do it with anon_vma lock after dropping page_table_lock, but
a long comment explaining why some code is safe suggests it's not.)

Signed-off-by: Hugh Dickins <hugh@veritas.com>

--- 2.6.7/mm/rmap.c	2004-06-16 06:21:02.000000000 +0100
+++ linux/mm/rmap.c	2004-06-25 22:15:41.164841904 +0100
@@ -18,14 +18,11 @@
  */
 
 /*
- * Locking:
- * - the page->mapcount field is protected by the PG_maplock bit,
- *   which nests within the mm->page_table_lock,
- *   which nests within the page lock.
- * - because swapout locking is opposite to the locking order
- *   in the page fault path, the swapout path uses trylocks
- *   on the mm->page_table_lock
+ * Locking: see "Lock ordering" summary in filemap.c.
+ * In swapout, page_map_lock is held on entry to page_referenced and
+ * try_to_unmap, so they trylock for i_mmap_lock and page_table_lock.
  */
+
 #include <linux/mm.h>
 #include <linux/pagemap.h>
 #include <linux/swap.h>
@@ -79,8 +76,12 @@ int anon_vma_prepare(struct vm_area_stru
 		/* page_table_lock to protect against threads */
 		spin_lock(&mm->page_table_lock);
 		if (likely(!vma->anon_vma)) {
+			if (!allocated)
+				spin_lock(&anon_vma->lock);
 			vma->anon_vma = anon_vma;
 			list_add(&vma->anon_vma_node, &anon_vma->head);
+			if (!allocated)
+				spin_unlock(&anon_vma->lock);
 			allocated = NULL;
 		}
 		spin_unlock(&mm->page_table_lock);


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

end of thread, other threads:[~2004-06-26  1:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-25 22:35 [PATCH] anon_vma list locking bug Hugh Dickins
2004-06-25 22:37 ` [PATCH] mm lock ordering summary Hugh Dickins
2004-06-25 23:34   ` Andrew Morton
2004-06-26  0:33     ` Hugh Dickins
2004-06-26  0:41       ` Andrew Morton
2004-06-26  1:22         ` Hugh Dickins
2004-06-26  1:39           ` Andrew Morton

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®