Re: [PATCH v8 03/30] loongarch: mm: add PMD swap-exclusive helpers

From: Usama Arif

Date: Tue Nov 03 2026 - 11:30:43 EST


On Fri, 2 Oct 2026 22:17:51 +0800 Huacai Chen <chenhuacai@xxxxxxxxxx> wrote:

> Hi, Usama,
>
> On Fri, Oct 2, 2026 at 5:55 PM Usama Arif <usama.arif@xxxxxxxxx> wrote:
> >
> > Prepare for keeping a PMD-mapped anonymous THP mapped by a PMD across the
> > swap round-trip, which makes PG_anon_exclusive have to survive in a swap
> > PMD and not just in a swap PTE.
> >
> > A LoongArch swap PMD is the swap PTE value plus _PAGE_HUGE, and
> > _PAGE_SWP_EXCLUSIVE sits outside both the type and the offset field, so the
> > PMD helpers can use the same bit.
> >
> > Cc: Huacai Chen <chenhuacai@xxxxxxxxxx>
> > Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>
> > Reviewed-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> > ---
> > arch/loongarch/include/asm/pgtable.h | 19 +++++++++++++++++++
> > 1 file changed, 19 insertions(+)
> >
> > diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h
> > index cf29a4c8ac593..87fecc3a51001 100644
> > --- a/arch/loongarch/include/asm/pgtable.h
> > +++ b/arch/loongarch/include/asm/pgtable.h
> > @@ -351,6 +351,25 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
> > return pte;
> > }
> >
> > +#ifdef CONFIG_ARCH_HAS_PMD_SOFTLEAVES
> > +static inline pmd_t pmd_swp_mkexclusive(pmd_t pmd)
> > +{
> > + pmd_val(pmd) |= _PAGE_SWP_EXCLUSIVE;
> > + return pmd;
> > +}
> > +
> > +static inline bool pmd_swp_exclusive(pmd_t pmd)
> > +{
> > + return pmd_val(pmd) & _PAGE_SWP_EXCLUSIVE;
> > +}
> > +
> > +static inline pmd_t pmd_swp_clear_exclusive(pmd_t pmd)
> > +{
> > + pmd_val(pmd) &= ~_PAGE_SWP_EXCLUSIVE;
> > + return pmd;
> > +}
> I think the order should be pmd_swp_exclusive, pmd_swp_mkexclusive and
> pmd_swp_clear_exclusive. That looks more natural.
>
> The riscv version is already like this, but others are not.

Done. The LoongArch helpers now use test/mk/clear. I also reordered
s390's PMD helpers to match its adjacent PTE helpers. RISC-V and arm64
already use test/mk/clear for their PMD helpers. Powerpc and x86 retain
the order used by their adjacent PTE helpers.

>
>
> Huacai
>
> > +#endif
> > +
> > #define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL))
> > #define pte_present(pte) (pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROTNONE))
> > #define pte_no_exec(pte) (pte_val(pte) & _PAGE_NO_EXEC)
> > --
> > 2.53.0-Meta
> >
>