mirror of
https://github.com/torvalds/linux.git
synced 2026-05-31 02:24:24 +02:00
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/20250724090958.455887-3-tujinjiang@huawei.com Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com> Acked-by: David Hildenbrand <david@redhat.com> Cc: Andrei Vagin <avagin@gmail.com> Cc: Andrii Nakryiko <andrii@kernel.org> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Brahmajit Das <brahmajit.xyz@gmail.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: David Rientjes <rientjes@google.com> Cc: Dev Jain <dev.jain@arm.com> Cc: Hugh Dickins <hughd@google.com> Cc: Joern Engel <joern@logfs.org> Cc: Kefeng Wang <wangkefeng.wang@huawei.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Thiago Jung Bauermann <thiago.bauermann@linaro.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
45d19b4b6c
commit
aa5a10b070
|
|
@ -2021,12 +2021,14 @@ static int pagemap_hugetlb_range(pte_t *ptep, unsigned long hmask,
|
|||
struct pagemapread *pm = walk->private;
|
||||
struct vm_area_struct *vma = walk->vma;
|
||||
u64 flags = 0, frame = 0;
|
||||
spinlock_t *ptl;
|
||||
int err = 0;
|
||||
pte_t pte;
|
||||
|
||||
if (vma->vm_flags & VM_SOFTDIRTY)
|
||||
flags |= PM_SOFT_DIRTY;
|
||||
|
||||
ptl = huge_pte_lock(hstate_vma(vma), walk->mm, ptep);
|
||||
pte = huge_ptep_get(walk->mm, addr, ptep);
|
||||
if (pte_present(pte)) {
|
||||
struct folio *folio = page_folio(pte_page(pte));
|
||||
|
|
@ -2054,11 +2056,12 @@ static int pagemap_hugetlb_range(pte_t *ptep, unsigned long hmask,
|
|||
|
||||
err = add_to_pagemap(&pme, pm);
|
||||
if (err)
|
||||
return err;
|
||||
break;
|
||||
if (pm->show_pfn && (flags & PM_PRESENT))
|
||||
frame++;
|
||||
}
|
||||
|
||||
spin_unlock(ptl);
|
||||
cond_resched();
|
||||
|
||||
return err;
|
||||
|
|
@ -3132,17 +3135,22 @@ static int gather_pte_stats(pmd_t *pmd, unsigned long addr,
|
|||
static int gather_hugetlb_stats(pte_t *pte, unsigned long hmask,
|
||||
unsigned long addr, unsigned long end, struct mm_walk *walk)
|
||||
{
|
||||
pte_t huge_pte = huge_ptep_get(walk->mm, addr, pte);
|
||||
pte_t huge_pte;
|
||||
struct numa_maps *md;
|
||||
struct page *page;
|
||||
spinlock_t *ptl;
|
||||
|
||||
ptl = huge_pte_lock(hstate_vma(walk->vma), walk->mm, pte);
|
||||
huge_pte = huge_ptep_get(walk->mm, addr, pte);
|
||||
if (!pte_present(huge_pte))
|
||||
return 0;
|
||||
goto out;
|
||||
|
||||
page = pte_page(huge_pte);
|
||||
|
||||
md = walk->private;
|
||||
gather_stats(page, md, pte_dirty(huge_pte), 1);
|
||||
out:
|
||||
spin_unlock(ptl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user