Skip to content

Commit 546e42c

Browse files
Alexandre GhitiPaul Walmsley
authored andcommitted
riscv: Use an atomic xchg in pudp_huge_get_and_clear()
Make sure we return the right pud value and not a value that could have been overwritten in between by a different core. Fixes: c3cc2a4 ("riscv: Add support for PUD THP") Cc: stable@vger.kernel.org Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> Link: https://lore.kernel.org/r/20250814-dev-alex-thp_pud_xchg-v1-1-b4704dfae206@rivosinc.com [pjw@kernel.org: use xchg rather than atomic_long_xchg; avoid atomic op for !CONFIG_SMP like x86] Signed-off-by: Paul Walmsley <pjw@kernel.org>
1 parent a03ee11 commit 546e42c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

arch/riscv/include/asm/pgtable.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,23 @@ static inline int pudp_test_and_clear_young(struct vm_area_struct *vma,
942942
return ptep_test_and_clear_young(vma, address, (pte_t *)pudp);
943943
}
944944

945+
#define __HAVE_ARCH_PUDP_HUGE_GET_AND_CLEAR
946+
static inline pud_t pudp_huge_get_and_clear(struct mm_struct *mm,
947+
unsigned long address, pud_t *pudp)
948+
{
949+
#ifdef CONFIG_SMP
950+
pud_t pud = __pud(xchg(&pudp->pud, 0));
951+
#else
952+
pud_t pud = *pudp;
953+
954+
pud_clear(pudp);
955+
#endif
956+
957+
page_table_check_pud_clear(mm, pud);
958+
959+
return pud;
960+
}
961+
945962
static inline int pud_young(pud_t pud)
946963
{
947964
return pte_young(pud_pte(pud));

0 commit comments

Comments
 (0)