FAILED: patch "[PATCH] migrate: correct lock ordering for hugetlb file folios" failed to apply to 5.15-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x b7880cb166ab62c2409046b2347261abf701530e
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026012708-eardrum-operation-6193@gregkh' --subject-prefix 'PATCH 5.15.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From b7880cb166ab62c2409046b2347261abf701530e Mon Sep 17 00:00:00 2001
From: "Matthew Wilcox (Oracle)" <[email protected]>
Date: Fri, 9 Jan 2026 04:13:42 +0000
Subject: [PATCH] migrate: correct lock ordering for hugetlb file folios
Syzbot has found a deadlock (analyzed by Lance Yang):
1) Task (5749): Holds folio_lock, then tries to acquire i_mmap_rwsem(read lock).
2) Task (5754): Holds i_mmap_rwsem(write lock), then tries to acquire folio_lock.
migrate_pages()
-> migrate_hugetlbs()
-> unmap_and_move_huge_page() <- Takes folio_lock!
-> remove_migration_ptes()
-> __rmap_walk_file()
-> i_mmap_lock_read() <- Waits for i_mmap_rwsem(read lock)!hugetlbfs_fallocate()
-> hugetlbfs_punch_hole() <- Takes i_mmap_rwsem(write lock)!
-> hugetlbfs_zero_partial_page()
-> filemap_lock_hugetlb_folio()
-> filemap_lock_folio()
-> __filemap_get_folio <- Waits for folio_lock!The migration path is the one taking locks in the wrong order according to the documentation at the top of mm/rmap.c. So expand the scope of the existing i_mmap_lock to cover the calls to remove_migration_ptes() too.
This is (mostly) how it used to be after commit c0d0381ade79. That was removed by 336bf30eb765 for both file & anon hugetlb pages when it should only have been removed for anon hugetlb pages.
mm/migrate.c +6 -6
@@ -1458,6 +1458,7 @@ static int unmap_and_move_huge_page(new_folio_t get_new_folio,int page_was_mapped =0 ;struct anon_vma *anon_vma =NULL ;struct address_space *mapping =NULL ; +enum ttu_flags ttu =0 ;if (folio_ref_count (src) ==1 ) {/* page was freed from under us. So we are done. */
@@ -1498,8 +1499,6 @@ static int unmap_and_move_huge_page(new_folio_t get_new_folio, goto put_anon;if (folio_mapped (src)) { -enum ttu_flags ttu =0 ; -if (!folio_test_anon (src)) {/* * In shared mappings, try_to_unmap could potentially
@@ -1516,16 +1515,17 @@ static int unmap_and_move_huge_page(new_folio_t get_new_folio,try_to_migrate (src, ttu); page_was_mapped =1 ; - -if (ttu &TTU_RMAP_LOCKED ) -i_mmap_unlock_write (mapping); }if (!folio_mapped (src)) rc =move_to_new_folio (dst, src, mode);if (page_was_mapped) -remove_migration_ptes (src, !rc ? dst : src,0 ); +remove_migration_ptes (src, !rc ? dst : src, + ttu ?RMP_LOCKED :0 ); + +if (ttu &TTU_RMAP_LOCKED ) +i_mmap_unlock_write (mapping); unlock_put_anon:folio_unlock (dst);
PATCH 1/1 migrate: correct lock ordering for hugetlb file folios
Syzbot has found a deadlock (analyzed by Lance Yang):
1) Task (5749): Holds folio_lock, then tries to acquire i_mmap_rwsem(read lock).
2) Task (5754): Holds i_mmap_rwsem(write lock), then tries to acquire folio_lock.
migrate_pages()
-> migrate_hugetlbs()
-> unmap_and_move_huge_page() <- Takes folio_lock!
-> remove_migration_ptes()
-> __rmap_walk_file()
-> i_mmap_lock_read() <- Waits for i_mmap_rwsem(read lock)!hugetlbfs_fallocate()
-> hugetlbfs_punch_hole() <- Takes i_mmap_rwsem(write lock)!
-> hugetlbfs_zero_partial_page()
-> filemap_lock_hugetlb_folio()
-> filemap_lock_folio()
-> __filemap_get_folio <- Waits for folio_lock!The migration path is the one taking locks in the wrong order according to the documentation at the top of mm/rmap.c. So expand the scope of the existing i_mmap_lock to cover the calls to remove_migration_ptes() too.
This is (mostly) how it used to be after commit c0d0381ade79. That was removed by 336bf30eb765 for both file & anon hugetlb pages when it should only have been removed for anon hugetlb pages.
--- mm/migrate.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
mm/migrate.c +6 -8
@@ -1291,6 +1291,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,struct page *new_hpage;struct anon_vma *anon_vma =NULL ;struct address_space *mapping =NULL ; +enum ttu_flags ttu =0 ;/* * Migratability of hugepages depends on architectures and their size.
@@ -1344,9 +1345,6 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, goto put_anon;if (page_mapped (hpage)) { -bool mapping_locked = false; -enum ttu_flags ttu =0 ; -if (!PageAnon (hpage)) {/* * In shared mappings, try_to_unmap could potentially
@@ -1358,15 +1356,11 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,if (unlikely (!mapping)) goto unlock_put_anon; - mapping_locked = true; ttu |=TTU_RMAP_LOCKED ; }try_to_migrate (hpage, ttu); page_was_mapped =1 ; - -if (mapping_locked) -i_mmap_unlock_write (mapping); }if (!page_mapped (hpage))
@@ -1374,7 +1368,11 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,if (page_was_mapped)remove_migration_ptes (hpage, - rc ==MIGRATEPAGE_SUCCESS ? new_hpage : hpage, false); + rc ==MIGRATEPAGE_SUCCESS ? new_hpage : hpage, + ttu ? true : false); + +if (ttu &TTU_RMAP_LOCKED ) +i_mmap_unlock_write (mapping); unlock_put_anon:unlock_page (new_hpage);
Signature · 1 line
2.47.3