Re: [PATCH 3/3] mm,migration: Remove straggling migration PTEs when page tables are being moved after the VMA has already moved

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

On Tue, 27 Apr 2010 22:30:52 +0100
Mel Gorman <mel@csn.ul.ie> wrote:


Here is my final proposal (before going vacation.)

I think this is very simple. The biggest problem is when move_page_range
fails, setup_arg_pages pass it all to exit() ;)

==
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

This is an band-aid patch for avoiding unmap->remap of stack pages
while it's udner exec(). At exec, pages for stack is moved by
setup_arg_pages(). Under this, (vma,page)<->address relationship
can be in broken state.
Moreover, if moving ptes fails, pages with not-valid-rmap remains
in the page table and objrmap for the page is completely broken
until exit() frees all up.

This patch adds vma->broken_rmap. If broken_rmap != 0, vma_address()
returns -EFAULT always and try_to_unmap() fails.
(IOW, the pages for stack are pinned until setup_arg_pages() ends.)

And this prevents page migration because the page's mapcount never
goes to 0 until exec() fixes it up.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
 fs/exec.c                |    4 +++-
 include/linux/mm_types.h |    5 +++++
 mm/rmap.c                |    5 +++++
 3 files changed, 13 insertions(+), 1 deletion(-)

Index: mel-test/fs/exec.c
===================================================================
--- mel-test.orig/fs/exec.c
+++ mel-test/fs/exec.c
@@ -250,7 +250,8 @@ static int __bprm_mm_init(struct linux_b
 	err = insert_vm_struct(mm, vma);
 	if (err)
 		goto err;
-
+	/* prevent rmap_walk, try_to_unmap() etc..until we get fixed rmap */
+	vma->unstable_rmap = 1;
 	mm->stack_vm = mm->total_vm = 1;
 	up_write(&mm->mmap_sem);
 	bprm->p = vma->vm_end - sizeof(void *);
@@ -653,6 +654,7 @@ int setup_arg_pages(struct linux_binprm 
 		ret = -EFAULT;
 
 out_unlock:
+	vma->unstable_rmap = 0;
 	up_write(&mm->mmap_sem);
 	return ret;
 }
Index: mel-test/include/linux/mm_types.h
===================================================================
--- mel-test.orig/include/linux/mm_types.h
+++ mel-test/include/linux/mm_types.h
@@ -183,6 +183,11 @@ struct vm_area_struct {
 #ifdef CONFIG_NUMA
 	struct mempolicy *vm_policy;	/* NUMA policy for the VMA */
 #endif
+	/*
+ 	 * updated only under down_write(mmap_sem). while this is not 0,
+ 	 * objrmap is not trustable.
+ 	 */
+	int unstable_rmap;
 };
 
 struct core_thread {
Index: mel-test/mm/rmap.c
===================================================================
--- mel-test.orig/mm/rmap.c
+++ mel-test/mm/rmap.c
@@ -332,6 +332,11 @@ vma_address(struct page *page, struct vm
 {
 	pgoff_t pgoff = page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT);
 	unsigned long address;
+#ifdef CONFIG_MIGRATION
+	/* While unstable_rmap is set, we cannot trust objrmap */
+	if (unlikely(vma->unstable_rmap))
+		return -EFAULT:
+#endif
 
 	address = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
 	if (unlikely(address < vma->vm_start || address >= vma->vm_end)) {

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/3] Fix migration races in rmap_walk() V2, Mel Gorman, (Tue Apr 27, 2:30 pm)
Re: [PATCH 0/3] Fix migration races in rmap_walk() V2, Christoph Lameter, (Tue Apr 27, 3:27 pm)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., Andrea Arcangeli, (Tue Apr 27, 3:30 pm)
Re: [PATCH 0/3] Fix migration races in rmap_walk() V2, Andrea Arcangeli, (Tue Apr 27, 3:32 pm)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., Andrea Arcangeli, (Tue Apr 27, 3:58 pm)
Re: [PATCH 1/3] mm,migration: During fork(), wait for migr ..., KAMEZAWA Hiroyuki, (Tue Apr 27, 4:52 pm)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., KAMEZAWA Hiroyuki, (Tue Apr 27, 5:03 pm)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., Andrea Arcangeli, (Tue Apr 27, 5:08 pm)
Re: [PATCH 0/3] Fix migration races in rmap_walk() V2, KAMEZAWA Hiroyuki, (Tue Apr 27, 5:13 pm)
Re: [PATCH 0/3] Fix migration races in rmap_walk() V2, Andrea Arcangeli, (Tue Apr 27, 5:20 pm)
Re: [PATCH 1/3] mm,migration: During fork(), wait for migr ..., KAMEZAWA Hiroyuki, (Tue Apr 27, 5:28 pm)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., KAMEZAWA Hiroyuki, (Tue Apr 27, 5:36 pm)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., KAMEZAWA Hiroyuki, (Tue Apr 27, 5:39 pm)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., Andrea Arcangeli, (Tue Apr 27, 6:05 pm)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., Andrea Arcangeli, (Tue Apr 27, 6:09 pm)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., KAMEZAWA Hiroyuki, (Tue Apr 27, 6:18 pm)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., KAMEZAWA Hiroyuki, (Tue Apr 27, 6:29 pm)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., Andrea Arcangeli, (Tue Apr 27, 6:36 pm)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., Andrea Arcangeli, (Tue Apr 27, 6:44 pm)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., KAMEZAWA Hiroyuki, (Tue Apr 27, 7:12 pm)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., Andrea Arcangeli, (Tue Apr 27, 7:42 pm)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., KAMEZAWA Hiroyuki, (Tue Apr 27, 7:49 pm)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., KAMEZAWA Hiroyuki, (Wed Apr 28, 12:28 am)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., KAMEZAWA Hiroyuki, (Wed Apr 28, 1:30 am)
Re: [PATCH 3/3] mm,migration: Remove straggling migration ..., Andrea Arcangeli, (Wed Apr 28, 7:46 am)
Re: [PATCH 0/3] Fix migration races in rmap_walk() V2, Andrea Arcangeli, (Wed Apr 28, 8:16 am)
Re: [PATCH 0/3] Fix migration races in rmap_walk() V2, Andrea Arcangeli, (Wed Apr 28, 8:45 am)
[RFC PATCH] take all anon_vma locks in anon_vma_lock, Rik van Riel, (Wed Apr 28, 10:47 am)
Re: [PATCH 2/3] mm,migration: Prevent rmap_walk_[anon|ksm] ..., Andrea Arcangeli, (Wed Apr 28, 10:58 am)
Re: [RFC PATCH] take all anon_vma locks in anon_vma_lock, Andrea Arcangeli, (Wed Apr 28, 11:03 am)
Re: [RFC PATCH] take all anon_vma locks in anon_vma_lock, Rik van Riel, (Wed Apr 28, 11:09 am)
[RFC PATCH -v2] take all anon_vma locks in anon_vma_lock, Rik van Riel, (Wed Apr 28, 11:25 am)
Re: [PATCH 0/3] Fix migration races in rmap_walk() V2, Andrea Arcangeli, (Wed Apr 28, 1:40 pm)
Re: [PATCH 0/3] Fix migration races in rmap_walk() V2, Andrea Arcangeli, (Wed Apr 28, 2:05 pm)