Re: [PATCH v3 10/16] mm: replace pmd_to_swp_entry() with softleaf_from_pmd()

From: Vlastimil Babka

Date: Fri Nov 21 2025 - 13:42:53 EST


On 11/10/25 23:21, Lorenzo Stoakes wrote:
> Introduce softleaf_from_pmd() to do the equivalent operation for PMDs that
> softleaf_from_pte() fulfils, and cascade changes through code base
> accordingly, introducing helpers as necessary.

Some of that is adding new pte stuff too, so it could have been separate
patch, but it's not a big deal.

> We are then able to eliminate pmd_to_swp_entry(), is_pmd_migration_entry(),
> is_pmd_device_private_entry() and is_pmd_non_present_folio_entry().
>
> This further establishes the use of leaf operations throughout the code
> base and further establishes the foundations for eliminating is_swap_pmd().
>
> No functional change intended.
>
> Reviewed-by: SeongJae Park <sj@xxxxxxxxxx>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx>

Reviewed-by: Vlastimil Babka <vbabka@xxxxxxx>

Assuming the below is fixed. Glad I could demonstrate I'm not just rubber
stamping all this ;P
(probably missed stuff anyway, as usual)

> --- a/mm/page_table_check.c
> +++ b/mm/page_table_check.c
> @@ -8,7 +8,7 @@
> #include <linux/mm.h>
> #include <linux/page_table_check.h>
> #include <linux/swap.h>
> -#include <linux/swapops.h>
> +#include <linux/leafops.h>
>
> #undef pr_fmt
> #define pr_fmt(fmt) "page_table_check: " fmt
> @@ -179,10 +179,10 @@ void __page_table_check_pud_clear(struct mm_struct *mm, pud_t pud)
> EXPORT_SYMBOL(__page_table_check_pud_clear);
>
> /* Whether the swap entry cached writable information */
> -static inline bool swap_cached_writable(swp_entry_t entry)
> +static inline bool softleaf_cached_writable(softleaf_t entry)
> {
> - return is_writable_device_private_entry(entry) ||
> - is_writable_migration_entry(entry);
> + return softleaf_is_device_private(entry) ||

Shouldn't there be softleaf_is_device_private_write(entry) ?

> + softleaf_is_migration_write(entry);
> }
>
> static void page_table_check_pte_flags(pte_t pte)
> @@ -190,9 +190,9 @@ static void page_table_check_pte_flags(pte_t pte)
> if (pte_present(pte)) {
> WARN_ON_ONCE(pte_uffd_wp(pte) && pte_write(pte));
> } else if (pte_swp_uffd_wp(pte)) {
> - const swp_entry_t entry = pte_to_swp_entry(pte);
> + const softleaf_t entry = softleaf_from_pte(pte);
>
> - WARN_ON_ONCE(swap_cached_writable(entry));
> + WARN_ON_ONCE(softleaf_cached_writable(entry));
> }
> }
>
> @@ -219,9 +219,9 @@ static inline void page_table_check_pmd_flags(pmd_t pmd)
> if (pmd_uffd_wp(pmd))
> WARN_ON_ONCE(pmd_write(pmd));
> } else if (pmd_swp_uffd_wp(pmd)) {
> - swp_entry_t entry = pmd_to_swp_entry(pmd);
> + const softleaf_t entry = softleaf_from_pmd(pmd);
>
> - WARN_ON_ONCE(swap_cached_writable(entry));
> + WARN_ON_ONCE(softleaf_cached_writable(entry));
> }
> }
>