mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-01 10:45:49 +00:00
filemap: Fix serialization adding transparent huge pages to page cache
Commit793917d997
("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 commit730633f0b7
("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:793917d997
("mm/readahead: Add large folio readahead") Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
This commit is contained in:
parent
b653db7735
commit
00fa15e0d5
@ -510,6 +510,7 @@ void page_cache_ra_order(struct readahead_control *ractl,
|
||||
new_order--;
|
||||
}
|
||||
|
||||
filemap_invalidate_lock_shared(mapping);
|
||||
while (index <= limit) {
|
||||
unsigned int order = new_order;
|
||||
|
||||
@ -536,6 +537,7 @@ void page_cache_ra_order(struct readahead_control *ractl,
|
||||
}
|
||||
|
||||
read_pages(ractl);
|
||||
filemap_invalidate_unlock_shared(mapping);
|
||||
|
||||
/*
|
||||
* If there were already pages in the page cache, then we may have
|
||||
|
Loading…
Reference in New Issue
Block a user