Skip to content

Commit

Permalink
mm: fix sleeping function warning from __put_anon_vma
Browse files Browse the repository at this point in the history
Trinity reports BUG:

  sleeping function called from invalid context at kernel/locking/rwsem.c:47
  in_atomic(): 0, irqs_disabled(): 0, pid: 5787, name: trinity-c27

__might_sleep < down_write < __put_anon_vma < page_get_anon_vma <
migrate_pages < compact_zone < compact_zone_order < try_to_compact_pages ..

Right, since conversion to mutex then rwsem, we should not put_anon_vma()
from inside an rcu_read_lock()ed section: fix the two places that did so.
And add might_sleep() to anon_vma_free(), as suggested by Peter Zijlstra.

Fixes: 88c2208 ("mm: optimize page_lock_anon_vma() fast-path")
Reported-by: Dave Jones <[email protected]>
Signed-off-by: Hugh Dickins <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Hugh Dickins authored and torvalds committed Jun 4, 2014
1 parent f9625c4 commit 7f39dda
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mm/rmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ static inline void anon_vma_free(struct anon_vma *anon_vma)
* LOCK should suffice since the actual taking of the lock must
* happen _before_ what follows.
*/
might_sleep();
if (rwsem_is_locked(&anon_vma->root->rwsem)) {
anon_vma_lock_write(anon_vma);
anon_vma_unlock_write(anon_vma);
Expand Down Expand Up @@ -426,8 +427,9 @@ struct anon_vma *page_get_anon_vma(struct page *page)
* above cannot corrupt).
*/
if (!page_mapped(page)) {
rcu_read_unlock();
put_anon_vma(anon_vma);
anon_vma = NULL;
return NULL;
}
out:
rcu_read_unlock();
Expand Down Expand Up @@ -477,9 +479,9 @@ struct anon_vma *page_lock_anon_vma_read(struct page *page)
}

if (!page_mapped(page)) {
rcu_read_unlock();
put_anon_vma(anon_vma);
anon_vma = NULL;
goto out;
return NULL;
}

/* we pinned the anon_vma, its safe to sleep */
Expand Down

0 comments on commit 7f39dda

Please sign in to comment.