Skip to content

Commit 45d19b4

Browse files
tujinjiang11akpm00
authored andcommitted
mm/smaps: fix race between smaps_hugetlb_range and migration
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/[email protected] Link: https://lkml.kernel.org/r/[email protected] Fixes: 25ee01a ("mm: hugetlb: proc: add hugetlb-related fields to /proc/PID/smaps") Signed-off-by: Jinjiang Tu <[email protected]> Acked-by: David Hildenbrand <[email protected]> Cc: Andrei Vagin <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Baolin Wang <[email protected]> Cc: Brahmajit Das <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: David Rientjes <[email protected]> Cc: Dev Jain <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Joern Engel <[email protected]> Cc: Kefeng Wang <[email protected]> Cc: Lorenzo Stoakes <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Thiago Jung Bauermann <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 366a453 commit 45d19b4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

fs/proc/task_mmu.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,10 +1148,13 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask,
11481148
{
11491149
struct mem_size_stats *mss = walk->private;
11501150
struct vm_area_struct *vma = walk->vma;
1151-
pte_t ptent = huge_ptep_get(walk->mm, addr, pte);
11521151
struct folio *folio = NULL;
11531152
bool present = false;
1153+
spinlock_t *ptl;
1154+
pte_t ptent;
11541155

1156+
ptl = huge_pte_lock(hstate_vma(vma), walk->mm, pte);
1157+
ptent = huge_ptep_get(walk->mm, addr, pte);
11551158
if (pte_present(ptent)) {
11561159
folio = page_folio(pte_page(ptent));
11571160
present = true;
@@ -1170,6 +1173,7 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask,
11701173
else
11711174
mss->private_hugetlb += huge_page_size(hstate_vma(vma));
11721175
}
1176+
spin_unlock(ptl);
11731177
return 0;
11741178
}
11751179
#else

0 commit comments

Comments
 (0)