[RFC PATCH 0/1] mm/debug_vm_pgtable: Use a swp_entry_t input value for swap tests
From: Gerald Schaefer
Date: Mon Jun 23 2025 - 14:44:01 EST
Hi,
currently working on enabling THP_SWAP and THP_MIGRATION support for s390,
and stumbling over the WARN_ON(args->fixed_pmd_pfn != pmd_pfn(pmd)) in
debug_vm_pgtable pmd_swap_tests(). The problem is that pmd_pfn() on s390
will use different shift values for leaf (large) and non-leaf PMDs. And
when used on swapped PMDs, for which pmd_leaf() will always return false
because !pmd_present(), the result is not really well defined.
I think that pmd_pfn() is not safe or ever meant to be called on swapped
PMD entries, and it doesn't seem to be used in that way anywhere else but
debug_vm_pgtable. Also, the whole logic to test the various swap helpers
on normal PTE/PMD entries seems wrong to me. It just works by chance,
because e.g. __pmd_to_swp_entry() and __swp_entry_to_pmd() are just no-ops
on other architectures (also on s390, but only for PTEs), and also
pmd_pfn() does not have any dependency on leaf/non-leaf entries there.
So, I started with a small patch to make pmd_swap_tests() use a proper
swapped PMD entry as input value, similar to how it is already done in
pte_swap_exclusive_tests(), and not use pmd_pfn() for compare but rather
compare the whole entries, again similar to pte_swap_exclusive_tests().
But then I noticed that such a change would probably also make sense for
the other swap tests, and also a small inconsistency in Documentation,
where it says e.g.
__pte_to_swp_entry | Creates a swapped entry (arch) from a mapped PTE
I think this is wrong, those helpers should never operate on present and
mapped PTEs, and they certainly don't create any swapped entry from a
mapped entry, given that they are just no-ops on most architectures.
Instead, in this example, it just returns the arch-dependent
representation of a swp_entry_t, which happens to be just the entry
itself on most architectures. See also pte_to_swp_entry() /
swp_entry_to_pte() in include/linux/swapops.h.
Now it became a larger clean-up, and I hope it makes sense. This is all
rather new common code for me, so maybe I got things wrong, feedback is
welcome.
Gerald Schaefer (1):
mm/debug_vm_pgtable: Use a swp_entry_t input value for swap tests
Documentation/mm/arch_pgtable_helpers.rst | 8 ++--
mm/debug_vm_pgtable.c | 55 ++++++++++++++---------
2 files changed, 38 insertions(+), 25 deletions(-)
--
2.48.1