[PATCH v7 12/16] arm: mm: define clear_user_highpages()

Ankur Arora posted 16 patches 2 weeks ago
[PATCH v7 12/16] arm: mm: define clear_user_highpages()
Posted by Ankur Arora 2 weeks ago
For configurations with CONFIG_MMU we do not define clear_user_page().
This runs into issues for configurations with !CONFIG_HIGHMEM, because
clear_user_highpages() expects to clear_user_page() (via a default
version of clear_user_pages()).

Define clear_user_highpages() so it can supercede the generic version.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202509030341.jBuh7Fma-lkp@intel.com/
Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
---
 arch/arm/include/asm/page.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
index ef11b721230e..ddcc8159b075 100644
--- a/arch/arm/include/asm/page.h
+++ b/arch/arm/include/asm/page.h
@@ -151,6 +151,13 @@ extern void __cpu_copy_user_highpage(struct page *to, struct page *from,
 #define clear_user_highpage(page,vaddr)		\
 	 __cpu_clear_user_highpage(page, vaddr)
 
+#define clear_user_highpages(page, vaddr, npages)	\
+do {							\
+	clear_user_highpage(page, vaddr);		\
+	vaddr += PAGE_SIZE;				\
+	page++;						\
+} while (--npages)
+
 #define __HAVE_ARCH_COPY_USER_HIGHPAGE
 #define copy_user_highpage(to,from,vaddr,vma)	\
 	__cpu_copy_user_highpage(to, from, vaddr, vma)
-- 
2.43.5
Re: [PATCH v7 12/16] arm: mm: define clear_user_highpages()
Posted by David Hildenbrand 1 week, 2 days ago
On 17.09.25 17:24, Ankur Arora wrote:
> For configurations with CONFIG_MMU we do not define clear_user_page().
> This runs into issues for configurations with !CONFIG_HIGHMEM, because
> clear_user_highpages() expects to clear_user_page() (via a default
> version of clear_user_pages()).

I'm confused. Can you elaborate once more why we cannot take care of 
that in common code?

If it's about clear_user_pages(), then you can just switch from 
!IS_ENABLED(CONFIG_HIGHMEM) to ifdef in patch #11.

-- 
Cheers

David / dhildenb
Re: [PATCH v7 12/16] arm: mm: define clear_user_highpages()
Posted by Ankur Arora 1 week, 1 day ago
David Hildenbrand <david@redhat.com> writes:

> On 17.09.25 17:24, Ankur Arora wrote:
>> For configurations with CONFIG_MMU we do not define clear_user_page().
>> This runs into issues for configurations with !CONFIG_HIGHMEM, because
>> clear_user_highpages() expects to clear_user_page() (via a default
>> version of clear_user_pages()).
>
> I'm confused. Can you elaborate once more why we cannot take care of that in
> common code?

So my definition of clear_user_highpages,

    +#ifndef clear_user_highpages
    +static inline void clear_user_highpages(struct page *page, unsigned long vaddr,
    +					unsigned int npages)
    +{
    +	if (!IS_ENABLED(CONFIG_HIGHMEM)) {
    +		void *base = page_address(page);
    +		clear_user_pages(base, vaddr, page, npages);
    +		return;
    +	}
    +
    +	do {
    +		clear_user_highpage(page, vaddr);
    +		vaddr += PAGE_SIZE;
    +		page++;
    +	} while (--npages);
    +}
    +#endif

assumes one of the following:

  1. clear_user_highpages is defined by the architecture or,
  2. HIGHMEM => arch defines clear_user_highpage or clear_user_page
  3. !HIGHMEM => arch defines clear_user_pages or clear_user_page

Case 2 is fine, since ARM has clear_user_highpage().

Case 3 runs into a problem since ARM doesn't have clear_user_pages()
or clear_user_page() (it does have the second, but only with !CONFIG_MMU).

> If it's about clear_user_pages(), then you can just switch from
> !IS_ENABLED(CONFIG_HIGHMEM) to ifdef in patch #11.

It's worse than just clear_user_pages(), since we will have
clear_user_pages() (due to the defintion in patch-10) but that
is broken since the arch doesn't define clear_user_page().

I think the fallback defintions of clear_user_highpages() and
clear_user_pages() are reasonably sane so this needs to be addressed
in the arch code.

I defined clear_user_highpages() since it already has clear_user_highpage().

Another solution might be to define clear_user_page() for ARM which
would also address the broken-ness of clear_user_pages() but that
is more intrusive since that needs actual knowledge of the ARM mapping
model(s).

--
ankur
Re: [PATCH v7 12/16] arm: mm: define clear_user_highpages()
Posted by David Hildenbrand 1 week ago
On 24.09.25 00:25, Ankur Arora wrote:
> 
> David Hildenbrand <david@redhat.com> writes:
> 
>> On 17.09.25 17:24, Ankur Arora wrote:
>>> For configurations with CONFIG_MMU we do not define clear_user_page().
>>> This runs into issues for configurations with !CONFIG_HIGHMEM, because
>>> clear_user_highpages() expects to clear_user_page() (via a default
>>> version of clear_user_pages()).
>>
>> I'm confused. Can you elaborate once more why we cannot take care of that in
>> common code?
> 
> So my definition of clear_user_highpages,
> 
>      +#ifndef clear_user_highpages
>      +static inline void clear_user_highpages(struct page *page, unsigned long vaddr,
>      +					unsigned int npages)
>      +{
>      +	if (!IS_ENABLED(CONFIG_HIGHMEM)) {
>      +		void *base = page_address(page);
>      +		clear_user_pages(base, vaddr, page, npages);
>      +		return;
>      +	}
>      +
>      +	do {
>      +		clear_user_highpage(page, vaddr);
>      +		vaddr += PAGE_SIZE;
>      +		page++;
>      +	} while (--npages);
>      +}
>      +#endif
> 
> assumes one of the following:
> 
>    1. clear_user_highpages is defined by the architecture or,
>    2. HIGHMEM => arch defines clear_user_highpage or clear_user_page
>    3. !HIGHMEM => arch defines clear_user_pages or clear_user_page
> 
> Case 2 is fine, since ARM has clear_user_highpage().
> 
> Case 3 runs into a problem since ARM doesn't have clear_user_pages()
> or clear_user_page() (it does have the second, but only with !CONFIG_MMU).

I think we should look into having a generic fallback version in common 
code instead for that case, and not require the arch to implement such a 
loop around clear_user_highpage().

-- 
Cheers

David / dhildenb