[PATCH v6 12/15] highmem: define clear_highpages()

Ankur Arora posted 15 patches 1 month ago
There is a newer version of this series
[PATCH v6 12/15] highmem: define clear_highpages()
Posted by Ankur Arora 1 month ago
Define clear_user_highpages() which clears sequentially using the
single page variant.

With !CONFIG_HIGHMEM, pages are contiguous so use the range clearing
primitive clear_user_pages().

Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
---
 include/linux/highmem.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index 6234f316468c..eeb0b7bc0a22 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -207,6 +207,18 @@ static inline void clear_user_highpage(struct page *page, unsigned long vaddr)
 }
 #endif
 
+#ifndef clear_user_highpages
+static inline void clear_user_highpages(struct page *page, unsigned long vaddr,
+					unsigned int npages)
+{
+	if (!IS_ENABLED(CONFIG_HIGHMEM))
+		clear_user_pages(page_address(page), vaddr, page, npages);
+	else
+		for (int i = 0; i < npages; i++)
+			clear_user_highpage(page+i, vaddr + i * PAGE_SIZE);
+}
+#endif
+
 #ifndef vma_alloc_zeroed_movable_folio
 /**
  * vma_alloc_zeroed_movable_folio - Allocate a zeroed page for a VMA.
-- 
2.31.1
Re: [PATCH v6 12/15] highmem: define clear_highpages()
Posted by David Hildenbrand 1 month ago
On 02.09.25 10:08, Ankur Arora wrote:

subject is wrong.

Maybe call it

mm/highmem: introduce clear_user_highpages()

> Define clear_user_highpages() which clears sequentially using the
> single page variant.
> 
> With !CONFIG_HIGHMEM, pages are contiguous so use the range clearing
> primitive clear_user_pages().
> 
> Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
> ---
>   include/linux/highmem.h | 12 ++++++++++++
>   1 file changed, 12 insertions(+)
> 
> diff --git a/include/linux/highmem.h b/include/linux/highmem.h
> index 6234f316468c..eeb0b7bc0a22 100644
> --- a/include/linux/highmem.h
> +++ b/include/linux/highmem.h
> @@ -207,6 +207,18 @@ static inline void clear_user_highpage(struct page *page, unsigned long vaddr)
>   }
>   #endif
>   
> +#ifndef clear_user_highpages
> +static inline void clear_user_highpages(struct page *page, unsigned long vaddr,
> +					unsigned int npages)
> +{
> +	if (!IS_ENABLED(CONFIG_HIGHMEM))
> +		clear_user_pages(page_address(page), vaddr, page, npages);
> +	else
> +		for (int i = 0; i < npages; i++)
> +			clear_user_highpage(page+i, vaddr + i * PAGE_SIZE);

Maybe

if (!IS_ENABLED(CONFIG_HIGHMEM)) {
	clear_user_pages(page_address(page), vaddr, page, npages);
	return;
}

...

And maybe then the do while() pattern I suggested for the other variants.


-- 
Cheers

David / dhildenb
Re: [PATCH v6 12/15] highmem: define clear_highpages()
Posted by Ankur Arora 1 month ago
David Hildenbrand <david@redhat.com> writes:

> On 02.09.25 10:08, Ankur Arora wrote:
>
> subject is wrong.

Ugh. Side effect of dropping clear_highpages etc at the last minute.

> Maybe call it
>
> mm/highmem: introduce clear_user_highpages()

Will change.

>
>> Define clear_user_highpages() which clears sequentially using the
>> single page variant.
>> With !CONFIG_HIGHMEM, pages are contiguous so use the range clearing
>> primitive clear_user_pages().
>> Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
>> ---
>>   include/linux/highmem.h | 12 ++++++++++++
>>   1 file changed, 12 insertions(+)
>> diff --git a/include/linux/highmem.h b/include/linux/highmem.h
>> index 6234f316468c..eeb0b7bc0a22 100644
>> --- a/include/linux/highmem.h
>> +++ b/include/linux/highmem.h
>> @@ -207,6 +207,18 @@ static inline void clear_user_highpage(struct page *page, unsigned long vaddr)
>>   }
>>   #endif
>>   +#ifndef clear_user_highpages
>> +static inline void clear_user_highpages(struct page *page, unsigned long vaddr,
>> +					unsigned int npages)
>> +{
>> +	if (!IS_ENABLED(CONFIG_HIGHMEM))
>> +		clear_user_pages(page_address(page), vaddr, page, npages);
>> +	else
>> +		for (int i = 0; i < npages; i++)
>> +			clear_user_highpage(page+i, vaddr + i * PAGE_SIZE);
>
> Maybe
>
> if (!IS_ENABLED(CONFIG_HIGHMEM)) {
> 	clear_user_pages(page_address(page), vaddr, page, npages);
> 	return;
> }
>
> ...
>
> And maybe then the do while() pattern I suggested for the other variants.

Sounds good.

--
ankur