Re: [PATCH v3 1/4] x86/clear_page: extend clear_page*() for multi-page clearing

From: Ankur Arora
Date: Mon Apr 14 2025 - 15:47:53 EST



Peter Zijlstra <peterz@xxxxxxxxxxxxx> writes:

> On Mon, Apr 14, 2025 at 08:32:29AM +0200, Ingo Molnar wrote:

[ ... ]

>> > -SYM_TYPED_FUNC_START(clear_page_orig)
>> > +/*
>> > + * Original page zeroing loop.
>> > + * Input:
>> > + * %rdi - destination
>> > + * %esi - length
>> > + *
>> > + * Clobbers: %rax, %rcx, %rflags
>> > + */
>> > +SYM_TYPED_FUNC_START(clear_pages_orig)
>> > + movl %esi, %ecx
>> > xorl %eax,%eax
>> > - movl $4096/64,%ecx
>> > + shrl $6,%ecx
>>
>> So if the natural input parameter is RCX, why is this function using
>> RSI as the input 'length' parameter? Causes unnecessary register
>> shuffling.
>
> This symbol is written as a C function with C calling convention, even
> though it is only meant to be called from that clear_page() alternative.
>
> If we want to go change all this, then we should go do the same we do
> for __clear_user() and write it thusly:
>
> asm volatile(ALTERNATIVE("rep stosb",
> "call rep_stos_alternative", ALT_NOT(X86_FEATURE_FSRS)
> : "+c" (size), "+D" (addr), ASM_CALL_CONSTRAINT
> : "a" (0))
>
> And forget about all those clear_page_*() thingies.

Yeah, this makes sense. We don't call any of the clear_pages_*() variants
from anywhere else.

clear_pages_rep() and clear_pages_erms() are trivial enough to be
inlined in the ALTERNATIVE as well.

Thanks!

--
ankur