From 31895438e702f48e25b7aa6d88f9c97c795c79c7 Mon Sep 17 00:00:00 2001 From: Song Liu Date: Mon, 23 Sep 2019 15:37:47 -0700 Subject: [PATCH] filemap: check compound_head(page)->mapping in pagecache_get_page() Similar to previous patch, pagecache_get_page() avoids race condition with truncate by checking page->mapping == mapping. This does not work for compound pages. This patch let it check compound_head(page)->mapping instead. Link: http://lkml.kernel.org/r/20190801184244.3169074-3-songliubraving@fb.com Signed-off-by: Song Liu Suggested-by: Johannes Weiner Acked-by: Johannes Weiner Cc: Hillf Danton Cc: Hugh Dickins Cc: Kirill A. Shutemov Cc: Rik van Riel Cc: William Kucharski Cc: Oleg Nesterov Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index fc7818b4537e..0b301103ea80 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1647,7 +1647,7 @@ repeat: } /* Has the page been truncated? */ - if (unlikely(page->mapping != mapping)) { + if (unlikely(compound_head(page)->mapping != mapping)) { unlock_page(page); put_page(page); goto repeat;