 migrate: correct lock ordering for hugetlb file folios · gregkh/linux@5edb985 · GitHub Skip to content Navigation Menu Toggle navigation Sign in Appearance settings Platform AI CODE CREATION GitHub Copilot Write better code with AI GitHub Spark Build and deploy intelligent apps GitHub Models Manage and compare prompts MCP Registry New Integrate external tools DEVELOPER WORKFLOWS Actions Automate any workflow Codespaces Instant dev environments Issues Plan and track work Code Review Manage code changes APPLICATION SECURITY GitHub Advanced Security Find and fix vulnerabilities Code security Secure your code as you build Secret protection  EXPLORE Why GitHub Documentation Blog Changelog Marketplace View all features Solutions BY COMPANY SIZE Enterprises Small and medium teams Startups Nonprofits BY USE CASE App Modernization DevSecOps DevOps CI/CD View all use cases BY INDUSTRY Healthcare Financial services Manufacturing Government View all industries View all solutions Resources EXPLORE BY TOPIC AI Software Development DevOps Security View all topics EXPLORE BY TYPE Customer stories Events &amp; webinars Ebooks &amp; reports Business insights GitHub Skills SUPPORT &amp; SERVICES Documentation Customer support Community forum Trust center Partners View all resources Open Source COMMUNITY GitHub Sponsors Fund open source developers PROGRAMS Security Lab Maintainer Community Accelerator GitHub Stars Archive Program REPOSITORIES Topics Trending Collections Enterprise ENTERPRISE SOLUTIONS Enterprise platform AI-powered developer platform AVAILABLE ADD-ONS GitHub Advanced Security Enterprise-grade security features Copilot for Business Enterprise-grade AI features Premium Support Enterprise-grade 24/7 support Pricing Search or jump to... Search code, repositories, users, issues, pull requests... --> Search Clear Search syntax tips Provide feedback --> We read every piece of feedback, and take your input very seriously.  Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly --> Name Query To see all available qualifiers, see our documentation . Cancel Create saved search Sign in Sign up Appearance settings Resetting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} gregkh / linux Public Notifications You must be signed in to change notification settings Fork 676 Star 636 Code Actions Security and quality 0 Insights Additional navigation options Code Actions Security and quality Insights Commit 5edb985 Browse files Browse files Matthew Wilcox (Oracle) authored and gregkh committed migrate: correct lock ordering for hugetlb file folios commit b7880cb upstream. 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() -&gt; migrate_hugetlbs() -&gt; unmap_and_move_huge_page() &lt;- Takes folio_lock! -&gt; remove_migration_ptes() -&gt; __rmap_walk_file() -&gt; i_mmap_lock_read() &lt;- Waits for i_mmap_rwsem(read lock)! hugetlbfs_fallocate() -&gt; hugetlbfs_punch_hole() &lt;- Takes i_mmap_rwsem(write lock)! -&gt; hugetlbfs_zero_partial_page() -&gt; filemap_lock_hugetlb_folio() -&gt; filemap_lock_folio() -&gt; __filemap_get_folio &lt;- 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 c0d0381 . That was removed by 336bf30 for both file &amp; anon hugetlb pages when it should only have been removed for anon hugetlb pages. Link: https://lkml.kernel.org/r/20260109041345.3863089-2-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) &lt;willy@infradead.org&gt; Fixes: 336bf30 ("hugetlbfs: fix anon huge page migration race") Reported-by: syzbot+2d9c96466c978346b55f@syzkaller.appspotmail.com Link: https://lore.kernel.org/all/68e9715a.050a0220.1186a4.000d.GAE@google.com Debugged-by: Lance Yang &lt;lance.yang@linux.dev&gt; Acked-by: David Hildenbrand (Red Hat) &lt;david@kernel.org&gt; Acked-by: Zi Yan &lt;ziy@nvidia.com&gt; Cc: Alistair Popple &lt;apopple@nvidia.com&gt; Cc: Byungchul Park &lt;byungchul@sk.com&gt; Cc: Gregory Price &lt;gourry@gourry.net&gt; Cc: Jann Horn &lt;jannh@google.com&gt; Cc: Joshua Hahn &lt;joshua.hahnjy@gmail.com&gt; Cc: Liam Howlett &lt;liam.howlett@oracle.com&gt; Cc: Lorenzo Stoakes &lt;lorenzo.stoakes@oracle.com&gt; Cc: Matthew Brost &lt;matthew.brost@intel.com&gt; Cc: Rakie Kim &lt;rakie.kim@sk.com&gt; Cc: Rik van Riel &lt;riel@surriel.com&gt; Cc: Vlastimil Babka &lt;vbabka@suse.cz&gt; Cc: Ying Huang &lt;ying.huang@linux.alibaba.com&gt; Cc: &lt;stable@vger.kernel.org&gt; Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt; Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt; 1 parent 6071966 commit 5edb985 Copy full SHA for 5edb985 1 file changed + 6 - 6 Lines changed: 6 additions &amp; 6 deletions File tree Expand file tree Collapse file tree Open diff view settings Filter options mm migrate.c Expand file tree Collapse file tree Open diff view settings Collapse file ‎ mm/migrate.c ‎ Copy file name to clipboard Expand all lines: mm/migrate.c + 6 - 6 Lines changed: 6 additions &amp; 6 deletions Original file line number Diff line number Diff line change @@ -1357,6 +1357,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, 1357 1357 struct page * new_hpage ; 1358 1358 struct anon_vma * anon_vma = NULL ; 1359 1359 struct address_space * mapping = NULL ; 1360 + enum ttu_flags ttu = 0 ; 1360 1361 1361 1362 /* 1362 1363 * Migratability of hugepages depends on architectures and their size. @@ -1409,8 +1410,6 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, 1409 1410 goto put_anon ; 1410 1411 1411 1412 if ( folio_mapped ( src )) { 1412 - enum ttu_flags ttu = 0 ; 1413 - 1414 1413 if (! folio_test_anon ( src )) { 1415 1414 /* 1416 1415 * In shared mappings, try_to_unmap could potentially @@ -1427,17 +1426,18 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, 1427 1426 1428 1427 try_to_migrate ( src , ttu ); 1429 1428 page_was_mapped = 1 ; 1430 - 1431 - if ( ttu &amp; TTU_RMAP_LOCKED ) 1432 - i_mmap_unlock_write ( mapping ); 1433 1429 } 1434 1430 1435 1431 if (! folio_mapped ( src )) 1436 1432 rc = move_to_new_folio ( dst , src , mode ); 1437 1433 1438 1434 if ( page_was_mapped ) 1439 1435 remove_migration_ptes ( src , 1440 - rc == MIGRATEPAGE_SUCCESS ? dst : src , false); 1436 + rc == MIGRATEPAGE_SUCCESS ? dst : src , 1437 + ttu ? true : false); 1438 + 1439 + if ( ttu &amp; TTU_RMAP_LOCKED ) 1440 + i_mmap_unlock_write ( mapping ); 1441 1441 1442 1442 unlock_put_anon : 1443 1443 folio_unlock ( dst ); 0 commit comments Comments 0 ( 0 ) Footer &copy; 2026 GitHub,&nbsp;Inc. Footer navigation Terms Privacy Security Status Community Docs Contact Manage cookies Do not share my personal information You can’t perform that action at this time. 