All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] mm: cleanup clear_not_present_full_ptes()
@ 2026-06-11 11:50 David Hildenbrand (Arm)
  2026-06-11 11:50 ` [PATCH 1/3] sparc/mm: drop custom pte_clear_not_present_full() David Hildenbrand (Arm)
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: David Hildenbrand (Arm) @ 2026-06-11 11:50 UTC (permalink / raw)
  To: David S. Miller, Andreas Larsson, Andrew Morton, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Jann Horn, Peter Zijlstra
  Cc: sparclinux, linux-kernel, linux-mm, David Hildenbrand (Arm)

While doing some review, I stumbled over clear_not_present_full_ptes()
and concluded that it needs some love.

Let's remove pte_clear_not_present_full() and cleanup
clear_not_present_full_ptes(), renaming it to clear_non_present_ptes().

Heavily build-tested, runtime tested only on x86-64.

Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
David Hildenbrand (Arm) (3):
      sparc/mm: drop custom pte_clear_not_present_full()
      mm: drop pte_clear_not_present_full()
      mm: cleanup clear_not_present_full_ptes() and rename to clear_non_present_ptes()

 arch/sparc/include/asm/pgtable_64.h |  4 ----
 include/linux/pgtable.h             | 31 +++++--------------------------
 mm/madvise.c                        |  6 +++---
 mm/memory.c                         |  2 +-
 4 files changed, 9 insertions(+), 34 deletions(-)

---

base-commit: be18cf77e1e749c6469ff44df00eb026f7c0a365

change-id: 20260610-clear_not_present_full_ptes-df3258baf7ed

--

Cheers,

David



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] sparc/mm: drop custom pte_clear_not_present_full()
  2026-06-11 11:50 [PATCH 0/3] mm: cleanup clear_not_present_full_ptes() David Hildenbrand (Arm)
@ 2026-06-11 11:50 ` David Hildenbrand (Arm)
  2026-06-11 11:50 ` [PATCH 2/3] mm: drop pte_clear_not_present_full() David Hildenbrand (Arm)
  2026-06-11 11:50 ` [PATCH 3/3] mm: cleanup clear_not_present_full_ptes() and rename to clear_non_present_ptes() David Hildenbrand (Arm)
  2 siblings, 0 replies; 8+ messages in thread
From: David Hildenbrand (Arm) @ 2026-06-11 11:50 UTC (permalink / raw)
  To: David S. Miller, Andreas Larsson, Andrew Morton, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Jann Horn, Peter Zijlstra
  Cc: sparclinux, linux-kernel, linux-mm, David Hildenbrand (Arm)

On sparc64, pte_clear_not_present_full() nowadays does a simple
__set_pte_at(). In __set_pte_at() -> maybe_tlb_batch_add(), we check
pte_accessible() to see whether to call tlb_batch_add().

However, non-present PTEs are surely not accessible, so tlb_batch_add()
is never called and the "full" parameter is irrelevant.

Let's drop the helper and just let common code do a pte_clear().

pte_clear() on sparc64 maps to set_pte_at()->set_ptes()->__set_pte_at()
... so it ends up calling the same function, just with "full=0".

Given that "full" is irrelevant, there is no change.

We added pte_clear_not_present_full() for sparc64 in commit 90f08e399d05
("sparc: mmu_gather rework"), and I suspect that it was already not
required back then.

Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
 arch/sparc/include/asm/pgtable_64.h | 4 ----
 1 file changed, 4 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)				\

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] mm: drop pte_clear_not_present_full()
  2026-06-11 11:50 [PATCH 0/3] mm: cleanup clear_not_present_full_ptes() David Hildenbrand (Arm)
  2026-06-11 11:50 ` [PATCH 1/3] sparc/mm: drop custom pte_clear_not_present_full() David Hildenbrand (Arm)
@ 2026-06-11 11:50 ` David Hildenbrand (Arm)
  2026-06-11 13:49   ` Oscar Salvador (SUSE)
  2026-06-11 11:50 ` [PATCH 3/3] mm: cleanup clear_not_present_full_ptes() and rename to clear_non_present_ptes() David Hildenbrand (Arm)
  2 siblings, 1 reply; 8+ messages in thread
From: David Hildenbrand (Arm) @ 2026-06-11 11:50 UTC (permalink / raw)
  To: David S. Miller, Andreas Larsson, Andrew Morton, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Jann Horn, Peter Zijlstra
  Cc: sparclinux, linux-kernel, linux-mm, David Hildenbrand (Arm)

In general, there is no good reason to do anything special when clearing
non-present PTEs.

In theory, HW that does have to invalidate TLBs for non-present PTEs could
benefit from a "full" parameter, but fortunately
pte_clear_not_present_full() is not wired up anymore ... and there would
have to be something very convincing for us to care about that to re-add
it.

So, let's just use pte_clear() directly now.

Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
 include/linux/pgtable.h | 19 ++-----------------
 mm/madvise.c            |  4 ++--
 2 files changed, 4 insertions(+), 19 deletions(-)

diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index cdd68ed3ae1a..cf328f4d1e12 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -954,21 +954,6 @@ 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
@@ -980,7 +965,7 @@ static inline void pte_clear_not_present_full(struct mm_struct *mm,
  * @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().
+ * 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.
@@ -989,7 +974,7 @@ static inline void clear_not_present_full_ptes(struct mm_struct *mm,
 		unsigned long addr, pte_t *ptep, unsigned int nr, int full)
 {
 	for (;;) {
-		pte_clear_not_present_full(mm, addr, ptep, full);
+		pte_clear(mm, addr, ptep);
 		if (--nr == 0)
 			break;
 		ptep++;
diff --git a/mm/madvise.c b/mm/madvise.c
index cd9bb077072c..f3cda54c1d6a 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -698,7 +698,7 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr,
 				clear_not_present_full_ptes(mm, addr, pte, nr, tlb->fullmm);
 			} 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);
 	}
 

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] mm: cleanup clear_not_present_full_ptes() and rename to clear_non_present_ptes()
  2026-06-11 11:50 [PATCH 0/3] mm: cleanup clear_not_present_full_ptes() David Hildenbrand (Arm)
  2026-06-11 11:50 ` [PATCH 1/3] sparc/mm: drop custom pte_clear_not_present_full() David Hildenbrand (Arm)
  2026-06-11 11:50 ` [PATCH 2/3] mm: drop pte_clear_not_present_full() David Hildenbrand (Arm)
@ 2026-06-11 11:50 ` David Hildenbrand (Arm)
  2026-06-11 14:02   ` Oscar Salvador (SUSE)
  2 siblings, 1 reply; 8+ messages in thread
From: David Hildenbrand (Arm) @ 2026-06-11 11:50 UTC (permalink / raw)
  To: David S. Miller, Andreas Larsson, Andrew Morton, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Jann Horn, Peter Zijlstra
  Cc: sparclinux, linux-kernel, linux-mm, David Hildenbrand (Arm)

Let's clean it up a bit:

(1) There is no need to pass "full" anymore.

(2) No architecture overwrites it, and there isn't really a good reason
    to do so when dealing with non-resent PTEs.

(3) While at it, call it "non-present", similar to copy_nonpresent_pte()
    and zap_nonpresent_ptes().

It's a shame that we have clear_non_present_ptes() correspond to
pte_clear() and clear_ptes() correspond to ptep_get_and_clear*().

Likely we should rename pte_clear() to pte_clear_nonpresent() or sth.
like that, to make it clearer that it is usually the wrong interface
for dealing with present PTEs.

Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
 include/linux/pgtable.h | 14 ++++----------
 mm/madvise.c            |  2 +-
 mm/memory.c             |  2 +-
 3 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index cf328f4d1e12..a72c40708461 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -954,24 +954,19 @@ static inline void update_mmu_tlb(struct vm_area_struct *vma,
 	update_mmu_tlb_range(vma, address, ptep, 1);
 }
 
-#ifndef clear_not_present_full_ptes
 /**
- * clear_not_present_full_ptes - Clear multiple not present PTEs which are
- *				 consecutive in the pgtable.
+ * clear_nonpresent_ptes - Clear multiple non-present PTEs which are
+ *			    consecutive in the pgtable.
  * @mm: Address space the ptes represent.
  * @addr: Address of the first pte.
  * @ptep: Page table pointer for the first entry.
  * @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().
  *
  * 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_nonpresent_ptes(struct mm_struct *mm,
+		unsigned long addr, pte_t *ptep, unsigned int nr)
 {
 	for (;;) {
 		pte_clear(mm, addr, ptep);
@@ -981,7 +976,6 @@ static inline void clear_not_present_full_ptes(struct mm_struct *mm,
 		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 f3cda54c1d6a..3db143c442ea 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -695,7 +695,7 @@ 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_nonpresent_ptes(mm, addr, pte, nr);
 			} else if (softleaf_is_hwpoison(entry) ||
 				   softleaf_is_poison_marker(entry)) {
 				pte_clear(mm, addr, pte);
diff --git a/mm/memory.c b/mm/memory.c
index 56be920c56d7..d4b3540ae659 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1797,7 +1797,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_nonpresent_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



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] mm: drop pte_clear_not_present_full()
  2026-06-11 11:50 ` [PATCH 2/3] mm: drop pte_clear_not_present_full() David Hildenbrand (Arm)
@ 2026-06-11 13:49   ` Oscar Salvador (SUSE)
  2026-06-11 14:57     ` David Hildenbrand (Arm)
  0 siblings, 1 reply; 8+ messages in thread
From: Oscar Salvador (SUSE) @ 2026-06-11 13:49 UTC (permalink / raw)
  To: David Hildenbrand (Arm)
  Cc: David S. Miller, Andreas Larsson, Andrew Morton, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Jann Horn, Peter Zijlstra,
	sparclinux, linux-kernel, linux-mm

On Thu, Jun 11, 2026 at 01:50:48PM +0200, David Hildenbrand (Arm) wrote:
> In general, there is no good reason to do anything special when clearing
> non-present PTEs.
> 
> In theory, HW that does have to invalidate TLBs for non-present PTEs could
> benefit from a "full" parameter, but fortunately

That would be on arches like arm64 where it can cache non-present
entries, right?
Then, we could signal a global invalidation instead of doing per page.

> pte_clear_not_present_full() is not wired up anymore ... and there would
> have to be something very convincing for us to care about that to re-add
> it.
> 
> So, let's just use pte_clear() directly now.
> 
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>

Reviewed-by: Oscar Salvador (SUSE) <osalvador@kernel.org>

 

-- 
Oscar Salvador
SUSE Labs


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] mm: cleanup clear_not_present_full_ptes() and rename to clear_non_present_ptes()
  2026-06-11 11:50 ` [PATCH 3/3] mm: cleanup clear_not_present_full_ptes() and rename to clear_non_present_ptes() David Hildenbrand (Arm)
@ 2026-06-11 14:02   ` Oscar Salvador (SUSE)
  2026-06-11 16:14     ` David Hildenbrand (Arm)
  0 siblings, 1 reply; 8+ messages in thread
From: Oscar Salvador (SUSE) @ 2026-06-11 14:02 UTC (permalink / raw)
  To: David Hildenbrand (Arm)
  Cc: David S. Miller, Andreas Larsson, Andrew Morton, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Jann Horn, Peter Zijlstra,
	sparclinux, linux-kernel, linux-mm

On Thu, Jun 11, 2026 at 01:50:49PM +0200, David Hildenbrand (Arm) wrote:
> Let's clean it up a bit:
> 
> (1) There is no need to pass "full" anymore.
> 
> (2) No architecture overwrites it, and there isn't really a good reason
>     to do so when dealing with non-resent PTEs.
> 
> (3) While at it, call it "non-present", similar to copy_nonpresent_pte()
>     and zap_nonpresent_ptes().
> 
> It's a shame that we have clear_non_present_ptes() correspond to
> pte_clear() and clear_ptes() correspond to ptep_get_and_clear*().
> 
> Likely we should rename pte_clear() to pte_clear_nonpresent() or sth.
> like that, to make it clearer that it is usually the wrong interface
> for dealing with present PTEs.

Is that always the case, that pte_clear() is only used on non-present
entries? Or there maybe users that do not care about the current value
and just want it to nuke?

I guess that such a renaming would have to first audit that all current
users obey that? Othen than that, is there anything else stopping us
from doing so?

> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>

Reviewed-by: Oscar Salvador (SUSE) <osalvador@kernel.org>

 

-- 
Oscar Salvador
SUSE Labs


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] mm: drop pte_clear_not_present_full()
  2026-06-11 13:49   ` Oscar Salvador (SUSE)
@ 2026-06-11 14:57     ` David Hildenbrand (Arm)
  0 siblings, 0 replies; 8+ messages in thread
From: David Hildenbrand (Arm) @ 2026-06-11 14:57 UTC (permalink / raw)
  To: Oscar Salvador (SUSE)
  Cc: David S. Miller, Andreas Larsson, Andrew Morton, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Jann Horn, Peter Zijlstra,
	sparclinux, linux-kernel, linux-mm

On 6/11/26 15:49, Oscar Salvador (SUSE) wrote:
> On Thu, Jun 11, 2026 at 01:50:48PM +0200, David Hildenbrand (Arm) wrote:
>> In general, there is no good reason to do anything special when clearing
>> non-present PTEs.
>>
>> In theory, HW that does have to invalidate TLBs for non-present PTEs could
>> benefit from a "full" parameter, but fortunately
> 
> That would be on arches like arm64 where it can cache non-present
> entries, right?

arm64 cannot cache them, it may only have them in the CPU pipeline temporarily,
and a special barrier (isb) is sufficient.

Risc-v has something like that, but they seem to handle it differently.

-- 
Cheers,

David

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] mm: cleanup clear_not_present_full_ptes() and rename to clear_non_present_ptes()
  2026-06-11 14:02   ` Oscar Salvador (SUSE)
@ 2026-06-11 16:14     ` David Hildenbrand (Arm)
  0 siblings, 0 replies; 8+ messages in thread
From: David Hildenbrand (Arm) @ 2026-06-11 16:14 UTC (permalink / raw)
  To: Oscar Salvador (SUSE)
  Cc: David S. Miller, Andreas Larsson, Andrew Morton, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Jann Horn, Peter Zijlstra,
	sparclinux, linux-kernel, linux-mm

On 6/11/26 16:02, Oscar Salvador (SUSE) wrote:
> On Thu, Jun 11, 2026 at 01:50:49PM +0200, David Hildenbrand (Arm) wrote:
>> Let's clean it up a bit:
>>
>> (1) There is no need to pass "full" anymore.
>>
>> (2) No architecture overwrites it, and there isn't really a good reason
>>     to do so when dealing with non-resent PTEs.
>>
>> (3) While at it, call it "non-present", similar to copy_nonpresent_pte()
>>     and zap_nonpresent_ptes().
>>
>> It's a shame that we have clear_non_present_ptes() correspond to
>> pte_clear() and clear_ptes() correspond to ptep_get_and_clear*().
>>
>> Likely we should rename pte_clear() to pte_clear_nonpresent() or sth.
>> like that, to make it clearer that it is usually the wrong interface
>> for dealing with present PTEs.
> 
> Is that always the case, that pte_clear() is only used on non-present
> entries? Or there maybe users that do not care about the current value
> and just want it to nuke?

Usually, you want to get access and dirty bits, and that requires get_and_clear
semantics. I suspect there are some more details to the low-level helpers.

> 
> I guess that such a renaming would have to first audit that all current
> users obey that? Othen than that, is there anything else stopping us
> from doing so?

When I last skimmed over some users, they were all dealing with non-present
entries. (mremap.c, rmap.c, mpreotect.c, memory.c, madvise.c)

But yes, we would have to audit and make sure that's the case.

-- 
Cheers,

David

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-06-11 16:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-11 11:50 [PATCH 0/3] mm: cleanup clear_not_present_full_ptes() David Hildenbrand (Arm)
2026-06-11 11:50 ` [PATCH 1/3] sparc/mm: drop custom pte_clear_not_present_full() David Hildenbrand (Arm)
2026-06-11 11:50 ` [PATCH 2/3] mm: drop pte_clear_not_present_full() David Hildenbrand (Arm)
2026-06-11 13:49   ` Oscar Salvador (SUSE)
2026-06-11 14:57     ` David Hildenbrand (Arm)
2026-06-11 11:50 ` [PATCH 3/3] mm: cleanup clear_not_present_full_ptes() and rename to clear_non_present_ptes() David Hildenbrand (Arm)
2026-06-11 14:02   ` Oscar Salvador (SUSE)
2026-06-11 16:14     ` David Hildenbrand (Arm)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.