Skip to content

Commit 173d9d9

Browse files
Hugh Dickinstorvalds
authored andcommitted
mm/huge_memory: splitting set mapping+index before unfreeze
Huge tmpfs stress testing has occasionally hit shmem_undo_range()'s VM_BUG_ON_PAGE(page_to_pgoff(page) != index, page). Move the setting of mapping and index up before the page_ref_unfreeze() in __split_huge_page_tail() to fix this: so that a page cache lookup cannot get a reference while the tail's mapping and index are unstable. In fact, might as well move them up before the smp_wmb(): I don't see an actual need for that, but if I'm missing something, this way round is safer than the other, and no less efficient. You might argue that VM_BUG_ON_PAGE(page_to_pgoff(page) != index, page) is misplaced, and should be left until after the trylock_page(); but left as is has not crashed since, and gives more stringent assurance. Link: http://lkml.kernel.org/r/alpine.LSU.2.11.1811261516380.2275@eggly.anvils Fixes: e9b61f1 ("thp: reintroduce split_huge_page()") Requires: 605ca5e ("mm/huge_memory.c: reorder operations in __split_huge_page_tail()") Signed-off-by: Hugh Dickins <hughd@google.com> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Cc: Jerome Glisse <jglisse@redhat.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: <stable@vger.kernel.org> [4.8+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 906f9cd commit 173d9d9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

mm/huge_memory.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,6 +2402,12 @@ static void __split_huge_page_tail(struct page *head, int tail,
24022402
(1L << PG_unevictable) |
24032403
(1L << PG_dirty)));
24042404

2405+
/* ->mapping in first tail page is compound_mapcount */
2406+
VM_BUG_ON_PAGE(tail > 2 && page_tail->mapping != TAIL_MAPPING,
2407+
page_tail);
2408+
page_tail->mapping = head->mapping;
2409+
page_tail->index = head->index + tail;
2410+
24052411
/* Page flags must be visible before we make the page non-compound. */
24062412
smp_wmb();
24072413

@@ -2422,12 +2428,6 @@ static void __split_huge_page_tail(struct page *head, int tail,
24222428
if (page_is_idle(head))
24232429
set_page_idle(page_tail);
24242430

2425-
/* ->mapping in first tail page is compound_mapcount */
2426-
VM_BUG_ON_PAGE(tail > 2 && page_tail->mapping != TAIL_MAPPING,
2427-
page_tail);
2428-
page_tail->mapping = head->mapping;
2429-
2430-
page_tail->index = head->index + tail;
24312431
page_cpupid_xchg_last(page_tail, page_cpupid_last(head));
24322432

24332433
/*

0 commit comments

Comments
 (0)