 migrate: correct lock ordering for hugetlb file folios · gregkh/linux@b750708 · 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 b750708 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 c775ea4 commit b750708 Copy full SHA for b750708 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 @@ -1439,6 +1439,7 @@ static int unmap_and_move_huge_page(new_folio_t get_new_folio, 1439 1439 int page_was_mapped = 0 ; 1440 1440 struct anon_vma * anon_vma = NULL ; 1441 1441 struct address_space * mapping = NULL ; 1442 + enum ttu_flags ttu = 0 ; 1442 1443 1443 1444 if ( folio_ref_count ( src ) == 1 ) { 1444 1445 /* page was freed from under us. So we are done. */ @@ -1479,8 +1480,6 @@ static int unmap_and_move_huge_page(new_folio_t get_new_folio, 1479 1480 goto put_anon ; 1480 1481 1481 1482 if ( folio_mapped ( src )) { 1482 - enum ttu_flags ttu = 0 ; 1483 - 1484 1483 if (! folio_test_anon ( src )) { 1485 1484 /* 1486 1485 * In shared mappings, try_to_unmap could potentially @@ -1497,17 +1496,18 @@ static int unmap_and_move_huge_page(new_folio_t get_new_folio, 1497 1496 1498 1497 try_to_migrate ( src , ttu ); 1499 1498 page_was_mapped = 1 ; 1500 - 1501 - if ( ttu &amp; TTU_RMAP_LOCKED ) 1502 - i_mmap_unlock_write ( mapping ); 1503 1499 } 1504 1500 1505 1501 if (! folio_mapped ( src )) 1506 1502 rc = move_to_new_folio ( dst , src , mode ); 1507 1503 1508 1504 if ( page_was_mapped ) 1509 1505 remove_migration_ptes ( src , 1510 - rc == MIGRATEPAGE_SUCCESS ? dst : src , 0 ); 1506 + rc == MIGRATEPAGE_SUCCESS ? dst : src , 1507 + ttu ? RMP_LOCKED : 0 ); 1508 + 1509 + if ( ttu &amp; TTU_RMAP_LOCKED ) 1510 + i_mmap_unlock_write ( mapping ); 1511 1511 1512 1512 unlock_put_anon : 1513 1513 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. 