[Devel,RHEL7,COMMIT] ms/mm: fix sleeping function warning from __put_anon_vma

Submitted by Konstantin Khorenko on Aug. 7, 2017, 9:40 a.m.

Details

Message ID 201708070940.v779erGt007154@finist_cl7.x64_64.work.ct
State New
Series "mm: fix sleeping function warning from __put_anon_vma"
Headers show

Commit Message

Konstantin Khorenko Aug. 7, 2017, 9:40 a.m.
The commit is pushed to "branch-rh7-3.10.0-514.26.1.vz7.35.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-514.26.1.vz7.33.22
------>
commit 1c7e7932ba7de7636e02a32d88f365bcc0f2a2b1
Author: Hugh Dickins <hughd@google.com>
Date:   Mon Aug 7 13:40:52 2017 +0400

    ms/mm: fix sleeping function warning from __put_anon_vma
    
    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: 88c22088bf23 ("mm: optimize page_lock_anon_vma() fast-path")
    Reported-by: Dave Jones <davej@redhat.com>
    Signed-off-by: Hugh Dickins <hughd@google.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    
    Backport of ms commit 7f39dda ("mm: fix sleeping function warning from
    __put_anon_vma")
    
    Found in scope of https://jira.sw.ru/browse/PSBM-65033
    
    Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
---
 mm/rmap.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/mm/rmap.c b/mm/rmap.c
index 4668df5..f3aac5a 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -110,6 +110,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);
@@ -480,8 +481,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();
@@ -531,9 +533,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 */