Skip to content

Commit aa5a10b

Browse files
tujinjiang11akpm00
authored andcommitted
fs/proc/task_mmu: hold PTL in pagemap_hugetlb_range and gather_hugetlb_stats
Hold PTL in pagemap_hugetlb_range() and gather_hugetlb_stats() to avoid operating on stale page, as pagemap_pmd_range() and gather_pte_stats() have done. Link: https://lkml.kernel.org/r/[email protected] 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 45d19b4 commit aa5a10b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

fs/proc/task_mmu.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,12 +2021,14 @@ static int pagemap_hugetlb_range(pte_t *ptep, unsigned long hmask,
20212021
struct pagemapread *pm = walk->private;
20222022
struct vm_area_struct *vma = walk->vma;
20232023
u64 flags = 0, frame = 0;
2024+
spinlock_t *ptl;
20242025
int err = 0;
20252026
pte_t pte;
20262027

20272028
if (vma->vm_flags & VM_SOFTDIRTY)
20282029
flags |= PM_SOFT_DIRTY;
20292030

2031+
ptl = huge_pte_lock(hstate_vma(vma), walk->mm, ptep);
20302032
pte = huge_ptep_get(walk->mm, addr, ptep);
20312033
if (pte_present(pte)) {
20322034
struct folio *folio = page_folio(pte_page(pte));
@@ -2054,11 +2056,12 @@ static int pagemap_hugetlb_range(pte_t *ptep, unsigned long hmask,
20542056

20552057
err = add_to_pagemap(&pme, pm);
20562058
if (err)
2057-
return err;
2059+
break;
20582060
if (pm->show_pfn && (flags & PM_PRESENT))
20592061
frame++;
20602062
}
20612063

2064+
spin_unlock(ptl);
20622065
cond_resched();
20632066

20642067
return err;
@@ -3132,17 +3135,22 @@ static int gather_pte_stats(pmd_t *pmd, unsigned long addr,
31323135
static int gather_hugetlb_stats(pte_t *pte, unsigned long hmask,
31333136
unsigned long addr, unsigned long end, struct mm_walk *walk)
31343137
{
3135-
pte_t huge_pte = huge_ptep_get(walk->mm, addr, pte);
3138+
pte_t huge_pte;
31363139
struct numa_maps *md;
31373140
struct page *page;
3141+
spinlock_t *ptl;
31383142

3143+
ptl = huge_pte_lock(hstate_vma(walk->vma), walk->mm, pte);
3144+
huge_pte = huge_ptep_get(walk->mm, addr, pte);
31393145
if (!pte_present(huge_pte))
3140-
return 0;
3146+
goto out;
31413147

31423148
page = pte_page(huge_pte);
31433149

31443150
md = walk->private;
31453151
gather_stats(page, md, pte_dirty(huge_pte), 1);
3152+
out:
3153+
spin_unlock(ptl);
31463154
return 0;
31473155
}
31483156

0 commit comments

Comments
 (0)