Skip to content

Commit aa5b917

Browse files
Hugh Dickinsbrauner
authored andcommitted
mm: invalidation check mapping before folio_contains
Enabling tmpfs "direct IO" exposes it to invalidate_inode_pages2_range(), which when swapping can hit the VM_BUG_ON_FOLIO(!folio_contains()): the folio has been moved from page cache to swap cache (with folio->mapping reset to NULL), but the folio_index() embedded in folio_contains() sees swapcache, and so returns the swapcache_index() - whereas folio->index would be the right one to check against the index from mapping's xarray. There are different ways to fix this, but my preference is just to order the checks in invalidate_inode_pages2_range() the same way that they are in __filemap_get_folio() and find_lock_entries() and filemap_fault(): check folio->mapping before folio_contains(). Signed-off-by: Hugh Dickins <[email protected]> Reviewed-by: Jan Kara <[email protected]> Message-Id: <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent e88e0d3 commit aa5b917

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mm/truncate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,11 +657,11 @@ int invalidate_inode_pages2_range(struct address_space *mapping,
657657
}
658658

659659
folio_lock(folio);
660-
VM_BUG_ON_FOLIO(!folio_contains(folio, indices[i]), folio);
661-
if (folio->mapping != mapping) {
660+
if (unlikely(folio->mapping != mapping)) {
662661
folio_unlock(folio);
663662
continue;
664663
}
664+
VM_BUG_ON_FOLIO(!folio_contains(folio, indices[i]), folio);
665665
folio_wait_writeback(folio);
666666

667667
if (folio_mapped(folio))

0 commit comments

Comments
 (0)