Re: [RESEND v7 05/29] riscv: mm: add PMD swap-exclusive helpers
From: David Hildenbrand (Arm)
Date: Fri Sep 18 2026 - 17:25:13 EST
On 9/14/26 14:27, Usama Arif wrote:
> A later patch keeps a PMD-mapped anonymous THP mapped by a PMD across the
> swap round-trip, so PG_anon_exclusive now has to survive in a swap PMD and
> not just in a swap PTE.
>
> riscv encodes a swap PMD exactly like a swap PTE, so the new helpers wrap
> the PTE ones and reuse _PAGE_SWP_EXCLUSIVE.
>
> Cc: Paul Walmsley <pjw@xxxxxxxxxx>
> Cc: Palmer Dabbelt <palmer@xxxxxxxxxxx>
> Cc: Albert Ou <aou@xxxxxxxxxxxxxxxxx>
> Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>
> ---
> arch/riscv/include/asm/pgtable.h | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
> index d48f90140841e..b644db16bda94 100644
> --- a/arch/riscv/include/asm/pgtable.h
> +++ b/arch/riscv/include/asm/pgtable.h
> @@ -1219,6 +1219,21 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
> }
>
> #ifdef CONFIG_ARCH_HAS_PMD_SOFTLEAVES
> +static inline bool pmd_swp_exclusive(pmd_t pmd)
> +{
> + return pte_swp_exclusive(pmd_pte(pmd));
> +}
> +
> +static inline pmd_t pmd_swp_mkexclusive(pmd_t pmd)
> +{
> + return pte_pmd(pte_swp_mkexclusive(pmd_pte(pmd)));
> +}
> +
> +static inline pmd_t pmd_swp_clear_exclusive(pmd_t pmd)
> +{
> + return pte_pmd(pte_swp_clear_exclusive(pmd_pte(pmd)));
> +}
> +
> #define __pmd_to_swp_entry(pmd) ((swp_entry_t) { pmd_val(pmd) })
> #define __swp_entry_to_pmd(swp) __pmd((swp).val)
> #endif /* CONFIG_ARCH_HAS_PMD_SOFTLEAVES */
Reviewed-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
--
Cheers,
David