filemap: Don't release a locked folio
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Tue, 7 Jun 2022 19:45:53 +0000 (15:45 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 9 Jun 2022 20:24:25 +0000 (16:24 -0400)
commit6bf74cddcffac0bc5ee0fad724aac778d2e53f75
treeed0e4594baaf65b943a2a522ebcba63bcc4e69f4
parent3d9f55c57bc3659f986acc421eac431ff6edcc83
filemap: Don't release a locked folio

We must hold a reference over the call to filemap_release_folio(),
otherwise the page cache will put the last reference to the folio
before we unlock it, leading to splats like this:

 BUG: Bad page state in process u8:5  pfn:1ab1f4
 page:ffffea0006ac7d00 refcount:0 mapcount:0 mapping:0000000000000000 index:0x28b1de pfn:0x1ab1f4
 flags: 0x17ff80000040001(locked|reclaim|node=0|zone=2|lastcpupid=0xfff)
 raw: 017ff80000040001 dead000000000100 dead000000000122 0000000000000000
 raw: 000000000028b1de 0000000000000000 00000000ffffffff 0000000000000000
 page dumped because: PAGE_FLAGS_CHECK_AT_FREE flag(s) set

It's an error path, so it doesn't see much testing.

Reported-by: Darrick J. Wong <djwong@kernel.org>
Fixes: a42634a6c07d ("readahead: Use a folio in read_pages()")
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
mm/readahead.c