Skip to content

Commit 3445cb2

Browse files
Hugh Dickinsgregkh
Hugh Dickins
authored andcommitted
mm: fix invalidate_complete_page2() lock ordering
commit ec4d9f6 upstream. In fuzzing with trinity, lockdep protested "possible irq lock inversion dependency detected" when isolate_lru_page() reenabled interrupts while still holding the supposedly irq-safe tree_lock: invalidate_inode_pages2 invalidate_complete_page2 spin_lock_irq(&mapping->tree_lock) clear_page_mlock isolate_lru_page spin_unlock_irq(&zone->lru_lock) isolate_lru_page() is correct to enable interrupts unconditionally: invalidate_complete_page2() is incorrect to call clear_page_mlock() while holding tree_lock, which is supposed to nest inside lru_lock. Both truncate_complete_page() and invalidate_complete_page() call clear_page_mlock() before taking tree_lock to remove page from radix_tree. I guess invalidate_complete_page2() preferred to test PageDirty (again) under tree_lock before committing to the munlock; but since the page has already been unmapped, its state is already somewhat inconsistent, and no worse if clear_page_mlock() moved up. Reported-by: Sasha Levin <levinsasha928@gmail.com> Deciphered-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Hugh Dickins <hughd@google.com> Acked-by: Mel Gorman <mel@csn.ul.ie> Cc: Rik van Riel <riel@redhat.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michel Lespinasse <walken@google.com> Cc: Ying Han <yinghan@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f037cf0 commit 3445cb2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

mm/truncate.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,12 @@ invalidate_complete_page2(struct address_space *mapping, struct page *page)
394394
if (page_has_private(page) && !try_to_release_page(page, GFP_KERNEL))
395395
return 0;
396396

397+
clear_page_mlock(page);
398+
397399
spin_lock_irq(&mapping->tree_lock);
398400
if (PageDirty(page))
399401
goto failed;
400402

401-
clear_page_mlock(page);
402403
BUG_ON(page_has_private(page));
403404
__delete_from_page_cache(page);
404405
spin_unlock_irq(&mapping->tree_lock);

0 commit comments

Comments
 (0)