Re: [RESEND v7 02/29] arm64: mm: add PMD swap-exclusive helpers
From: Usama Arif
Date: Tue Sep 22 2026 - 11:38:33 EST
On 22/09/2026 15:45, David Hildenbrand (Arm) wrote:
> On 9/22/26 14:34, Usama Arif wrote:
>>
>>
>> On 18/09/2026 22:11, David Hildenbrand (Arm) wrote:
>>> 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.
>>>>
>>>> arm64 encodes a swap PMD exactly like a swap PTE, so the new helpers wrap
>>>> the PTE ones and reuse PTE_SWP_EXCLUSIVE.
>>>>
>>>> Cc: Catalin Marinas <catalin.marinas@xxxxxxx>
>>>> Cc: Will Deacon <will@xxxxxxxxxx>
>>>> Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>
>>>> ---
>>>> arch/arm64/include/asm/pgtable.h | 6 ++++++
>>>> 1 file changed, 6 insertions(+)
>>>>
>>>> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
>>>> index e89ec5f4787b4..d3f53a601aed3 100644
>>>> --- a/arch/arm64/include/asm/pgtable.h
>>>> +++ b/arch/arm64/include/asm/pgtable.h
>>>> @@ -599,6 +599,12 @@ static inline int pmd_protnone(pmd_t pmd)
>>>> #define pmd_swp_clear_uffd(pmd) \
>>>> pte_pmd(pte_swp_clear_uffd(pmd_pte(pmd)))
>>>> #endif /* CONFIG_HAVE_ARCH_USERFAULTFD_WP */
>>>> +#ifdef CONFIG_ARCH_HAS_PMD_SOFTLEAVES
>>>> +#define pmd_swp_exclusive(pmd) pte_swp_exclusive(pmd_pte(pmd))
>>>> +#define pmd_swp_mkexclusive(pmd) pte_pmd(pte_swp_mkexclusive(pmd_pte(pmd)))
>>>> +#define pmd_swp_clear_exclusive(pmd) \
>>>> + pte_pmd(pte_swp_clear_exclusive(pmd_pte(pmd)))
>>>> +#endif
>>>
>>> Why do we #ifdef that here, but not the uffd-wp swp PMD helper?
>>>
>>
>> uffd-wp is gated on CONFIG_HAVE_ARCH_USERFAULTFD_WP.
>>
>> If I removed the CONFIG_ARCH_HAS_PMD_SOFTLEAVES guards above, when THP=n, arm64
>> will use the generic macro which is wrong.
>>
>> I tried building uffd-wp swp with just ARCH_HAS_PMD_SOFTLEAVES guard and I got
>> the build error
>>
>> mm/page_table_check.c:232:20: error: implicit declaration of
>> function 'pmd_swp_uffd'
>>
>> we will probably need a separate patch like:
>>
>> #ifdef CONFIG_ARCH_HAS_PMD_SOFTLEAVES
>> static inline bool pmd_softleaf_uffd(pmd_t pmd)
>> {
>> return pmd_swp_uffd(pmd);
>> }
>> #else
>> static inline bool pmd_softleaf_uffd(pmd_t pmd)
>> {
>> return false;
>> }
>> #endif
>>
>>
>> to avoid the above build error.
>
> Just to explain where I am coming from: for all these patches I took a look how
> the other pmd_swp_* functions where handled (and separated from the pte_swp_*
> variants). Nothing earth shattering, was mostly looking for keeping things
> consistent within these architecture codes.
>
Makes sense, this is how I wrote the functions as well, just looking at the
existing functions.