Re: [RESEND v7 04/29] powerpc: mm: add PMD swap-exclusive helpers

From: David Hildenbrand (Arm)

Date: Fri Sep 18 2026 - 17:26:39 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.
>
> book3s64 builds a swap PMD by running the PTE encoding over pmd_pte(), so
> the PMD helpers use the same _PAGE_SWP_EXCLUSIVE bit. It is also the only
> powerpc variant that selects ARCH_HAS_PMD_SOFTLEAVES, via PPC_THP.
>
> Cc: Madhavan Srinivasan <maddy@xxxxxxxxxxxxx>
> Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>
> ---
> arch/powerpc/include/asm/book3s/64/pgtable.h | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
> index dff8790a047db..28943ef3c1c80 100644
> --- a/arch/powerpc/include/asm/book3s/64/pgtable.h
> +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
> @@ -699,6 +699,23 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
> return __pte_raw(pte_raw(pte) & cpu_to_be64(~_PAGE_SWP_EXCLUSIVE));
> }
>
> +#ifdef CONFIG_ARCH_HAS_PMD_SOFTLEAVES
> +static inline pmd_t pmd_swp_mkexclusive(pmd_t pmd)
> +{
> + return __pmd_raw(pmd_raw(pmd) | cpu_to_be64(_PAGE_SWP_EXCLUSIVE));
> +}
> +
> +static inline bool pmd_swp_exclusive(pmd_t pmd)
> +{
> + return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_SWP_EXCLUSIVE));
> +}
> +
> +static inline pmd_t pmd_swp_clear_exclusive(pmd_t pmd)
> +{
> + return __pmd_raw(pmd_raw(pmd) & cpu_to_be64(~_PAGE_SWP_EXCLUSIVE));
> +}
> +#endif

This should likely go below the pmd_swp_mksoft_dirty() handling block?

For softdirty it's e.g.,

#define pmd_swp_mksoft_dirty(pmd) pte_pmd(pte_swp_mksoft_dirty(pmd_pte(pmd)))


Why can't we follow a similar model here?

--
Cheers,

David