 migrate: correct lock ordering for hugetlb file folios · gregkh/linux@b7880cb · 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 b7880cb Browse files Browse files Matthew Wilcox (Oracle) authored and akpm00 committed 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() -&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; 1 parent 90f3c12 commit b7880cb Copy full SHA for b7880cb 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 @@ -1458,6 +1458,7 @@ static int unmap_and_move_huge_page(new_folio_t get_new_folio, 1458 1458 int page_was_mapped = 0 ; 1459 1459 struct anon_vma * anon_vma = NULL ; 1460 1460 struct address_space * mapping = NULL ; 1461 + enum ttu_flags ttu = 0 ; 1461 1462 1462 1463 if ( folio_ref_count ( src ) == 1 ) { 1463 1464 /* 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, 1498 1499 goto put_anon ; 1499 1500 1500 1501 if ( folio_mapped ( src )) { 1501 - enum ttu_flags ttu = 0 ; 1502 - 1503 1502 if (! folio_test_anon ( src )) { 1504 1503 /* 1505 1504 * 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, 1516 1515 1517 1516 try_to_migrate ( src , ttu ); 1518 1517 page_was_mapped = 1 ; 1519 - 1520 - if ( ttu &amp; TTU_RMAP_LOCKED ) 1521 - i_mmap_unlock_write ( mapping ); 1522 1518 } 1523 1519 1524 1520 if (! folio_mapped ( src )) 1525 1521 rc = move_to_new_folio ( dst , src , mode ); 1526 1522 1527 1523 if ( page_was_mapped ) 1528 - remove_migration_ptes ( src , ! rc ? dst : src , 0 ); 1524 + remove_migration_ptes ( src , ! rc ? dst : src , 1525 + ttu ? RMP_LOCKED : 0 ); 1526 + 1527 + if ( ttu &amp; TTU_RMAP_LOCKED ) 1528 + i_mmap_unlock_write ( mapping ); 1529 1529 1530 1530 unlock_put_anon : 1531 1531 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. 