]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm/memory-failure: hold PTL in hwpoison_hugetlb_range
authorJinjiang Tu <tujinjiang@huawei.com>
Fri, 25 Jul 2025 03:31:12 +0000 (11:31 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 2 Aug 2025 19:06:10 +0000 (12:06 -0700)
Hold PTL in hwpoison_hugetlb_range() to avoid operating on stale page, as
hwpoison_pte_range() have done.

This change is not known to address any issues which users have
experienced.

Link: https://lkml.kernel.org/r/20250725033112.2690158-1-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>
mm/memory-failure.c

index 9e2cff1999347af43f4fd49ce77b38a5667a6551..f0f0b23dcf2d639f41f53f62fdba98510279f577 100644 (file)
@@ -837,11 +837,17 @@ static int hwpoison_hugetlb_range(pte_t *ptep, unsigned long hmask,
                            struct mm_walk *walk)
 {
        struct hwpoison_walk *hwp = walk->private;
-       pte_t pte = huge_ptep_get(walk->mm, addr, ptep);
        struct hstate *h = hstate_vma(walk->vma);
+       spinlock_t *ptl;
+       pte_t pte;
+       int ret;
 
-       return check_hwpoisoned_entry(pte, addr, huge_page_shift(h),
-                                     hwp->pfn, &hwp->tk);
+       ptl = huge_pte_lock(h, walk->mm, ptep);
+       pte = huge_ptep_get(walk->mm, addr, ptep);
+       ret = check_hwpoisoned_entry(pte, addr, huge_page_shift(h),
+                                       hwp->pfn, &hwp->tk);
+       spin_unlock(ptl);
+       return ret;
 }
 #else
 #define hwpoison_hugetlb_range NULL