Re: [PATCH 04/14] mm,migration: Allow the migration of PageSwapCache pages

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Mel Gorman
Date: Thursday, April 22, 2010 - 7:14 am

On Thu, Apr 22, 2010 at 07:51:53PM +0900, KAMEZAWA Hiroyuki wrote:

Ok wow. That is exceptionally well-spotted. This looks like a proper bug
that compaction exposes as opposed to a bug that compaction introduces.


In the event the VMA is backed by a file, the mapping i_mmap_lock is taken for
the duration of the update and is  taken elsewhere where the VMA information
is read such as rmap_walk_file()

In the event the VMA is anon, vma_adjust currently talks no locks and your
patch introduces a new one but why not use the anon_vma lock here? Am I
missing something that requires the new lock?

For example;

==== CUT HERE ====
mm: Take the anon_vma lock in vma_adjust()

vma_adjust() is updating anon VMA information without any locks taken.
In constract, file-backed mappings use the i_mmap_lock. This lack of
locking can result in races with page migration. During rmap_walk(),
vma_address() can return -EFAULT for an address that will soon be valid.
This leaves a dangling migration PTE behind which can later cause a
BUG_ON to trigger when the page is faulted in.

This patch takes the anon_vma->lock during vma_adjust to avoid such
races.

Signed-off-by: Mel Gorman <mel@csn.ul.ie>
---
 mm/mmap.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index f90ea92..61d6f1d 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -578,6 +578,9 @@ again:			remove_next = 1 + (end > next->vm_end);
 		}
 	}
 
+	if (vma->anon_vma)
+		spin_lock(&vma->anon_vma->lock);
+
 	if (root) {
 		flush_dcache_mmap_lock(mapping);
 		vma_prio_tree_remove(vma, root);
@@ -620,6 +623,9 @@ again:			remove_next = 1 + (end > next->vm_end);
 	if (mapping)
 		spin_unlock(&mapping->i_mmap_lock);
 
+	if (vma->anon_vma)
+		spin_unlock(&vma->anon_vma->lock);
+
 	if (remove_next) {
 		if (file) {
 			fput(file);
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/14] Memory Compaction v8, Mel Gorman, (Tue Apr 20, 2:01 pm)
[PATCH 09/14] mm,compaction: Memory compaction core, Mel Gorman, (Tue Apr 20, 2:01 pm)
Re: [PATCH 01/14] mm,migration: Take a reference to the an ..., KAMEZAWA Hiroyuki, (Tue Apr 20, 7:49 pm)
Re: [PATCH 04/14] mm,migration: Allow the migration of Pag ..., Christoph Lameter, (Wed Apr 21, 7:30 am)
Re: [PATCH 04/14] mm,migration: Allow the migration of Pag ..., Christoph Lameter, (Wed Apr 21, 8:05 am)
Re: [PATCH 04/14] mm,migration: Allow the migration of Pag ..., Christoph Lameter, (Wed Apr 21, 8:31 am)
Re: [PATCH 04/14] mm,migration: Allow the migration of Pag ..., Christoph Lameter, (Wed Apr 21, 8:46 am)
Re: [PATCH 04/14] mm,migration: Allow the migration of Pag ..., KAMEZAWA Hiroyuki, (Wed Apr 21, 4:59 pm)
Re: [PATCH 04/14] mm,migration: Allow the migration of Pag ..., KAMEZAWA Hiroyuki, (Thu Apr 22, 2:46 am)
Re: [PATCH 04/14] mm,migration: Allow the migration of Pag ..., KAMEZAWA Hiroyuki, (Thu Apr 22, 3:31 am)
Re: [PATCH 04/14] mm,migration: Allow the migration of Pag ..., KAMEZAWA Hiroyuki, (Thu Apr 22, 3:51 am)
Re: [PATCH 04/14] mm,migration: Allow the migration of Pag ..., Mel Gorman, (Thu Apr 22, 7:14 am)
Re: [PATCH 04/14] mm,migration: Allow the migration of Pag ..., Christoph Lameter, (Thu Apr 22, 8:14 am)
Re: [PATCH 04/14] mm,migration: Allow the migration of Pag ..., Christoph Lameter, (Thu Apr 22, 12:40 pm)
Re: [PATCH 04/14] mm,migration: Allow the migration of Pag ..., KAMEZAWA Hiroyuki, (Thu Apr 22, 4:52 pm)
Re: [PATCH 04/14] mm,migration: Allow the migration of Pag ..., Andrea Arcangeli, (Fri Apr 23, 11:31 am)
Re: [PATCH 04/14] mm,migration: Allow the migration of Pag ..., Andrea Arcangeli, (Fri Apr 23, 12:39 pm)
Re: [PATCH 04/14] mm,migration: Allow the migration of Pag ..., KAMEZAWA Hiroyuki, (Tue Apr 27, 3:41 am)