Commit 0aedadf9 authored by Christoph Lameter's avatar Christoph Lameter Committed by Linus Torvalds

mm: move migrate_prep out from under mmap_sem

Move the migrate_prep outside the mmap_sem for the following system calls

1. sys_move_pages
2. sys_migrate_pages
3. sys_mbind()

It really does not matter when we flush the lru.  The system is free to
add pages onto the lru even during migration which will make the page
migration either skip the page (mbind, migrate_pages) or return a busy
state (move_pages).

Fixes this lockdep warning (and potential deadlock):

Some VM place has
      mmap_sem -> kevent_wq via lru_add_drain_all()

net/core/dev.c::dev_ioctl()  has
     rtnl_lock  ->  mmap_sem        (*) the ioctl has copy_from_user() and it can do page fault.

linkwatch_event has
     kevent_wq -> rtnl_lock
Signed-off-by: default avatarChristoph Lameter <cl@linux-foundation.org>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Reported-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Hugh Dickins <hugh@veritas.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Lee Schermerhorn <lee.schermerhorn@hp.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 17a1217e
...@@ -489,12 +489,6 @@ check_range(struct mm_struct *mm, unsigned long start, unsigned long end, ...@@ -489,12 +489,6 @@ check_range(struct mm_struct *mm, unsigned long start, unsigned long end,
int err; int err;
struct vm_area_struct *first, *vma, *prev; struct vm_area_struct *first, *vma, *prev;
if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) {
err = migrate_prep();
if (err)
return ERR_PTR(err);
}
first = find_vma(mm, start); first = find_vma(mm, start);
if (!first) if (!first)
...@@ -809,9 +803,13 @@ int do_migrate_pages(struct mm_struct *mm, ...@@ -809,9 +803,13 @@ int do_migrate_pages(struct mm_struct *mm,
const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags) const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags)
{ {
int busy = 0; int busy = 0;
int err = 0; int err;
nodemask_t tmp; nodemask_t tmp;
err = migrate_prep();
if (err)
return err;
down_read(&mm->mmap_sem); down_read(&mm->mmap_sem);
err = migrate_vmas(mm, from_nodes, to_nodes, flags); err = migrate_vmas(mm, from_nodes, to_nodes, flags);
...@@ -974,6 +972,12 @@ static long do_mbind(unsigned long start, unsigned long len, ...@@ -974,6 +972,12 @@ static long do_mbind(unsigned long start, unsigned long len,
start, start + len, mode, mode_flags, start, start + len, mode, mode_flags,
nmask ? nodes_addr(*nmask)[0] : -1); nmask ? nodes_addr(*nmask)[0] : -1);
if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) {
err = migrate_prep();
if (err)
return err;
}
down_write(&mm->mmap_sem); down_write(&mm->mmap_sem);
vma = check_range(mm, start, end, nmask, vma = check_range(mm, start, end, nmask,
flags | MPOL_MF_INVERT, &pagelist); flags | MPOL_MF_INVERT, &pagelist);
......
...@@ -841,12 +841,12 @@ static int do_move_page_to_node_array(struct mm_struct *mm, ...@@ -841,12 +841,12 @@ static int do_move_page_to_node_array(struct mm_struct *mm,
struct page_to_node *pp; struct page_to_node *pp;
LIST_HEAD(pagelist); LIST_HEAD(pagelist);
migrate_prep();
down_read(&mm->mmap_sem); down_read(&mm->mmap_sem);
/* /*
* Build a list of pages to migrate * Build a list of pages to migrate
*/ */
migrate_prep();
for (pp = pm; pp->node != MAX_NUMNODES; pp++) { for (pp = pm; pp->node != MAX_NUMNODES; pp++) {
struct vm_area_struct *vma; struct vm_area_struct *vma;
struct page *page; struct page *page;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment