[PATCH v10 4/8] highmem: do range clearing in clear_user_highpages()

Ankur Arora posted 8 patches 3 days, 23 hours ago
[PATCH v10 4/8] highmem: do range clearing in clear_user_highpages()
Posted by Ankur Arora 3 days, 23 hours ago
Use the range clearing primitive clear_user_pages() when clearing
contiguous pages in clear_user_highpages().

We can safely do that when we have !CONFIG_HIGHMEM and when the
architecture does not have clear_user_highpage.

The first is necessary because not doing intermediate maps for
pages lets contiguous page ranges stay contiguous. The second,
because if the architecture has clear_user_highpage(), it likely
needs flushing magic when clearing the page, magic that we aren't
privy to.

Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
---
Note:
  - reorganized based on the previous two patches. 
  - Removed David's acked-by.

 include/linux/highmem.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index 92aa1053c9c1..c6219700569f 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -278,11 +278,28 @@ static inline void clear_user_highpage(struct page *page, unsigned long vaddr)
 static inline void clear_user_highpages(struct page *page, unsigned long vaddr,
 					unsigned int npages)
 {
+
+#if defined(clear_user_highpage) || defined(CONFIG_HIGHMEM)
+	/*
+	 * An architecture defined clear_user_highpage() implies special
+	 * handling is needed.
+	 *
+	 * So we use that or, the generic variant if CONFIG_HIGHMEM is
+	 * enabled.
+	 */
 	do {
 		clear_user_highpage(page, vaddr);
 		vaddr += PAGE_SIZE;
 		page++;
 	} while (--npages);
+#else
+
+	/*
+	 * Prefer clear_user_pages() to allow for architectural optimizations
+	 * when operating on contiguous page ranges.
+	 */
+	clear_user_pages(page_address(page), vaddr, page, npages);
+#endif
 }
 
 #ifndef vma_alloc_zeroed_movable_folio
-- 
2.31.1
Re: [PATCH v10 4/8] highmem: do range clearing in clear_user_highpages()
Posted by David Hildenbrand (Red Hat) 1 day, 13 hours ago
On 12/15/25 21:49, Ankur Arora wrote:
> Use the range clearing primitive clear_user_pages() when clearing
> contiguous pages in clear_user_highpages().
> 
> We can safely do that when we have !CONFIG_HIGHMEM and when the
> architecture does not have clear_user_highpage.
> 
> The first is necessary because not doing intermediate maps for
> pages lets contiguous page ranges stay contiguous. The second,
> because if the architecture has clear_user_highpage(), it likely
> needs flushing magic when clearing the page, magic that we aren't
> privy to.
> 
> Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
> ---

Can't you squash #4 into #2 if you move #3 in front of them? Or is there 
a dependency with #2 that I am missing?

-- 
Cheers

David
Re: [PATCH v10 4/8] highmem: do range clearing in clear_user_highpages()
Posted by Ankur Arora 1 day ago
David Hildenbrand (Red Hat) <david@kernel.org> writes:

> On 12/15/25 21:49, Ankur Arora wrote:
>> Use the range clearing primitive clear_user_pages() when clearing
>> contiguous pages in clear_user_highpages().
>> We can safely do that when we have !CONFIG_HIGHMEM and when the
>> architecture does not have clear_user_highpage.
>> The first is necessary because not doing intermediate maps for
>> pages lets contiguous page ranges stay contiguous. The second,
>> because if the architecture has clear_user_highpage(), it likely
>> needs flushing magic when clearing the page, magic that we aren't
>> privy to.
>> Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
>> ---
>
> Can't you squash #4 into #2 if you move #3 in front of them? Or is there a
> dependency with #2 that I am missing?

I thought it would be clearer to split this into #2 and #4 but #2
is completely obvious so doesn't help much.

Will squash.

--
ankur