 mm/smaps: fix race between smaps_hugetlb_range and migration · gregkh/linux@b625883 · 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 681 Star 637 Code Actions Security and quality 0 Insights Additional navigation options Code Actions Security and quality Insights Commit b625883 Browse files Browse files tujinjiang11 authored and gregkh committed mm/smaps: fix race between smaps_hugetlb_range and migration [ Upstream commit 45d19b4 ] smaps_hugetlb_range() handles the pte without holdling ptl, and may be concurrenct with migration, leaing to BUG_ON in pfn_swap_entry_to_page(). The race is as follows. smaps_hugetlb_range migrate_pages huge_ptep_get remove_migration_ptes folio_unlock pfn_swap_entry_folio BUG_ON To fix it, hold ptl lock in smaps_hugetlb_range(). Link: https://lkml.kernel.org/r/20250724090958.455887-1-tujinjiang@huawei.com Link: https://lkml.kernel.org/r/20250724090958.455887-2-tujinjiang@huawei.com Fixes: 25ee01a ("mm: hugetlb: proc: add hugetlb-related fields to /proc/PID/smaps") Signed-off-by: Jinjiang Tu &lt;tujinjiang@huawei.com&gt; Acked-by: David Hildenbrand &lt;david@redhat.com&gt; Cc: Andrei Vagin &lt;avagin@gmail.com&gt; Cc: Andrii Nakryiko &lt;andrii@kernel.org&gt; Cc: Baolin Wang &lt;baolin.wang@linux.alibaba.com&gt; Cc: Brahmajit Das &lt;brahmajit.xyz@gmail.com&gt; Cc: Catalin Marinas &lt;catalin.marinas@arm.com&gt; Cc: Christophe Leroy &lt;christophe.leroy@csgroup.eu&gt; Cc: David Rientjes &lt;rientjes@google.com&gt; Cc: Dev Jain &lt;dev.jain@arm.com&gt; Cc: Hugh Dickins &lt;hughd@google.com&gt; Cc: Joern Engel &lt;joern@logfs.org&gt; Cc: Kefeng Wang &lt;wangkefeng.wang@huawei.com&gt; Cc: Lorenzo Stoakes &lt;lorenzo.stoakes@oracle.com&gt; Cc: Michal Hocko &lt;mhocko@suse.com&gt; Cc: Ryan Roberts &lt;ryan.roberts@arm.com&gt; Cc: Thiago Jung Bauermann &lt;thiago.bauermann@linaro.org&gt; Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt; Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt; 1 parent 55c232d commit b625883 Copy full SHA for b625883 1 file changed + 5 - 1 Lines changed: 5 additions &amp; 1 deletion File tree Expand file tree Collapse file tree Open diff view settings Filter options fs/proc task_mmu.c Expand file tree Collapse file tree Open diff view settings Collapse file ‎ fs/proc/task_mmu.c ‎ Copy file name to clipboard Expand all lines: fs/proc/task_mmu.c + 5 - 1 Lines changed: 5 additions &amp; 1 deletion Original file line number Diff line number Diff line change @@ -1020,10 +1020,13 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask, 1020 1020 { 1021 1021 struct mem_size_stats * mss = walk -&gt; private ; 1022 1022 struct vm_area_struct * vma = walk -&gt; vma ; 1023 - pte_t ptent = huge_ptep_get ( walk -&gt; mm , addr , pte ); 1024 1023 struct folio * folio = NULL ; 1025 1024 bool present = false; 1025 + spinlock_t * ptl ; 1026 + pte_t ptent ; 1026 1027 1028 + ptl = huge_pte_lock ( hstate_vma ( vma ), walk -&gt; mm , pte ); 1029 + ptent = huge_ptep_get ( walk -&gt; mm , addr , pte ); 1027 1030 if ( pte_present ( ptent )) { 1028 1031 folio = page_folio ( pte_page ( ptent )); 1029 1032 present = true; @@ -1042,6 +1045,7 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask, 1042 1045 else 1043 1046 mss -&gt; private_hugetlb += huge_page_size ( hstate_vma ( vma )); 1044 1047 } 1048 + spin_unlock ( ptl ); 1045 1049 return 0 ; 1046 1050 } 1047 1051 #else 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. 