]> git.itanic.dy.fi Git - linux-stable/commit
filemap: Fix serialization adding transparent huge pages to page cache
authorAlistair Popple <apopple@nvidia.com>
Mon, 20 Jun 2022 09:05:36 +0000 (19:05 +1000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Jun 2022 07:04:35 +0000 (09:04 +0200)
commit28e016f00c67c03a1081a090a620f67aeef48044
tree6b594ad7e5f8b2d6c9ac523644c04a5d5f364f1b
parentd49ed6713f21ba1d53b45f46fe3e141e9d0c67e5
filemap: Fix serialization adding transparent huge pages to page cache

[ Upstream commit 00fa15e0d56482e32d8ca1f51d76b0ee00afb16b ]

Commit 793917d997df ("mm/readahead: Add large folio readahead")
introduced support for using large folios for filebacked pages if the
filesystem supports it.

page_cache_ra_order() was introduced to allocate and add these large
folios to the page cache. However adding pages to the page cache should
be serialized against truncation and hole punching by taking
invalidate_lock. Not doing so can lead to data races resulting in stale
data getting added to the page cache and marked up-to-date. See commit
730633f0b7f9 ("mm: Protect operations adding pages to page cache with
invalidate_lock") for more details.

This issue was found by inspection but a testcase revealed it was
possible to observe in practice on XFS. Fix this by taking
invalidate_lock in page_cache_ra_order(), to mirror what is done for the
non-thp case in page_cache_ra_unbounded().

Signed-off-by: Alistair Popple <apopple@nvidia.com>
Fixes: 793917d997df ("mm/readahead: Add large folio readahead")
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
mm/readahead.c