mm: remove is_swap_[pte, pmd]() + non-swap entries, introduce leaf entries
Subsystems (26)
cover mm: remove is_swap_[pte, pmd]() + non-swap entries, introduce leaf entries
There's an established convention in the kernel that we treat leaf page tables (so far at the PTE, PMD level) as containing 'swap entries' should they be neither empty (i.e. p**_none() evaluating true) nor present (i.e. p**_present() evaluating true).
However, at the same time we also have helper predicates - is_swap_pte(), is_swap_pmd() - which are inconsistently used.
This is problematic, as it is logical to assume that should somebody wish to operate upon a page table swap entry they should first check to see if it is in fact one.
It also implies that perhaps, in future, we might introduce a non-present, none page table entry that is not a swap entry.
This series resolves this issue by systematically eliminating all use of the is_swap_pte() and is swap_pmd() predicates so we retain only the convention that should a leaf page table entry be neither none nor present it is a swap entry.
We also have the further issue that 'swap entry' is unfortunately a really rather overloaded term and in fact refers to both entries for swap and for other information such as migration entries, page table markers, and device private entries.
We therefore have the rather 'unique' concept of a 'non-swap' swap entry.
This series therefore introduces the concept of 'leaf entries' to eliminate this confusion.
A leaf entry in this sense is any page table entry which is non-present, and represented by the leaf_entry_t type.
This includes 'none' or empty entries, which are simply represented by an zero leaf entry value.
In order to maintain compatibility as we transition the kernel to this new type, we simply typedef swp_entry_t to leaf_entry_t.
We introduce a number of predicates and helpers to interact with leaf entries in include/linux/leafops.h which, as it imports swapops.h, can be treated as a drop-in replacement for swapops.h wherever leaf entry helpers are used.
Since leafent_from_[pte, pmd]() treats present entries as they were empty/none leaf entries, this allows for a great deal of simplification of code throughout the code base, which this series utilises a great deal.
We additionally change from swap entry to leaf entry handling where it makes sense to and eliminate functions from swapops.h where leaf entries obviate the need for the functions.
non-RFC v1:
* As part of efforts to eliminate swp_entry_t usage, remove pte_none_mostly() and correct UFFD PTE marker handling.
* Introduce leaf_entry_t - credit to Gregory for naming, and to Jason for the concept of simply using a leafent_*() set of functions to interact with these entities.
* Replace pte_to_swp_entry_or_zero() with leafent_from_pte() and simply categorise pte_none() cases as an empty leaf entry, as per Jason.
* Eliminate get_pte_swap_entry() - as we can simply do this with leafent_from_pte() also, as discussed with Jason.
* Put pmd_trans_huge_lock() acquisition/release in pagemap_pmd_range() rather than pmd_trans_huge_lock_thp() as per Gregory.
* Eliminate pmd_to_swp_entry() and related and introduce leafent_from_pmd() to replace it and further propagate leaf entry usage.
* Remove the confusing and unnecessary is_hugetlb_entry_[migration, hwpoison]() functions.
* Replace is_pfn_swap_entry(), pfn_swap_entry_to_page(), is_writable_device_private_entry(), is_device_exclusive_entry(), is_migration_entry(), is_writable_migration_entry(), is_readable_migration_entry(), is_readable_exclusive_migration_entry() and pfn_swap_entry_folio() with leafent equivalents.
* Wrapped up the 'safe' behaviour discussed with Jason in leafent_from_[pte, pmd]() so these can be used unconditionally which simplifies things a lot.
* Further changes that are a consequence of the introduction of leaf entries.
RFC:
https://lore.kernel.org/all/[email protected]/
Lorenzo Stoakes (16):
mm: correctly handle UFFD PTE markers
mm: introduce leaf entry type and use to simplify leaf entry logic
mm: avoid unnecessary uses of is_swap_pte()
mm: eliminate uses of is_swap_pte() when leafent_from_pte() suffices
mm: use leaf entries in debug pgtable + remove is_swap_pte() fs/proc/task_mmu: refactor pagemap_pmd_range()
mm: avoid unnecessary use of is_swap_pmd() mm/huge_memory: refactor copy_huge_pmd() non-present logic mm/huge_memory: refactor change_huge_pmd() non-present logic
mm: replace pmd_to_swp_entry() with leafent_from_pmd()
mm: introduce pmd_is_huge() and use where appropriate
mm: remove remaining is_swap_pmd() users and is_swap_pmd()
mm: remove non_swap_entry() and use leaf entry helpers instead
mm: remove is_hugetlb_entry_[migration, hwpoisoned]()
mm: eliminate further swapops predicates
mm: replace remaining pte_to_swp_entry() with leafent_from_pte()
MAINTAINERS | 1 + arch/s390/mm/gmap_helpers.c | 18 +- arch/s390/mm/pgtable.c | 12 +- fs/proc/task_mmu.c | 294 +++++++++------- fs/userfaultfd.c | 85 ++--- include/asm-generic/hugetlb.h | 8 - include/linux/huge_mm.h | 48 ++- include/linux/hugetlb.h | 2 - include/linux/leafops.h | 622 ++++++++++++++++++++++++++++++++++ include/linux/migrate.h | 3 +- include/linux/mm_inline.h | 6 +- include/linux/swapops.h | 273 +-------------- include/linux/userfaultfd_k.h | 33 +- mm/damon/ops-common.c | 6 +- mm/debug_vm_pgtable.c | 86 +++-- mm/filemap.c | 8 +- mm/hmm.c | 36 +- mm/huge_memory.c | 263 +++++++------- mm/hugetlb.c | 165 ++++----- mm/internal.h | 20 +- mm/khugepaged.c | 33 +- mm/ksm.c | 6 +- mm/madvise.c | 28 +- mm/memory-failure.c | 8 +- mm/memory.c | 150 ++++---- mm/mempolicy.c | 25 +- mm/migrate.c | 45 +-- mm/migrate_device.c | 24 +- mm/mincore.c | 25 +- mm/mprotect.c | 59 ++-- mm/mremap.c | 13 +- mm/page_table_check.c | 33 +- mm/page_vma_mapped.c | 65 ++-- mm/pagewalk.c | 15 +- mm/rmap.c | 17 +- mm/shmem.c | 7 +- mm/swap_state.c | 12 +- mm/swapfile.c | 14 +- mm/userfaultfd.c | 53 +-- 39 files changed, 1537 insertions(+), 1084 deletions(-) create mode 100644 include/linux/leafops.h
--
2.51.0
PATCH 3/16 mm: avoid unnecessary uses of is_swap_pte()
There's an established convention in the kernel that we treat PTEs as containing swap entries (and the unfortunately named non-swap swap entries) should they be neither empty (i.e. pte_none() evaluating true) nor present (i.e. pte_present() evaluating true).
However, there is some inconsistency in how this is applied, as we also have the is_swap_pte() helper which explicitly performs this check:
/* check whether a pte points to a swap entry */
static inline int is_swap_pte(pte_t pte)
{
return !pte_none(pte) && !pte_present(pte);
}As this represents a predicate, and it's logical to assume that in order to establish that a PTE entry can correctly be manipulated as a swap/non-swap entry, this predicate seems as if it must first be checked.
But we instead, we far more often utilise the established convention of checking pte_none() / pte_present() before operating on entries as if they were swap/non-swap.
This patch works towards correcting this inconsistency by removing all uses of is_swap_pte() where we are already in a position where we perform pte_none()/pte_present() checks anyway or otherwise it is clearly logical to do so.
We also take advantage of the fact that pte_swp_uffd_wp() is only set on swap entries.
Additionally, update comments referencing to is_swap_pte() and non_swap_entry().
No functional change intended.
--- fs/proc/task_mmu.c | 49 ++++++++++++++++++++++++----------- include/linux/userfaultfd_k.h | 3 +-- mm/hugetlb.c | 6 ++--- mm/internal.h | 6 ++--- mm/khugepaged.c | 29 +++++++++++---------- mm/migrate.c | 2 +- mm/mprotect.c | 43 ++++++++++++++---------------- mm/mremap.c | 7 +++-- mm/page_table_check.c | 13 ++++++---- mm/page_vma_mapped.c | 31 +++++++++++----------- 10 files changed, 104 insertions(+), 85 deletions(-)
fs/proc/task_mmu.c +34 -15
@@ -1017,7 +1017,9 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, young =pte_young (ptent); dirty =pte_dirty (ptent); present = true; - }else if (is_swap_pte (ptent)) { + }else if (pte_none (ptent)) { +smaps_pte_hole_lookup (addr, walk); + }else {swp_entry_t swpent =pte_to_swp_entry (ptent);if (!non_swap_entry (swpent)) {
@@ -1038,9 +1040,6 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, present = true; page =pfn_swap_entry_to_page (swpent); } - }else { -smaps_pte_hole_lookup (addr, walk); -return ; }if (!page)
@@ -1611,6 +1610,9 @@ static inline void clear_soft_dirty(struct vm_area_struct *vma,*/ pte_t ptent =ptep_get (pte); +if (pte_none (ptent)) +return ; +if (pte_present (ptent)) {pte_t old_pte;
@@ -1620,7 +1622,7 @@ static inline void clear_soft_dirty(struct vm_area_struct *vma, ptent =pte_wrprotect (old_pte); ptent =pte_clear_soft_dirty (ptent);ptep_modify_prot_commit (vma, addr, pte, old_pte, ptent); - }else if (is_swap_pte (ptent)) { + }else { ptent =pte_swp_clear_soft_dirty (ptent);set_pte_at (vma->vm_mm, addr, pte, ptent); }
@@ -1923,6 +1925,9 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm,struct page *page =NULL ;struct folio *folio; +if (pte_none (pte)) + goto out; +if (pte_present (pte)) {if (pm->show_pfn) frame =pte_pfn (pte);
@@ -1932,8 +1937,9 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, flags |=PM_SOFT_DIRTY ;if (pte_uffd_wp (pte)) flags |=PM_UFFD_WP ; - }else if (is_swap_pte (pte)) { + }else {swp_entry_t entry; +if (pte_swp_soft_dirty (pte)) flags |=PM_SOFT_DIRTY ;if (pte_swp_uffd_wp (pte))
@@ -1941,6 +1947,7 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, entry =pte_to_swp_entry (pte);if (pm->show_pfn) {pgoff_t offset; +/* * For PFN swap offsets, keeping the offset field * to be PFN only to be compatible with old smaps.
@@ -1969,6 +1976,8 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, __folio_page_mapped_exclusively(folio, page)) flags |=PM_MMAP_EXCLUSIVE ; } + +out:if (vma->vm_flags &VM_SOFTDIRTY ) flags |=PM_SOFT_DIRTY ;
@@ -2310,12 +2319,16 @@ static unsigned long pagemap_page_category(struct pagemap_scan_private *p,struct vm_area_struct *vma, unsigned long addr, pte_t pte) { - unsigned long categories = 0; + unsigned long categories; + +if (pte_none (pte)) +return 0 ;if (pte_present (pte)) {struct page *page; - categories |=PAGE_IS_PRESENT ; + categories =PAGE_IS_PRESENT ; +if (!pte_uffd_wp (pte)) categories |=PAGE_IS_WRITTEN ;
@@ -2329,10 +2342,11 @@ static unsigned long pagemap_page_category(struct pagemap_scan_private *p, categories |=PAGE_IS_PFNZERO ;if (pte_soft_dirty (pte)) categories |=PAGE_IS_SOFT_DIRTY ; - }else if (is_swap_pte (pte)) { + }else {leaf_entry_t entry; - categories |=PAGE_IS_SWAPPED ; + categories =PAGE_IS_SWAPPED ; +if (!pte_swp_uffd_wp_any (pte)) categories |=PAGE_IS_WRITTEN ;
@@ -2360,12 +2374,12 @@ static void make_uffd_wp_pte(struct vm_area_struct *vma, old_pte =ptep_modify_prot_start (vma, addr, pte); ptent =pte_mkuffd_wp (old_pte);ptep_modify_prot_commit (vma, addr, pte, old_pte, ptent); - }else if (is_swap_pte (ptent)) { - ptent =pte_swp_mkuffd_wp (ptent); -set_pte_at (vma->vm_mm, addr, pte, ptent); - }else { + }else if (pte_none (ptent)) {set_pte_at (vma->vm_mm, addr, pte,make_pte_marker (PTE_MARKER_UFFD_WP )); + }else { + ptent =pte_swp_mkuffd_wp (ptent); +set_pte_at (vma->vm_mm, addr, pte, ptent); } }
@@ -2434,6 +2448,9 @@ static unsigned long pagemap_hugetlb_category(pte_t pte) {unsigned long categories =PAGE_IS_HUGE ; +if (pte_none (pte)) +return categories; +/* * According to pagemap_hugetlb_range(), file-backed HugeTLB * page cannot be swapped. So PAGE_IS_FILE is not checked for
@@ -2441,6 +2458,7 @@ static unsigned long pagemap_hugetlb_category(pte_t pte)*/ if (pte_present (pte)) { categories |=PAGE_IS_PRESENT ; +if (!huge_pte_uffd_wp (pte)) categories |=PAGE_IS_WRITTEN ;if (!PageAnon (pte_page (pte)))
@@ -2449,8 +2467,9 @@ static unsigned long pagemap_hugetlb_category(pte_t pte) categories |=PAGE_IS_PFNZERO ;if (pte_soft_dirty (pte)) categories |=PAGE_IS_SOFT_DIRTY ; - }else if (is_swap_pte (pte)) { + }else { categories |=PAGE_IS_SWAPPED ; +if (!pte_swp_uffd_wp_any (pte)) categories |=PAGE_IS_WRITTEN ;if (pte_swp_soft_dirty (pte))
include/linux/userfaultfd_k.h +1 -2
@@ -441,9 +441,8 @@ static inline bool userfaultfd_wp_use_markers(struct vm_area_struct *vma)static inline bool pte_swp_uffd_wp_any (pte_t pte) {#ifdef CONFIG_PTE_MARKER_UFFD_WP -if (!is_swap_pte (pte)) +if (pte_present (pte))return false; -if (pte_swp_uffd_wp (pte))return true;
mm/hugetlb.c +3 -3
@@ -5798,13 +5798,13 @@ static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr, pte =huge_ptep_get_and_clear (mm, old_addr, src_pte, sz); -if (need_clear_uffd_wp &&pte_is_uffd_wp_marker (pte)) +if (need_clear_uffd_wp &&pte_is_uffd_wp_marker (pte)) {huge_pte_clear (mm, new_addr, dst_pte, sz); -else { + }else {if (need_clear_uffd_wp) {if (pte_present (pte)) pte =huge_pte_clear_uffd_wp (pte); -else if (is_swap_pte (pte)) +else pte =pte_swp_clear_uffd_wp (pte); }set_huge_pte_at (mm, new_addr, dst_pte, pte, sz);
mm/internal.h +2 -4
@@ -325,8 +325,7 @@ unsigned int folio_pte_batch(struct folio *folio, pte_t *ptep, pte_t pte,/** * pte_move_swp_offset - Move the swap entry offset field of a swap pte * forward or backward by delta -* @pte: The initial pte state; is_swap_pte(pte) must be true and -* non_swap_entry() must be false. +* @pte: The initial pte state; must be a swap entry * @delta: The direction and the offset we are moving; forward if delta * is positive; backward if delta is negative *
@@ -352,8 +351,7 @@ static inline pte_t pte_move_swp_offset(pte_t pte, long delta)/** * pte_next_swp_offset - Increment the swap entry offset field of a swap pte. -* @pte: The initial pte state; is_swap_pte(pte) must be true and -* non_swap_entry() must be false. +* @pte: The initial pte state; must be a swap entry. * * Increments the swap offset, while maintaining all other fields, including * swap type, and any swp pte bits. The resulting pte is returned.
mm/khugepaged.c +15 -14
@@ -1019,7 +1019,8 @@ static int __collapse_huge_page_swapin(struct mm_struct *mm, } vmf.orig_pte =ptep_get_lockless (pte); -if (!is_swap_pte (vmf.orig_pte)) +if (pte_none (vmf.orig_pte) || +pte_present (vmf.orig_pte))continue ; vmf.pte = pte;
@@ -1276,7 +1277,19 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,for (addr = start_addr, _pte = pte; _pte < pte +HPAGE_PMD_NR ; _pte++, addr +=PAGE_SIZE ) {pte_t pteval =ptep_get (_pte); -if (is_swap_pte (pteval)) { +if (pte_none_or_zero (pteval)) { + ++none_or_zero; +if (!userfaultfd_armed (vma) && + (!cc->is_khugepaged || + none_or_zero <= khugepaged_max_ptes_none)) { +continue ; + }else { + result =SCAN_EXCEED_NONE_PTE ; +count_vm_event (THP_SCAN_EXCEED_NONE_PTE ); + goto out_unmap; + } + } +if (!pte_present (pteval)) { ++unmapped;if (!cc->is_khugepaged || unmapped <= khugepaged_max_ptes_swap) {
@@ -1296,18 +1309,6 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, goto out_unmap; } } -if (pte_none_or_zero (pteval)) { - ++none_or_zero; -if (!userfaultfd_armed (vma) && - (!cc->is_khugepaged || - none_or_zero <= khugepaged_max_ptes_none)) { -continue ; - }else { - result =SCAN_EXCEED_NONE_PTE ; -count_vm_event (THP_SCAN_EXCEED_NONE_PTE ); - goto out_unmap; - } - }if (pte_uffd_wp (pteval)) {/* * Don't collapse the page if any of the small
mm/migrate.c +1 -1
@@ -492,7 +492,7 @@ void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd, pte =ptep_get (ptep);pte_unmap (ptep); -if (!is_swap_pte (pte)) +if (pte_none (pte) ||pte_present (pte)) goto out; entry =pte_to_swp_entry (pte);
mm/mprotect.c +20 -23
55 lines not on this page · raw message
mm/mremap.c +5 -2
@@ -158,6 +158,9 @@ static void drop_rmap_locks(struct vm_area_struct *vma)static pte_t move_soft_dirty_pte (pte_t pte) { +if (pte_none (pte)) +return pte; +/* * Set soft dirty bit so we can notice * in userspace the ptes were moved.
@@ -165,7 +168,7 @@ static pte_t move_soft_dirty_pte(pte_t pte)#ifdef CONFIG_MEM_SOFT_DIRTY if (pte_present (pte)) pte =pte_mksoft_dirty (pte); -else if (is_swap_pte (pte)) +else pte =pte_swp_mksoft_dirty (pte);#endif return pte;
@@ -294,7 +297,7 @@ static int move_ptes(struct pagetable_move_control *pmc,if (need_clear_uffd_wp) {if (pte_present (pte)) pte =pte_clear_uffd_wp (pte); -else if (is_swap_pte (pte)) +else pte =pte_swp_clear_uffd_wp (pte); }set_ptes (mm, new_addr, new_ptep, pte, nr_ptes);
mm/page_table_check.c +8 -5
@@ -185,12 +185,15 @@ static inline bool swap_cached_writable(swp_entry_t entry)is_writable_migration_entry (entry); } -static inline void page_table_check_pte_flags (pte_t pte) +static void page_table_check_pte_flags (pte_t pte) { -if (pte_present (pte) &&pte_uffd_wp (pte)) -WARN_ON_ONCE (pte_write (pte)); -else if (is_swap_pte (pte) &&pte_swp_uffd_wp (pte)) -WARN_ON_ONCE (swap_cached_writable (pte_to_swp_entry (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); + +WARN_ON_ONCE (swap_cached_writable (entry)); + } } void __page_table_check_ptes_set(struct mm_struct *mm, pte_t *ptep, pte_t pte,
mm/page_vma_mapped.c +15 -16
@@ -16,6 +16,7 @@ static inline bool not_found(struct page_vma_mapped_walk *pvmw)static bool map_pte (struct page_vma_mapped_walk *pvmw,pmd_t *pmdvalp,spinlock_t **ptlp) { +bool is_migration;pte_t ptent;if (pvmw->flags &PVMW_SYNC ) {
@@ -26,6 +27,7 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw, pmd_t *pmdvalp,return !!pvmw->pte; } + is_migration = pvmw->flags &PVMW_MIGRATION ; again:/* * It is important to return the ptl corresponding to pte,
@@ -41,11 +43,14 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw, pmd_t *pmdvalp, ptent =ptep_get (pvmw->pte); -if (pvmw->flags &PVMW_MIGRATION ) { -if (!is_swap_pte (ptent)) +if (pte_none (ptent)) { +return false; + }else if (pte_present (ptent)) { +if (is_migration)return false; - }else if (is_swap_pte (ptent)) { + }else if (!is_migration) {swp_entry_t entry; +/* * Handle un-addressable ZONE_DEVICE memory. *
@@ -66,8 +71,6 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw, pmd_t *pmdvalp,if (!is_device_private_entry (entry) && !is_device_exclusive_entry (entry))return false; - }else if (!pte_present (ptent)) { -return false; }spin_lock (*ptlp);if (unlikely (!pmd_same (*pmdvalp,pmdp_get_lockless (pvmw->pmd)))) {
@@ -113,21 +116,17 @@ static bool check_pte(struct page_vma_mapped_walk *pvmw, unsigned long pte_nr)return false; pfn =leafent_to_pfn (entry); - }else if (is_swap_pte (ptent)) { -swp_entry_t entry; + }else if (pte_present (ptent)) { + pfn =pte_pfn (ptent); + }else { +const leaf_entry_t entry =leafent_from_pte (ptent);/* Handle un-addressable ZONE_DEVICE memory */ - entry =pte_to_swp_entry (ptent); -if (!is_device_private_entry (entry) && - !is_device_exclusive_entry (entry)) -return false; - - pfn =swp_offset_pfn (entry); - }else { -if (!pte_present (ptent)) +if (!leafent_is_device_private (entry) && + !leafent_is_device_exclusive (entry))return false; - pfn =pte_pfn (ptent); + pfn =leafent_to_pfn (entry); }if ((pfn + pte_nr -1 ) < pvmw->pfn)
Signature · 1 line
2.51.0
PATCH 4/16 mm: eliminate uses of is_swap_pte() when leafent_from_pte() suffices
In reply to Lorenzo StoakesIn cases where we can simply utilise the fact that leafent_from_pte() treats present entries as if they were none entries and thus eliminate spurious uses of is_swap_pte(), do so.
No functional change intended.
--- mm/internal.h | 7 +++---- mm/madvise.c | 8 +++----- mm/swap_state.c | 12 ++++++------ mm/swapfile.c | 9 ++++----- 4 files changed, 16 insertions(+), 20 deletions(-)
mm/internal.h +3 -4
@@ -15,7 +15,7 @@#include <linux/pagewalk.h> #include <linux/rmap.h> #include <linux/swap.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/swap_cgroup.h> #include <linux/tracepoint-defs.h>
@@ -380,13 +380,12 @@ static inline int swap_pte_batch(pte_t *start_ptep, int max_nr, pte_t pte) {pte_t expected_pte =pte_next_swp_offset (pte);const pte_t *end_ptep = start_ptep + max_nr; -swp_entry_t entry =pte_to_swp_entry (pte); +const leaf_entry_t entry =leafent_from_pte (pte);pte_t *ptep = start_ptep +1 ;unsigned short cgroup_id;VM_WARN_ON (max_nr <1 ); -VM_WARN_ON (!is_swap_pte (pte)); -VM_WARN_ON (non_swap_entry (entry)); +VM_WARN_ON (!leafent_is_swap (entry)); cgroup_id =lookup_swap_cgroup_id (entry);while (ptep < end_ptep) {
mm/madvise.c +3 -5
@@ -195,7 +195,7 @@ static int swapin_walk_pmd_entry(pmd_t *pmd, unsigned long start,for (addr = start; addr < end; addr +=PAGE_SIZE ) {pte_t pte; -swp_entry_t entry; +leaf_entry_t entry;struct folio *folio;if (!ptep++) {
@@ -205,10 +205,8 @@ static int swapin_walk_pmd_entry(pmd_t *pmd, unsigned long start, } pte =ptep_get (ptep); -if (!is_swap_pte (pte)) -continue ; - entry =pte_to_swp_entry (pte); -if (unlikely (non_swap_entry (entry))) + entry =leafent_from_pte (pte); +if (unlikely (!leafent_is_swap (entry)))continue ;pte_unmap_unlock (ptep, ptl);
mm/swap_state.c +6 -6
@@ -12,7 +12,7 @@#include <linux/kernel_stat.h> #include <linux/mempolicy.h> #include <linux/swap.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/init.h> #include <linux/pagemap.h> #include <linux/pagevec.h>
@@ -732,7 +732,6 @@ static struct folio *swap_vma_readahead(swp_entry_t targ_entry, gfp_t gfp_mask,pte_t *pte =NULL , pentry;int win;unsigned long start, end, addr; -swp_entry_t entry;pgoff_t ilx;bool page_allocated;
@@ -744,16 +743,17 @@ static struct folio *swap_vma_readahead(swp_entry_t targ_entry, gfp_t gfp_mask,blk_start_plug (&plug);for (addr = start; addr < end; ilx++, addr +=PAGE_SIZE ) { +leaf_entry_t entry; +if (!pte++) { pte =pte_offset_map (vmf->pmd, addr);if (!pte)break ; } pentry =ptep_get_lockless (pte); -if (!is_swap_pte (pentry)) -continue ; - entry =pte_to_swp_entry (pentry); -if (unlikely (non_swap_entry (entry))) + entry =leafent_from_pte (pentry); + +if (!leafent_is_swap (entry))continue ;pte_unmap (pte); pte =NULL ;
mm/swapfile.c +4 -5
@@ -44,7 +44,7 @@#include <linux/plist.h> #include <asm/tlbflush.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/swap_cgroup.h> #include "swap_table.h" #include "internal.h"
@@ -2256,7 +2256,7 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,struct folio *folio;unsigned long offset;unsigned char swp_count; -swp_entry_t entry; +leaf_entry_t entry;int ret;pte_t ptent;
@@ -2267,11 +2267,10 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd, } ptent =ptep_get_lockless (pte); + entry =leafent_from_pte (ptent); -if (!is_swap_pte (ptent)) +if (!leafent_is_swap (entry))continue ; - - entry =pte_to_swp_entry (ptent);if (swp_type (entry) != type)continue ;
Signature · 1 line
2.51.0
PATCH 1/16 mm: correctly handle UFFD PTE markers
In reply to Lorenzo StoakesPTE markers were previously only concerned with UFFD-specific logic - that is, PTE entries with the UFFD WP marker set or those marked via UFFDIO_POISON.
However since the introduction of guard markers in commit
7c53dfbdb024 ("mm: add PTE_MARKER_GUARD PTE marker"), this has no longer been the case.
Issues have been avoided as guard regions are not permitted in conjunction with UFFD, but it still leaves very confusing logic in place, most notably the misleading and poorly named pte_none_mostly() and huge_pte_none_mostly().
This predicate returns true for PTE entries that ought to be treated as none, but only in certain circumstances, and on the assumption we are dealing with H/W poison markers or UFFD WP markers.
This patch removes these functions and makes each invocation of these functions instead explicitly check what it needs to check.
As part of this effort it introduces is_uffd_pte_marker() to explicitly determine if a marker in fact is used as part of UFFD or not.
In the HMM logic we note that the only time we would need to check for a fault is in the case of a UFFD WP marker, otherwise we simply encounter a fault error (VM_FAULT_HWPOISON for H/W poisoned marker, VM_FAULT_SIGSEGV for a guard marker), so only check for the UFFD WP case.
While we're here we also refactor code to make it easier to understand.
--- fs/userfaultfd.c | 83 +++++++++++++++++++---------------- include/asm-generic/hugetlb.h | 8 ---- include/linux/swapops.h | 18 -------- include/linux/userfaultfd_k.h | 21 +++++++++ mm/hmm.c | 2 +- mm/hugetlb.c | 47 ++++++++++---------- mm/mincore.c | 17 +++++-- mm/userfaultfd.c | 27 +++++++----- 8 files changed, 123 insertions(+), 100 deletions(-)
fs/userfaultfd.c +46 -37
@@ -233,40 +233,46 @@ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx, {struct vm_area_struct *vma = vmf->vma;pte_t *ptep, pte; -bool ret = true;assert_fault_locked (vmf); ptep =hugetlb_walk (vma, vmf->address,vma_mmu_pagesize (vma));if (!ptep) - goto out; +return true; - ret = false; pte =huge_ptep_get (vma->vm_mm, vmf->address, ptep);/* * Lockless access: we're in a wait_event so it's ok if it -* changes under us. PTE markers should be handled the same as none -* ptes here. +* changes under us. */ -if (huge_pte_none_mostly (pte)) - ret = true; + +/* If missing entry, wait for handler. */ +if (huge_pte_none (pte)) +return true; +/* UFFD PTE markers require handling. */ +if (is_uffd_pte_marker (pte)) +return true; +/* If VMA has UFFD WP faults enabled and WP fault, wait for handler. */ if (!huge_pte_write (pte) && (reason &VM_UFFD_WP )) - ret = true; -out: -return ret; +return true; + +/* Otherwise, if entry isn't present, let fault handler deal with it. */ +return false; }#else static inline bool userfaultfd_huge_must_wait (struct userfaultfd_ctx *ctx,struct vm_fault *vmf,unsigned long reason) { -return false;/* should never get here */ +/* Should never get here. */ +VM_WARN_ON_ONCE (1 ); +return false; }#endif /* CONFIG_HUGETLB_PAGE */ /* -* Verify the pagetables are still not ok after having reigstered into +* Verify the pagetables are still not ok after having registered into * the fault_pending_wqh to avoid userland having to UFFDIO_WAKE any * userfault that has already been resolved, if userfaultfd_read_iter and * UFFDIO_COPY|ZEROPAGE are being run simultaneously on two different
@@ -284,53 +290,55 @@ static inline bool userfaultfd_must_wait(struct userfaultfd_ctx *ctx,pmd_t *pmd, _pmd;pte_t *pte;pte_t ptent; -bool ret = true; +bool ret;assert_fault_locked (vmf); pgd =pgd_offset (mm, address);if (!pgd_present (*pgd)) - goto out; +return true; p4d =p4d_offset (pgd, address);if (!p4d_present (*p4d)) - goto out; +return true; pud =pud_offset (p4d, address);if (!pud_present (*pud)) - goto out; +return true; pmd =pmd_offset (pud, address); again: _pmd =pmdp_get_lockless (pmd);if (pmd_none (_pmd)) - goto out; +return true; - ret = false;if (!pmd_present (_pmd)) - goto out; +return false; -if (pmd_trans_huge (_pmd)) { -if (!pmd_write (_pmd) && (reason &VM_UFFD_WP )) - ret = true; - goto out; - } +if (pmd_trans_huge (_pmd)) +return !pmd_write (_pmd) && (reason &VM_UFFD_WP ); pte =pte_offset_map (pmd, address); -if (!pte) { - ret = true; +if (!pte) goto again; - } +/* * Lockless access: we're in a wait_event so it's ok if it -* changes under us. PTE markers should be handled the same as none -* ptes here. +* changes under us. */ ptent =ptep_get (pte); -if (pte_none_mostly (ptent)) - ret = true; + + ret = true; +/* If missing entry, wait for handler. */ +if (pte_none (ptent)) + goto out; +/* UFFD PTE markers require handling. */ +if (is_uffd_pte_marker (ptent)) + goto out; +/* If VMA has UFFD WP faults enabled and WP fault, wait for handler. */ if (!pte_write (ptent) && (reason &VM_UFFD_WP )) - ret = true; -pte_unmap (pte); + goto out; + ret = false; out: +pte_unmap (pte);return ret; }
@@ -490,12 +498,13 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason)set_current_state (blocking_state);spin_unlock_irq (&ctx->fault_pending_wqh.lock); -if (!is_vm_hugetlb_page (vma)) - must_wait =userfaultfd_must_wait (ctx, vmf, reason); -else +if (is_vm_hugetlb_page (vma)) { must_wait =userfaultfd_huge_must_wait (ctx, vmf, reason); -if (is_vm_hugetlb_page (vma))hugetlb_vma_unlock_read (vma); + }else { + must_wait =userfaultfd_must_wait (ctx, vmf, reason); + } +release_fault_lock (vmf);if (likely (must_wait && !READ_ONCE (ctx->released))) {
include/asm-generic/hugetlb.h +0 -8
@@ -97,14 +97,6 @@ static inline int huge_pte_none(pte_t pte) }#endif -/* Please refer to comments above pte_none_mostly() for the usage */ -#ifndef __HAVE_ARCH_HUGE_PTE_NONE_MOSTLY -static inline int huge_pte_none_mostly (pte_t pte) -{ -return huge_pte_none (pte) ||is_pte_marker (pte); -} -#endif -#ifndef __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECTstatic inline void huge_ptep_set_wrprotect (struct mm_struct *mm,unsigned long addr,pte_t *ptep)
include/linux/swapops.h +0 -18
@@ -469,24 +469,6 @@ static inline int is_guard_swp_entry(swp_entry_t entry) (pte_marker_get (entry) &PTE_MARKER_GUARD ); } -/* -* This is a special version to check pte_none() just to cover the case when -* the pte is a pte marker. It existed because in many cases the pte marker -* should be seen as a none pte; it's just that we have stored some information -* onto the none pte so it becomes not-none any more. -* -* It should be used when the pte is file-backed, ram-based and backing -* userspace pages, like shmem. It is not needed upon pgtables that do not -* support pte markers at all. For example, it's not needed on anonymous -* memory, kernel-only memory (including when the system is during-boot), -* non-ram based generic file-system. It's fine to be used even there, but the -* extra pte marker check will be pure overhead. -*/ -static inline int pte_none_mostly (pte_t pte) -{ -return pte_none (pte) ||is_pte_marker (pte); -} -static inline struct page *pfn_swap_entry_to_page (swp_entry_t entry) {struct page *p =pfn_to_page (swp_offset_pfn (entry));
include/linux/userfaultfd_k.h +21 -0
@@ -479,4 +479,25 @@ static inline bool pte_swp_uffd_wp_any(pte_t pte) return false; } + +static inline bool is_uffd_pte_marker (pte_t pte) +{ +swp_entry_t entry; + +if (pte_present (pte)) +return false; + + entry =pte_to_swp_entry (pte); +if (!is_pte_marker_entry (entry)) +return false; + +/* UFFD WP, poisoned swap entries are UFFD handled. */ +if (pte_marker_entry_uffd_wp (entry)) +return true; +if (is_poisoned_swp_entry (entry)) +return true; + +return false; +} +#endif /* _LINUX_USERFAULTFD_K_H */
mm/hmm.c +1 -1
@@ -244,7 +244,7 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr,uint64_t pfn_req_flags = *hmm_pfn;uint64_t new_pfn_flags =0 ; -if (pte_none_mostly (pte)) { +if (pte_none (pte) ||pte_marker_uffd_wp (pte)) { required_fault =hmm_pte_need_fault (hmm_vma_walk, pfn_req_flags,0 );if (required_fault)
mm/hugetlb.c +24 -23
72 lines not on this page · raw message
mm/mincore.c +14 -3
@@ -32,11 +32,22 @@ static int mincore_hugetlb(pte_t *pte, unsigned long hmask, unsigned long addr,spinlock_t *ptl; ptl =huge_pte_lock (hstate_vma (walk->vma), walk->mm, pte); +/* * Hugepages under user process are always in RAM and never * swapped out, but theoretically it needs to be checked. */ - present = pte && !huge_pte_none_mostly (huge_ptep_get (walk->mm, addr, pte)); +if (!pte) { + present =0 ; + }else { +const pte_t ptep =huge_ptep_get (walk->mm, addr, pte); + +if (huge_pte_none (ptep) ||is_pte_marker (ptep)) + present =0 ; +else + present =1 ; + } +for (; addr != end; vec++, addr +=PAGE_SIZE ) *vec = present; walk->private = vec;
@@ -175,8 +186,8 @@ static int mincore_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,pte_t pte =ptep_get (ptep); step =1 ; -/* We need to do cache lookup too for pte markers */ -if (pte_none_mostly (pte)) +/* We need to do cache lookup too for UFFD pte markers */ +if (pte_none (pte) ||is_uffd_pte_marker (pte))__mincore_unmapped_range (addr, addr +PAGE_SIZE , vma, vec);else if (pte_present (pte)) {
mm/userfaultfd.c +17 -10
@@ -178,6 +178,7 @@ int mfill_atomic_install_pte(pmd_t *dst_pmd,spinlock_t *ptl;struct folio *folio =page_folio (page);bool page_in_cache =folio_mapping (folio); +pte_t dst_ptep; _dst_pte =mk_pte (page, dst_vma->vm_page_prot); _dst_pte =pte_mkdirty (_dst_pte);
@@ -199,12 +200,15 @@ int mfill_atomic_install_pte(pmd_t *dst_pmd, } ret = -EEXIST ; + + dst_ptep =ptep_get (dst_pte); +/* -* We allow to overwrite a pte marker: consider when both MISSING|WP -* registered, we firstly wr-protect a none pte which has no page cache -* page backing it, then access the page. +* We are allowed to overwrite a UFFD pte marker: consider when both +* MISSING|WP registered, we firstly wr-protect a none pte which has no +* page cache page backing it, then access the page. */ -if (!pte_none_mostly (ptep_get (dst_pte))) +if (!pte_none (dst_ptep) && !is_uffd_pte_marker (dst_ptep)) goto out_unlock;if (page_in_cache) {
@@ -583,12 +587,15 @@ static __always_inline ssize_t mfill_atomic_hugetlb( goto out_unlock; } -if (!uffd_flags_mode_is (flags,MFILL_ATOMIC_CONTINUE ) && - !huge_pte_none_mostly (huge_ptep_get (dst_mm, dst_addr, dst_pte))) { - err = -EEXIST ; -hugetlb_vma_unlock_read (dst_vma); -mutex_unlock (&hugetlb_fault_mutex_table[hash]); - goto out_unlock; +if (!uffd_flags_mode_is (flags,MFILL_ATOMIC_CONTINUE )) { +const pte_t ptep =huge_ptep_get (dst_mm, dst_addr, dst_pte); + +if (!huge_pte_none (ptep) && !is_uffd_pte_marker (ptep)) { + err = -EEXIST ; +hugetlb_vma_unlock_read (dst_vma); +mutex_unlock (&hugetlb_fault_mutex_table[hash]); + goto out_unlock; + } } err = hugetlb_mfill_atomic_pte(dst_pte, dst_vma, dst_addr,
Signature · 1 line
2.51.0
PATCH 5/16 mm: use leaf entries in debug pgtable + remove is_swap_pte()
In reply to Lorenzo StoakesRemove invocations of is_swap_pte() in mm/debug_vm_pgtable.c and use leafent_from_pte() and leafent_is_swap() as necessary to replace this usage.
We update the test code to use a 'true' swap entry throughout so we are guaranteed this is not a non-swap entry, so all asserts continue to operate correctly.
With this change in place, we no longer use is_swap_pte() anywhere, so remove it.
--- include/linux/swapops.h | 6 ------ mm/debug_vm_pgtable.c | 39 ++++++++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 21 deletions(-)
include/linux/swapops.h +0 -6
@@ -120,12 +120,6 @@ static inline unsigned long swp_offset_pfn(swp_entry_t entry)return swp_offset (entry) &SWP_PFN_MASK ; } -/* check whether a pte points to a swap entry */ -static inline int is_swap_pte (pte_t pte) -{ -return !pte_none (pte) && !pte_present (pte); -} -/* * Convert the arch-dependent pte representation of a swp_entry_t into an * arch-independent swp_entry_t.
mm/debug_vm_pgtable.c +24 -15
@@ -25,7 +25,7 @@#include <linux/random.h> #include <linux/spinlock.h> #include <linux/swap.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/start_kernel.h> #include <linux/sched/mm.h> #include <linux/io.h>
@@ -714,14 +714,16 @@ static void __init pte_soft_dirty_tests(struct pgtable_debug_args *args)static void __init pte_swap_soft_dirty_tests (struct pgtable_debug_args *args) {pte_t pte; +leaf_entry_t entry;if (!IS_ENABLED (CONFIG_MEM_SOFT_DIRTY ))return ;pr_debug ("Validating PTE swap soft dirty\n" ); pte =swp_entry_to_pte (args->swp_entry); -WARN_ON (!is_swap_pte (pte)); + entry =leafent_from_pte (pte); +WARN_ON (!leafent_is_swap (entry));WARN_ON (!pte_swp_soft_dirty (pte_swp_mksoft_dirty (pte)));WARN_ON (pte_swp_soft_dirty (pte_swp_clear_soft_dirty (pte))); }
@@ -768,40 +770,47 @@ static void __init pmd_swap_soft_dirty_tests(struct pgtable_debug_args *args) {static void __init pte_swap_exclusive_tests (struct pgtable_debug_args *args) { -swp_entry_t entry, entry2; +swp_entry_t entry; +leaf_entry_t leafent;pte_t pte;pr_debug ("Validating PTE swap exclusive\n" ); entry = args->swp_entry; pte =swp_entry_to_pte (entry); + leafent =leafent_from_pte (pte); +WARN_ON (pte_swp_exclusive (pte)); -WARN_ON (!is_swap_pte (pte)); - entry2 =pte_to_swp_entry (pte); -WARN_ON (memcmp (&entry, &entry2,sizeof (entry))); +WARN_ON (!leafent_is_swap (leafent)); +WARN_ON (memcmp (&entry, &leafent,sizeof (entry))); pte =pte_swp_mkexclusive (pte); + leafent =leafent_from_pte (pte); +WARN_ON (!pte_swp_exclusive (pte)); -WARN_ON (!is_swap_pte (pte)); +WARN_ON (!leafent_is_swap (leafent));WARN_ON (pte_swp_soft_dirty (pte)); - entry2 =pte_to_swp_entry (pte); -WARN_ON (memcmp (&entry, &entry2,sizeof (entry))); +WARN_ON (memcmp (&entry, &leafent,sizeof (entry))); pte =pte_swp_clear_exclusive (pte); + leafent =leafent_from_pte (pte); +WARN_ON (pte_swp_exclusive (pte)); -WARN_ON (!is_swap_pte (pte)); - entry2 =pte_to_swp_entry (pte); -WARN_ON (memcmp (&entry, &entry2,sizeof (entry))); +WARN_ON (!leafent_is_swap (leafent)); +WARN_ON (memcmp (&entry, &leafent,sizeof (entry))); }static void __init pte_swap_tests (struct pgtable_debug_args *args) {swp_entry_t arch_entry; +leaf_entry_t entry;pte_t pte1, pte2;pr_debug ("Validating PTE swap\n" ); pte1 =swp_entry_to_pte (args->swp_entry); -WARN_ON (!is_swap_pte (pte1)); + entry =leafent_from_pte (pte1); + +WARN_ON (!leafent_is_swap (entry)); arch_entry =__pte_to_swp_entry (pte1); pte2 =__swp_entry_to_pte (arch_entry);
@@ -1218,8 +1227,8 @@ static int __init init_args(struct pgtable_debug_args *args)/* See generic_max_swapfile_size(): probe the maximum offset */ max_swap_offset =swp_offset (pte_to_swp_entry (swp_entry_to_pte (swp_entry (0 , ~0UL )))); -/* Create a swp entry with all possible bits set */ - args->swp_entry =swp_entry ((1 <<MAX_SWAPFILES_SHIFT ) -1 , max_swap_offset); +/* Create a swp entry with all possible bits set while still being swap. */ + args->swp_entry =swp_entry (MAX_SWAPFILES -1 , max_swap_offset);/* * Allocate (huge) pages because some of the tests need to access
Signature · 1 line
2.51.0
PATCH 2/16 mm: introduce leaf entry type and use to simplify leaf entry logic
In reply to Lorenzo StoakesThe kernel maintains leaf page table entries which contain either:
- Nothing ('none' entries)
- Present entries (that is stuff the hardware can navigate without fault)
- Everything else that will cause a fault which the kernel handles
In the 'everything else' group we include swap entries, but we also include a number of other things such as migration entries, device private entries and marker entries.
Unfortunately this 'everything else' group expresses everything through a swp_entry_t type, and these entries are referred to swap entries even though they may well not contain a... swap entry.
This is compounded by the rather mind-boggling concept of a non-swap swap entry (checked via non_swap_entry()) and the means by which we twist and turn to satisfy this.
This patch lays the foundation for reducing this confusion.
We refer to 'everything else' as a 'leaf entry'. And in fact we scoop up the 'none' entries into this concept also so we are left with:
- Present entries
- Leaf entries (which may be empty)
This allows for radical simplification across the board - one can simply convert any leaf page table entry to a leaf entry via leafent_from_pte().
If the entry is present, we return an empty leaf entry, so it is assumed the caller is aware that they must differentiate between the two categories of page table entries, checking for the former via pte_present().
As a result, we can eliminate a number of places where we would otherwise need to use predicates to see if we can proceed with leaf page table entry conversion and instead just go ahead and do it unconditionally.
We do so where we can, adjusting surrounding logic as necessary to integrate the new leaf_entry_t logic as far as seems reasonable at this stage.
We typedef swp_entry_t to leaf_entry_t for the time being until the conversion can be complete, meaning everything remains compatible regardless of which type is used. We will eventually remove swp_entry_t when the conversion is complete.
We introduce a new header file to keep things clear - leafops.h - this imports swapops.h so can direct replace swapops imports without issue, and we do so in all the files that require it.
Additionally, add new leafops.h file to core mm maintainers entry.
--- MAINTAINERS | 1 + fs/proc/task_mmu.c | 26 +-- fs/userfaultfd.c | 6 +- include/linux/leafops.h | 394 ++++++++++++++++++++++++++++++++++ include/linux/mm_inline.h | 6 +- include/linux/swapops.h | 28 --- include/linux/userfaultfd_k.h | 51 +---- mm/hmm.c | 2 +- mm/hugetlb.c | 37 ++-- mm/madvise.c | 16 +- mm/memory.c | 41 ++-- mm/mincore.c | 6 +- mm/mprotect.c | 6 +- mm/mremap.c | 4 +- mm/page_vma_mapped.c | 11 +- mm/shmem.c | 7 +- mm/userfaultfd.c | 6 +- 17 files changed, 484 insertions(+), 164 deletions(-) create mode 100644 include/linux/leafops.h
MAINTAINERS +1 -0
@@ -16257,6 +16257,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm F: include/linux/gfp.h F: include/linux/gfp_types.h F: include/linux/highmem.h +F: include/linux/leafops.h F: include/linux/memory.h F: include/linux/mm.h F: include/linux/mm_*.h
fs/proc/task_mmu.c +13 -13
@@ -14,7 +14,7 @@#include <linux/rmap.h> #include <linux/swap.h> #include <linux/sched/mm.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/mmu_notifier.h> #include <linux/page_idle.h> #include <linux/shmem_fs.h>
@@ -1230,11 +1230,11 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask,if (pte_present (ptent)) { folio =page_folio (pte_page (ptent)); present = true; - }else if (is_swap_pte (ptent)) { -swp_entry_t swpent =pte_to_swp_entry (ptent); + }else { +const leaf_entry_t entry =leafent_from_pte (ptent); -if (is_pfn_swap_entry (swpent)) - folio =pfn_swap_entry_folio (swpent); +if (leafent_has_pfn (entry)) + folio =leafent_to_folio (entry); }if (folio) {
@@ -1955,9 +1955,9 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, flags |=PM_SWAP ;if (is_pfn_swap_entry (entry)) page =pfn_swap_entry_to_page (entry); -if (pte_marker_entry_uffd_wp (entry)) +if (leafent_is_uffd_wp_marker (entry)) flags |=PM_UFFD_WP ; -if (is_guard_swp_entry (entry)) +if (leafent_is_guard_marker (entry)) flags |=PM_GUARD_REGION ; }
@@ -2330,18 +2330,18 @@ static unsigned long pagemap_page_category(struct pagemap_scan_private *p,if (pte_soft_dirty (pte)) categories |=PAGE_IS_SOFT_DIRTY ; }else if (is_swap_pte (pte)) { -swp_entry_t swp; +leaf_entry_t entry; categories |=PAGE_IS_SWAPPED ;if (!pte_swp_uffd_wp_any (pte)) categories |=PAGE_IS_WRITTEN ; - swp =pte_to_swp_entry (pte); -if (is_guard_swp_entry (swp)) + entry =leafent_from_pte (pte); +if (leafent_is_guard_marker (entry)) categories |=PAGE_IS_GUARD ;else if ((p->masks_of_interest &PAGE_IS_FILE ) && -is_pfn_swap_entry (swp) && - !folio_test_anon (pfn_swap_entry_folio (swp))) +leafent_has_pfn (entry) && + !folio_test_anon (leafent_to_folio (entry))) categories |=PAGE_IS_FILE ;if (pte_swp_soft_dirty (pte))
@@ -2466,7 +2466,7 @@ static void make_uffd_wp_huge_pte(struct vm_area_struct *vma, {unsigned long psize; -if (is_hugetlb_entry_hwpoisoned (ptent) ||is_pte_marker (ptent)) +if (is_hugetlb_entry_hwpoisoned (ptent) ||pte_is_marker (ptent))return ; psize =huge_page_size (hstate_vma (vma));
fs/userfaultfd.c +3 -3
@@ -29,7 +29,7 @@#include <linux/ioctl.h> #include <linux/security.h> #include <linux/hugetlb.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/miscdevice.h> #include <linux/uio.h>
@@ -251,7 +251,7 @@ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx,if (huge_pte_none (pte))return true;/* UFFD PTE markers require handling. */ -if (is_uffd_pte_marker (pte)) +if (pte_is_uffd_marker (pte))return true;/* If VMA has UFFD WP faults enabled and WP fault, wait for handler. */ if (!huge_pte_write (pte) && (reason &VM_UFFD_WP ))
@@ -330,7 +330,7 @@ static inline bool userfaultfd_must_wait(struct userfaultfd_ctx *ctx,if (pte_none (ptent)) goto out;/* UFFD PTE markers require handling. */ -if (is_uffd_pte_marker (ptent)) +if (pte_is_uffd_marker (ptent)) goto out;/* If VMA has UFFD WP faults enabled and WP fault, wait for handler. */ if (!pte_write (ptent) && (reason &VM_UFFD_WP ))
include/linux/leafops.h new file +394 -0
394 lines not on this page · raw message
include/linux/mm_inline.h +3 -3
@@ -8,7 +8,7 @@#include <linux/swap.h> #include <linux/string.h> #include <linux/userfaultfd_k.h> -#include <linux/swapops.h> +#include <linux/leafops.h> /** * folio_is_file_lru - Should the folio be on a file LRU or anon LRU?
@@ -541,9 +541,9 @@ static inline bool mm_tlb_flush_nested(const struct mm_struct *mm)* The caller should insert a new pte created with make_pte_marker(). */ static inline pte_marker copy_pte_marker ( -swp_entry_t entry,struct vm_area_struct *dst_vma) +leaf_entry_t entry,struct vm_area_struct *dst_vma) { -pte_marker srcm =pte_marker_get (entry); +const pte_marker srcm =leafent_to_marker (entry);/* Always copy error entries. */ pte_marker dstm = srcm & (PTE_MARKER_POISONED |PTE_MARKER_GUARD );
include/linux/swapops.h +0 -28
@@ -426,21 +426,6 @@ static inline swp_entry_t make_pte_marker_entry(pte_marker marker)return swp_entry (SWP_PTE_MARKER , marker); } -static inline bool is_pte_marker_entry (swp_entry_t entry) -{ -return swp_type (entry) ==SWP_PTE_MARKER ; -} - -static inline pte_marker pte_marker_get (swp_entry_t entry) -{ -return swp_offset (entry) &PTE_MARKER_MASK ; -} - -static inline bool is_pte_marker (pte_t pte) -{ -return is_swap_pte (pte) &&is_pte_marker_entry (pte_to_swp_entry (pte)); -} -static inline pte_t make_pte_marker (pte_marker marker) {return swp_entry_to_pte (make_pte_marker_entry (marker));
@@ -451,24 +436,11 @@ static inline swp_entry_t make_poisoned_swp_entry(void)return make_pte_marker_entry (PTE_MARKER_POISONED ); } -static inline int is_poisoned_swp_entry (swp_entry_t entry) -{ -return is_pte_marker_entry (entry) && - (pte_marker_get (entry) &PTE_MARKER_POISONED ); - -} -static inline swp_entry_t make_guard_swp_entry (void ) {return make_pte_marker_entry (PTE_MARKER_GUARD ); } -static inline int is_guard_swp_entry (swp_entry_t entry) -{ -return is_pte_marker_entry (entry) && - (pte_marker_get (entry) &PTE_MARKER_GUARD ); -} -static inline struct page *pfn_swap_entry_to_page (swp_entry_t entry) {struct page *p =pfn_to_page (swp_offset_pfn (entry));
include/linux/userfaultfd_k.h +2 -49
72 lines not on this page · raw message
mm/hmm.c +1 -1
@@ -244,7 +244,7 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr,uint64_t pfn_req_flags = *hmm_pfn;uint64_t new_pfn_flags =0 ; -if (pte_none (pte) ||pte_marker_uffd_wp (pte)) { +if (pte_none (pte) ||pte_is_uffd_wp_marker (pte)) { required_fault =hmm_pte_need_fault (hmm_vma_walk, pfn_req_flags,0 );if (required_fault)
mm/hugetlb.c +19 -18
@@ -28,7 +28,7 @@#include <linux/string_choices.h> #include <linux/string_helpers.h> #include <linux/swap.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/jhash.h> #include <linux/numa.h> #include <linux/llist.h>
@@ -5662,17 +5662,17 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, entry =huge_pte_clear_uffd_wp (entry);set_huge_pte_at (dst, addr, dst_pte, entry, sz); }else if (unlikely (is_hugetlb_entry_migration (entry))) { -swp_entry_t swp_entry =pte_to_swp_entry (entry); +leaf_entry_t leafent =leafent_from_pte (entry);bool uffd_wp =pte_swp_uffd_wp (entry); -if (!is_readable_migration_entry (swp_entry) && cow) { +if (!is_readable_migration_entry (leafent) && cow) {/* * COW mappings require pages in both * parent and child to be set to read. */ - swp_entry =make_readable_migration_entry ( -swp_offset (swp_entry)); - entry =swp_entry_to_pte (swp_entry); + leafent =make_readable_migration_entry ( +swp_offset (leafent)); + entry =swp_entry_to_pte (leafent);if (userfaultfd_wp (src_vma) && uffd_wp) entry =pte_swp_mkuffd_wp (entry);set_huge_pte_at (src, addr, src_pte, entry, sz);
@@ -5680,9 +5680,9 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,if (!userfaultfd_wp (dst_vma)) entry =huge_pte_clear_uffd_wp (entry);set_huge_pte_at (dst, addr, dst_pte, entry, sz); - }else if (unlikely (is_pte_marker (entry))) { -pte_marker marker =copy_pte_marker ( -pte_to_swp_entry (entry), dst_vma); + }else if (unlikely (pte_is_marker (entry))) { +const leaf_entry_t leafent =leafent_from_pte (entry); +const pte_marker marker =copy_pte_marker (leafent, dst_vma);if (marker) set_huge_pte_at(dst, addr, dst_pte,
@@ -5798,7 +5798,7 @@ static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr, pte =huge_ptep_get_and_clear (mm, old_addr, src_pte, sz); -if (need_clear_uffd_wp &&pte_marker_uffd_wp (pte)) +if (need_clear_uffd_wp &&pte_is_uffd_wp_marker (pte))huge_pte_clear (mm, new_addr, dst_pte, sz);else {if (need_clear_uffd_wp) {
@@ -6617,7 +6617,7 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping,* If this pte was previously wr-protected, keep it wr-protected even * if populated. */ -if (unlikely (pte_marker_uffd_wp (vmf->orig_pte))) +if (unlikely (pte_is_uffd_wp_marker (vmf->orig_pte))) new_pte =huge_pte_mkuffd_wp (new_pte);set_huge_pte_at (mm, vmf->address, vmf->pte, new_pte,huge_page_size (h));
@@ -6750,9 +6750,9 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,*/ return hugetlb_no_page (mapping, &vmf); -if (is_pte_marker (vmf.orig_pte)) { +if (pte_is_marker (vmf.orig_pte)) {const pte_marker marker = -pte_marker_get (pte_to_swp_entry (vmf.orig_pte)); +leafent_to_marker (leafent_from_pte (vmf.orig_pte));if (marker &PTE_MARKER_POISONED ) { ret = VM_FAULT_HWPOISON_LARGE |
@@ -7080,7 +7080,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte,* See comment about UFFD marker overwriting in * mfill_atomic_install_pte(). */ -if (!huge_pte_none (dst_ptep) && !is_uffd_pte_marker (dst_ptep)) +if (!huge_pte_none (dst_ptep) && !pte_is_uffd_marker (dst_ptep)) goto out_release_unlock;if (folio_in_pagecache)
@@ -7201,8 +7201,9 @@ long hugetlb_change_protection(struct vm_area_struct *vma,if (unlikely (is_hugetlb_entry_hwpoisoned (pte))) {/* Nothing to do. */ }else if (unlikely (is_hugetlb_entry_migration (pte))) { -swp_entry_t entry =pte_to_swp_entry (pte); -struct folio *folio =pfn_swap_entry_folio (entry); +leaf_entry_t entry =leafent_from_pte (pte); + +struct folio *folio =leafent_to_folio (entry);pte_t newpte = pte;if (is_writable_migration_entry (entry)) {
@@ -7222,14 +7223,14 @@ long hugetlb_change_protection(struct vm_area_struct *vma, newpte =pte_swp_clear_uffd_wp (newpte);if (!pte_same (pte, newpte))set_huge_pte_at (mm, address, ptep, newpte, psize); - }else if (unlikely (is_pte_marker (pte))) { + }else if (unlikely (pte_is_marker (pte))) {/* * Do nothing on a poison marker; page is * corrupted, permissions do not apply. Here * pte_marker_uffd_wp()==true implies !poison * because they're mutual exclusive. */ -if (pte_marker_uffd_wp (pte) && uffd_wp_resolve) +if (pte_is_uffd_wp_marker (pte) && uffd_wp_resolve)/* Safe to modify directly (non-present->none). */ huge_pte_clear (mm, address, ptep, psize); }else if (!huge_pte_none (pte)) {
mm/madvise.c +8 -8
@@ -29,7 +29,7 @@#include <linux/backing-dev.h> #include <linux/pagewalk.h> #include <linux/swap.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/shmem_fs.h> #include <linux/mmu_notifier.h>
@@ -690,17 +690,16 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr,* (page allocation + zeroing). */ if (!pte_present (ptent)) { -swp_entry_t entry; +leaf_entry_t entry =leafent_from_pte (ptent); - entry =pte_to_swp_entry (ptent); -if (!non_swap_entry (entry)) { +if (leafent_is_swap (entry)) { max_nr = (end - addr) /PAGE_SIZE ; nr =swap_pte_batch (pte, max_nr, ptent); nr_swap -= nr;free_swap_and_cache_nr (entry, nr);clear_not_present_full_ptes (mm, addr, pte, nr, tlb->fullmm); - }else if (is_hwpoison_entry (entry) || -is_poisoned_swp_entry (entry)) { + }else if (leafent_is_hwpoison (entry) || +leafent_is_poison_marker (entry)) {pte_clear_not_present_full (mm, addr, pte, tlb->fullmm); }continue ;
@@ -1071,8 +1070,9 @@ static bool is_valid_guard_vma(struct vm_area_struct *vma, bool allow_locked)static bool is_guard_pte_marker (pte_t ptent) { -return is_swap_pte (ptent) && -is_guard_swp_entry (pte_to_swp_entry (ptent)); +const leaf_entry_t entry =leafent_from_pte (ptent); + +return leafent_is_guard_marker (entry); } static int guard_install_pud_entry(pud_t *pud, unsigned long addr,
mm/memory.c +21 -20
129 lines not on this page · raw message
mm/mincore.c +3 -3
@@ -14,7 +14,7 @@#include <linux/mman.h> #include <linux/syscalls.h> #include <linux/swap.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/shmem_fs.h> #include <linux/hugetlb.h> #include <linux/pgtable.h>
@@ -42,7 +42,7 @@ static int mincore_hugetlb(pte_t *pte, unsigned long hmask, unsigned long addr, }else {const pte_t ptep =huge_ptep_get (walk->mm, addr, pte); -if (huge_pte_none (ptep) ||is_pte_marker (ptep)) +if (huge_pte_none (ptep) ||pte_is_marker (ptep)) present =0 ;else present =1 ;
@@ -187,7 +187,7 @@ static int mincore_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, step =1 ;/* We need to do cache lookup too for UFFD pte markers */ -if (pte_none (pte) ||is_uffd_pte_marker (pte)) +if (pte_none (pte) ||pte_is_uffd_marker (pte))__mincore_unmapped_range (addr, addr +PAGE_SIZE , vma, vec);else if (pte_present (pte)) {
mm/mprotect.c +3 -3
@@ -326,14 +326,14 @@ static long change_pte_range(struct mmu_gather *tlb, newpte =swp_entry_to_pte (entry);if (pte_swp_uffd_wp (oldpte)) newpte =pte_swp_mkuffd_wp (newpte); - }else if (is_pte_marker_entry (entry)) { + }else if (leafent_is_marker (entry)) {/* * Ignore error swap entries unconditionally, * because any access should sigbus/sigsegv * anyway. */ -if (is_poisoned_swp_entry (entry) || -is_guard_swp_entry (entry)) +if (leafent_is_poison_marker (entry) || +leafent_is_guard_marker (entry))continue ;/* * If this is uffd-wp pte marker and we'd like
mm/mremap.c +2 -2
@@ -17,7 +17,7 @@#include <linux/swap.h> #include <linux/capability.h> #include <linux/fs.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/highmem.h> #include <linux/security.h> #include <linux/syscalls.h>
@@ -288,7 +288,7 @@ static int move_ptes(struct pagetable_move_control *pmc, pte =move_pte (pte, old_addr, new_addr); pte =move_soft_dirty_pte (pte); -if (need_clear_uffd_wp &&pte_marker_uffd_wp (pte)) +if (need_clear_uffd_wp &&pte_is_uffd_wp_marker (pte))pte_clear (mm, new_addr, new_ptep);else {if (need_clear_uffd_wp) {
mm/page_vma_mapped.c +4 -7
@@ -3,7 +3,7 @@#include <linux/rmap.h> #include <linux/hugetlb.h> #include <linux/swap.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include "internal.h"
@@ -107,15 +107,12 @@ static bool check_pte(struct page_vma_mapped_walk *pvmw, unsigned long pte_nr)pte_t ptent =ptep_get (pvmw->pte);if (pvmw->flags &PVMW_MIGRATION ) { -swp_entry_t entry; -if (!is_swap_pte (ptent)) -return false; - entry =pte_to_swp_entry (ptent); +const leaf_entry_t entry =leafent_from_pte (ptent); -if (!is_migration_entry (entry)) +if (!leafent_is_migration (entry))return false; - pfn =swp_offset_pfn (entry); + pfn =leafent_to_pfn (entry); }else if (is_swap_pte (ptent)) {swp_entry_t entry;
mm/shmem.c +4 -3
@@ -66,7 +66,7 @@ static struct vfsmount *shm_mnt __ro_after_init;#include <linux/falloc.h> #include <linux/splice.h> #include <linux/security.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/mempolicy.h> #include <linux/namei.h> #include <linux/ctype.h>
@@ -2286,7 +2286,8 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,struct address_space *mapping = inode->i_mapping;struct mm_struct *fault_mm = vma ? vma->vm_mm :NULL ;struct shmem_inode_info *info =SHMEM_I (inode); -swp_entry_t swap, index_entry; +swp_entry_t swap; +leaf_entry_t index_entry;struct swap_info_struct *si;struct folio *folio =NULL ;bool skip_swapcache = false;
@@ -2298,7 +2299,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, swap = index_entry; *foliop =NULL ; -if (is_poisoned_swp_entry (index_entry)) +if (leafent_is_poison_marker (index_entry))return -EIO ; si =get_swap_device (index_entry);
mm/userfaultfd.c +3 -3
@@ -10,7 +10,7 @@#include <linux/pagemap.h> #include <linux/rmap.h> #include <linux/swap.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/userfaultfd_k.h> #include <linux/mmu_notifier.h> #include <linux/hugetlb.h>
@@ -208,7 +208,7 @@ int mfill_atomic_install_pte(pmd_t *dst_pmd,* MISSING|WP registered, we firstly wr-protect a none pte which has no * page cache page backing it, then access the page. */ -if (!pte_none (dst_ptep) && !is_uffd_pte_marker (dst_ptep)) +if (!pte_none (dst_ptep) && !pte_is_uffd_marker (dst_ptep)) goto out_unlock;if (page_in_cache) {
@@ -590,7 +590,7 @@ static __always_inline ssize_t mfill_atomic_hugetlb(if (!uffd_flags_mode_is (flags,MFILL_ATOMIC_CONTINUE )) {const pte_t ptep =huge_ptep_get (dst_mm, dst_addr, dst_pte); -if (!huge_pte_none (ptep) && !is_uffd_pte_marker (ptep)) { +if (!huge_pte_none (ptep) && !pte_is_uffd_marker (ptep)) { err = -EEXIST ;hugetlb_vma_unlock_read (dst_vma);mutex_unlock (&hugetlb_fault_mutex_table[hash]);
Signature · 1 line
2.51.0
PATCH 7/16 mm: avoid unnecessary use of is_swap_pmd()
In reply to Lorenzo StoakesPMD 'non-swap' swap entries are currently used for PMD-level migration entries and device private entries.
To add to the confusion in this terminology we use is_swap_pmd() in an inconsistent way similar to how is_swap_pte() was being used - sometimes adopting the convention that pmd_none(), !pmd_present() implies PMD 'swap' entry, sometimes not.
This patch handles the low-hanging fruit of cases where we can simply substitute other predicates for is_swap_pmd().
No functional change intended.
--- fs/proc/task_mmu.c | 15 ++++++++++--- include/linux/swapops.h | 16 +++++++++++-- mm/huge_memory.c | 4 +++- mm/memory.c | 50 +++++++++++++++++++++++------------------ mm/page_table_check.c | 12 ++++++---- 5 files changed, 65 insertions(+), 32 deletions(-)
fs/proc/task_mmu.c +12 -3
@@ -1059,10 +1059,12 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr,bool present = false;struct folio *folio; +if (pmd_none (*pmd)) +return ;if (pmd_present (*pmd)) { page =vm_normal_page_pmd (vma, addr, *pmd); present = true; - }else if (unlikely (thp_migration_supported () &&is_swap_pmd (*pmd))) { + }else if (unlikely (thp_migration_supported ())) {swp_entry_t entry =pmd_to_swp_entry (*pmd);if (is_pfn_swap_entry (entry))
@@ -1999,6 +2001,9 @@ static int pagemap_pmd_range_thp(pmd_t *pmdp, unsigned long addr,if (vma->vm_flags &VM_SOFTDIRTY ) flags |=PM_SOFT_DIRTY ; +if (pmd_none (pmd)) + goto populate_pagemap; +if (pmd_present (pmd)) { page =pmd_page (pmd);
@@ -2009,7 +2014,7 @@ static int pagemap_pmd_range_thp(pmd_t *pmdp, unsigned long addr, flags |=PM_UFFD_WP ;if (pm->show_pfn) frame =pmd_pfn (pmd) + idx; - }else if (thp_migration_supported () &&is_swap_pmd (pmd)) { + }else if (thp_migration_supported ()) {swp_entry_t entry =pmd_to_swp_entry (pmd);unsigned long offset;
@@ -2036,6 +2041,7 @@ static int pagemap_pmd_range_thp(pmd_t *pmdp, unsigned long addr, flags |=PM_FILE ; } +populate_pagemap:for (; addr != end; addr +=PAGE_SIZE , idx++) {u64 cur_flags = flags;pagemap_entry_t pme;
@@ -2398,6 +2404,9 @@ static unsigned long pagemap_thp_category(struct pagemap_scan_private *p, {unsigned long categories =PAGE_IS_HUGE ; +if (pmd_none (pmd)) +return categories; +if (pmd_present (pmd)) {struct page *page;
@@ -2415,7 +2424,7 @@ static unsigned long pagemap_thp_category(struct pagemap_scan_private *p, categories |=PAGE_IS_PFNZERO ;if (pmd_soft_dirty (pmd)) categories |=PAGE_IS_SOFT_DIRTY ; - }else if (is_swap_pmd (pmd)) { + }else {swp_entry_t swp; categories |=PAGE_IS_SWAPPED ;
include/linux/swapops.h +14 -2
@@ -509,7 +509,13 @@ static inline pmd_t swp_entry_to_pmd(swp_entry_t entry)static inline int is_pmd_migration_entry (pmd_t pmd) { -return is_swap_pmd (pmd) &&is_migration_entry (pmd_to_swp_entry (pmd)); +swp_entry_t entry; + +if (pmd_present (pmd)) +return 0 ; + + entry =pmd_to_swp_entry (pmd); +return is_migration_entry (entry); }#else /* CONFIG_ARCH_ENABLE_THP_MIGRATION */ static inline int set_pmd_migration_entry(struct page_vma_mapped_walk *pvmw,
@@ -557,7 +563,13 @@ static inline int is_pmd_migration_entry(pmd_t pmd)*/ static inline int is_pmd_device_private_entry (pmd_t pmd) { -return is_swap_pmd (pmd) &&is_device_private_entry (pmd_to_swp_entry (pmd)); +swp_entry_t entry; + +if (pmd_present (pmd)) +return 0 ; + + entry =pmd_to_swp_entry (pmd); +return is_device_private_entry (entry); }#else /* CONFIG_ZONE_DEVICE && CONFIG_ARCH_ENABLE_THP_MIGRATION */
mm/huge_memory.c +3 -1
@@ -2429,9 +2429,11 @@ static pmd_t move_soft_dirty_pmd(pmd_t pmd)static pmd_t clear_uffd_wp_pmd (pmd_t pmd) { +if (pmd_none (pmd)) +return pmd;if (pmd_present (pmd)) pmd =pmd_clear_uffd_wp (pmd); -else if (is_swap_pmd (pmd)) +else pmd =pmd_swp_clear_uffd_wp (pmd);return pmd;
mm/memory.c +28 -22
69 lines not on this page · raw message
mm/page_table_check.c +8 -4
@@ -215,10 +215,14 @@ EXPORT_SYMBOL(__page_table_check_ptes_set);static inline void page_table_check_pmd_flags (pmd_t pmd) { -if (pmd_present (pmd) &&pmd_uffd_wp (pmd)) -WARN_ON_ONCE (pmd_write (pmd)); -else if (is_swap_pmd (pmd) &&pmd_swp_uffd_wp (pmd)) -WARN_ON_ONCE (swap_cached_writable (pmd_to_swp_entry (pmd))); +if (pmd_present (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); + +WARN_ON_ONCE (swap_cached_writable (entry)); + } } void __page_table_check_pmds_set(struct mm_struct *mm, pmd_t *pmdp, pmd_t pmd,
Signature · 1 line
2.51.0
PATCH 6/16 fs/proc/task_mmu: refactor pagemap_pmd_range()
In reply to Lorenzo StoakesSeparate out THP logic so we can drop an indentation level and reduce the amount of noise in this function.
We add pagemap_pmd_range_thp() for this purpose.
While we're here, convert the VM_BUG_ON() to a VM_WARN_ON_ONCE() at the same time.
No functional change intended.
--- fs/proc/task_mmu.c | 146 ++++++++++++++++++++++++--------------------- 1 file changed, 77 insertions(+), 69 deletions(-)
fs/proc/task_mmu.c +77 -69
@@ -1984,90 +1984,98 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm,return make_pme (frame, flags); } -static int pagemap_pmd_range (pmd_t *pmdp,unsigned long addr,unsigned long end, -struct mm_walk *walk) +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +static int pagemap_pmd_range_thp (pmd_t *pmdp,unsigned long addr, +unsigned long end,struct vm_area_struct *vma, +struct pagemapread *pm) { -struct vm_area_struct *vma = walk->vma; -struct pagemapread *pm = walk->private; -spinlock_t *ptl; -pte_t *pte, *orig_pte; +unsigned int idx = (addr & ~PMD_MASK ) >>PAGE_SHIFT ; +u64 flags =0 , frame =0 ; +pmd_t pmd = *pmdp; +struct page *page =NULL ; +struct folio *folio =NULL ;int err =0 ; -#ifdef CONFIG_TRANSPARENT_HUGEPAGE - ptl =pmd_trans_huge_lock (pmdp, vma); -if (ptl) { -unsigned int idx = (addr & ~PMD_MASK ) >>PAGE_SHIFT ; -u64 flags =0 , frame =0 ; -pmd_t pmd = *pmdp; -struct page *page =NULL ; -struct folio *folio =NULL ; +if (vma->vm_flags &VM_SOFTDIRTY ) + flags |=PM_SOFT_DIRTY ; -if (vma->vm_flags &VM_SOFTDIRTY ) - flags |=PM_SOFT_DIRTY ; +if (pmd_present (pmd)) { + page =pmd_page (pmd); -if (pmd_present (pmd)) { - page =pmd_page (pmd); + flags |=PM_PRESENT ; +if (pmd_soft_dirty (pmd)) + flags |=PM_SOFT_DIRTY ; +if (pmd_uffd_wp (pmd)) + flags |=PM_UFFD_WP ; +if (pm->show_pfn) + frame =pmd_pfn (pmd) + idx; + }else if (thp_migration_supported () &&is_swap_pmd (pmd)) { +swp_entry_t entry =pmd_to_swp_entry (pmd); +unsigned long offset; - flags |=PM_PRESENT ; -if (pmd_soft_dirty (pmd)) - flags |=PM_SOFT_DIRTY ; -if (pmd_uffd_wp (pmd)) - flags |=PM_UFFD_WP ; -if (pm->show_pfn) - frame =pmd_pfn (pmd) + idx; - } -#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION - else if (is_swap_pmd(pmd)) { -swp_entry_t entry =pmd_to_swp_entry (pmd); -unsigned long offset; - -if (pm->show_pfn) { -if (is_pfn_swap_entry (entry)) - offset =swp_offset_pfn (entry) + idx; -else - offset =swp_offset (entry) + idx; - frame =swp_type (entry) | - (offset <<MAX_SWAPFILES_SHIFT ); - } - flags |=PM_SWAP ; -if (pmd_swp_soft_dirty (pmd)) - flags |=PM_SOFT_DIRTY ; -if (pmd_swp_uffd_wp (pmd)) - flags |=PM_UFFD_WP ; -VM_BUG_ON (!is_pmd_migration_entry (pmd)); - page =pfn_swap_entry_to_page (entry); +if (pm->show_pfn) { +if (is_pfn_swap_entry (entry)) + offset =swp_offset_pfn (entry) + idx; +else + offset =swp_offset (entry) + idx; + frame =swp_type (entry) | + (offset <<MAX_SWAPFILES_SHIFT ); } -#endif + flags |=PM_SWAP ; +if (pmd_swp_soft_dirty (pmd)) + flags |=PM_SOFT_DIRTY ; +if (pmd_swp_uffd_wp (pmd)) + flags |=PM_UFFD_WP ; +VM_WARN_ON_ONCE (!is_pmd_migration_entry (pmd)); + page =pfn_swap_entry_to_page (entry); + } -if (page) { - folio =page_folio (page); -if (!folio_test_anon (folio)) - flags |=PM_FILE ; - } +if (page) { + folio =page_folio (page); +if (!folio_test_anon (folio)) + flags |=PM_FILE ; + } -for (; addr != end; addr +=PAGE_SIZE , idx++) { -u64 cur_flags = flags; -pagemap_entry_t pme; +for (; addr != end; addr +=PAGE_SIZE , idx++) { +u64 cur_flags = flags; +pagemap_entry_t pme; -if (folio && (flags &PM_PRESENT ) && -__folio_page_mapped_exclusively (folio, page)) - cur_flags |=PM_MMAP_EXCLUSIVE ; +if (folio && (flags &PM_PRESENT ) && +__folio_page_mapped_exclusively (folio, page)) + cur_flags |=PM_MMAP_EXCLUSIVE ; - pme =make_pme (frame, cur_flags); - err =add_to_pagemap (&pme, pm); -if (err) -break ; -if (pm->show_pfn) { -if (flags &PM_PRESENT ) - frame++; -else if (flags &PM_SWAP ) - frame += (1 <<MAX_SWAPFILES_SHIFT ); - } + pme =make_pme (frame, cur_flags); + err =add_to_pagemap (&pme, pm); +if (err) +break ; +if (pm->show_pfn) { +if (flags &PM_PRESENT ) + frame++; +else if (flags &PM_SWAP ) + frame += (1 <<MAX_SWAPFILES_SHIFT ); } + } +return err; +} +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + +static int pagemap_pmd_range (pmd_t *pmdp,unsigned long addr,unsigned long end, +struct mm_walk *walk) +{ +struct vm_area_struct *vma = walk->vma; +struct pagemapread *pm = walk->private; +spinlock_t *ptl; +pte_t *pte, *orig_pte; +int err =0 ; + +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + ptl =pmd_trans_huge_lock (pmdp, vma); +if (ptl) { + err =pagemap_pmd_range_thp (pmdp, addr, end, vma, pm);spin_unlock (ptl);return err; } -#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ +#endif /* * We can assume that @vma always points to a valid one and @end never
Signature · 1 line
2.51.0
PATCH 9/16 mm/huge_memory: refactor change_huge_pmd() non-present logic
In reply to Lorenzo StoakesSimilar to copy_huge_pmd(), there is a large mass of open-coded logic for the CONFIG_ARCH_ENABLE_THP_MIGRATION non-present entry case that does not use thp_migration_supported() consistently.
Resolve this by separating out this logic and introduce change_non_present_huge_pmd().
No functional change intended.
--- mm/huge_memory.c | 72 ++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 33 deletions(-)
mm/huge_memory.c +39 -33
@@ -2499,6 +2499,42 @@ bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr,return false; } +static void change_non_present_huge_pmd (struct mm_struct *mm, +unsigned long addr,pmd_t *pmd,bool uffd_wp, +bool uffd_wp_resolve) +{ +swp_entry_t entry =pmd_to_swp_entry (*pmd); +struct folio *folio =pfn_swap_entry_folio (entry); +pmd_t newpmd; + +VM_WARN_ON (!is_pmd_non_present_folio_entry (*pmd)); +if (is_writable_migration_entry (entry)) { +/* +* A protection check is difficult so +* just be safe and disable write +*/ +if (folio_test_anon (folio)) + entry =make_readable_exclusive_migration_entry (swp_offset (entry)); +else + entry =make_readable_migration_entry (swp_offset (entry)); + newpmd =swp_entry_to_pmd (entry); +if (pmd_swp_soft_dirty (*pmd)) + newpmd =pmd_swp_mksoft_dirty (newpmd); + }else if (is_writable_device_private_entry (entry)) { + entry =make_readable_device_private_entry (swp_offset (entry)); + newpmd =swp_entry_to_pmd (entry); + }else { + newpmd = *pmd; + } + +if (uffd_wp) + newpmd =pmd_swp_mkuffd_wp (newpmd); +else if (uffd_wp_resolve) + newpmd =pmd_swp_clear_uffd_wp (newpmd); +if (!pmd_same (*pmd, newpmd)) +set_pmd_at (mm, addr, pmd, newpmd); +} +/* * Returns * - 0 if PMD could not be locked
@@ -2527,41 +2563,11 @@ int change_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,if (!ptl)return 0 ; -#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION -if (is_swap_pmd (*pmd)) { -swp_entry_t entry =pmd_to_swp_entry (*pmd); -struct folio *folio =pfn_swap_entry_folio (entry); -pmd_t newpmd; - -VM_WARN_ON (!is_pmd_non_present_folio_entry (*pmd)); -if (is_writable_migration_entry (entry)) { -/* -* A protection check is difficult so -* just be safe and disable write -*/ -if (folio_test_anon (folio)) - entry =make_readable_exclusive_migration_entry (swp_offset (entry)); -else - entry =make_readable_migration_entry (swp_offset (entry)); - newpmd =swp_entry_to_pmd (entry); -if (pmd_swp_soft_dirty (*pmd)) - newpmd =pmd_swp_mksoft_dirty (newpmd); - }else if (is_writable_device_private_entry (entry)) { - entry =make_readable_device_private_entry (swp_offset (entry)); - newpmd =swp_entry_to_pmd (entry); - }else { - newpmd = *pmd; - } - -if (uffd_wp) - newpmd =pmd_swp_mkuffd_wp (newpmd); -else if (uffd_wp_resolve) - newpmd =pmd_swp_clear_uffd_wp (newpmd); -if (!pmd_same (*pmd, newpmd)) -set_pmd_at (mm, addr, pmd, newpmd); +if (thp_migration_supported () &&is_swap_pmd (*pmd)) { +change_non_present_huge_pmd (mm, addr, pmd, uffd_wp, + uffd_wp_resolve); goto unlock; } -#endif if (prot_numa) {
Signature · 1 line
2.51.0
PATCH 10/16 mm: replace pmd_to_swp_entry() with leafent_from_pmd()
In reply to Lorenzo StoakesIntroduce leafent_from_pmd() to do the equivalent operation for PMDs that leafent_from_pte() fulfils, and cascade changes through code base accordingly, introducing helpers as necessary.
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.
--- fs/proc/task_mmu.c | 27 +++--- include/linux/leafops.h | 210 ++++++++++++++++++++++++++++++++++++++++ include/linux/migrate.h | 3 +- include/linux/swapops.h | 100 ------------------- mm/damon/ops-common.c | 6 +- mm/filemap.c | 6 +- mm/hmm.c | 16 +-- mm/huge_memory.c | 98 +++++++++---------- mm/khugepaged.c | 4 +- mm/madvise.c | 2 +- mm/memory.c | 4 +- mm/mempolicy.c | 4 +- mm/migrate.c | 20 ++-- mm/migrate_device.c | 14 +-- mm/page_table_check.c | 16 +-- mm/page_vma_mapped.c | 15 +-- mm/pagewalk.c | 8 +- mm/rmap.c | 4 +- 18 files changed, 334 insertions(+), 223 deletions(-)
fs/proc/task_mmu.c +13 -14
@@ -1065,10 +1065,10 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, page =vm_normal_page_pmd (vma, addr, *pmd); present = true; }else if (unlikely (thp_migration_supported ())) { -swp_entry_t entry =pmd_to_swp_entry (*pmd); +const leaf_entry_t entry =leafent_from_pmd (*pmd); -if (is_pfn_swap_entry (entry)) - page =pfn_swap_entry_to_page (entry); +if (leafent_has_pfn (entry)) + page =leafent_to_page (entry); }if (IS_ERR_OR_NULL (page))return ;
@@ -1654,7 +1654,7 @@ static inline void clear_soft_dirty_pmd(struct vm_area_struct *vma, pmd =pmd_clear_soft_dirty (pmd);set_pmd_at (vma->vm_mm, addr, pmdp, pmd); - }else if (is_migration_entry (pmd_to_swp_entry (pmd))) { + }else if (pmd_is_migration_entry (pmd)) { pmd =pmd_swp_clear_soft_dirty (pmd);set_pmd_at (vma->vm_mm, addr, pmdp, pmd); }
@@ -2015,12 +2015,12 @@ static int pagemap_pmd_range_thp(pmd_t *pmdp, unsigned long addr,if (pm->show_pfn) frame =pmd_pfn (pmd) + idx; }else if (thp_migration_supported ()) { -swp_entry_t entry =pmd_to_swp_entry (pmd); +const leaf_entry_t entry =leafent_from_pmd (pmd);unsigned long offset;if (pm->show_pfn) { -if (is_pfn_swap_entry (entry)) - offset =swp_offset_pfn (entry) + idx; +if (leafent_has_pfn (entry)) + offset =leafent_to_pfn (entry) + idx;else offset =swp_offset (entry) + idx; frame = swp_type(entry) |
@@ -2031,7 +2031,7 @@ static int pagemap_pmd_range_thp(pmd_t *pmdp, unsigned long addr, flags |=PM_SOFT_DIRTY ;if (pmd_swp_uffd_wp (pmd)) flags |=PM_UFFD_WP ; -VM_WARN_ON_ONCE (!is_pmd_migration_entry (pmd)); +VM_WARN_ON_ONCE (!pmd_is_migration_entry (pmd)); page =pfn_swap_entry_to_page (entry); }
@@ -2425,8 +2425,6 @@ static unsigned long pagemap_thp_category(struct pagemap_scan_private *p,if (pmd_soft_dirty (pmd)) categories |=PAGE_IS_SOFT_DIRTY ; }else { -swp_entry_t swp; - categories |=PAGE_IS_SWAPPED ;if (!pmd_swp_uffd_wp (pmd)) categories |=PAGE_IS_WRITTEN ;
@@ -2434,9 +2432,10 @@ static unsigned long pagemap_thp_category(struct pagemap_scan_private *p, categories |=PAGE_IS_SOFT_DIRTY ;if (p->masks_of_interest &PAGE_IS_FILE ) { - swp =pmd_to_swp_entry (pmd); -if (is_pfn_swap_entry (swp) && - !folio_test_anon (pfn_swap_entry_folio (swp))) +const leaf_entry_t entry =leafent_from_pmd (pmd); + +if (leafent_has_pfn (entry) && + !folio_test_anon (leafent_to_folio (entry))) categories |=PAGE_IS_FILE ; } }
@@ -2453,7 +2452,7 @@ static void make_uffd_wp_pmd(struct vm_area_struct *vma, old =pmdp_invalidate_ad (vma, addr, pmdp); pmd =pmd_mkuffd_wp (old);set_pmd_at (vma->vm_mm, addr, pmdp, pmd); - }else if (is_migration_entry (pmd_to_swp_entry (pmd))) { + }else if (pmd_is_migration_entry (pmd)) { pmd =pmd_swp_mkuffd_wp (pmd);set_pmd_at (vma->vm_mm, addr, pmdp, pmd); }
include/linux/leafops.h +210 -0
245 lines not on this page · raw message
include/linux/migrate.h +2 -1
@@ -6,6 +6,7 @@#include <linux/mempolicy.h> #include <linux/migrate_mode.h> #include <linux/hugetlb.h> +#include <linux/leafops.h> typedef struct folio *new_folio_t (struct folio *folio,unsigned long private);typedef void free_folio_t (struct folio *folio,unsigned long private);
@@ -65,7 +66,7 @@ bool isolate_folio_to_list(struct folio *folio, struct list_head *list);int migrate_huge_page_move_mapping (struct address_space *mapping,struct folio *dst,struct folio *src); -void migration_entry_wait_on_locked(swp_entry_t entry, spinlock_t *ptl) +void migration_entry_wait_on_locked(leaf_entry_t entry, spinlock_t *ptl) __releases(ptl);void folio_migrate_flags (struct folio *newfolio,struct folio *folio); int folio_migrate_mapping(struct address_space *mapping,
include/linux/swapops.h +0 -100
153 lines not on this page · raw message
mm/damon/ops-common.c +3 -3
@@ -11,7 +11,7 @@#include <linux/pagemap.h> #include <linux/rmap.h> #include <linux/swap.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include "../internal.h" #include "ops-common.h"
@@ -51,7 +51,7 @@ void damon_ptep_mkold(pte_t *pte, struct vm_area_struct *vma, unsigned long addrif (likely (pte_present (pteval))) pfn =pte_pfn (pteval);else - pfn =swp_offset_pfn (pte_to_swp_entry (pteval)); + pfn =leafent_to_pfn (leafent_from_pte (pteval)); folio =damon_get_folio (pfn);if (!folio)
@@ -83,7 +83,7 @@ void damon_pmdp_mkold(pmd_t *pmd, struct vm_area_struct *vma, unsigned long addrif (likely (pmd_present (pmdval))) pfn =pmd_pfn (pmdval);else - pfn =swp_offset_pfn (pmd_to_swp_entry (pmdval)); + pfn =leafent_to_pfn (leafent_from_pmd (pmdval)); folio =damon_get_folio (pfn);if (!folio)
mm/filemap.c +3 -3
@@ -21,7 +21,7 @@#include <linux/gfp.h> #include <linux/mm.h> #include <linux/swap.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/syscalls.h> #include <linux/mman.h> #include <linux/pagemap.h>
@@ -1402,7 +1402,7 @@ static inline int folio_wait_bit_common(struct folio *folio, int bit_nr,* This follows the same logic as folio_wait_bit_common() so see the comments * there. */ -void migration_entry_wait_on_locked (swp_entry_t entry,spinlock_t *ptl) +void migration_entry_wait_on_locked (leaf_entry_t entry,spinlock_t *ptl)__releases (ptl) {struct wait_page_queue wait_page;
@@ -1411,7 +1411,7 @@ void migration_entry_wait_on_locked(swp_entry_t entry, spinlock_t *ptl)unsigned long pflags;bool in_thrashing;wait_queue_head_t *q; -struct folio *folio =pfn_swap_entry_folio (entry); +struct folio *folio =leafent_to_folio (entry); q =folio_waitqueue (folio);if (!folio_test_uptodate (folio) &&folio_test_workingset (folio)) {
mm/hmm.c +8 -8
@@ -18,7 +18,7 @@#include <linux/sched.h> #include <linux/mmzone.h> #include <linux/pagemap.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/hugetlb.h> #include <linux/memremap.h> #include <linux/sched/mm.h>
@@ -334,19 +334,19 @@ static int hmm_vma_handle_absent_pmd(struct mm_walk *walk, unsigned long start,struct hmm_vma_walk *hmm_vma_walk = walk->private;struct hmm_range *range = hmm_vma_walk->range;unsigned long npages = (end - start) >>PAGE_SHIFT ; +const leaf_entry_t entry =leafent_from_pmd (pmd);unsigned long addr = start; -swp_entry_t entry =pmd_to_swp_entry (pmd);unsigned int required_fault; -if (is_device_private_entry (entry) && -pfn_swap_entry_folio (entry)->pgmap->owner == +if (leafent_is_device_private (entry) && +leafent_to_folio (entry)->pgmap->owner == range->dev_private_owner) {unsigned long cpu_flags =HMM_PFN_VALID |hmm_pfn_flags_order (PMD_SHIFT -PAGE_SHIFT ); -unsigned long pfn =swp_offset_pfn (entry); +unsigned long pfn =leafent_to_pfn (entry);unsigned long i; -if (is_writable_device_private_entry (entry)) +if (leafent_is_device_private_write (entry)) cpu_flags |=HMM_PFN_WRITE ;/*
@@ -365,7 +365,7 @@ static int hmm_vma_handle_absent_pmd(struct mm_walk *walk, unsigned long start, required_fault =hmm_range_need_fault (hmm_vma_walk, hmm_pfns, npages,0 );if (required_fault) { -if (is_device_private_entry (entry)) +if (leafent_is_device_private (entry))return hmm_vma_fault (addr, end, required_fault, walk);else return -EFAULT ;
@@ -407,7 +407,7 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp,if (pmd_none (pmd))return hmm_vma_walk_hole (start, end,-1 , walk); -if (thp_migration_supported () &&is_pmd_migration_entry (pmd)) { +if (thp_migration_supported () &&pmd_is_migration_entry (pmd)) {if (hmm_range_need_fault (hmm_vma_walk, hmm_pfns, npages,0 )) { hmm_vma_walk->last = addr;pmd_migration_entry_wait (walk->mm, pmdp);
mm/huge_memory.c +49 -49
262 lines not on this page · raw message
mm/khugepaged.c +2 -2
@@ -17,7 +17,7 @@#include <linux/page_idle.h> #include <linux/page_table_check.h> #include <linux/rcupdate_wait.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/shmem_fs.h> #include <linux/dax.h> #include <linux/ksm.h>
@@ -941,7 +941,7 @@ static inline int check_pmd_state(pmd_t *pmd)* collapse it. Migration success or failure will eventually end * up with a present PMD mapping a folio again. */ -if (is_pmd_migration_entry (pmde)) +if (pmd_is_migration_entry (pmde))return SCAN_PMD_MAPPED ;if (!pmd_present (pmde))return SCAN_PMD_NULL ;
mm/madvise.c +1 -1
@@ -390,7 +390,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,if (unlikely (!pmd_present (orig_pmd))) {VM_BUG_ON (thp_migration_supported () && - !is_pmd_migration_entry (orig_pmd)); + !pmd_is_migration_entry (orig_pmd)); goto huge_unlock; }
mm/memory.c +2 -2
@@ -6362,10 +6362,10 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma, goto fallback;if (unlikely (!pmd_present (vmf.orig_pmd))) { -if (is_pmd_device_private_entry (vmf.orig_pmd)) +if (pmd_is_device_private_entry (vmf.orig_pmd))return do_huge_pmd_device_private (&vmf); -if (is_pmd_migration_entry (vmf.orig_pmd)) +if (pmd_is_migration_entry (vmf.orig_pmd))pmd_migration_entry_wait (mm, vmf.pmd);return 0 ; }
mm/mempolicy.c +2 -2
@@ -110,7 +110,7 @@#include <linux/mm_inline.h> #include <linux/mmu_notifier.h> #include <linux/printk.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/gcd.h> #include <asm/tlbflush.h>
@@ -647,7 +647,7 @@ static void queue_folios_pmd(pmd_t *pmd, struct mm_walk *walk)struct folio *folio;struct queue_pages *qp = walk->private; -if (unlikely (is_pmd_migration_entry (*pmd))) { +if (unlikely (pmd_is_migration_entry (*pmd))) { qp->nr_failed++;return ; }
mm/migrate.c +10 -10
@@ -16,7 +16,7 @@#include <linux/migrate.h> #include <linux/export.h> #include <linux/swap.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/pagemap.h> #include <linux/buffer_head.h> #include <linux/mm_inline.h>
@@ -353,7 +353,7 @@ static bool remove_migration_pte(struct folio *folio,rmap_t rmap_flags =RMAP_NONE ;pte_t old_pte;pte_t pte; -swp_entry_t entry; +leaf_entry_t entry;struct page *new;unsigned long idx =0 ;
@@ -379,22 +379,22 @@ static bool remove_migration_pte(struct folio *folio,folio_get (folio); pte =mk_pte (new,READ_ONCE (vma->vm_page_prot)); - entry =pte_to_swp_entry (old_pte); -if (!is_migration_entry_young (entry)) + entry =leafent_from_pte (old_pte); +if (!leafent_is_migration_young (entry)) pte =pte_mkold (pte); -if (folio_test_dirty (folio) &&is_migration_entry_dirty (entry)) +if (folio_test_dirty (folio) &&leafent_is_migration_dirty (entry)) pte =pte_mkdirty (pte);if (pte_swp_soft_dirty (old_pte)) pte =pte_mksoft_dirty (pte);else pte =pte_clear_soft_dirty (pte); -if (is_writable_migration_entry (entry)) +if (leafent_is_migration_write (entry)) pte =pte_mkwrite (pte, vma);else if (pte_swp_uffd_wp (old_pte)) pte =pte_mkuffd_wp (pte); -if (folio_test_anon (folio) && !is_readable_migration_entry (entry)) +if (folio_test_anon (folio) && !leafent_is_migration_read (entry)) rmap_flags |=RMAP_EXCLUSIVE ;if (unlikely (is_device_private_page (new))) {
@@ -404,7 +404,7 @@ static bool remove_migration_pte(struct folio *folio,else entry =make_readable_device_private_entry (page_to_pfn (new)); - pte =swp_entry_to_pte (entry); + pte =leafent_to_pte (entry);if (pte_swp_soft_dirty (old_pte)) pte =pte_swp_mksoft_dirty (pte);if (pte_swp_uffd_wp (old_pte))
@@ -543,9 +543,9 @@ void pmd_migration_entry_wait(struct mm_struct *mm, pmd_t *pmd)spinlock_t *ptl; ptl =pmd_lock (mm, pmd); -if (!is_pmd_migration_entry (*pmd)) +if (!pmd_is_migration_entry (*pmd)) goto unlock; -migration_entry_wait_on_locked (pmd_to_swp_entry (*pmd), ptl); +migration_entry_wait_on_locked (leafent_from_pmd (*pmd), ptl);return ; unlock:spin_unlock (ptl);
mm/migrate_device.c +7 -7
@@ -13,7 +13,7 @@#include <linux/oom.h> #include <linux/pagewalk.h> #include <linux/rmap.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/pgalloc.h> #include <asm/tlbflush.h> #include "internal.h"
@@ -145,7 +145,6 @@ static int migrate_vma_collect_huge_pmd(pmd_t *pmdp, unsigned long start,struct folio *folio;struct migrate_vma *migrate = walk->private;spinlock_t *ptl; -swp_entry_t entry;int ret;unsigned long write =0 ;
@@ -169,23 +168,24 @@ static int migrate_vma_collect_huge_pmd(pmd_t *pmdp, unsigned long start,if (pmd_write (*pmdp)) write =MIGRATE_PFN_WRITE ; }else if (!pmd_present (*pmdp)) { - entry =pmd_to_swp_entry (*pmdp); - folio =pfn_swap_entry_folio (entry); +const leaf_entry_t entry =leafent_from_pmd (*pmdp); -if (!is_device_private_entry (entry) || + folio =leafent_to_folio (entry); + +if (!leafent_is_device_private (entry) || !(migrate->flags &MIGRATE_VMA_SELECT_DEVICE_PRIVATE ) || (folio->pgmap->owner != migrate->pgmap_owner)) {spin_unlock (ptl);return migrate_vma_collect_skip (start, end, walk); } -if (is_migration_entry (entry)) { +if (leafent_is_migration (entry)) {migration_entry_wait_on_locked (entry, ptl);spin_unlock (ptl);return -EAGAIN ; } -if (is_writable_device_private_entry (entry)) +if (leafent_is_device_private_write (entry)) write =MIGRATE_PFN_WRITE ; }else {spin_unlock (ptl);
mm/page_table_check.c +8 -8
@@ -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 leafent_cached_writable (leaf_entry_t entry) { -return is_writable_device_private_entry (entry) || -is_writable_migration_entry (entry); +return leafent_is_device_private (entry) || +leafent_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 leaf_entry_t entry =leafent_from_pte (pte); -WARN_ON_ONCE (swap_cached_writable (entry)); +WARN_ON_ONCE (leafent_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 leaf_entry_t entry =leafent_from_pmd (pmd); -WARN_ON_ONCE (swap_cached_writable (entry)); +WARN_ON_ONCE (leafent_cached_writable (entry)); } }
mm/page_vma_mapped.c +8 -7
@@ -242,18 +242,19 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)*/ pmde =pmdp_get_lockless (pvmw->pmd); -if (pmd_trans_huge (pmde) ||is_pmd_migration_entry (pmde)) { +if (pmd_trans_huge (pmde) ||pmd_is_migration_entry (pmde)) { pvmw->ptl =pmd_lock (mm, pvmw->pmd); pmde = *pvmw->pmd;if (!pmd_present (pmde)) { -swp_entry_t entry; +leaf_entry_t entry;if (!thp_migration_supported () || !(pvmw->flags &PVMW_MIGRATION ))return not_found (pvmw); - entry =pmd_to_swp_entry (pmde); -if (!is_migration_entry (entry) || - !check_pmd (swp_offset_pfn (entry), pvmw)) + entry =leafent_from_pmd (pmde); + +if (!leafent_is_migration (entry) || + !check_pmd (leafent_to_pfn (entry), pvmw))return not_found (pvmw);return true; }
@@ -273,9 +274,9 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)* cannot return prematurely, while zap_huge_pmd() has * cleared *pmd but not decremented compound_mapcount(). */ -swp_entry_t entry =pmd_to_swp_entry (pmde); +const leaf_entry_t entry =leafent_from_pmd (pmde); -if (is_device_private_entry (entry)) { +if (leafent_is_device_private (entry)) { pvmw->ptl =pmd_lock (mm, pvmw->pmd);return true; }
mm/pagewalk.c +4 -4
@@ -5,7 +5,7 @@#include <linux/hugetlb.h> #include <linux/mmu_context.h> #include <linux/swap.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <asm/tlbflush.h>
@@ -966,10 +966,10 @@ struct folio *folio_walk_start(struct folio_walk *fw, goto found; } }else if ((flags &FW_MIGRATION ) && -is_pmd_migration_entry (pmd)) { -swp_entry_t entry =pmd_to_swp_entry (pmd); +pmd_is_migration_entry (pmd)) { +const leaf_entry_t entry =leafent_from_pmd (pmd); - page =pfn_swap_entry_to_page (entry); + page =leafent_to_page (entry); expose_page = false; goto found; }
mm/rmap.c +2 -2
@@ -57,7 +57,7 @@#include <linux/sched/task.h> #include <linux/pagemap.h> #include <linux/swap.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/slab.h> #include <linux/init.h> #include <linux/ksm.h>
@@ -2341,7 +2341,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,if (likely (pmd_present (pmdval))) pfn =pmd_pfn (pmdval);else - pfn =swp_offset_pfn (pmd_to_swp_entry (pmdval)); + pfn =leafent_to_pfn (leafent_from_pmd (pmdval)); subpage =folio_page (folio, pfn -folio_pfn (folio));
Signature · 1 line
2.51.0
PATCH 11/16 mm: introduce pmd_is_huge() and use where appropriate
In reply to Lorenzo StoakesThe leaf entry PMD case is confusing as only migration entries and device private entries are valid at PMD level, not true swap entries.
We repeatedly perform checks of the form is_swap_pmd() || pmd_trans_huge() which is itself confusing - it implies that leaf entries at PMD level exist and are different from huge entries.
Address this confusion by introduced pmd_is_huge() which checks for either case. Sadly due to header dependency issues (huge_mm.h is included very early on in headers and cannot really rely on much else) we cannot pmd_is_valid_leafent() here.
However since these are the only valid, handled cases the function is still achieving what it intends to do.
We then replace all instances of is_swap_pmd() || pmd_trans_huge() with pmd_is_huge() invocations and adjust logic accordingly to accommodate this.
No functional change intended.
--- include/linux/huge_mm.h | 39 +++++++++++++++++++++++++++++++++++---- include/linux/swapops.h | 6 ++++++ mm/huge_memory.c | 3 ++- mm/memory.c | 4 ++-- mm/mprotect.c | 2 +- mm/mremap.c | 2 +- 6 files changed, 47 insertions(+), 9 deletions(-)
include/linux/huge_mm.h +35 -4
@@ -419,10 +419,36 @@ void reparent_deferred_split_queue(struct mem_cgroup *memcg);void __split_huge_pmd (struct vm_area_struct *vma,pmd_t *pmd,unsigned long address,bool freeze); +/** +* pmd_is_huge() - Is this PMD either a huge PMD entry or a leafentry? +* @pmd: The PMD to check. +* +* A huge PMD entry is a non-empty entry which is present and marked huge or a +* huge laef entry. This check be performed without the appropriate locks +* held, in which case the condition should be rechecked after they are +* acquired. +* +* Returns: true if this PMD is huge, false otherwise. +*/ +static inline bool pmd_is_huge (pmd_t pmd) +{ +if (pmd_present (pmd)) { +return pmd_trans_huge (pmd); + }else if (!pmd_none (pmd)) { +/* +* Non-present PMDs must be valid huge non-present entries. We +* cannot assert that here due to header dependency issues. +*/ +return true; + } + +return false; +} +#define split_huge_pmd (__vma, __pmd, __address) \ do { \ pmd_t *____pmd = (__pmd); \ - if (is_swap_pmd(*____pmd) || pmd_trans_huge(*____pmd)) \ + if (pmd_is_huge(*____pmd)) \ __split_huge_pmd(__vma, __pmd, __address, \ false); \ } while (0)
@@ -469,10 +495,10 @@ static inline int is_swap_pmd(pmd_t pmd)static inline spinlock_t *pmd_trans_huge_lock (pmd_t *pmd,struct vm_area_struct *vma) { -if (is_swap_pmd (*pmd) ||pmd_trans_huge (*pmd)) +if (pmd_is_huge (*pmd))return __pmd_trans_huge_lock (pmd, vma); -else -return NULL ; + +return NULL ; }static inline spinlock_t *pud_trans_huge_lock (pud_t *pud,struct vm_area_struct *vma)
@@ -744,6 +770,11 @@ static inline struct folio *get_persistent_huge_zero_folio(void) {return NULL ; } + +static inline bool pmd_is_huge (pmd_t pmd) +{ +return false; +}#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ static inline int split_folio_to_list_to_order(struct folio *folio,
include/linux/swapops.h +6 -0
@@ -471,6 +471,12 @@ static inline pmd_t swp_entry_to_pmd(swp_entry_t entry) }#else /* CONFIG_ARCH_ENABLE_THP_MIGRATION */ +static inline int set_pmd_migration_entry (struct page_vma_mapped_walk *pvmw, +struct page *page) +{ +BUILD_BUG (); +} +static inline void remove_migration_pmd (struct page_vma_mapped_walk *pvmw,struct page *new) {
mm/huge_memory.c +2 -1
@@ -2810,8 +2810,9 @@ int move_pages_huge_pmd(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, pmspinlock_t *__pmd_trans_huge_lock (pmd_t *pmd,struct vm_area_struct *vma) {spinlock_t *ptl; + ptl =pmd_lock (vma->vm_mm, pmd); -if (likely (is_swap_pmd (*pmd) ||pmd_trans_huge (*pmd))) +if (likely (pmd_is_huge (*pmd)))return ptl;spin_unlock (ptl);return NULL ;
mm/memory.c +2 -2
@@ -1374,7 +1374,7 @@ copy_pmd_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, src_pmd =pmd_offset (src_pud, addr); do { next = pmd_addr_end(addr, end); - if (is_swap_pmd(*src_pmd) || pmd_trans_huge(*src_pmd)) { + if (pmd_is_huge(*src_pmd)) { int err; VM_BUG_ON_VMA(next-addr != HPAGE_PMD_SIZE, src_vma);
@@ -1923,7 +1923,7 @@ static inline unsigned long zap_pmd_range(struct mmu_gather *tlb, pmd =pmd_offset (pud, addr); do { next = pmd_addr_end(addr, end); - if (is_swap_pmd(*pmd) || pmd_trans_huge(*pmd)) { + if (pmd_is_huge(*pmd)) { if (next - addr != HPAGE_PMD_SIZE) __split_huge_pmd(vma, pmd, addr, false); else if (zap_huge_pmd(tlb, vma, pmd, addr)) {
mm/mprotect.c +1 -1
@@ -474,7 +474,7 @@ static inline long change_pmd_range(struct mmu_gather *tlb, goto next; _pmd =pmdp_get_lockless (pmd); -if (is_swap_pmd (_pmd) ||pmd_trans_huge (_pmd)) { +if (pmd_is_huge (_pmd)) {if ((next - addr !=HPAGE_PMD_SIZE ) ||pgtable_split_needed (vma, cp_flags)) {__split_huge_pmd (vma, pmd, addr, false);
mm/mremap.c +1 -1
@@ -850,7 +850,7 @@ unsigned long move_page_tables(struct pagetable_move_control *pmc)if (!new_pmd)break ; again: -if (is_swap_pmd (*old_pmd) ||pmd_trans_huge (*old_pmd)) { +if (pmd_is_huge (*old_pmd)) {if (extent ==HPAGE_PMD_SIZE &&move_pgt_entry (pmc,HPAGE_PMD , old_pmd, new_pmd))continue ;
Signature · 1 line
2.51.0
PATCH 12/16 mm: remove remaining is_swap_pmd() users and is_swap_pmd()
In reply to Lorenzo StoakesUpdate copy_huge_pmd() and change_huge_pmd() to use pmd_is_valid_leafent()
- as this checks for the only valid non-present huge PMD states.
Also update mm/debug_vm_pgtable.c to explicitly test for a valid leaf PMD entry (which it was not before, which was incorrect), and have it test against pmd_is_huge() and pmd_is_valid_leafent() rather than is_swap_pmd().
With these changes done there are no further users of is_swap_pmd(), so remove it.
--- include/linux/huge_mm.h | 9 --------- mm/debug_vm_pgtable.c | 25 +++++++++++++++---------- mm/huge_memory.c | 5 +++-- 3 files changed, 18 insertions(+), 21 deletions(-)
include/linux/huge_mm.h +0 -9
@@ -486,11 +486,6 @@ void vma_adjust_trans_huge(struct vm_area_struct *vma, unsigned long start,spinlock_t *__pmd_trans_huge_lock (pmd_t *pmd,struct vm_area_struct *vma);spinlock_t *__pud_trans_huge_lock (pud_t *pud,struct vm_area_struct *vma); -static inline int is_swap_pmd (pmd_t pmd) -{ -return !pmd_none (pmd) && !pmd_present (pmd); -} -/* mmap_lock must be held on entry */ static inline spinlock_t *pmd_trans_huge_lock (pmd_t *pmd,struct vm_area_struct *vma)
@@ -693,10 +688,6 @@ static inline void vma_adjust_trans_huge(struct vm_area_struct *vma, struct vm_area_struct *next) { } -static inline int is_swap_pmd (pmd_t pmd) -{ -return 0 ; -}static inline spinlock_t *pmd_trans_huge_lock (pmd_t *pmd,struct vm_area_struct *vma) {
mm/debug_vm_pgtable.c +15 -10
@@ -74,6 +74,7 @@ struct pgtable_debug_args {unsigned long fixed_pte_pfn;swp_entry_t swp_entry; +swp_entry_t leaf_entry; };static void __init pte_basic_tests (struct pgtable_debug_args *args,int idx)
@@ -745,7 +746,7 @@ static void __init pmd_soft_dirty_tests(struct pgtable_debug_args *args)WARN_ON (pmd_soft_dirty (pmd_clear_soft_dirty (pmd))); } -static void __init pmd_swap_soft_dirty_tests (struct pgtable_debug_args *args) +static void __init pmd_leaf_soft_dirty_tests (struct pgtable_debug_args *args) {pmd_t pmd;
@@ -757,15 +758,16 @@ static void __init pmd_swap_soft_dirty_tests(struct pgtable_debug_args *args)return ;pr_debug ("Validating PMD swap soft dirty\n" ); - pmd =swp_entry_to_pmd (args->swp_entry); -WARN_ON (!is_swap_pmd (pmd)); + pmd =swp_entry_to_pmd (args->leaf_entry); +WARN_ON (!pmd_is_huge (pmd)); +WARN_ON (!pmd_is_valid_leafent (pmd));WARN_ON (!pmd_swp_soft_dirty (pmd_swp_mksoft_dirty (pmd))); WARN_ON(pmd_swp_soft_dirty(pmd_swp_clear_soft_dirty(pmd))); }#else /* !CONFIG_TRANSPARENT_HUGEPAGE */ static void __init pmd_soft_dirty_tests (struct pgtable_debug_args *args) { } -static void __init pmd_swap_soft_dirty_tests (struct pgtable_debug_args *args) { } +static void __init pmd_leaf_soft_dirty_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ static void __init pte_swap_exclusive_tests (struct pgtable_debug_args *args)
@@ -818,7 +820,7 @@ static void __init pte_swap_tests(struct pgtable_debug_args *args) }#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION -static void __init pmd_swap_tests (struct pgtable_debug_args *args) +static void __init pmd_leafent_tests (struct pgtable_debug_args *args) {swp_entry_t arch_entry;pmd_t pmd1, pmd2;
@@ -827,15 +829,16 @@ static void __init pmd_swap_tests(struct pgtable_debug_args *args)return ;pr_debug ("Validating PMD swap\n" ); - pmd1 =swp_entry_to_pmd (args->swp_entry); -WARN_ON (!is_swap_pmd (pmd1)); + pmd1 =swp_entry_to_pmd (args->leaf_entry); +WARN_ON (!pmd_is_huge (pmd1)); +WARN_ON (!pmd_is_valid_leafent (pmd1)); arch_entry =__pmd_to_swp_entry (pmd1); pmd2 =__swp_entry_to_pmd (arch_entry); WARN_ON(memcmp(&pmd1, &pmd2, sizeof(pmd1))); }#else /* !CONFIG_ARCH_ENABLE_THP_MIGRATION */ -static void __init pmd_swap_tests (struct pgtable_debug_args *args) { } +static void __init pmd_leafent_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_ARCH_ENABLE_THP_MIGRATION */ static void __init swap_migration_tests (struct pgtable_debug_args *args)
@@ -1229,6 +1232,8 @@ static int __init init_args(struct pgtable_debug_args *args) max_swap_offset =swp_offset (pte_to_swp_entry (swp_entry_to_pte (swp_entry (0 , ~0UL ))));/* Create a swp entry with all possible bits set while still being swap. */ args->swp_entry =swp_entry (MAX_SWAPFILES -1 , max_swap_offset); +/* Create a non-present migration entry. */ + args->leaf_entry =make_writable_migration_entry (~0UL );/* * Allocate (huge) pages because some of the tests need to access
@@ -1318,12 +1323,12 @@ static int __init debug_vm_pgtable(void)pte_soft_dirty_tests (&args);pmd_soft_dirty_tests (&args);pte_swap_soft_dirty_tests (&args); -pmd_swap_soft_dirty_tests (&args); +pmd_leaf_soft_dirty_tests (&args);pte_swap_exclusive_tests (&args);pte_swap_tests (&args); -pmd_swap_tests (&args); +pmd_leafent_tests (&args);swap_migration_tests (&args);
mm/huge_memory.c +3 -2
@@ -1875,7 +1875,8 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm, ret = -EAGAIN ; pmd = *src_pmd; -if (unlikely (thp_migration_supported () &&is_swap_pmd (pmd))) { +if (unlikely (thp_migration_supported () && +pmd_is_valid_leafent (pmd))) {copy_huge_non_present_pmd (dst_mm, src_mm, dst_pmd, src_pmd, addr, dst_vma, src_vma, pmd, pgtable); ret =0 ;
@@ -2562,7 +2563,7 @@ int change_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,if (!ptl)return 0 ; -if (thp_migration_supported () &&is_swap_pmd (*pmd)) { +if (thp_migration_supported () &&pmd_is_valid_leafent (*pmd)) {change_non_present_huge_pmd (mm, addr, pmd, uffd_wp, uffd_wp_resolve); goto unlock;
Signature · 1 line
2.51.0
PATCH 13/16 mm: remove non_swap_entry() and use leaf entry helpers instead
In reply to Lorenzo StoakesThere is simply no need for the hugely confusing concept of 'non-swap' swap entries now we have the concept of leaf entries and relevant leafent_xxx() helpers.
Adjust all callers to use these instead and remove non_swap_entry() altogether.
No functional change intended.
--- arch/s390/mm/gmap_helpers.c | 18 +++++++++--------- arch/s390/mm/pgtable.c | 12 ++++++------ fs/proc/task_mmu.c | 12 ++++++------ include/linux/swapops.h | 5 ----- mm/filemap.c | 2 +- mm/hmm.c | 16 ++++++++-------- mm/madvise.c | 2 +- mm/memory.c | 36 ++++++++++++++++++------------------ mm/mincore.c | 2 +- mm/userfaultfd.c | 24 ++++++++++++------------ 10 files changed, 62 insertions(+), 67 deletions(-)
arch/s390/mm/gmap_helpers.c +9 -9
@@ -11,27 +11,27 @@#include <linux/mm.h> #include <linux/hugetlb.h> #include <linux/swap.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/pagewalk.h> #include <linux/ksm.h> #include <asm/gmap_helpers.h> #include <asm/pgtable.h> /** -* ptep_zap_swap_entry() - discard a swap entry. +* ptep_zap_leaf_entry() - discard a leaf entry. * @mm: the mm -* @entry: the swap entry that needs to be zapped +* @entry: the leaf entry that needs to be zapped * -* Discards the given swap entry. If the swap entry was an actual swap +* Discards the given leaf entry. If the leaf entry was an actual swap * entry (and not a migration entry, for example), the actual swapped * page is also discarded from swap. */ -static void ptep_zap_swap_entry (struct mm_struct *mm,swp_entry_t entry) +static void ptep_zap_leaf_entry (struct mm_struct *mm,leaf_entry_t entry) { -if (!non_swap_entry (entry)) +if (leafent_is_swap (entry))dec_mm_counter (mm,MM_SWAPENTS ); -else if (is_migration_entry (entry)) -dec_mm_counter (mm,mm_counter (pfn_swap_entry_folio (entry))); +else if (leafent_is_migration (entry)) +dec_mm_counter (mm,mm_counter (leafent_to_folio (entry)));free_swap_and_cache (entry); }
@@ -66,7 +66,7 @@ void gmap_helper_zap_one_page(struct mm_struct *mm, unsigned long vmaddr)preempt_disable (); pgste =pgste_get_lock (ptep); -ptep_zap_swap_entry (mm,pte_to_swp_entry (*ptep)); +ptep_zap_leaf_entry (mm,leafent_from_pte (*ptep));pte_clear (mm, vmaddr, ptep);pgste_set_unlock (ptep, pgste);
arch/s390/mm/pgtable.c +6 -6
@@ -16,7 +16,7 @@#include <linux/spinlock.h> #include <linux/rcupdate.h> #include <linux/slab.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/sysctl.h> #include <linux/ksm.h> #include <linux/mman.h>
@@ -683,12 +683,12 @@ void ptep_unshadow_pte(struct mm_struct *mm, unsigned long saddr, pte_t *ptep)pgste_set_unlock (ptep, pgste); } -static void ptep_zap_swap_entry (struct mm_struct *mm,swp_entry_t entry) +static void ptep_zap_leaf_entry (struct mm_struct *mm,leaf_entry_t entry) { -if (!non_swap_entry (entry)) +if (leafent_is_swap (entry))dec_mm_counter (mm,MM_SWAPENTS ); -else if (is_migration_entry (entry)) { -struct folio *folio =pfn_swap_entry_folio (entry); +else if (leafent_is_migration (entry)) { +const struct folio *folio =leafent_to_folio (entry);dec_mm_counter (mm,mm_counter (folio)); }
@@ -710,7 +710,7 @@ void ptep_zap_unused(struct mm_struct *mm, unsigned long addr,if (!reset &&pte_swap (pte) && ((pgstev & _PGSTE_GPS_USAGE_MASK) == _PGSTE_GPS_USAGE_UNUSED || (pgstev & _PGSTE_GPS_ZERO))) { -ptep_zap_swap_entry (mm,pte_to_swp_entry (pte)); +ptep_zap_leaf_entry (mm,leafent_from_pte (pte));pte_clear (mm, addr, ptep); }if (reset)
fs/proc/task_mmu.c +6 -6
@@ -1020,13 +1020,13 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, }else if (pte_none (ptent)) {smaps_pte_hole_lookup (addr, walk); }else { -swp_entry_t swpent =pte_to_swp_entry (ptent); +const leaf_entry_t entry =leafent_from_pte (ptent); -if (!non_swap_entry (swpent)) { +if (leafent_is_swap (entry)) {int mapcount; mss->swap +=PAGE_SIZE ; - mapcount =swp_swapcount (swpent); + mapcount =swp_swapcount (entry);if (mapcount >=2 ) {u64 pss_delta = (u64 )PAGE_SIZE <<PSS_SHIFT ;
@@ -1035,10 +1035,10 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, }else { mss->swap_pss += (u64 )PAGE_SIZE <<PSS_SHIFT ; } - }else if (is_pfn_swap_entry (swpent)) { -if (is_device_private_entry (swpent)) + }else if (leafent_has_pfn (entry)) { +if (leafent_is_device_private (entry)) present = true; - page =pfn_swap_entry_to_page (swpent); + page =leafent_to_page (entry); } }
include/linux/swapops.h +0 -5
@@ -492,10 +492,5 @@ static inline pmd_t swp_entry_to_pmd(swp_entry_t entry)#endif /* CONFIG_ARCH_ENABLE_THP_MIGRATION */ -static inline int non_swap_entry (swp_entry_t entry) -{ -return swp_type (entry) >=MAX_SWAPFILES ; -} -#endif /* CONFIG_MMU */ #endif /* _LINUX_SWAPOPS_H */
mm/filemap.c +1 -1
@@ -4566,7 +4566,7 @@ static void filemap_cachestat(struct address_space *mapping,swp_entry_t swp =radix_to_swp_entry (folio);/* swapin error results in poisoned entry */ -if (non_swap_entry (swp)) +if (!leafent_is_swap (swp)) goto resched;/*
mm/hmm.c +8 -8
@@ -253,17 +253,17 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr, }if (!pte_present (pte)) { -swp_entry_t entry =pte_to_swp_entry (pte); +const leaf_entry_t entry =leafent_from_pte (pte);/* * Don't fault in device private pages owned by the caller, * just report the PFN. */ -if (is_device_private_entry (entry) && -page_pgmap (pfn_swap_entry_to_page (entry))->owner == +if (leafent_is_device_private (entry) && +page_pgmap (leafent_to_page (entry))->owner == range->dev_private_owner) { cpu_flags =HMM_PFN_VALID ; -if (is_writable_device_private_entry (entry)) +if (leafent_is_device_private_write (entry)) cpu_flags |=HMM_PFN_WRITE ; new_pfn_flags =swp_offset_pfn (entry) | cpu_flags; goto out;
@@ -274,16 +274,16 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr,if (!required_fault) goto out; -if (!non_swap_entry (entry)) +if (leafent_is_swap (entry)) goto fault; -if (is_device_private_entry (entry)) +if (leafent_is_device_private (entry)) goto fault; -if (is_device_exclusive_entry (entry)) +if (leafent_is_device_exclusive (entry)) goto fault; -if (is_migration_entry (entry)) { +if (leafent_is_migration (entry)) {pte_unmap (ptep); hmm_vma_walk->last = addr;migration_entry_wait (walk->mm, pmdp, addr);
mm/madvise.c +1 -1
@@ -249,7 +249,7 @@ static void shmem_swapin_range(struct vm_area_struct *vma,continue ; entry =radix_to_swp_entry (folio);/* There might be swapin error entries in shmem mapping. */ -if (non_swap_entry (entry)) +if (!leafent_is_swap (entry))continue ; addr = vma->vm_start +
mm/memory.c +18 -18
@@ -932,7 +932,7 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,struct folio *folio;struct page *page; -if (likely (!non_swap_entry (entry))) { +if (likely (leafent_is_swap (entry))) {if (swap_duplicate (entry) <0 )return -EIO ;
@@ -950,12 +950,12 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,set_pte_at (src_mm, addr, src_pte, pte); } rss[MM_SWAPENTS ]++; - }else if (is_migration_entry (entry)) { - folio =pfn_swap_entry_folio (entry); + }else if (leafent_is_migration (entry)) { + folio =leafent_to_folio (entry); rss[mm_counter (folio)]++; -if (!is_readable_migration_entry (entry) && +if (!leafent_is_migration_read (entry) &&is_cow_mapping (vm_flags)) {/* * COW mappings require pages in both parent and child
@@ -964,15 +964,15 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,*/ entry =make_readable_migration_entry (swp_offset (entry)); - pte =swp_entry_to_pte (entry); + pte =leafent_to_pte (entry);if (pte_swp_soft_dirty (orig_pte)) pte =pte_swp_mksoft_dirty (pte);if (pte_swp_uffd_wp (orig_pte)) pte =pte_swp_mkuffd_wp (pte);set_pte_at (src_mm, addr, src_pte, pte); } - }else if (is_device_private_entry (entry)) { - page =pfn_swap_entry_to_page (entry); + }else if (leafent_is_device_private (entry)) { + page =leafent_to_page (entry); folio =page_folio (page);/*
@@ -996,7 +996,7 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,* when a device driver is involved (you cannot easily * save and restore device driver state). */ -if (is_writable_device_private_entry (entry) && +if (leafent_is_device_private_write (entry) &&is_cow_mapping (vm_flags)) { entry =make_readable_device_private_entry (swp_offset (entry));
@@ -1005,7 +1005,7 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, pte =pte_swp_mkuffd_wp (pte);set_pte_at (src_mm, addr, src_pte, pte); } - }else if (is_device_exclusive_entry (entry)) { + }else if (leafent_is_device_exclusive (entry)) {/* * Make device exclusive entries present by restoring the * original entry then copying as for a present pte. Device
@@ -4635,7 +4635,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)rmap_t rmap_flags =RMAP_NONE ;bool need_clear_cache = false;bool exclusive = false; -swp_entry_t entry; +leaf_entry_t entry;pte_t pte;vm_fault_t ret =0 ;void *shadow =NULL ;
@@ -4647,15 +4647,15 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)if (!pte_unmap_same (vmf)) goto out; - entry =pte_to_swp_entry (vmf->orig_pte); -if (unlikely (non_swap_entry (entry))) { -if (is_migration_entry (entry)) { + entry =leafent_from_pte (vmf->orig_pte); +if (unlikely (!leafent_is_swap (entry))) { +if (leafent_is_migration (entry)) {migration_entry_wait (vma->vm_mm, vmf->pmd, vmf->address); - }else if (is_device_exclusive_entry (entry)) { - vmf->page =pfn_swap_entry_to_page (entry); + }else if (leafent_is_device_exclusive (entry)) { + vmf->page =leafent_to_page (entry); ret =remove_device_exclusive_entry (vmf); - }else if (is_device_private_entry (entry)) { + }else if (leafent_is_device_private (entry)) {if (vmf->flags &FAULT_FLAG_VMA_LOCK ) {/* * migrate_to_ram is not yet ready to operate
@@ -4666,7 +4666,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) goto out; } - vmf->page =pfn_swap_entry_to_page (entry); + vmf->page =leafent_to_page (entry); vmf->pte =pte_offset_map_lock (vma->vm_mm, vmf->pmd, vmf->address, &vmf->ptl); if (unlikely(!vmf->pte ||
@@ -4690,7 +4690,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) }else {pte_unmap_unlock (vmf->pte, vmf->ptl); } - }else if (is_hwpoison_entry (entry)) { + }else if (leafent_is_hwpoison (entry)) { ret =VM_FAULT_HWPOISON ; }else if (leafent_is_marker (entry)) { ret =handle_pte_marker (vmf);
mm/mincore.c +1 -1
@@ -74,7 +74,7 @@ static unsigned char mincore_swap(swp_entry_t entry, bool shmem)* absent. Page table may contain migration or hwpoison * entries which are always uptodate. */ -if (non_swap_entry (entry)) +if (!leafent_is_swap (entry))return !shmem;/*
mm/userfaultfd.c +12 -12
@@ -1256,7 +1256,6 @@ static long move_pages_ptes(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd unsigned long dst_addr, unsigned long src_addr, unsigned long len, __u64 mode) { - swp_entry_t entry; struct swap_info_struct *si = NULL;pte_t orig_src_pte, orig_dst_pte;pte_t src_folio_pte;
@@ -1430,19 +1429,20 @@ static long move_pages_ptes(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd orig_dst_pte, orig_src_pte, dst_pmd, dst_pmdval, dst_ptl, src_ptl, &src_folio, len); - }else { + }else {/* !pte_present() */ struct folio *folio =NULL ; +const leaf_entry_t entry =leafent_from_pte (orig_src_pte); - entry =pte_to_swp_entry (orig_src_pte); -if (non_swap_entry (entry)) { -if (is_migration_entry (entry)) { -pte_unmap (src_pte); -pte_unmap (dst_pte); - src_pte = dst_pte =NULL ; -migration_entry_wait (mm, src_pmd, src_addr); - ret = -EAGAIN ; - }else - ret = -EFAULT ; +if (leafent_is_migration (entry)) { +pte_unmap (src_pte); +pte_unmap (dst_pte); + src_pte = dst_pte =NULL ; +migration_entry_wait (mm, src_pmd, src_addr); + + ret = -EAGAIN ; + goto out; + }else if (!leafent_is_swap (entry)) { + ret = -EFAULT ; goto out; }
Signature · 1 line
2.51.0
PATCH 8/16 mm/huge_memory: refactor copy_huge_pmd() non-present logic
In reply to Lorenzo StoakesRight now we are inconsistent in our use of thp_migration_supported():
static inline bool thp_migration_supported(void)
{
return IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION);
}And simply having arbitrary and ugly #ifdefCONFIG_ARCH_ENABLE_THP_MIGRATION blocks in code.
This is exhibited in copy_huge_pmd(), which inserts a large #ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION block and an if-branch which is difficult to follow
It's difficult to follow the logic of such a large function and the non-present PMD logic is clearly separate as it sits in a giant if-branch.
Therefore this patch both separates out the logic and utilises thp_migration_supported().
No functional change intended.
--- mm/huge_memory.c | 109 +++++++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 50 deletions(-)
mm/huge_memory.c +59 -50
@@ -1774,6 +1774,62 @@ void touch_pmd(struct vm_area_struct *vma, unsigned long addr,update_mmu_cache_pmd (vma, addr, pmd); } +static void copy_huge_non_present_pmd ( +struct mm_struct *dst_mm,struct mm_struct *src_mm, +pmd_t *dst_pmd,pmd_t *src_pmd,unsigned long addr, +struct vm_area_struct *dst_vma,struct vm_area_struct *src_vma, +pmd_t pmd,pgtable_t pgtable) +{ +swp_entry_t entry =pmd_to_swp_entry (pmd); +struct folio *src_folio; + +VM_WARN_ON (!is_pmd_non_present_folio_entry (pmd)); + +if (is_writable_migration_entry (entry) || +is_readable_exclusive_migration_entry (entry)) { + entry =make_readable_migration_entry (swp_offset (entry)); + pmd =swp_entry_to_pmd (entry); +if (pmd_swp_soft_dirty (*src_pmd)) + pmd =pmd_swp_mksoft_dirty (pmd); +if (pmd_swp_uffd_wp (*src_pmd)) + pmd =pmd_swp_mkuffd_wp (pmd); +set_pmd_at (src_mm, addr, src_pmd, pmd); + }else if (is_device_private_entry (entry)) { +/* +* For device private entries, since there are no +* read exclusive entries, writable = !readable +*/ +if (is_writable_device_private_entry (entry)) { + entry =make_readable_device_private_entry (swp_offset (entry)); + pmd =swp_entry_to_pmd (entry); + +if (pmd_swp_soft_dirty (*src_pmd)) + pmd =pmd_swp_mksoft_dirty (pmd); +if (pmd_swp_uffd_wp (*src_pmd)) + pmd =pmd_swp_mkuffd_wp (pmd); +set_pmd_at (src_mm, addr, src_pmd, pmd); + } + + src_folio =pfn_swap_entry_folio (entry); +VM_WARN_ON (!folio_test_large (src_folio)); + +folio_get (src_folio); +/* +* folio_try_dup_anon_rmap_pmd does not fail for +* device private entries. +*/ +folio_try_dup_anon_rmap_pmd (src_folio, &src_folio->page, + dst_vma, src_vma); + } + +add_mm_counter (dst_mm,MM_ANONPAGES ,HPAGE_PMD_NR ); +mm_inc_nr_ptes (dst_mm); +pgtable_trans_huge_deposit (dst_mm, dst_pmd, pgtable); +if (!userfaultfd_wp (dst_vma)) + pmd =pmd_swp_clear_uffd_wp (pmd); +set_pmd_at (dst_mm, addr, dst_pmd, pmd); +} +int copy_huge_pmd (struct mm_struct *dst_mm,struct mm_struct *src_mm,pmd_t *dst_pmd,pmd_t *src_pmd,unsigned long addr,struct vm_area_struct *dst_vma,struct vm_area_struct *src_vma)
@@ -1819,59 +1875,12 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm, ret = -EAGAIN ; pmd = *src_pmd; -#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION -if (unlikely (is_swap_pmd (pmd))) { -swp_entry_t entry =pmd_to_swp_entry (pmd); - -VM_WARN_ON (!is_pmd_non_present_folio_entry (pmd)); - -if (is_writable_migration_entry (entry) || -is_readable_exclusive_migration_entry (entry)) { - entry =make_readable_migration_entry (swp_offset (entry)); - pmd =swp_entry_to_pmd (entry); -if (pmd_swp_soft_dirty (*src_pmd)) - pmd =pmd_swp_mksoft_dirty (pmd); -if (pmd_swp_uffd_wp (*src_pmd)) - pmd =pmd_swp_mkuffd_wp (pmd); -set_pmd_at (src_mm, addr, src_pmd, pmd); - }else if (is_device_private_entry (entry)) { -/* -* For device private entries, since there are no -* read exclusive entries, writable = !readable -*/ -if (is_writable_device_private_entry (entry)) { - entry =make_readable_device_private_entry (swp_offset (entry)); - pmd =swp_entry_to_pmd (entry); - -if (pmd_swp_soft_dirty (*src_pmd)) - pmd =pmd_swp_mksoft_dirty (pmd); -if (pmd_swp_uffd_wp (*src_pmd)) - pmd =pmd_swp_mkuffd_wp (pmd); -set_pmd_at (src_mm, addr, src_pmd, pmd); - } - - src_folio =pfn_swap_entry_folio (entry); -VM_WARN_ON (!folio_test_large (src_folio)); - -folio_get (src_folio); -/* -* folio_try_dup_anon_rmap_pmd does not fail for -* device private entries. -*/ -folio_try_dup_anon_rmap_pmd (src_folio, &src_folio->page, - dst_vma, src_vma); - } - -add_mm_counter (dst_mm,MM_ANONPAGES ,HPAGE_PMD_NR ); -mm_inc_nr_ptes (dst_mm); -pgtable_trans_huge_deposit (dst_mm, dst_pmd, pgtable); -if (!userfaultfd_wp (dst_vma)) - pmd =pmd_swp_clear_uffd_wp (pmd); -set_pmd_at (dst_mm, addr, dst_pmd, pmd); +if (unlikely (thp_migration_supported () &&is_swap_pmd (pmd))) { +copy_huge_non_present_pmd (dst_mm, src_mm, dst_pmd, src_pmd, addr, + dst_vma, src_vma, pmd, pgtable); ret =0 ; goto out_unlock; } -#endif if (unlikely (!pmd_trans_huge (pmd))) {pte_free (dst_mm, pgtable);
Signature · 1 line
2.51.0
PATCH 14/16 mm: remove is_hugetlb_entry_[migration, hwpoisoned]()
In reply to Lorenzo StoakesWe do not need to have explicit helper functions for these, it adds a level of confusion and indirection when we can simply use leaf entry logic here instead and spell out the special huge_pte_none() case we must consider.
No functional change intended.
--- fs/proc/task_mmu.c | 19 +++++---- include/linux/hugetlb.h | 2 - mm/hugetlb.c | 91 +++++++++++++++++------------------------ mm/mempolicy.c | 17 +++++--- mm/migrate.c | 15 +++++-- 5 files changed, 69 insertions(+), 75 deletions(-)
fs/proc/task_mmu.c +10 -9
@@ -2499,22 +2499,23 @@ static void make_uffd_wp_huge_pte(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t ptent) { - unsigned long psize; + const unsigned long psize = huge_page_size(hstate_vma(vma)); +leaf_entry_t entry; -if (is_hugetlb_entry_hwpoisoned (ptent) ||pte_is_marker (ptent)) -return ; +if (huge_pte_none (ptent)) +set_huge_pte_at (vma->vm_mm, addr, ptep, +make_pte_marker (PTE_MARKER_UFFD_WP ), psize); - psize =huge_page_size (hstate_vma (vma)); + entry =leafent_from_pte (ptent); +if (leafent_is_hwpoison (entry) ||leafent_is_marker (entry)) +return ; -if (is_hugetlb_entry_migration (ptent)) +if (leafent_is_migration (entry))set_huge_pte_at (vma->vm_mm, addr, ptep,pte_swp_mkuffd_wp (ptent), psize); -else if (!huge_pte_none (ptent)) +else huge_ptep_modify_prot_commit (vma, addr, ptep, ptent,huge_pte_mkuffd_wp (ptent)); -else -set_huge_pte_at (vma->vm_mm, addr, ptep, -make_pte_marker (PTE_MARKER_UFFD_WP ), psize); }#endif /* CONFIG_HUGETLB_PAGE */
include/linux/hugetlb.h +0 -2
@@ -274,8 +274,6 @@ void hugetlb_vma_lock_release(struct kref *kref);long hugetlb_change_protection (struct vm_area_struct *vma,unsigned long address,unsigned long end,pgprot_t newprot,unsigned long cp_flags); -bool is_hugetlb_entry_migration (pte_t pte); -bool is_hugetlb_entry_hwpoisoned (pte_t pte);void hugetlb_unshare_all_pmds (struct vm_area_struct *vma);void fixup_hugetlb_reservations (struct vm_area_struct *vma);void hugetlb_split (struct vm_area_struct *vma,unsigned long addr);
mm/hugetlb.c +37 -54
175 lines not on this page · raw message
mm/mempolicy.c +11 -6
@@ -768,16 +768,21 @@ static int queue_folios_hugetlb(pte_t *pte, unsigned long hmask,unsigned long flags = qp->flags;struct folio *folio;spinlock_t *ptl; -pte_t entry; +pte_t ptep; ptl =huge_pte_lock (hstate_vma (walk->vma), walk->mm, pte); - entry =huge_ptep_get (walk->mm, addr, pte); -if (!pte_present (entry)) { -if (unlikely (is_hugetlb_entry_migration (entry))) - qp->nr_failed++; + ptep =huge_ptep_get (walk->mm, addr, pte); +if (!pte_present (ptep)) { +if (!huge_pte_none (ptep)) { +const leaf_entry_t entry =leafent_from_pte (ptep); + +if (unlikely (leafent_is_migration (entry))) + qp->nr_failed++; + } + goto unlock; } - folio =pfn_folio (pte_pfn (entry)); + folio =pfn_folio (pte_pfn (ptep));if (!queue_folio_required (folio, qp)) goto unlock; if (!(flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) ||
mm/migrate.c +11 -4
@@ -515,16 +515,18 @@ void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd,void migration_entry_wait_huge (struct vm_area_struct *vma,unsigned long addr,pte_t *ptep) {spinlock_t *ptl =huge_pte_lockptr (hstate_vma (vma), vma->vm_mm, ptep); +leaf_entry_t entry;pte_t pte;hugetlb_vma_assert_locked (vma);spin_lock (ptl); pte =huge_ptep_get (vma->vm_mm, addr, ptep); -if (unlikely (!is_hugetlb_entry_migration (pte))) { -spin_unlock (ptl); -hugetlb_vma_unlock_read (vma); - }else { +if (huge_pte_none (pte)) + goto fail; + + entry =leafent_from_pte (pte); +if (leafent_is_migration (entry)) {/* * If migration entry existed, safe to release vma lock * here because the pgtable page won't be freed without the
@@ -533,7 +535,12 @@ void migration_entry_wait_huge(struct vm_area_struct *vma, unsigned long addr, p*/ hugetlb_vma_unlock_read (vma);migration_entry_wait_on_locked (pte_to_swp_entry (pte), ptl); + return; } + +fail: +spin_unlock (ptl); +hugetlb_vma_unlock_read (vma); }#endif
Signature · 1 line
2.51.0
PATCH 15/16 mm: eliminate further swapops predicates
In reply to Lorenzo StoakesHaving converted so much of the code base to leaf entries, we can mop up some remaining cases.
We replace is_pfn_swap_entry(), pfn_swap_entry_to_page(), is_writable_device_private_entry(), is_device_exclusive_entry(), is_migration_entry(), is_writable_migration_entry(), is_readable_migration_entry(), swp_offset_pfn() and pfn_swap_entry_folio() with leafent equivalents.
No functional change intended.
--- fs/proc/task_mmu.c | 14 ++--- include/linux/leafops.h | 25 +++++++-- include/linux/swapops.h | 121 +--------------------------------------- mm/debug_vm_pgtable.c | 20 +++---- mm/hmm.c | 2 +- mm/hugetlb.c | 2 +- mm/ksm.c | 6 +- mm/memory-failure.c | 6 +- mm/memory.c | 3 +- mm/mempolicy.c | 4 +- mm/migrate.c | 6 +- mm/migrate_device.c | 10 ++-- mm/mprotect.c | 8 +-- mm/page_vma_mapped.c | 8 +-- mm/pagewalk.c | 7 +-- mm/rmap.c | 9 ++- 16 files changed, 75 insertions(+), 176 deletions(-)
fs/proc/task_mmu.c +7 -7
@@ -1940,13 +1940,13 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm,if (pte_uffd_wp (pte)) flags |=PM_UFFD_WP ; }else { -swp_entry_t entry; +leaf_entry_t entry;if (pte_swp_soft_dirty (pte)) flags |=PM_SOFT_DIRTY ;if (pte_swp_uffd_wp (pte)) flags |=PM_UFFD_WP ; - entry =pte_to_swp_entry (pte); + entry =leafent_from_pte (pte);if (pm->show_pfn) {pgoff_t offset;
@@ -1954,16 +1954,16 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm,* For PFN swap offsets, keeping the offset field * to be PFN only to be compatible with old smaps. */ -if (is_pfn_swap_entry (entry)) - offset =swp_offset_pfn (entry); +if (leafent_has_pfn (entry)) + offset =leafent_to_pfn (entry);else offset =swp_offset (entry); frame =swp_type (entry) | (offset <<MAX_SWAPFILES_SHIFT ); } flags |=PM_SWAP ; -if (is_pfn_swap_entry (entry)) - page =pfn_swap_entry_to_page (entry); +if (leafent_has_pfn (entry)) + page =leafent_to_page (entry);if (leafent_is_uffd_wp_marker (entry)) flags |=PM_UFFD_WP ;if (leafent_is_guard_marker (entry))
@@ -2032,7 +2032,7 @@ static int pagemap_pmd_range_thp(pmd_t *pmdp, unsigned long addr,if (pmd_swp_uffd_wp (pmd)) flags |=PM_UFFD_WP ;VM_WARN_ON_ONCE (!pmd_is_migration_entry (pmd)); - page =pfn_swap_entry_to_page (entry); + page =leafent_to_page (entry); }if (page) {
include/linux/leafops.h +19 -6
@@ -357,7 +357,7 @@ static inline unsigned long leafent_to_pfn(leaf_entry_t entry)VM_WARN_ON_ONCE (!leafent_has_pfn (entry));/* Temporary until swp_entry_t eliminated. */ -return swp_offset_pfn (entry); +return swp_offset (entry) &SWP_PFN_MASK ; }/**
@@ -368,10 +368,16 @@ static inline unsigned long leafent_to_pfn(leaf_entry_t entry)*/ static inline struct page *leafent_to_page (leaf_entry_t entry) { +struct page *page =pfn_to_page (leafent_to_pfn (entry)); +VM_WARN_ON_ONCE (!leafent_has_pfn (entry)); +/* +* Any use of migration entries may only occur while the +* corresponding page is locked +*/ +VM_WARN_ON_ONCE (leafent_is_migration (entry) && !PageLocked (page)); -/* Temporary until swp_entry_t eliminated. */ -return pfn_swap_entry_to_page (entry); +return page; }/**
@@ -383,10 +389,17 @@ static inline struct page *leafent_to_page(leaf_entry_t entry)*/ static inline struct folio *leafent_to_folio (leaf_entry_t entry) { -VM_WARN_ON_ONCE (!leafent_has_pfn (entry)); +struct folio *folio =pfn_folio (leafent_to_pfn (entry)); -/* Temporary until swp_entry_t eliminated. */ -return pfn_swap_entry_folio (entry); +VM_WARN_ON_ONCE (!leafent_has_pfn (entry)); +/* +* Any use of migration entries may only occur while the +* corresponding folio is locked. +*/ +VM_WARN_ON_ONCE (leafent_is_migration (entry) && + !folio_test_locked (folio)); + +return folio; }/**
include/linux/swapops.h +1 -120
180 lines not on this page · raw message
mm/debug_vm_pgtable.c +10 -10
@@ -844,7 +844,7 @@ static void __init pmd_leafent_tests(struct pgtable_debug_args *args) { }static void __init swap_migration_tests (struct pgtable_debug_args *args) {struct page *page; -swp_entry_t swp; +leaf_entry_t entry;if (!IS_ENABLED (CONFIG_MIGRATION ))return ;
@@ -867,17 +867,17 @@ static void __init swap_migration_tests(struct pgtable_debug_args *args)* be locked, otherwise it stumbles upon a BUG_ON(). */ __SetPageLocked (page); - swp =make_writable_migration_entry (page_to_pfn (page)); -WARN_ON (!is_migration_entry (swp)); -WARN_ON (!is_writable_migration_entry (swp)); + entry =make_writable_migration_entry (page_to_pfn (page)); +WARN_ON (!leafent_is_migration (entry)); +WARN_ON (!leafent_is_migration_write (entry)); - swp =make_readable_migration_entry (swp_offset (swp)); -WARN_ON (!is_migration_entry (swp)); -WARN_ON (is_writable_migration_entry (swp)); + entry =make_readable_migration_entry (swp_offset (entry)); +WARN_ON (!leafent_is_migration (entry)); +WARN_ON (leafent_is_migration_write (entry)); - swp =make_readable_migration_entry (page_to_pfn (page)); -WARN_ON (!is_migration_entry (swp)); -WARN_ON (is_writable_migration_entry (swp)); + entry =make_readable_migration_entry (page_to_pfn (page)); +WARN_ON (!leafent_is_migration (entry)); +WARN_ON (leafent_is_migration_write (entry));__ClearPageLocked (page); }
mm/hmm.c +1 -1
@@ -265,7 +265,7 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr, cpu_flags =HMM_PFN_VALID ;if (leafent_is_device_private_write (entry)) cpu_flags |=HMM_PFN_WRITE ; - new_pfn_flags =swp_offset_pfn (entry) | cpu_flags; + new_pfn_flags =leafent_to_pfn (entry) | cpu_flags; goto out; }
mm/hugetlb.c +1 -1
@@ -5640,7 +5640,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, }else if (unlikely (leafent_is_migration (leafent))) {bool uffd_wp =pte_swp_uffd_wp (entry); -if (!is_readable_migration_entry (leafent) && cow) { +if (!leafent_is_migration_read (leafent) && cow) {/* * COW mappings require pages in both * parent and child to be set to read.
mm/ksm.c +3 -3
@@ -637,14 +637,14 @@ static int break_ksm_pmd_entry(pmd_t *pmdp, unsigned long addr, unsigned long enif (pte_present (pte)) { folio =vm_normal_folio (walk->vma, addr, pte); }else if (!pte_none (pte)) { -swp_entry_t entry =pte_to_swp_entry (pte); +const leaf_entry_t entry =leafent_from_pte (pte);/* * As KSM pages remain KSM pages until freed, no need to wait * here for migration to end. */ -if (is_migration_entry (entry)) - folio =pfn_swap_entry_folio (entry); +if (leafent_is_migration (entry)) + folio =leafent_to_folio (entry); }/* return 1 if the page is an normal ksm page or KSM-placed zero page */ found = (folio &&folio_test_ksm (folio)) ||is_ksm_zero_pte (pte);
mm/memory-failure.c +3 -3
@@ -691,10 +691,10 @@ static int check_hwpoisoned_entry(pte_t pte, unsigned long addr, short shift,if (pte_present (pte)) { pfn =pte_pfn (pte); }else { -swp_entry_t swp =pte_to_swp_entry (pte); +const leaf_entry_t entry =leafent_from_pte (pte); -if (is_hwpoison_entry (swp)) - pfn =swp_offset_pfn (swp); +if (leafent_is_hwpoison (entry)) + pfn =leafent_to_pfn (entry); }if (!pfn || pfn != poisoned_pfn)
mm/memory.c +2 -1
@@ -902,7 +902,8 @@ static void restore_exclusive_pte(struct vm_area_struct *vma,static int try_restore_exclusive_pte (struct vm_area_struct *vma,unsigned long addr,pte_t *ptep,pte_t orig_pte) { -struct page *page =pfn_swap_entry_to_page (pte_to_swp_entry (orig_pte)); +const leaf_entry_t entry =leafent_from_pte (orig_pte); +struct page *page =leafent_to_page (entry);struct folio *folio =page_folio (page);if (folio_trylock (folio)) {
mm/mempolicy.c +3 -1
@@ -705,7 +705,9 @@ static int queue_folios_pte_range(pmd_t *pmd, unsigned long addr,if (pte_none (ptent))continue ;if (!pte_present (ptent)) { -if (is_migration_entry (pte_to_swp_entry (ptent))) +const leaf_entry_t entry =leafent_from_pte (ptent); + +if (leafent_is_migration (entry)) qp->nr_failed++;continue ; }
mm/migrate.c +3 -3
@@ -483,7 +483,7 @@ void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd,spinlock_t *ptl;pte_t *ptep;pte_t pte; -swp_entry_t entry; +leaf_entry_t entry; ptep =pte_offset_map_lock (mm, pmd, address, &ptl);if (!ptep)
@@ -495,8 +495,8 @@ void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd,if (pte_none (pte) ||pte_present (pte)) goto out; - entry =pte_to_swp_entry (pte); -if (!is_migration_entry (entry)) + entry =leafent_from_pte (pte); +if (!leafent_is_migration (entry)) goto out;migration_entry_wait_on_locked (entry, ptl);
mm/migrate_device.c +5 -5
@@ -282,7 +282,7 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,unsigned long mpfn =0 , pfn;struct folio *folio;struct page *page; -swp_entry_t entry; +leaf_entry_t entry;pte_t pte; pte =ptep_get (ptep);
@@ -301,11 +301,11 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,* page table entry. Other special swap entries are not * migratable, and we ignore regular swapped page. */ - entry =pte_to_swp_entry (pte); -if (!is_device_private_entry (entry)) + entry =leafent_from_pte (pte); +if (!leafent_is_device_private (entry)) goto next; - page =pfn_swap_entry_to_page (entry); + page =leafent_to_page (entry); pgmap =page_pgmap (page); if (!(migrate->flags & MIGRATE_VMA_SELECT_DEVICE_PRIVATE) ||
@@ -331,7 +331,7 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, mpfn =migrate_pfn (page_to_pfn (page)) |MIGRATE_PFN_MIGRATE ; -if (is_writable_device_private_entry (entry)) +if (leafent_is_device_private_write (entry)) mpfn |=MIGRATE_PFN_WRITE ; }else { pfn =pte_pfn (pte);
mm/mprotect.c +4 -4
@@ -317,11 +317,11 @@ static long change_pte_range(struct mmu_gather *tlb, pages++; } }else { -swp_entry_t entry =pte_to_swp_entry (oldpte); +leaf_entry_t entry =leafent_from_pte (oldpte);pte_t newpte; -if (is_writable_migration_entry (entry)) { -struct folio *folio =pfn_swap_entry_folio (entry); +if (leafent_is_migration_write (entry)) { +const struct folio *folio =leafent_to_folio (entry);/* * A protection check is difficult so
@@ -335,7 +335,7 @@ static long change_pte_range(struct mmu_gather *tlb, newpte =swp_entry_to_pte (entry);if (pte_swp_soft_dirty (oldpte)) newpte =pte_swp_mksoft_dirty (newpte); - }else if (is_writable_device_private_entry (entry)) { + }else if (leafent_is_device_private_write (entry)) {/* * We do not preserve soft-dirtiness. See * copy_nonpresent_pte() for explanation.
mm/page_vma_mapped.c +4 -4
@@ -49,7 +49,7 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw, pmd_t *pmdvalp,if (is_migration)return false; }else if (!is_migration) { -swp_entry_t entry; +leaf_entry_t entry;/* * Handle un-addressable ZONE_DEVICE memory.
@@ -67,9 +67,9 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw, pmd_t *pmdvalp,* For more details on device private memory see HMM * (include/linux/hmm.h or mm/hmm.c). */ - entry =pte_to_swp_entry (ptent); -if (!is_device_private_entry (entry) && - !is_device_exclusive_entry (entry)) + entry =leafent_from_pte (ptent); +if (!leafent_is_device_private (entry) && + !leafent_is_device_exclusive (entry))return false; }spin_lock (*ptlp);
mm/pagewalk.c +3 -4
@@ -1000,11 +1000,10 @@ struct folio *folio_walk_start(struct folio_walk *fw, goto found; } }else if (!pte_none (pte)) { -swp_entry_t entry =pte_to_swp_entry (pte); +const leaf_entry_t entry =leafent_from_pte (pte); -if ((flags &FW_MIGRATION ) && -is_migration_entry (entry)) { - page =pfn_swap_entry_to_page (entry); +if ((flags &FW_MIGRATION ) &&leafent_is_migration (entry)) { + page =leafent_to_page (entry); expose_page = false; goto found; }
mm/rmap.c +6 -3
@@ -1969,7 +1969,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,if (likely (pte_present (pteval))) { pfn =pte_pfn (pteval); }else { - pfn =swp_offset_pfn (pte_to_swp_entry (pteval)); + pfn =leafent_to_pfn (pte_to_swp_entry (pteval));VM_WARN_ON_FOLIO (folio_test_hugetlb (folio), folio); }
@@ -2368,7 +2368,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,if (likely (pte_present (pteval))) { pfn =pte_pfn (pteval); }else { - pfn =swp_offset_pfn (pte_to_swp_entry (pteval)); + pfn =leafent_to_pfn (pte_to_swp_entry (pteval));VM_WARN_ON_FOLIO (folio_test_hugetlb (folio), folio); }
@@ -2453,8 +2453,11 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,folio_mark_dirty (folio); writable =pte_write (pteval); }else { +const leaf_entry_t entry =leafent_from_pte (pteval); +pte_clear (mm, address, pvmw.pte); - writable =is_writable_device_private_entry (pte_to_swp_entry (pteval)); + + writable =leafent_is_device_private_write (entry); } VM_WARN_ON_FOLIO(writable && folio_test_anon(folio) &&
Signature · 1 line
2.51.0
PATCH 16/16 mm: replace remaining pte_to_swp_entry() with leafent_from_pte()
In reply to Lorenzo StoakesThere are straggler invocations of pte_to_swp_entry() lying around, replace all of these with the leaf entry equivalent - leafent_from_pte().
With those removed, eliminate pte_to_swp_entry() altogether.
No functional change intended.
--- include/linux/leafops.h | 7 ++++++- include/linux/swapops.h | 13 ------------- mm/debug_vm_pgtable.c | 2 +- mm/internal.h | 7 +++++-- mm/memory-failure.c | 2 +- mm/memory.c | 16 ++++++++-------- mm/migrate.c | 2 +- mm/mincore.c | 4 +++- mm/rmap.c | 8 ++++++-- mm/swapfile.c | 5 +++-- 10 files changed, 34 insertions(+), 32 deletions(-)
include/linux/leafops.h +6 -1
@@ -66,11 +66,16 @@ static inline leaf_entry_t leafent_mk_none(void)*/ static inline leaf_entry_t leafent_from_pte (pte_t pte) { +leaf_entry_t arch_entry; +if (pte_present (pte))return leafent_mk_none (); + pte =pte_swp_clear_flags (pte); + arch_entry =__pte_to_swp_entry (pte); +/* Temporary until swp_entry_t eliminated. */ -return pte_to_swp_entry (pte); +return swp_entry (__swp_type (arch_entry),__swp_offset (arch_entry)); }/**
include/linux/swapops.h +0 -13
@@ -107,19 +107,6 @@ static inline pgoff_t swp_offset(swp_entry_t entry)return entry.val &SWP_OFFSET_MASK ; } -/* -* Convert the arch-dependent pte representation of a swp_entry_t into an -* arch-independent swp_entry_t. -*/ -static inline swp_entry_t pte_to_swp_entry (pte_t pte) -{ -swp_entry_t arch_entry; - - pte =pte_swp_clear_flags (pte); - arch_entry =__pte_to_swp_entry (pte); -return swp_entry (__swp_type (arch_entry),__swp_offset (arch_entry)); -} -/* * Convert the arch-independent representation of a swp_entry_t into the * arch-dependent pte representation.
mm/debug_vm_pgtable.c +1 -1
@@ -1229,7 +1229,7 @@ static int __init init_args(struct pgtable_debug_args *args)init_fixed_pfns (args);/* See generic_max_swapfile_size(): probe the maximum offset */ - max_swap_offset =swp_offset (pte_to_swp_entry (swp_entry_to_pte (swp_entry (0 , ~0UL )))); + max_swap_offset =swp_offset (leafent_from_pte (leafent_to_pte (swp_entry (0 , ~0UL ))));/* Create a swp entry with all possible bits set while still being swap. */ args->swp_entry =swp_entry (MAX_SWAPFILES -1 , max_swap_offset);/* Create a non-present migration entry. */
mm/internal.h +5 -2
@@ -334,7 +334,7 @@ unsigned int folio_pte_batch(struct folio *folio, pte_t *ptep, pte_t pte,*/ static inline pte_t pte_move_swp_offset (pte_t pte,long delta) { -swp_entry_t entry =pte_to_swp_entry (pte); +const leaf_entry_t entry =leafent_from_pte (pte);pte_t new =__swp_entry_to_pte (__swp_entry (swp_type (entry), (swp_offset (entry) + delta)));
@@ -389,11 +389,14 @@ static inline int swap_pte_batch(pte_t *start_ptep, int max_nr, pte_t pte) cgroup_id =lookup_swap_cgroup_id (entry);while (ptep < end_ptep) { +leaf_entry_t entry; + pte =ptep_get (ptep);if (!pte_same (pte, expected_pte))break ; -if (lookup_swap_cgroup_id (pte_to_swp_entry (pte)) != cgroup_id) + entry =leafent_from_pte (pte); +if (lookup_swap_cgroup_id (entry) != cgroup_id)break ; expected_pte =pte_next_swp_offset (expected_pte); ptep++;
mm/memory-failure.c +1 -1
@@ -50,7 +50,7 @@#include <linux/backing-dev.h> #include <linux/migrate.h> #include <linux/slab.h> -#include <linux/swapops.h> +#include <linux/leafops.h> #include <linux/hugetlb.h> #include <linux/memory_hotplug.h> #include <linux/mm_inline.h>
mm/memory.c +8 -8
@@ -1218,7 +1218,7 @@ copy_pte_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma,spinlock_t *src_ptl, *dst_ptl;int progress, max_nr, ret =0 ;int rss[NR_MM_COUNTERS ]; -swp_entry_t entry = (swp_entry_t ){0 }; +leaf_entry_t entry =leafent_mk_none ();struct folio *prealloc =NULL ;int nr;
@@ -1282,7 +1282,7 @@ copy_pte_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, dst_vma, src_vma, addr, rss);if (ret == -EIO ) { - entry =pte_to_swp_entry (ptep_get (src_pte)); + entry =leafent_from_pte (ptep_get (src_pte));break ; }else if (ret == -EBUSY ) {break ;
@@ -4456,13 +4456,13 @@ static struct folio *__alloc_swap_folio(struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma;struct folio *folio; -swp_entry_t entry; +leaf_entry_t entry; folio =vma_alloc_folio (GFP_HIGHUSER_MOVABLE ,0 , vma, vmf->address);if (!folio)return NULL ; - entry =pte_to_swp_entry (vmf->orig_pte); + entry =leafent_from_pte (vmf->orig_pte);if (mem_cgroup_swapin_charge_folio (folio, vma->vm_mm,GFP_KERNEL , entry)) {folio_put (folio);
@@ -4480,7 +4480,7 @@ static struct folio *__alloc_swap_folio(struct vm_fault *vmf)static bool can_swapin_thp (struct vm_fault *vmf,pte_t *ptep,int nr_pages) {unsigned long addr; -swp_entry_t entry; +leaf_entry_t entry;int idx;pte_t pte;
@@ -4490,7 +4490,7 @@ static bool can_swapin_thp(struct vm_fault *vmf, pte_t *ptep, int nr_pages)if (!pte_same (pte,pte_move_swp_offset (vmf->orig_pte, -idx)))return false; - entry =pte_to_swp_entry (pte); + entry =leafent_from_pte (pte);if (swap_pte_batch (ptep, nr_pages, pte) != nr_pages)return false;
@@ -4536,7 +4536,7 @@ static struct folio *alloc_swap_folio(struct vm_fault *vmf)unsigned long orders;struct folio *folio;unsigned long addr; -swp_entry_t entry; +leaf_entry_t entry;spinlock_t *ptl;pte_t *pte;gfp_t gfp;
@@ -4557,7 +4557,7 @@ static struct folio *alloc_swap_folio(struct vm_fault *vmf)if (!zswap_never_enabled ()) goto fallback; - entry =pte_to_swp_entry (vmf->orig_pte); + entry =leafent_from_pte (vmf->orig_pte);/* * Get a list of all the (large) orders below PMD_ORDER that are enabled * and suitable for swapping THP.
mm/migrate.c +1 -1
@@ -534,7 +534,7 @@ void migration_entry_wait_huge(struct vm_area_struct *vma, unsigned long addr, p* lock release in migration_entry_wait_on_locked(). */ hugetlb_vma_unlock_read (vma); -migration_entry_wait_on_locked (pte_to_swp_entry (pte), ptl); +migration_entry_wait_on_locked (entry, ptl);return ; }
mm/mincore.c +3 -1
@@ -202,7 +202,9 @@ static int mincore_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,for (i =0 ; i < step; i++) vec[i] =1 ; }else {/* pte is a swap entry */ - *vec =mincore_swap (pte_to_swp_entry (pte), false); +const leaf_entry_t entry =leafent_from_pte (pte); + + *vec =mincore_swap (entry, false); } vec += step; }
mm/rmap.c +6 -2
@@ -1969,7 +1969,9 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,if (likely (pte_present (pteval))) { pfn =pte_pfn (pteval); }else { - pfn =leafent_to_pfn (pte_to_swp_entry (pteval)); +const leaf_entry_t entry =leafent_from_pte (pteval); + + pfn =leafent_to_pfn (entry);VM_WARN_ON_FOLIO (folio_test_hugetlb (folio), folio); }
@@ -2368,7 +2370,9 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,if (likely (pte_present (pteval))) { pfn =pte_pfn (pteval); }else { - pfn =leafent_to_pfn (pte_to_swp_entry (pteval)); +const leaf_entry_t entry =leafent_from_pte (pteval); + + pfn =leafent_to_pfn (entry);VM_WARN_ON_FOLIO (folio_test_hugetlb (folio), folio); }
mm/swapfile.c +3 -2
@@ -3201,8 +3201,9 @@ static int claim_swapfile(struct swap_info_struct *si, struct inode *inode)*/ unsigned long generic_max_swapfile_size (void ) { -return swp_offset (pte_to_swp_entry ( -swp_entry_to_pte (swp_entry (0 , ~0UL )))) +1 ; +const leaf_entry_t entry =swp_entry (0 , ~0UL ); + +return swp_offset (leafent_from_pte (leafent_to_pte (entry))) +1 ; }/* Can be overridden by an architecture for additional checks. */
Signature · 1 line
2.51.0
kernel test robot
build botRe: [PATCH 10/16] mm: replace pmd_to_swp_entry() with leafent_from_pmd()
In reply to Lorenzo Stoakeskernel test robot noticed the following build errors:
Hi Lorenzo,
kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Lorenzo-Stoakes/mm-correctly-handle-UFFD-PTE-markers/20251103-204118 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/38c26e75ed00263e9ecbebb0c045dd6d8183ec67.1762171281.git.lorenzo.stoakes%40oracle.com patch subject: [PATCH 10/16] mm: replace pmd_to_swp_entry() with leafent_from_pmd() config: openrisc-allnoconfig (https://download.01.org/0day-ci/archive/20251103/[email protected]/config) compiler: or1k-linux-gcc (GCC) 15.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251103/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from include/linux/mm_inline.h:11,
from kernel/fork.c:46:
include/linux/leafops.h: In function 'leafent_from_pmd':
>> include/linux/leafops.h:111:22: error: implicit declaration of function '__pmd_to_swp_entry'; did you mean 'pte_to_swp_entry'? [-Wimplicit-function-declaration]
111 | arch_entry = __pmd_to_swp_entry(pmd);
| ^~~~~~~~~~~~~~~~~~
| pte_to_swp_entry
>> include/linux/leafops.h:111:22: error: incompatible types when assigning to type 'leaf_entry_t' {aka 'swp_entry_t'} from type 'int'--
In file included from include/linux/leafops.h:6,
from include/linux/migrate.h:9, from mm/folio-compat.c:7:
include/linux/swapops.h: In function 'swp_entry':
>> include/linux/swapops.h:27:46: error: 'MAX_SWAPFILES_SHIFT' undeclared (first use in this function)
27 | #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
| ^~~~~~~~~~~~~~~~~~~
include/linux/swapops.h:90:28: note: in expansion of macro 'SWP_TYPE_SHIFT'
90 | ret.val = (type << SWP_TYPE_SHIFT) | (offset & SWP_OFFSET_MASK);
| ^~~~~~~~~~~~~~
include/linux/swapops.h:27:46: note: each undeclared identifier is reported only once for each function it appears in
27 | #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
| ^~~~~~~~~~~~~~~~~~~
include/linux/swapops.h:90:28: note: in expansion of macro 'SWP_TYPE_SHIFT'
90 | ret.val = (type << SWP_TYPE_SHIFT) | (offset & SWP_OFFSET_MASK);
| ^~~~~~~~~~~~~~
include/linux/swapops.h: In function 'swp_type':
>> include/linux/swapops.h:27:46: error: 'MAX_SWAPFILES_SHIFT' undeclared (first use in this function)
27 | #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
| ^~~~~~~~~~~~~~~~~~~
include/linux/swapops.h:100:30: note: in expansion of macro 'SWP_TYPE_SHIFT'
100 | return (entry.val >> SWP_TYPE_SHIFT);
| ^~~~~~~~~~~~~~
include/linux/swapops.h: In function 'swp_offset':
>> include/linux/swapops.h:27:46: error: 'MAX_SWAPFILES_SHIFT' undeclared (first use in this function)
27 | #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
| ^~~~~~~~~~~~~~~~~~~
include/linux/swapops.h:28:34: note: in expansion of macro 'SWP_TYPE_SHIFT'
28 | #define SWP_OFFSET_MASK ((1UL << SWP_TYPE_SHIFT) - 1)
| ^~~~~~~~~~~~~~
include/linux/swapops.h:109:28: note: in expansion of macro 'SWP_OFFSET_MASK'
109 | return entry.val & SWP_OFFSET_MASK;
| ^~~~~~~~~~~~~~~
In file included from include/linux/bits.h:5,
from include/linux/ratelimit_types.h:5,
from include/linux/printk.h:9,
from include/asm-generic/bug.h:22,
from arch/openrisc/include/asm/bug.h:5,
from include/linux/bug.h:5,
from include/linux/mmdebug.h:5,
from include/linux/mm.h:6,
from include/linux/migrate.h:5:
include/linux/swapops.h: In function 'swp_offset_pfn':
>> include/linux/swapops.h:27:46: error: 'MAX_SWAPFILES_SHIFT' undeclared (first use in this function)
27 | #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
| ^~~~~~~~~~~~~~~~~~~
include/vdso/bits.h:7:44: note: in definition of macro 'BIT'
7 | #define BIT(nr) (UL(1) << (nr))
| ^~
include/linux/minmax.h:89:9: note: in expansion of macro '__cmp_once_unique'
89 | __cmp_once_unique(op, type, x, y, __UNIQUE_ID(x_), __UNIQUE_ID(y_))
| ^~~~~~~~~~~~~~~~~
include/linux/minmax.h:161:27: note: in expansion of macro '__cmp_once'
161 | #define min_t(type, x, y) __cmp_once(min, type, x, y)
| ^~~~~~~~~~
include/linux/swapops.h:38:33: note: in expansion of macro 'min_t'
38 | #define SWP_PFN_BITS min_t(int, \
| ^~~~~
include/linux/swapops.h:40:39: note: in expansion of macro 'SWP_TYPE_SHIFT'
40 | SWP_TYPE_SHIFT)
| ^~~~~~~~~~~~~~
include/linux/swapops.h:42:38: note: in expansion of macro 'SWP_PFN_BITS'
42 | #define SWP_PFN_MASK (BIT(SWP_PFN_BITS) - 1)
| ^~~~~~~~~~~~
include/linux/swapops.h:120:36: note: in expansion of macro 'SWP_PFN_MASK'
120 | return swp_offset(entry) & SWP_PFN_MASK;
| ^~~~~~~~~~~~
include/linux/swapops.h: In function 'make_pte_marker_entry':
>> include/linux/swapops.h:395:26: error: 'SWP_PTE_MARKER' undeclared (first use in this function)
395 | return swp_entry(SWP_PTE_MARKER, marker);
| ^~~~~~~~~~~~~~
In file included from <command-line>:
include/linux/swapops.h: In function 'is_pfn_swap_entry':
>> include/linux/swapops.h:27:46: error: 'MAX_SWAPFILES_SHIFT' undeclared (first use in this function)
27 | #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
| ^~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:577:23: note: in definition of macro '__compiletime_assert'
577 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:597:9: note: in expansion of macro '_compiletime_assert'
597 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:50:9: note: in expansion of macro 'BUILD_BUG_ON_MSG'
50 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
| ^~~~~~~~~~~~~~~~
include/linux/swapops.h:448:9: note: in expansion of macro 'BUILD_BUG_ON'
448 | BUILD_BUG_ON(SWP_TYPE_SHIFT < SWP_PFN_BITS);
| ^~~~~~~~~~~~
include/linux/swapops.h:448:22: note: in expansion of macro 'SWP_TYPE_SHIFT'
448 | BUILD_BUG_ON(SWP_TYPE_SHIFT < SWP_PFN_BITS);
| ^~~~~~~~~~~~~~
include/linux/swapops.h: In function 'non_swap_entry':
include/linux/swapops.h:491:35: error: 'MAX_SWAPFILES' undeclared (first use in this function); did you mean 'S_SWAPFILE'?
491 | return swp_type(entry) >= MAX_SWAPFILES;
| ^~~~~~~~~~~~~
| S_SWAPFILE
include/linux/leafops.h: In function 'leafent_from_pmd':
>> include/linux/leafops.h:111:22: error: implicit declaration of function '__pmd_to_swp_entry'; did you mean 'pte_to_swp_entry'? [-Wimplicit-function-declaration]
111 | arch_entry = __pmd_to_swp_entry(pmd);
| ^~~~~~~~~~~~~~~~~~
| pte_to_swp_entry
>> include/linux/leafops.h:111:22: error: incompatible types when assigning to type 'leaf_entry_t' {aka 'swp_entry_t'} from type 'int'vim +111 include/linux/leafops.h
90
91 /**
92 * leafent_from_pmd() - Obtain a leaf entry from a PMD entry.
93 * @pmd: PMD entry.
94 *
95 * If @pmd is present (therefore not a leaf entry) the function returns an empty
96 * leaf entry. Otherwise, it returns a leaf entry.
97 *
98 * Returns: Leaf entry.
99 */
100 static inline leaf_entry_t leafent_from_pmd(pmd_t pmd)
101 {
102 leaf_entry_t arch_entry;
103
104 if (pmd_present(pmd))
105 return leafent_mk_none();
106
107 if (pmd_swp_soft_dirty(pmd))
108 pmd = pmd_swp_clear_soft_dirty(pmd);
109 if (pmd_swp_uffd_wp(pmd))
110 pmd = pmd_swp_clear_uffd_wp(pmd);
> 111 arch_entry = __pmd_to_swp_entry(pmd); 112
113 /* Temporary until swp_entry_t eliminated. */
114 return swp_entry(__swp_type(arch_entry), __swp_offset(arch_entry));
115 }
116
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH 10/16] mm: replace pmd_to_swp_entry() with leafent_from_pmd()
Quoted 21 lines · kernel test robot
Hi Lorenzo,
kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Lorenzo-Stoakes/mm-correctly-handle-UFFD-PTE-markers/20251103-204118 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/38c26e75ed00263e9ecbebb0c045dd6d8183ec67.1762171281.git.lorenzo.stoakes%40oracle.com patch subject: [PATCH 10/16] mm: replace pmd_to_swp_entry() with leafent_from_pmd() config: openrisc-allnoconfig (https://download.01.org/0day-ci/archive/20251103/[email protected]/config) compiler: or1k-linux-gcc (GCC) 15.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251103/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/All errors (new ones prefixed by >>):
Quoted 7 lines
In file included from
include/linux/mm_inline.h:11,from kernel/fork.c:46:
include/linux/leafops.h: In function 'leafent_from_pmd':Quoted 1 line
Quoted 1 line
include/linux/leafops.h:111:22: error: implicit declaration of function '__pmd_to_swp_entry'; did you mean 'pte_to_swp_entry'? [-Wimplicit-function-declaration]111 | arch_entry = __pmd_to_swp_entry(pmd); | ^~~~~~~~~~~~~~~~~~ | pte_to_swp_entry
Yeah this needs some #ifdeffery around CONFIG_ARCH_ENABLE_THP_MIGRATION.
Probably different arches do different things in terms of defining/not defining this.
Will send fix-patch...
Quoted 142 lines
Quoted 1 line
Quoted 1 line
include/linux/leafops.h:111:22: error: incompatible types when assigning to type 'leaf_entry_t' {aka 'swp_entry_t'} from type 'int'--
In file included frominclude/linux/leafops.h:6,
frominclude/linux/migrate.h:9, frommm/folio-compat.c:7:
include/linux/swapops.h: In function 'swp_entry':Quoted 1 line
Quoted 1 line
include/linux/swapops.h:27:46: error: 'MAX_SWAPFILES_SHIFT' undeclared (first use in this function)27 | #define
SWP_TYPE_SHIFT(BITS_PER_XA_VALUE-MAX_SWAPFILES_SHIFT)
| ^~~~~~~~~~~~~~~~~~~
include/linux/swapops.h:90:28: note: in expansion of macro 'SWP_TYPE_SHIFT'90 | ret.val = (type << SWP_TYPE_SHIFT) | (offset & SWP_OFFSET_MASK); | ^~~~~~~~~~~~~~ include/linux/swapops.h:27:46: note: each undeclared identifier is reported only once for each function it appears in 27 | #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT) | ^~~~~~~~~~~~~~~~~~~ include/linux/swapops.h:90:28: note: in expansion of macro 'SWP_TYPE_SHIFT' 90 | ret.val = (type << SWP_TYPE_SHIFT) | (offset & SWP_OFFSET_MASK); | ^~~~~~~~~~~~~~
include/linux/swapops.h: In function 'swp_type':Quoted 1 line
Quoted 1 line
include/linux/swapops.h:27:46: error: 'MAX_SWAPFILES_SHIFT' undeclared (first use in this function)27 | #define
SWP_TYPE_SHIFT(BITS_PER_XA_VALUE-MAX_SWAPFILES_SHIFT)
| ^~~~~~~~~~~~~~~~~~~
include/linux/swapops.h:100:30: note: in expansion of macro 'SWP_TYPE_SHIFT'100 | return (entry.val >> SWP_TYPE_SHIFT); | ^~~~~~~~~~~~~~
include/linux/swapops.h: In function 'swp_offset':Quoted 1 line
Quoted 1 line
include/linux/swapops.h:27:46: error: 'MAX_SWAPFILES_SHIFT' undeclared (first use in this function)27 | #define
SWP_TYPE_SHIFT(BITS_PER_XA_VALUE-MAX_SWAPFILES_SHIFT)
| ^~~~~~~~~~~~~~~~~~~
include/linux/swapops.h:28:34: note: in expansion of macro 'SWP_TYPE_SHIFT'28 | #define SWP_OFFSET_MASK ((1UL << SWP_TYPE_SHIFT) - 1) | ^~~~~~~~~~~~~~ include/linux/swapops.h:109:28: note: in expansion of macro 'SWP_OFFSET_MASK' 109 | return entry.val & SWP_OFFSET_MASK; | ^~~~~~~~~~~~~~~In file included from
include/linux/bits.h:5,
frominclude/linux/ratelimit_types.h:5, frominclude/linux/printk.h:9, frominclude/asm-generic/bug.h:22, fromarch/openrisc/include/asm/bug.h:5, frominclude/linux/bug.h:5, frominclude/linux/mmdebug.h:5, frominclude/linux/mm.h:6, frominclude/linux/migrate.h:5:
include/linux/swapops.h: In function 'swp_offset_pfn':Quoted 1 line
Quoted 1 line
include/linux/swapops.h:27:46: error: 'MAX_SWAPFILES_SHIFT' undeclared (first use in this function)27 | #define
SWP_TYPE_SHIFT(BITS_PER_XA_VALUE-MAX_SWAPFILES_SHIFT)
| ^~~~~~~~~~~~~~~~~~~
include/vdso/bits.h:7:44: note: in definition of macro 'BIT'7 | #define BIT(nr) (UL(1) << (nr)) | ^~ include/linux/minmax.h:89:9: note: in expansion of macro '__cmp_once_unique' 89 | __cmp_once_unique(op, type, x, y, __UNIQUE_ID(x_), __UNIQUE_ID(y_)) | ^~~~~~~~~~~~~~~~~ include/linux/minmax.h:161:27: note: in expansion of macro '__cmp_once' 161 | #define min_t(type, x, y) __cmp_once(min, type, x, y) | ^~~~~~~~~~ include/linux/swapops.h:38:33: note: in expansion of macro 'min_t' 38 | #define SWP_PFN_BITS min_t(int, \ | ^~~~~ include/linux/swapops.h:40:39: note: in expansion of macro 'SWP_TYPE_SHIFT' 40 | SWP_TYPE_SHIFT) | ^~~~~~~~~~~~~~ include/linux/swapops.h:42:38: note: in expansion of macro 'SWP_PFN_BITS' 42 | #define SWP_PFN_MASK (BIT(SWP_PFN_BITS) - 1) | ^~~~~~~~~~~~ include/linux/swapops.h:120:36: note: in expansion of macro 'SWP_PFN_MASK' 120 | return swp_offset(entry) & SWP_PFN_MASK; | ^~~~~~~~~~~~
include/linux/swapops.h: In function 'make_pte_marker_entry':Quoted 1 line
Quoted 1 line
include/linux/swapops.h:395:26: error: 'SWP_PTE_MARKER' undeclared (first use in this function)395 | return swp_entry(SWP_PTE_MARKER, marker); | ^~~~~~~~~~~~~~In file included from <command-line>:
include/linux/swapops.h: In function 'is_pfn_swap_entry':Quoted 1 line
Quoted 1 line
include/linux/swapops.h:27:46: error: 'MAX_SWAPFILES_SHIFT' undeclared (first use in this function)27 | #define
SWP_TYPE_SHIFT(BITS_PER_XA_VALUE-MAX_SWAPFILES_SHIFT)
| ^~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:577:23: note: in definition of macro '__compiletime_assert'577 | if (!(condition)) \ | ^~~~~~~~~ include/linux/compiler_types.h:597:9: note: in expansion of macro '_compiletime_assert' 597 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) | ^~~~~~~~~~~~~~~~~~~ include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert' 39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) | ^~~~~~~~~~~~~~~~~~ include/linux/build_bug.h:50:9: note: in expansion of macro 'BUILD_BUG_ON_MSG' 50 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition) | ^~~~~~~~~~~~~~~~ include/linux/swapops.h:448:9: note: in expansion of macro 'BUILD_BUG_ON' 448 | BUILD_BUG_ON(SWP_TYPE_SHIFT < SWP_PFN_BITS); | ^~~~~~~~~~~~ include/linux/swapops.h:448:22: note: in expansion of macro 'SWP_TYPE_SHIFT' 448 | BUILD_BUG_ON(SWP_TYPE_SHIFT < SWP_PFN_BITS); | ^~~~~~~~~~~~~~ include/linux/swapops.h: In function 'non_swap_entry': include/linux/swapops.h:491:35: error: 'MAX_SWAPFILES' undeclared (first use in this function); did you mean 'S_SWAPFILE'? 491 | return swp_type(entry) >= MAX_SWAPFILES; | ^~~~~~~~~~~~~ | S_SWAPFILE
include/linux/leafops.h: In function 'leafent_from_pmd':Quoted 1 line
Quoted 1 line
include/linux/leafops.h:111:22: error: implicit declaration of function '__pmd_to_swp_entry'; did you mean 'pte_to_swp_entry'? [-Wimplicit-function-declaration]111 | arch_entry = __pmd_to_swp_entry(pmd); | ^~~~~~~~~~~~~~~~~~ | pte_to_swp_entryQuoted 1 line
Quoted 1 line
include/linux/leafops.h:111:22: error: incompatible types when assigning to type 'leaf_entry_t' {aka 'swp_entry_t'} from type 'int'vim +111
include/linux/leafops.h90 91 /** 92 * leafent_from_pmd() - Obtain a leaf entry from a PMD entry. 93 * @pmd: PMD entry. 94 * 95 * If @pmd is present (therefore not a leaf entry) the function returns an empty 96 * leaf entry. Otherwise, it returns a leaf entry. 97 * 98 * Returns: Leaf entry. 99 */ 100 static inline leaf_entry_t leafent_from_pmd(pmd_t pmd) 101 { 102 leaf_entry_t arch_entry; 103 104 if (pmd_present(pmd)) 105 return leafent_mk_none(); 106 107 if (pmd_swp_soft_dirty(pmd)) 108 pmd = pmd_swp_clear_soft_dirty(pmd); 109 if (pmd_swp_uffd_wp(pmd)) 110 pmd = pmd_swp_clear_uffd_wp(pmd);Quoted 1 line
111
arch_entry=__pmd_to_swp_entry(pmd);112
113 /* Temporary untilswp_entry_teliminated. */114 return swp_entry(__swp_type(arch_entry), __swp_offset(arch_entry)); 115 } 116--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH 10/16] mm: replace pmd_to_swp_entry() with leafent_from_pmd()
In reply to Lorenzo Stoakeskernel test robot noticed the following build errors:
Hi Lorenzo,
kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Lorenzo-Stoakes/mm-correctly-handle-UFFD-PTE-markers/20251103-204118 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/38c26e75ed00263e9ecbebb0c045dd6d8183ec67.1762171281.git.lorenzo.stoakes%40oracle.com patch subject: [PATCH 10/16] mm: replace pmd_to_swp_entry() with leafent_from_pmd() config: x86_64-allnoconfig (https://download.01.org/0day-ci/archive/20251103/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251103/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from mm/folio-compat.c:7:
In file included from include/linux/migrate.h:9:
In file included from include/linux/leafops.h:6:
>> include/linux/swapops.h:90:21: error: use of undeclared identifier 'MAX_SWAPFILES_SHIFT'
90 | ret.val = (type << SWP_TYPE_SHIFT) | (offset & SWP_OFFSET_MASK);
| ^
include/linux/swapops.h:27:45: note: expanded from macro 'SWP_TYPE_SHIFT'
27 | #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
| ^
include/linux/swapops.h:90:49: error: use of undeclared identifier 'MAX_SWAPFILES_SHIFT'
90 | ret.val = (type << SWP_TYPE_SHIFT) | (offset & SWP_OFFSET_MASK);
| ^
include/linux/swapops.h:28:34: note: expanded from macro 'SWP_OFFSET_MASK'
28 | #define SWP_OFFSET_MASK ((1UL << SWP_TYPE_SHIFT) - 1)
| ^
include/linux/swapops.h:27:45: note: expanded from macro 'SWP_TYPE_SHIFT'
27 | #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
| ^
include/linux/swapops.h:100:23: error: use of undeclared identifier 'MAX_SWAPFILES_SHIFT'
100 | return (entry.val >> SWP_TYPE_SHIFT);
| ^
include/linux/swapops.h:27:45: note: expanded from macro 'SWP_TYPE_SHIFT'
27 | #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
| ^
include/linux/swapops.h:109:21: error: use of undeclared identifier 'MAX_SWAPFILES_SHIFT'
109 | return entry.val & SWP_OFFSET_MASK;
| ^
include/linux/swapops.h:28:34: note: expanded from macro 'SWP_OFFSET_MASK'
28 | #define SWP_OFFSET_MASK ((1UL << SWP_TYPE_SHIFT) - 1)
| ^
include/linux/swapops.h:27:45: note: expanded from macro 'SWP_TYPE_SHIFT'
27 | #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
| ^
>> include/linux/swapops.h:395:19: error: use of undeclared identifier 'SWP_PTE_MARKER'
395 | return swp_entry(SWP_PTE_MARKER, marker);
| ^
include/linux/swapops.h:448:15: error: use of undeclared identifier 'MAX_SWAPFILES_SHIFT'
448 | BUILD_BUG_ON(SWP_TYPE_SHIFT < SWP_PFN_BITS);
| ^
include/linux/swapops.h:27:45: note: expanded from macro 'SWP_TYPE_SHIFT'
27 | #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
| ^
include/linux/swapops.h:491:28: error: use of undeclared identifier 'MAX_SWAPFILES'
491 | return swp_type(entry) >= MAX_SWAPFILES;
| ^7 errors generated.
vim +/MAX_SWAPFILES_SHIFT +90 include/linux/swapops.h
099dd6878b9b12 Peter Xu 2021-06-15 82
^1da177e4c3f41 Linus Torvalds 2005-04-16 83 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 84 * Store a type+offset into a swp_entry_t in an arch-independent format
^1da177e4c3f41 Linus Torvalds 2005-04-16 85 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 86 static inline swp_entry_t swp_entry(unsigned long type, pgoff_t offset)
^1da177e4c3f41 Linus Torvalds 2005-04-16 87 {
^1da177e4c3f41 Linus Torvalds 2005-04-16 88 swp_entry_t ret;
^1da177e4c3f41 Linus Torvalds 2005-04-16 89
3159f943aafdba Matthew Wilcox 2017-11-03 @90 ret.val = (type << SWP_TYPE_SHIFT) | (offset & SWP_OFFSET_MASK);
^1da177e4c3f41 Linus Torvalds 2005-04-16 91 return ret;
^1da177e4c3f41 Linus Torvalds 2005-04-16 92 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 93
^1da177e4c3f41 Linus Torvalds 2005-04-16 94 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 95 * Extract the `type' field from a swp_entry_t. The swp_entry_t is in
^1da177e4c3f41 Linus Torvalds 2005-04-16 96 * arch-independent format
^1da177e4c3f41 Linus Torvalds 2005-04-16 97 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 98 static inline unsigned swp_type(swp_entry_t entry)
^1da177e4c3f41 Linus Torvalds 2005-04-16 99 {
3159f943aafdba Matthew Wilcox 2017-11-03 100 return (entry.val >> SWP_TYPE_SHIFT);
^1da177e4c3f41 Linus Torvalds 2005-04-16 101 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 102
^1da177e4c3f41 Linus Torvalds 2005-04-16 103 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 104 * Extract the `offset' field from a swp_entry_t. The swp_entry_t is in
^1da177e4c3f41 Linus Torvalds 2005-04-16 105 * arch-independent format
^1da177e4c3f41 Linus Torvalds 2005-04-16 106 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 107 static inline pgoff_t swp_offset(swp_entry_t entry)
^1da177e4c3f41 Linus Torvalds 2005-04-16 108 {3159f943aafdba Matthew Wilcox 2017-11-03 @109 return entry.val & SWP_OFFSET_MASK;
^1da177e4c3f41 Linus Torvalds 2005-04-16 110 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 111
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
In reply to Lorenzo StoakesHi Andrew,
The wonders of configs and include dependencies strikes again, could you apply this fix-patch to declare leaf_entry_t in mm_types.h so we avoid a later dependency issue in migrate.h?
Thanks, Lorenzo
----8<----
From 663deb7591f3ff5e14f42f09f89aa3c871c1cf29 Mon Sep 17 00:00:00 2001
From: Lorenzo Stoakes <[email protected]>
Date: Mon, 3 Nov 2025 17:23:52 +0000
Subject: [PATCH] fixpatch
--- include/linux/leafops.h | 17 ----------------- include/linux/mm_types.h | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-)
include/linux/leafops.h +0 -17
@@ -6,23 +6,6 @@#include <linux/swapops.h> #include <linux/swap.h> -/** -* leaf_entry_t - Describes a page table 'leaf entry'. -* -* Leaf entries are an abstract representation of all page table entries which -* are non-present. Therefore these describe: -* -* - None or 'empty' entries. -* -* - All other entries which cause page faults and therefore encode -* software-controlled metadata. -* -* NOTE: While we transition from the confusing swp_entry_t type used for this -* purpose, we simply alias this type. This will be removed once the -* transition is complete. -*/ -typedef swp_entry_t leaf_entry_t ; -#ifdef CONFIG_MMU /* Temporary until swp_entry_t eliminated. */
include/linux/mm_types.h +17 -0
@@ -285,6 +285,23 @@ typedef struct {unsigned long val; } swp_entry_t; +/** +* leaf_entry_t - Describes a page table 'leaf entry'. +* +* Leaf entries are an abstract representation of all page table entries which +* are non-present. Therefore these describe: +* +* - None or 'empty' entries. +* +* - All other entries which cause page faults and therefore encode +* software-controlled metadata. +* +* NOTE: While we transition from the confusing swp_entry_t type used for this +* purpose, we simply alias this type. This will be removed once the +* transition is complete. +*/ +typedef swp_entry_t leaf_entry_t ; +#if defined(CONFIG_MEMCG ) || defined(CONFIG_SLAB_OBJ_EXT )/* We have some extra room after the refcount in tail pages. */ #define NR_PAGES_IN_LARGE_FOLIO
--
2.51.0
Re: [PATCH 10/16] mm: replace pmd_to_swp_entry() with leafent_from_pmd()
In reply to Lorenzo StoakesHi Andrew,
Again header dependencies and configurations strike again, could you apply this fix-patch to resolve issues with allnoconfig + arches that disable e.g. CONFIG_SWAP? Thanks! :)
Cheers, Lorenzo
----8<----
From e68fa65fc278cf45a9e32a440eda07e1ca16895c Mon Sep 17 00:00:00 2001
From: Lorenzo Stoakes <[email protected]>
Date: Mon, 3 Nov 2025 17:08:07 +0000
Subject: [PATCH] fixpatch
--- include/linux/leafops.h | 10 ++++++++++ include/linux/migrate.h | 1 - 2 files changed, 10 insertions(+), 1 deletion(-)
include/linux/leafops.h +10 -0
@@ -71,6 +71,7 @@ static inline pte_t leafent_to_pte(leaf_entry_t entry)return swp_entry_to_pte (entry); } +#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION /** * leafent_from_pmd() - Obtain a leaf entry from a PMD entry. * @pmd: PMD entry.
@@ -97,6 +98,15 @@ static inline leaf_entry_t leafent_from_pmd(pmd_t pmd) return swp_entry(__swp_type(arch_entry), __swp_offset(arch_entry)); } +#else + +static inline leaf_entry_t leafent_from_pmd (pmd_t pmd) +{ +return leafent_mk_none (); +} + +#endif +/** * leafent_is_none() - Is the leaf entry empty? * @entry: Leaf entry.
include/linux/migrate.h +0 -1
@@ -6,7 +6,6 @@#include <linux/mempolicy.h> #include <linux/migrate_mode.h> #include <linux/hugetlb.h> -#include <linux/leafops.h> typedef struct folio *new_folio_t (struct folio *folio,unsigned long private);typedef void free_folio_t (struct folio *folio,unsigned long private);
--
2.51.0
kernel test robot
build botRe: [PATCH 10/16] mm: replace pmd_to_swp_entry() with leafent_from_pmd()
In reply to Lorenzo Stoakeskernel test robot noticed the following build warnings:
Hi Lorenzo,
kernel test robot noticed the following build warnings:
[auto build test WARNING on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Lorenzo-Stoakes/mm-correctly-handle-UFFD-PTE-markers/20251103-204118 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/38c26e75ed00263e9ecbebb0c045dd6d8183ec67.1762171281.git.lorenzo.stoakes%40oracle.com patch subject: [PATCH 10/16] mm: replace pmd_to_swp_entry() with leafent_from_pmd() config: sh-randconfig-001-20251104 (https://download.01.org/0day-ci/archive/20251104/[email protected]/config) compiler: sh4-linux-gcc (GCC) 13.4.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251104/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from include/linux/leafops.h:6,
from include/linux/migrate.h:9,
from mm/damon/ops-common.c:8:
include/linux/swapops.h: In function 'swp_entry':
include/linux/swapops.h:27:46: error: 'MAX_SWAPFILES_SHIFT' undeclared (first use in this function)
27 | #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
| ^~~~~~~~~~~~~~~~~~~
include/linux/swapops.h:90:28: note: in expansion of macro 'SWP_TYPE_SHIFT'
90 | ret.val = (type << SWP_TYPE_SHIFT) | (offset & SWP_OFFSET_MASK);
| ^~~~~~~~~~~~~~
include/linux/swapops.h:27:46: note: each undeclared identifier is reported only once for each function it appears in
27 | #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
| ^~~~~~~~~~~~~~~~~~~
include/linux/swapops.h:90:28: note: in expansion of macro 'SWP_TYPE_SHIFT'
90 | ret.val = (type << SWP_TYPE_SHIFT) | (offset & SWP_OFFSET_MASK);
| ^~~~~~~~~~~~~~
include/linux/swapops.h: In function 'swp_type':
include/linux/swapops.h:27:46: error: 'MAX_SWAPFILES_SHIFT' undeclared (first use in this function)
27 | #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
| ^~~~~~~~~~~~~~~~~~~
include/linux/swapops.h:100:30: note: in expansion of macro 'SWP_TYPE_SHIFT'
100 | return (entry.val >> SWP_TYPE_SHIFT);
| ^~~~~~~~~~~~~~
include/linux/swapops.h: In function 'swp_offset':
include/linux/swapops.h:27:46: error: 'MAX_SWAPFILES_SHIFT' undeclared (first use in this function)
27 | #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
| ^~~~~~~~~~~~~~~~~~~
include/linux/swapops.h:28:34: note: in expansion of macro 'SWP_TYPE_SHIFT'
28 | #define SWP_OFFSET_MASK ((1UL << SWP_TYPE_SHIFT) - 1)
| ^~~~~~~~~~~~~~
include/linux/swapops.h:109:28: note: in expansion of macro 'SWP_OFFSET_MASK'
109 | return entry.val & SWP_OFFSET_MASK;
| ^~~~~~~~~~~~~~~
include/linux/swapops.h: In function 'make_pte_marker_entry':
include/linux/swapops.h:395:26: error: 'SWP_PTE_MARKER' undeclared (first use in this function)
395 | return swp_entry(SWP_PTE_MARKER, marker);
| ^~~~~~~~~~~~~~
In file included from <command-line>:
include/linux/swapops.h: In function 'is_pfn_swap_entry':
include/linux/swapops.h:27:46: error: 'MAX_SWAPFILES_SHIFT' undeclared (first use in this function)
27 | #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT)
| ^~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:577:23: note: in definition of macro '__compiletime_assert'
577 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:597:9: note: in expansion of macro '_compiletime_assert'
597 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:50:9: note: in expansion of macro 'BUILD_BUG_ON_MSG'
50 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
| ^~~~~~~~~~~~~~~~
include/linux/swapops.h:448:9: note: in expansion of macro 'BUILD_BUG_ON'
448 | BUILD_BUG_ON(SWP_TYPE_SHIFT < SWP_PFN_BITS);
| ^~~~~~~~~~~~
include/linux/swapops.h:448:22: note: in expansion of macro 'SWP_TYPE_SHIFT'
448 | BUILD_BUG_ON(SWP_TYPE_SHIFT < SWP_PFN_BITS);
| ^~~~~~~~~~~~~~
include/linux/swapops.h: In function 'non_swap_entry':
include/linux/swapops.h:491:35: error: 'MAX_SWAPFILES' undeclared (first use in this function); did you mean 'S_SWAPFILE'?
491 | return swp_type(entry) >= MAX_SWAPFILES;
| ^~~~~~~~~~~~~
| S_SWAPFILE
include/linux/leafops.h: In function 'leafent_from_pmd':
include/linux/leafops.h:111:22: error: implicit declaration of function '__pmd_to_swp_entry'; did you mean 'pte_to_swp_entry'? [-Werror=implicit-function-declaration]
111 | arch_entry = __pmd_to_swp_entry(pmd);
| ^~~~~~~~~~~~~~~~~~
| pte_to_swp_entry
include/linux/leafops.h:111:22: error: incompatible types when assigning to type 'leaf_entry_t' {aka 'swp_entry_t'} from type 'int'
include/linux/swapops.h: In function 'swp_offset':
>> include/linux/swapops.h:110:1: warning: control reaches end of non-void function [-Wreturn-type]
110 | }
| ^cc1: some warnings being treated as errors
vim +110 include/linux/swapops.h
^1da177e4c3f41 Linus Torvalds 2005-04-16 102
^1da177e4c3f41 Linus Torvalds 2005-04-16 103 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 104 * Extract the `offset' field from a swp_entry_t. The swp_entry_t is in
^1da177e4c3f41 Linus Torvalds 2005-04-16 105 * arch-independent format
^1da177e4c3f41 Linus Torvalds 2005-04-16 106 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 107 static inline pgoff_t swp_offset(swp_entry_t entry)
^1da177e4c3f41 Linus Torvalds 2005-04-16 108 {
3159f943aafdba Matthew Wilcox 2017-11-03 109 return entry.val & SWP_OFFSET_MASK;^1da177e4c3f41 Linus Torvalds 2005-04-16 @110 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 111
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Andrew Morton
maintainerQuoted 7 lines · On Mon, 3 Nov 2025 12:31:41 +0000 Lorenzo Stoakes…
There's an established convention in the kernel that we treat leaf page tables (so far at the PTE, PMD level) as containing 'swap entries' should they be neither empty (i.e. p**_none() evaluating true) nor present (i.e. p**_present() evaluating true).
...
All queued up, along with two -fix patches, thanks.
I disabled the customary email spray.
kernel test robot
build botRe: [PATCH 13/16] mm: remove non_swap_entry() and use leaf entry helpers instead
In reply to Lorenzo Stoakeskernel test robot noticed the following build warnings:
Hi Lorenzo,
kernel test robot noticed the following build warnings:
[auto build test WARNING on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Lorenzo-Stoakes/mm-correctly-handle-UFFD-PTE-markers/20251103-204118 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/b4925aeaf6b7e8255b1cf1585476b718862b8104.1762171281.git.lorenzo.stoakes%40oracle.com patch subject: [PATCH 13/16] mm: remove non_swap_entry() and use leaf entry helpers instead config: s390-randconfig-r112-20251104 (https://download.01.org/0day-ci/archive/20251104/[email protected]/config) compiler: s390-linux-gcc (GCC) 12.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251104/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> arch/s390/mm/pgtable.c:693:47: sparse: sparse: incorrect type in argument 1 (different modifiers) @@ expected struct folio *folio @@ got struct folio const *folio @@
arch/s390/mm/pgtable.c:693:47: sparse: expected struct folio *folio
arch/s390/mm/pgtable.c:693:47: sparse: got struct folio const *folio
arch/s390/mm/pgtable.c:1098:9: sparse: sparse: context imbalance in 'pgste_perform_essa' - unexpected unlock arch/s390/mm/pgtable.c: note: in included file (through include/linux/pgtable.h, include/linux/mm.h):
arch/s390/include/asm/pgtable.h:2067:9: sparse: sparse: context imbalance in 'set_pgste_bits' - unexpected unlock arch/s390/mm/pgtable.c: note: in included file:
include/linux/mm.h:2832:9: sparse: sparse: context imbalance in 'get_pgste' - unexpected unlock
vim +693 arch/s390/mm/pgtable.c
4be130a08420d6 Martin Schwidefsky 2016-03-08 685
9c8ce56552b434 Lorenzo Stoakes 2025-11-03 686 static void ptep_zap_leaf_entry(struct mm_struct *mm, leaf_entry_t entry)
1e133ab296f3ff Martin Schwidefsky 2016-03-08 687 {
9c8ce56552b434 Lorenzo Stoakes 2025-11-03 688 if (leafent_is_swap(entry))
1e133ab296f3ff Martin Schwidefsky 2016-03-08 689 dec_mm_counter(mm, MM_SWAPENTS);
9c8ce56552b434 Lorenzo Stoakes 2025-11-03 690 else if (leafent_is_migration(entry)) {
9c8ce56552b434 Lorenzo Stoakes 2025-11-03 691 const struct folio *folio = leafent_to_folio(entry);
1e133ab296f3ff Martin Schwidefsky 2016-03-08 692
a23f517b0e1554 Kefeng Wang 2024-01-11 @693 dec_mm_counter(mm, mm_counter(folio));
1e133ab296f3ff Martin Schwidefsky 2016-03-08 694 }
1e133ab296f3ff Martin Schwidefsky 2016-03-08 695 free_swap_and_cache(entry);
1e133ab296f3ff Martin Schwidefsky 2016-03-08 696 }1e133ab296f3ff Martin Schwidefsky 2016-03-08 697
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH 13/16] mm: remove non_swap_entry() and use leaf entry helpers instead
Quoted 14 lines · kernel test robot
Hi Lorenzo,
kernel test robot noticed the following build warnings:
[auto build test WARNING on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Lorenzo-Stoakes/mm-correctly-handle-UFFD-PTE-markers/20251103-204118 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/b4925aeaf6b7e8255b1cf1585476b718862b8104.1762171281.git.lorenzo.stoakes%40oracle.com patch subject: [PATCH 13/16] mm: remove non_swap_entry() and use leaf entry helpers instead config: s390-randconfig-r112-20251104 (https://download.01.org/0day-ci/archive/20251104/[email protected]/config) compiler: s390-linux-gcc (GCC) 12.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251104/[email protected]/reproduce)
Quoted 7 lines
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/sparse warnings: (new ones prefixed by >>)
Quoted 1 line
Quoted 1 line
arch/s390/mm/pgtable.c:693:47: sparse: sparse: incorrect type in argument 1 (different modifiers) @@ expected struct folio *folio @@ got struct folio const *folio @@
OK over-zealous use of const here, will send fixpatch.
Re: [PATCH 13/16] mm: remove non_swap_entry() and use leaf entry helpers instead
In reply to Lorenzo StoakesHi Andrew,
One instance of over-zealous const usage in s390 here, could you apply the attached fix-patch please to fix?
Thanks!
----8<----
From 9745904b2ac48856cc97b33d54fd42764e8e3d4a Mon Sep 17 00:00:00 2001
From: Lorenzo Stoakes <[email protected]>
Date: Tue, 4 Nov 2025 06:16:03 +0000
Subject: [PATCH] fixpatch
--- arch/s390/mm/pgtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/mm/pgtable.c +1 -1
@@ -688,7 +688,7 @@ static void ptep_zap_leaf_entry(struct mm_struct *mm, leaf_entry_t entry)if (leafent_is_swap (entry))dec_mm_counter (mm,MM_SWAPENTS );else if (leafent_is_migration (entry)) { -const struct folio *folio =leafent_to_folio (entry); +struct folio *folio =leafent_to_folio (entry);dec_mm_counter (mm,mm_counter (folio)); }
--
2.51.0
Quoted 44 lines · Lorenzo Stoakes
There's an established convention in the kernel that we treat leaf page tables (so far at the PTE, PMD level) as containing 'swap entries' should they be neither empty (i.e. p**_none() evaluating true) nor present (i.e. p**_present() evaluating true).
However, at the same time we also have helper predicates -
is_swap_pte(),is_swap_pmd()- which are inconsistently used.This is problematic, as it is logical to assume that should somebody wish to operate upon a page table swap entry they should first check to see if it is in fact one.
It also implies that perhaps, in future, we might introduce a non-present, none page table entry that is not a swap entry.
This series resolves this issue by systematically eliminating all use of the
is_swap_pte()and isswap_pmd()predicates so we retain only the convention that should a leaf page table entry be neither none nor present it is a swap entry.We also have the further issue that 'swap entry' is unfortunately a really rather overloaded term and in fact refers to both entries for swap and for other information such as migration entries, page table markers, and device private entries.
We therefore have the rather 'unique' concept of a 'non-swap' swap entry.
This series therefore introduces the concept of 'leaf entries' to eliminate this confusion.
A leaf entry in this sense is any page table entry which is non-present, and represented by the
leaf_entry_ttype.This includes 'none' or empty entries, which are simply represented by an zero leaf entry value.
In order to maintain compatibility as we transition the kernel to this new type, we simply typedef
swp_entry_ttoleaf_entry_t.We introduce a number of predicates and helpers to interact with leaf entries in
include/linux/leafops.hwhich, as it importsswapops.h, can be treated as a drop-in replacement forswapops.hwherever leaf entry helpers are used.
Quoted 8 lines
Since leafent_from_[pte, pmd]() treats present entries as they were empty/none leaf entries, this allows for a great deal of simplification of code throughout the code base, which this series utilises a great deal.
We additionally change from swap entry to leaf entry handling where it makes sense to and eliminate functions from
swapops.hwhere leaf entries obviate the need for the functions.
Hi, Lorenzo
Thanks for the effort on cleanup this, which helps me clearing the confusing on checking swap entry.
Signature · 2 lines
Wei Yang Help you, Help me
Gregory Price
maintainerRe: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
In reply to Lorenzo StoakesQuoted 15 lines · Lorenzo Stoakes
include/linux/leafops.h new file +15
-0+typedef swp_entry_t leaf_entry_t ; + +#ifdef CONFIG_MMU + +/* Temporary until swp_entry_t eliminated. */ +#define LEAF_TYPE_SHIFT SWP_TYPE_SHIFT + +enum leaf_entry_type { +/* Fundamental types. */ +LEAFENT_NONE , +LEAFENT_SWAP , +/* Migration types. */ +LEAFENT_MIGRATION_READ , +LEAFENT_MIGRATION_READ_EXCLUSIVE , + LEAFENT_MIGRATION_WRITE,
include/linux/leafops.h line 48
Quoted 10 lines
include/linux/leafops.h new file +10
-0+/* Device types. */ +LEAFENT_DEVICE_PRIVATE_READ , +LEAFENT_DEVICE_PRIVATE_WRITE , +LEAFENT_DEVICE_EXCLUSIVE , +/* H/W posion types. */ +LEAFENT_HWPOISON , +/* Marker types. */ + LEAFENT_MARKER, +}; +
Have been browsing the patch set again, will get around a deeper review, but just wanted to say this is a thing of beauty :]
~Gregory
Re: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
Quoted 21 lines · Gregory Price
Quoted 20 lines · Lorenzo Stoakes
include/linux/leafops.h new file +20
-0+typedef swp_entry_t leaf_entry_t ; + +#ifdef CONFIG_MMU + +/* Temporary until swp_entry_t eliminated. */ +#define LEAF_TYPE_SHIFT SWP_TYPE_SHIFT + +enum leaf_entry_type { +/* Fundamental types. */ +LEAFENT_NONE , +LEAFENT_SWAP , +/* Migration types. */ +LEAFENT_MIGRATION_READ , +LEAFENT_MIGRATION_READ_EXCLUSIVE , +LEAFENT_MIGRATION_WRITE , +/* Device types. */ +LEAFENT_DEVICE_PRIVATE_READ , +LEAFENT_DEVICE_PRIVATE_WRITE , +LEAFENT_DEVICE_EXCLUSIVE , + /* H/W posion types. */
Quoted 8 lines
include/linux/leafops.h line 48
Quoted 5 lines
include/linux/leafops.h new file +5
-0+LEAFENT_HWPOISON , +/* Marker types. */ + LEAFENT_MARKER, +}; +Have been browsing the patch set again, will get around a deeper review, but just wanted to say this is a thing of beauty :]
+1 I thought the same thing. So much clearer what is going on here, and I didn't realize we had so many types already..
Jason
Re: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
Quoted 31 lines · Jason Gunthorpe
Quoted 21 lines · Gregory Price
Quoted 20 lines · Lorenzo Stoakes
include/linux/leafops.h new file +20
-0+typedef swp_entry_t leaf_entry_t ; + +#ifdef CONFIG_MMU + +/* Temporary until swp_entry_t eliminated. */ +#define LEAF_TYPE_SHIFT SWP_TYPE_SHIFT + +enum leaf_entry_type { +/* Fundamental types. */ +LEAFENT_NONE , +LEAFENT_SWAP , +/* Migration types. */ +LEAFENT_MIGRATION_READ , +LEAFENT_MIGRATION_READ_EXCLUSIVE , +LEAFENT_MIGRATION_WRITE , +/* Device types. */ +LEAFENT_DEVICE_PRIVATE_READ , +LEAFENT_DEVICE_PRIVATE_WRITE , +LEAFENT_DEVICE_EXCLUSIVE , + /* H/W posion types. */Quoted 8 lines
include/linux/leafops.h line 48
Quoted 5 lines
include/linux/leafops.h new file +5
-0+LEAFENT_HWPOISON , +/* Marker types. */ + LEAFENT_MARKER, +}; +Have been browsing the patch set again, will get around a deeper review, but just wanted to say this is a thing of beauty :]
Quoted 4 lines
+1 I thought the same thing. So much clearer what is going on here, and I didn't realize we had so many types already..
Jason
Thank you both guys much appreciated :)
Obviously heavily influenced by your great feedback, but I really did try to build it in a way that tried to simplify as much as possible.
Cheers, Lorenzo
Quoted 54 lines · Wei Yang
Quoted 44 lines · Lorenzo Stoakes
There's an established convention in the kernel that we treat leaf page tables (so far at the PTE, PMD level) as containing 'swap entries' should they be neither empty (i.e. p**_none() evaluating true) nor present (i.e. p**_present() evaluating true).
However, at the same time we also have helper predicates -
is_swap_pte(),is_swap_pmd()- which are inconsistently used.This is problematic, as it is logical to assume that should somebody wish to operate upon a page table swap entry they should first check to see if it is in fact one.
It also implies that perhaps, in future, we might introduce a non-present, none page table entry that is not a swap entry.
This series resolves this issue by systematically eliminating all use of the
is_swap_pte()and isswap_pmd()predicates so we retain only the convention that should a leaf page table entry be neither none nor present it is a swap entry.We also have the further issue that 'swap entry' is unfortunately a really rather overloaded term and in fact refers to both entries for swap and for other information such as migration entries, page table markers, and device private entries.
We therefore have the rather 'unique' concept of a 'non-swap' swap entry.
This series therefore introduces the concept of 'leaf entries' to eliminate this confusion.
A leaf entry in this sense is any page table entry which is non-present, and represented by the
leaf_entry_ttype.This includes 'none' or empty entries, which are simply represented by an zero leaf entry value.
In order to maintain compatibility as we transition the kernel to this new type, we simply typedef
swp_entry_ttoleaf_entry_t.We introduce a number of predicates and helpers to interact with leaf entries in
include/linux/leafops.hwhich, as it importsswapops.h, can be treated as a drop-in replacement forswapops.hwherever leaf entry helpers are used.Quoted 8 lines
Since leafent_from_[pte, pmd]() treats present entries as they were empty/none leaf entries, this allows for a great deal of simplification of code throughout the code base, which this series utilises a great deal.
We additionally change from swap entry to leaf entry handling where it makes sense to and eliminate functions from
swapops.hwhere leaf entries obviate the need for the functions.
Quoted 4 lines
Hi, Lorenzo
Thanks for the effort on cleanup this, which helps me clearing the confusing on checking swap entry.
Thank you :) much appreciated!
Hope it's useful, my ultimate initial aim was to address my own confusion and frustration (stemming out of a debate about use of the is_swap_pte() predicate on a review), I'm glad that via review and also thinking 'hmm we should address this also' etc. this his developed into something that hopefully makes life easier for everybody!
Quoted 5 lines
--
Wei Yang
Help you, Help me
Cheers, Lorenzo
Re: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
In reply to Lorenzo StoakesQuoted 2 lines · Lorenzo Stoakes
Obviously heavily influenced by your great feedback, but I really did try to build it in a way that tried to simplify as much as possible.
My main remark, and it is not something you should necessarily do anything about, but pte_none() can be given a consistent name too:
leafent_is_none_pte(pte)
Which is definted to be identical to:
leafent_is_none(leafent_from_pte(pte))
But presumably faster.
Jason
Re: [PATCH 01/16] mm: correctly handle UFFD PTE markers
In reply to Lorenzo StoakesQuoted 23 lines · Lorenzo Stoakes
PTE markers were previously only concerned with UFFD-specific logic - that is, PTE entries with the UFFD WP marker set or those marked via
UFFDIO_POISON.However since the introduction of guard markers in commit
7c53dfbdb024("mm: addPTE_MARKER_GUARDPTE marker"), this has no longer been the case.Issues have been avoided as guard regions are not permitted in conjunction with UFFD, but it still leaves very confusing logic in place, most notably the misleading and poorly named
pte_none_mostly()andhuge_pte_none_mostly().This predicate returns true for PTE entries that ought to be treated as none, but only in certain circumstances, and on the assumption we are dealing with H/W poison markers or UFFD WP markers.
This patch removes these functions and makes each invocation of these functions instead explicitly check what it needs to check.
As part of this effort it introduces
is_uffd_pte_marker()to explicitly determine if a marker in fact is used as part of UFFD or not.
Quoted 8 lines
In the HMM logic we note that the only time we would need to check for a fault is in the case of a UFFD WP marker, otherwise we simply encounter a fault error (
VM_FAULT_HWPOISONfor H/W poisoned marker,VM_FAULT_SIGSEGVfor a guard marker), so only check for the UFFD WP case.While we're here we also refactor code to make it easier to understand.
Signed-off-by Lorenzo Stoakes <[email protected]>
Nice cleanup!
Matthew Wilcox
maintainerRe: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
In reply to Lorenzo StoakesQuoted 5 lines · Lorenzo Stoakes
The kernel maintains leaf page table entries which contain either:
- Nothing ('none' entries)
- Present entries (that is stuff the hardware can navigate without fault)
- Everything else that will cause a fault which the kernel handles
The problem is that we're already using 'pmd leaf entries' to mean "this is a pointer to a PMD entry rather than a table of PTEs". So I think we need a new name. A boring name would be 'swent' (software entry). An acronym would be SWE. In the XArray I distinguish between pointer entries and value entries -- would calling them value entries work here? Or we could call them something entirely different. Say 'twig'. Or 'cask'.
Gregory Price
maintainerRe: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
Quoted 9 lines · Matthew Wilcox
Quoted 5 lines · Lorenzo Stoakes
The kernel maintains leaf page table entries which contain either:
- Nothing ('none' entries)
- Present entries (that is stuff the hardware can navigate without fault)
- Everything else that will cause a fault which the kernel handlesThe problem is that we're already using 'pmd leaf entries' to mean "this is a pointer to a PMD entry rather than a table of PTEs".
Having not looked at the implications of this for leafent_t prototypes
...
Can't this be solved by just adding a leafent type "Pointer" which implies there's exactly one leaf-ent type which won't cause faults?
is_present() => (table_ptr || leafent_ptr)else(): => !leafent_ptr
if is_none()
do the none-thing
if is_present()
if is_leafent(ent) (== is_leafent_ptr)
do the pointer thing
else
do the table thingelse()
type = leafent_type(ent) switch(type)
do the software things
can't be a present entry (see above)
A leaf is a leaf :shrug:
~Gregory
Re: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
Quoted 33 lines · Gregory Price
Quoted 9 lines · Matthew Wilcox
Quoted 5 lines · Lorenzo Stoakes
The kernel maintains leaf page table entries which contain either:
- Nothing ('none' entries)
- Present entries (that is stuff the hardware can navigate without fault)
- Everything else that will cause a fault which the kernel handlesThe problem is that we're already using 'pmd leaf entries' to mean "this is a pointer to a PMD entry rather than a table of PTEs".
Having not looked at the implications of this for
leafent_tprototypes
...
Can't this be solved by just adding a leafent type "Pointer" which implies there's exactly one leaf-ent type which won't cause faults?
is_present()=> (table_ptr||leafent_ptr)else(): => !leafent_ptrif
is_none()
do the none-thing
ifis_present()
ifis_leafent(ent)(==is_leafent_ptr)
do the pointer thing
else
do the table thingelse()
type =leafent_type(ent)switch(type)
do the software things
can't be a present entry (see above)
Quoted 3 lines
A leaf is a leaf :shrug:
~Gregory
I thought about doing this but it doesn't really work as the type is _abstracted_ from the architecture-specific value, _and_ we use what is currently the swp_type field to identify what this is.
So we would lose the architecture-specific information that any 'hardware leaf' entry would require and not be able to reliably identify it without losing bits.
Trying to preserve the value _and_ correctly identify it as a present entry would be difficult.
And I _really_ didn't want to go on a deep dive through all the architectures to see if we could encode it differently to allow for this.
Rather I think it's better to differentiate between s/w + h/w leaf entries.
Cheers, Lorenzo
Re: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
In reply to Jason GunthorpeQuoted 10 lines · Jason Gunthorpe
Quoted 2 lines · Lorenzo Stoakes
Obviously heavily influenced by your great feedback, but I really did try to build it in a way that tried to simplify as much as possible.
My main remark, and it is not something you should necessarily do anything about, but
pte_none()can be given a consistent name too:
leafent_is_none_pte(pte)
Quoted 7 lines
Which is definted to be identical to:
leafent_is_none(leafent_from_pte(pte))
But presumably faster.
Jason
Hm one nitpicky thing with this is I have tended to use pte_ or pmd_ prefixes for pte/pmd _tests_, as leafent_xxx() ultimately either deals with leaf entries or results in a leaf entry.
I do get the desire to get away from the pte_none() stuff though :) The fact we wrap up none entries in to leaf entries goes a long way towards this in any case I think! :)
Cheers, Lorenzo
Re: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
In reply to Matthew WilcoxQuoted 7 lines · Matthew Wilcox
Quoted 5 lines · Lorenzo Stoakes
The kernel maintains leaf page table entries which contain either:
- Nothing ('none' entries)
- Present entries (that is stuff the hardware can navigate without fault)
- Everything else that will cause a fault which the kernel handles
Quoted 8 lines
The problem is that we're already using 'pmd leaf entries' to mean "this is a pointer to a PMD entry rather than a table of PTEs". So I think we need a new name. A boring name would be 'swent' (software entry). An acronym would be SWE. In the XArray I distinguish between pointer entries and value entries -- would calling them value entries work here? Or we could call them something entirely different. Say 'twig'. Or 'cask'.
Yeah as discussed off-list I do concede 'leaf entry' is overloaded vs. hardware leaf entries, I just found the idea of sw_leaf_entry_t a bit gross and unclear.
Of course we now add a new ambiguity with this as really we do mean software leaf entry.
How about:
soft_leaf_t
softleaf_xxx()
?
Cheers, Lorenzo
Re: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
In reply to Lorenzo StoakesQuoted 45 lines · Lorenzo Stoakes
Quoted 33 lines · Gregory Price
Quoted 9 lines · Matthew Wilcox
Quoted 5 lines · Lorenzo Stoakes
The kernel maintains leaf page table entries which contain either:
- Nothing ('none' entries)
- Present entries (that is stuff the hardware can navigate without fault)
- Everything else that will cause a fault which the kernel handlesThe problem is that we're already using 'pmd leaf entries' to mean "this is a pointer to a PMD entry rather than a table of PTEs".
Having not looked at the implications of this for
leafent_tprototypes
...
Can't this be solved by just adding a leafent type "Pointer" which implies there's exactly one leaf-ent type which won't cause faults?
is_present()=> (table_ptr||leafent_ptr)else(): => !leafent_ptrif
is_none()
do the none-thing
ifis_present()
ifis_leafent(ent)(==is_leafent_ptr)
do the pointer thing
else
do the table thingelse()
type =leafent_type(ent)switch(type)
do the software things
can't be a present entry (see above)Quoted 3 lines
A leaf is a leaf :shrug:
~Gregory
I thought about doing this but it doesn't really work as the type is _abstracted_ from the architecture-specific value, _and_ we use what is currently the
swp_typefield to identify what this is.So we would lose the architecture-specific information that any 'hardware leaf' entry would require and not be able to reliably identify it without losing bits.
Quoted 7 lines
Trying to preserve the value _and_ correctly identify it as a present entry would be difficult.
And I _really_ didn't want to go on a deep dive through all the architectures to see if we could encode it differently to allow for this.
Rather I think it's better to differentiate between s/w + h/w leaf entries.
(Being rather silent because I'm busy with all kinds of other stuff)
I agree :)
As Willy said, something that spells out "sw leaf" would be nice.
Signature · 3 lines
Cheers David
Gregory Price
maintainerRe: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
In reply to Lorenzo StoakesQuoted 9 lines · Lorenzo Stoakes
Quoted 1 line · Gregory Price
On Wed, Nov 05, 2025 at 07:06:11PM +0000, Matthew Wilcox wrote:
I thought about doing this but it doesn't really work as the type is _abstracted_ from the architecture-specific value, _and_ we use what is currently the
swp_typefield to identify what this is.So we would lose the architecture-specific information that any 'hardware leaf' entry would require and not be able to reliably identify it without losing bits.
Quoted 8 lines
Trying to preserve the value _and_ correctly identify it as a present entry would be difficult.
And I _really_ didn't want to go on a deep dive through all the architectures to see if we could encode it differently to allow for this.
Rather I think it's better to differentiate between s/w + h/w leaf entries.
Reasonable - names are hard, but just about anything will be better than swp_entry.
SWE / sw_entry seems perfectly reasonable.
~Gregory
Re: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
Quoted 16 lines · Gregory Price
Quoted 15 lines · Lorenzo Stoakes
Quoted 1 line · Gregory Price
On Wed, Nov 05, 2025 at 07:06:11PM +0000, Matthew Wilcox wrote:
I thought about doing this but it doesn't really work as the type is _abstracted_ from the architecture-specific value, _and_ we use what is currently the
swp_typefield to identify what this is.So we would lose the architecture-specific information that any 'hardware leaf' entry would require and not be able to reliably identify it without losing bits.
Trying to preserve the value _and_ correctly identify it as a present entry would be difficult.
And I _really_ didn't want to go on a deep dive through all the architectures to see if we could encode it differently to allow for this.
Quoted 6 lines
Quoted 2 lines
Rather I think it's better to differentiate between s/w + h/w leaf entries.
Reasonable - names are hard, but just about anything will be better than
swp_entry.SWE /
sw_entryseems perfectly reasonable.
I'm not a lover of 'sw' in there it's just... eye-stabby. Is that a word?
I am quite fond of my suggested soft_leaf_t, softleaf_xxx()
'Soft leaf' breezing in the wind... quite poignant no? :)
But also embodies both the leaf entry and the fact it's software, coins a new term which is easy to figure out and of course the comment will describe what it means, and doesn't cause eye fatigue? :)
Yes naming is subjective and hard, as always :P
Quoted 3 lines
~Gregory
Cheers, Lorenzo
Re: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
Quoted 20 lines · Lorenzo Stoakes
Quoted 19 lines · Gregory Price
Quoted 17 lines · Lorenzo Stoakes
Quoted 1 line · Gregory Price
On Wed, Nov 05, 2025 at 07:06:11PM +0000, Matthew Wilcox wrote:
I thought about doing this but it doesn't really work as the type is _abstracted_ from the architecture-specific value, _and_ we use what is currently the
swp_typefield to identify what this is.So we would lose the architecture-specific information that any 'hardware leaf' entry would require and not be able to reliably identify it without losing bits.
Trying to preserve the value _and_ correctly identify it as a present entry would be difficult.
And I _really_ didn't want to go on a deep dive through all the architectures to see if we could encode it differently to allow for this.
Rather I think it's better to differentiate between s/w + h/w leaf entries.
Quoted 7 lines
Quoted 3 lines
Reasonable - names are hard, but just about anything will be better than
swp_entry.SWE /
sw_entryseems perfectly reasonable.I'm not a lover of 'sw' in there it's just... eye-stabby. Is that a word?
I am quite fond of my suggested
soft_leaf_t,softleaf_xxx()
We do have soft_dirty.
It will get interesting with pte_swp_soft_dirty() :)
ptw_softlead_soft_dirty() Well, at least I would understand it.
Re: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
Quoted 25 lines · David Hildenbrand (Red Hat)
Quoted 24 lines · Lorenzo Stoakes
Quoted 22 lines · Gregory Price
Quoted 9 lines · Lorenzo Stoakes
Quoted 1 line · Gregory Price
On Wed, Nov 05, 2025 at 07:06:11PM +0000, Matthew Wilcox wrote:
I thought about doing this but it doesn't really work as the type is _abstracted_ from the architecture-specific value, _and_ we use what is currently the
swp_typefield to identify what this is.So we would lose the architecture-specific information that any 'hardware leaf' entry would require and not be able to reliably identify it without losing bits.
Quoted 8 lines
Trying to preserve the value _and_ correctly identify it as a present entry would be difficult.
And I _really_ didn't want to go on a deep dive through all the architectures to see if we could encode it differently to allow for this.
Rather I think it's better to differentiate between s/w + h/w leaf entries.
Reasonable - names are hard, but just about anything will be better than
swp_entry.SWE /
sw_entryseems perfectly reasonable.
Quoted 7 lines
Quoted 3 lines
I'm not a lover of 'sw' in there it's just... eye-stabby. Is that a word?
I am quite fond of my suggested
soft_leaf_t,softleaf_xxx()We do have
soft_dirty.It will get interesting with
pte_swp_soft_dirty():)
Hmm but that's literally a swap entry, and is used against an actual PTE entry not an abstracted s/w leaf entry so I doubt that'd require renaming on any level.
Quoted 2 lines
ptw_softlead_soft_dirty()Well, at least I would understand it.
Yeah the naming would never be pte_softleaf_soft_dirty() anyway.
If it was to exist in softleaf terms it'd be softleaf_is_soft_dirty() which would be a lot clearer.
The PTE-specific functions implemented in leafops.h are prefixed pte_xxx() simply :)
(Other than e.g. softleaf_from_pte() or softleaf_from_pmd()).
I think you could find issues with any name, I maintain softleaf is a good compromise while remaining readable. :)
Cheers, Lorenzo
Re: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
Quoted 30 lines · Lorenzo Stoakes
Quoted 29 lines · David Hildenbrand (Red Hat)
Quoted 27 lines · Lorenzo Stoakes
Quoted 16 lines · Gregory Price
Quoted 15 lines · Lorenzo Stoakes
Quoted 1 line · Gregory Price
On Wed, Nov 05, 2025 at 07:06:11PM +0000, Matthew Wilcox wrote:
I thought about doing this but it doesn't really work as the type is _abstracted_ from the architecture-specific value, _and_ we use what is currently the
swp_typefield to identify what this is.So we would lose the architecture-specific information that any 'hardware leaf' entry would require and not be able to reliably identify it without losing bits.
Trying to preserve the value _and_ correctly identify it as a present entry would be difficult.
And I _really_ didn't want to go on a deep dive through all the architectures to see if we could encode it differently to allow for this.
Quoted 6 lines
Quoted 2 lines
Rather I think it's better to differentiate between s/w + h/w leaf entries.
Reasonable - names are hard, but just about anything will be better than
swp_entry.SWE /
sw_entryseems perfectly reasonable.I'm not a lover of 'sw' in there it's just... eye-stabby. Is that a word?
I am quite fond of my suggested
soft_leaf_t,softleaf_xxx()
Quoted 7 lines
Quoted 3 lines
We do have
soft_dirty.It will get interesting with
pte_swp_soft_dirty():)Hmm but that's literally a swap entry, and is used against an actual PTE entry not an abstracted s/w leaf entry so I doubt that'd require renaming on any level.
It's used on migration entries as well. Just like pte_swp_uffd_wp().
So, it's ... tricky :)
But maybe I am missing your point (my brain is exhausted from uffd code)
Re: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
Quoted 39 lines · David Hildenbrand (Red Hat)
Quoted 30 lines · Lorenzo Stoakes
Quoted 29 lines · David Hildenbrand (Red Hat)
Quoted 27 lines · Lorenzo Stoakes
Quoted 16 lines · Gregory Price
Quoted 15 lines · Lorenzo Stoakes
Quoted 1 line · Gregory Price
On Wed, Nov 05, 2025 at 07:06:11PM +0000, Matthew Wilcox wrote:
I thought about doing this but it doesn't really work as the type is _abstracted_ from the architecture-specific value, _and_ we use what is currently the
swp_typefield to identify what this is.So we would lose the architecture-specific information that any 'hardware leaf' entry would require and not be able to reliably identify it without losing bits.
Trying to preserve the value _and_ correctly identify it as a present entry would be difficult.
And I _really_ didn't want to go on a deep dive through all the architectures to see if we could encode it differently to allow for this.
Quoted 6 lines
Quoted 2 lines
Rather I think it's better to differentiate between s/w + h/w leaf entries.
Reasonable - names are hard, but just about anything will be better than
swp_entry.SWE /
sw_entryseems perfectly reasonable.I'm not a lover of 'sw' in there it's just... eye-stabby. Is that a word?
I am quite fond of my suggested
soft_leaf_t,softleaf_xxx()Quoted 7 lines
Quoted 3 lines
We do have
soft_dirty.It will get interesting with
pte_swp_soft_dirty():)Hmm but that's literally a swap entry, and is used against an actual PTE entry not an abstracted s/w leaf entry so I doubt that'd require renaming on any level.
Quoted 5 lines
It's used on migration entries as well. Just like
pte_swp_uffd_wp().So, it's ... tricky :)
But maybe I am missing your point (my brain is exhausted from uffd code)
We'd either not rename it or rename it to something like pte_is_uffd_wp(). So it's not even so relevant.
We'd probably call that something like pte_is_soft_dirty() in the soft dirty case. The 'swp' part of that is pretty redundant.
If people were insistent on having softleaf in there we could call it pte_softleaf_is_soft_dirty() which isn't qutie so bad. But I'd not want to put softleaf in there anyway.
sw_entry or sw_leaf or sw_leaf_entry would all have the same weirdness.
I want it to be something that is readable + not hideous to look at but still clear as to what it's referring too. Softleaf covers all of that off... :)
Re: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
Quoted 40 lines · Lorenzo Stoakes
Quoted 39 lines · David Hildenbrand (Red Hat)
Quoted 37 lines · Lorenzo Stoakes
Quoted 25 lines · David Hildenbrand (Red Hat)
Quoted 24 lines · Lorenzo Stoakes
Quoted 22 lines · Gregory Price
Quoted 9 lines · Lorenzo Stoakes
Quoted 1 line · Gregory Price
On Wed, Nov 05, 2025 at 07:06:11PM +0000, Matthew Wilcox wrote:
I thought about doing this but it doesn't really work as the type is _abstracted_ from the architecture-specific value, _and_ we use what is currently the
swp_typefield to identify what this is.So we would lose the architecture-specific information that any 'hardware leaf' entry would require and not be able to reliably identify it without losing bits.
Quoted 8 lines
Trying to preserve the value _and_ correctly identify it as a present entry would be difficult.
And I _really_ didn't want to go on a deep dive through all the architectures to see if we could encode it differently to allow for this.
Rather I think it's better to differentiate between s/w + h/w leaf entries.
Reasonable - names are hard, but just about anything will be better than
swp_entry.SWE /
sw_entryseems perfectly reasonable.Quoted 7 lines
Quoted 3 lines
I'm not a lover of 'sw' in there it's just... eye-stabby. Is that a word?
I am quite fond of my suggested
soft_leaf_t,softleaf_xxx()We do have
soft_dirty.It will get interesting with
pte_swp_soft_dirty():)Hmm but that's literally a swap entry, and is used against an actual PTE entry not an abstracted s/w leaf entry so I doubt that'd require renaming on any level.
Quoted 8 lines
Quoted 5 lines
It's used on migration entries as well. Just like
pte_swp_uffd_wp().So, it's ... tricky :)
But maybe I am missing your point (my brain is exhausted from uffd code)
We'd either not rename it or rename it to something like
pte_is_uffd_wp(). So it's not even so relevant.
We do have pte_uffd_wp() for present ptes.
Quoted 3 lines
We'd probably call that something like
pte_is_soft_dirty()in the soft dirty case. The 'swp' part of that is pretty redundant.
We do have pte_soft_dirty() for present ptes.
So we'd need some indication that these are for softleaf entries (where the bit positions will differ).
Quoted 9 lines
If people were insistent on having softleaf in there we could call it
pte_softleaf_is_soft_dirty()which isn't qutie so bad. But I'd not want to put softleaf in there anyway.
sw_entryorsw_leaforsw_leaf_entrywould all have the same weirdness.I want it to be something that is readable + not hideous to look at but still clear as to what it's referring too. Softleaf covers all of that off... :)
I think you misunderstood me: I have nothing against softleaf, I was rather saying that we already use the "soft" terminology elsewhere (soft_dirt), so it's not too crazy.
Re: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
Quoted 43 lines · David Hildenbrand (Red Hat)
Quoted 42 lines · Lorenzo Stoakes
Quoted 41 lines · David Hildenbrand (Red Hat)
Quoted 30 lines · Lorenzo Stoakes
Quoted 29 lines · David Hildenbrand (Red Hat)
Quoted 27 lines · Lorenzo Stoakes
Quoted 16 lines · Gregory Price
Quoted 15 lines · Lorenzo Stoakes
Quoted 1 line · Gregory Price
On Wed, Nov 05, 2025 at 07:06:11PM +0000, Matthew Wilcox wrote:
I thought about doing this but it doesn't really work as the type is _abstracted_ from the architecture-specific value, _and_ we use what is currently the
swp_typefield to identify what this is.So we would lose the architecture-specific information that any 'hardware leaf' entry would require and not be able to reliably identify it without losing bits.
Trying to preserve the value _and_ correctly identify it as a present entry would be difficult.
And I _really_ didn't want to go on a deep dive through all the architectures to see if we could encode it differently to allow for this.
Quoted 6 lines
Quoted 2 lines
Rather I think it's better to differentiate between s/w + h/w leaf entries.
Reasonable - names are hard, but just about anything will be better than
swp_entry.SWE /
sw_entryseems perfectly reasonable.I'm not a lover of 'sw' in there it's just... eye-stabby. Is that a word?
I am quite fond of my suggested
soft_leaf_t,softleaf_xxx()Quoted 7 lines
Quoted 3 lines
We do have
soft_dirty.It will get interesting with
pte_swp_soft_dirty():)Hmm but that's literally a swap entry, and is used against an actual PTE entry not an abstracted s/w leaf entry so I doubt that'd require renaming on any level.
It's used on migration entries as well. Just like
pte_swp_uffd_wp().
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
So, it's ... tricky :)
But maybe I am missing your point (my brain is exhausted from uffd code)
We'd either not rename it or rename it to something like
pte_is_uffd_wp(). So it's not even so relevant.We do have
pte_uffd_wp()for present ptes.
Of course we do :) fun.
I mean we can always invert it with pte_is_present_uffd_wp() or something.
Quoted 15 lines
Quoted 4 lines
We'd probably call that something like
pte_is_soft_dirty()in the soft dirty case. The 'swp' part of that is pretty redundant.We do have
pte_soft_dirty()for present ptes.So we'd need some indication that these are for softleaf entries (where the bit positions will differ).
Quoted 5 lines
If people were insistent on having softleaf in there we could call it
pte_softleaf_is_soft_dirty()which isn't qutie so bad. But I'd not want to put softleaf in there anyway.
Quoted 9 lines
Quoted 4 lines
sw_entryorsw_leaforsw_leaf_entrywould all have the same weirdness.I want it to be something that is readable + not hideous to look at but still clear as to what it's referring too. Softleaf covers all of that off... :)
I think you misunderstood me: I have nothing against softleaf, I was rather saying that we already use the "soft" terminology elsewhere (
soft_dirt), so it's not too crazy.
OK we can fix this mess in a number of ways, and mitigate any weird naming I think.
For instance, we could invert and reference hardware in the non-softleaf case, or we could have a function that detects whether present or not, or find a way to not reference softleaf, or just live with pte_is_softleaf_soft_dirty() (really not that bad, given softleaf is one word etc.)
Given these are niche cases I don't think it's a big issue.
Any reference to software will cause a possible slightly weird sounding name wrt soft-dirty, but it's right to reference software as that's the key difference between these leaf entries and present ones.
So yeah I think we're still good to go :)
Cheers, Lorenzo