]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
riscv: use an atomic xchg in pudp_huge_get_and_clear()
authorAlexandre Ghiti <alexghiti@rivosinc.com>
Thu, 14 Aug 2025 12:06:14 +0000 (12:06 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 12 Sep 2025 00:24:59 +0000 (17:24 -0700)
Make sure we return the right pud value and not a value that could have
been overwritten in between by a different core.

Link: https://lkml.kernel.org/r/20250814-dev-alex-thp_pud_xchg-v1-1-b4704dfae206@rivosinc.com
Fixes: c3cc2a4a3a23 ("riscv: Add support for PUD THP")
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: Andrew Donnellan <ajd@linux.ibm.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
arch/riscv/include/asm/pgtable.h

index 91697fbf1f9013005800f713797e4b6b1fc8d312..e69346307e78608dd98d8b7a77b7063c333448ee 100644 (file)
@@ -942,6 +942,17 @@ static inline int pudp_test_and_clear_young(struct vm_area_struct *vma,
        return ptep_test_and_clear_young(vma, address, (pte_t *)pudp);
 }
 
+#define __HAVE_ARCH_PUDP_HUGE_GET_AND_CLEAR
+static inline pud_t pudp_huge_get_and_clear(struct mm_struct *mm,
+                                           unsigned long address, pud_t *pudp)
+{
+       pud_t pud = __pud(atomic_long_xchg((atomic_long_t *)pudp, 0));
+
+       page_table_check_pud_clear(mm, pud);
+
+       return pud;
+}
+
 static inline int pud_young(pud_t pud)
 {
        return pte_young(pud_pte(pud));