Re: [PATCH v2 2/6] mm/pgtable: Fix bogus comment to clear_not_present_full_ptes()

David Hildenbrand (Arm)
2026-04-16T07:58:56Z

On 4/15/26 17:01, Alexander Gordeev wrote:
> The address provided to clear_not_present_full_ptes() is the
> address of the underlying memory, not address of the first PTE.
> The exact wording is taken from clear_ptes() comment.
>
> Suggested-by: Kevin Brodsky <kevin.brodsky@arm.com>
> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
> ---
> include/linux/pgtable.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> index 9ff7b78d65b1..2b82a71f13d7 100644
> --- a/include/linux/pgtable.h
> +++ b/include/linux/pgtable.h
> @@ -1021,8 +1021,8 @@ static inline void pte_clear_not_present_full(struct mm_struct *mm,
> /**
> * clear_not_present_full_ptes - Clear multiple not present PTEs which are
> * consecutive in the pgtable.
> - * @mm: Address space the ptes represent.
> - * @addr: Address of the first pte.
> + * @mm: Address space the pages are mapped into.
> + * @addr: Address the first page is mapped at.

Talking about pages with non-present entries does not make sense. So both changes
are wrong. Can you find something better and send that out separately?
I don't think this is required for your series, right?

Also, looking at it, it does not make sense to specify "full" when there is nothing
to flush. We are dealing with non-present PTEs after all.

Looking into the sparc variant of pte_clear_not_present_full(), it does

__set_pte_at((mm), (addr), (ptep), __pte(0UL), (fullmm))

and that does

pte_t orig = *ptep;

*ptep = pte;
maybe_tlb_batch_add(mm, addr, ptep, orig, fullmm, PAGE_SHIFT);

but in maybe_tlb_batch_add we have

if (likely(mm != &init_mm) && pte_accessible(mm, orig))
tlb_batch_add(mm, vaddr, ptep, orig, fullmm, hugepage_shift);

And as the pte is non-present, the pte is certainly not accessible. fullmm
is unused on that path.

All the talk about flushing TLBs about something that is non-present for
pte_clear_not_present_full looks weird.

@Ryan, you added clear_not_present_full_ptes() back then, but you were simply
reusing pte_clear_not_present_full(). Does below seem reasonable to you?

From 0899495ba8ecc73273450e58737bc458976dfa12 Mon Sep 17 00:00:00 2001
From: "David Hildenbrand (Arm)" <david@kernel.org>
Date: Thu, 16 Apr 2026 09:51:07 +0200
Subject: [PATCH] tmp

Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
arch/sparc/include/asm/pgtable_64.h | 4 ----
include/linux/pgtable.h | 28 +++++-----------------------
mm/madvise.c | 6 +++---
mm/memory.c | 2 +-
4 files changed, 9 insertions(+), 31 deletions(-)

diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h
index 74ede706fb32..0837ebbc5dce 100644
--- a/arch/sparc/include/asm/pgtable_64.h
+++ b/arch/sparc/include/asm/pgtable_64.h
@@ -945,10 +945,6 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
#define pte_clear(mm,addr,ptep) \
set_pte_at((mm), (addr), (ptep), __pte(0UL))

-#define __HAVE_ARCH_PTE_CLEAR_NOT_PRESENT_FULL
-#define pte_clear_not_present_full(mm,addr,ptep,fullmm) \
- __set_pte_at((mm), (addr), (ptep), __pte(0UL), (fullmm))
-
#ifdef DCACHE_ALIASING_POSSIBLE
#define __HAVE_ARCH_MOVE_PTE
#define move_pte(pte, old_addr, new_addr) \
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index 17d961c612fc..b3d6c8ddd687 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -955,24 +955,8 @@ static inline void update_mmu_tlb(struct vm_area_struct *vma,
update_mmu_tlb_range(vma, address, ptep, 1);
}

-/*
- * Some architectures may be able to avoid expensive synchronization
- * primitives when modifications are made to PTE's which are already
- * not present, or in the process of an address space destruction.
- */
-#ifndef __HAVE_ARCH_PTE_CLEAR_NOT_PRESENT_FULL
-static inline void pte_clear_not_present_full(struct mm_struct *mm,
- unsigned long address,
- pte_t *ptep,
- int full)
-{
- pte_clear(mm, address, ptep);
-}
-#endif
-
-#ifndef clear_not_present_full_ptes
/**
- * clear_not_present_full_ptes - Clear multiple not present PTEs which are
+ * clear_not_present_full_ptes - Clear multiple non-present PTEs which are
* consecutive in the pgtable.
* @mm: Address space the ptes represent.
* @addr: Address of the first pte.
@@ -980,24 +964,22 @@ static inline void pte_clear_not_present_full(struct mm_struct *mm,
* @nr: Number of entries to clear.
* @full: Whether we are clearing a full mm.
*
- * May be overridden by the architecture; otherwise, implemented as a simple
- * loop over pte_clear_not_present_full().
+ * Implemented as a simple loop over pte_clear().
*
* Context: The caller holds the page table lock. The PTEs are all not present.
* The PTEs are all in the same PMD.
*/
-static inline void clear_not_present_full_ptes(struct mm_struct *mm,
- unsigned long addr, pte_t *ptep, unsigned int nr, int full)
+static inline void clear_non_present_ptes(struct mm_struct *mm,
+ unsigned long addr, pte_t *ptep, unsigned int nr)
{
for (;;) {
- pte_clear_not_present_full(mm, addr, ptep, full);
+ pte_clear(mm, addr, ptep);
if (--nr == 0)
break;
ptep++;
addr += PAGE_SIZE;
}
}
-#endif

#ifndef __HAVE_ARCH_PTEP_CLEAR_FLUSH
extern pte_t ptep_clear_flush(struct vm_area_struct *vma,
diff --git a/mm/madvise.c b/mm/madvise.c
index 69708e953cf5..0e430e03e69c 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -695,10 +695,10 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr,
nr = swap_pte_batch(pte, max_nr, ptent);
nr_swap -= nr;
swap_put_entries_direct(entry, nr);
- clear_not_present_full_ptes(mm, addr, pte, nr, tlb->fullmm);
+ clear_non_present_(mm, addr, pte, nr);
} else if (softleaf_is_hwpoison(entry) ||
softleaf_is_poison_marker(entry)) {
- pte_clear_not_present_full(mm, addr, pte, tlb->fullmm);
+ pte_clear(mm, addr, pte);
}
continue;
}
@@ -1234,7 +1234,7 @@ static int guard_remove_pte_entry(pte_t *pte, unsigned long addr,

if (is_guard_pte_marker(ptent)) {
/* Simply clear the PTE marker. */
- pte_clear_not_present_full(walk->mm, addr, pte, false);
+ pte_clear(walk->mm, addr, pte);
update_mmu_cache(walk->vma, addr, pte);
}

diff --git a/mm/memory.c b/mm/memory.c
index 631205a384e1..d61d4ba906cd 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1781,7 +1781,7 @@ static inline int zap_nonpresent_ptes(struct mmu_gather *tlb,
pr_alert("unrecognized swap entry 0x%lx\n", entry.val);
WARN_ON_ONCE(1);
}
- clear_not_present_full_ptes(vma->vm_mm, addr, pte, nr, tlb->fullmm);
+ clear_non_present_ptes(vma->vm_mm, addr, pte, nr);
*any_skipped = zap_install_uffd_wp_if_needed(vma, addr, pte, nr, details, ptent);

return nr;
--
2.43.0

--
Cheers,

David