From: Zi Yan Date: Sun, 2 Mar 2025 03:34:24 +0000 (-0500) Subject: mm/truncate: make sure folio2 is large and has the same mapping after lock X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c430eaa3591dede56a48f70af36080cb951a5927;p=users%2Fjedix%2Flinux-maple.git mm/truncate: make sure folio2 is large and has the same mapping after lock It is possible that folio2 no longer belongs to the original mapping. Link: https://lkml.kernel.org/r/56EBE3B6-99EA-470E-B2B3-92C9C13032DF@nvidia.com Signed-off-by: Zi Yan Cc: Baolin Wang Cc: David Hildenbrand Cc: Hugh Dickins Cc: John Hubbard Cc: Kairui Song Cc: Kefeng Wang Cc: Kirill A. Shuemov Cc: Matthew Wilcox Cc: Miaohe Lin Cc: Ryan Roberts Cc: Yang Shi Cc: Yu Zhao Signed-off-by: Andrew Morton --- diff --git a/mm/truncate.c b/mm/truncate.c index 031d0be19f42..0790b6227512 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -244,8 +244,14 @@ bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end) if (!folio_trylock(folio2)) goto out; - /* split result does not matter here */ - try_folio_split(folio2, split_at2, NULL); + /* + * make sure folio2 is large and does not change its mapping. + * Its split result does not matter here. + */ + if (folio_test_large(folio2) && + folio2->mapping == folio->mapping) + try_folio_split(folio2, split_at2, NULL); + folio_unlock(folio2); out: folio_put(folio2);