Re: [PATCH] x86/lib: Use REP MOVSB for large memcpy() on ERMS CPUs without FSRM

From: David Laight

Date: Thu Oct 22 2026 - 04:50:09 EST


On Wed, 21 Oct 2026 08:18:25 -1000
Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:

> On Tue, 20 Oct 2026 at 23:55, Kiryl Shutsemau <kas@xxxxxxxxxx> wrote:
> >
> > Moving MOVQ inside ALTERNATIVE_2 is ugly...
>
> Yeah, maybe it would make sense to make that function be
>
> movq %rdi, %rax
> movq %rdx, %rcx
> ALTERNATIVE "jmp memcpy_orig", "rep movsb", X86_FEATURE_FSRM
> RET
>
> instead? No nop instructions at all, and both alternatives are two bytes.
>
> Then do any ERMS logic at the top of memcpy_orig, which now has the
> registers ready for string instructions anyway.

Is it possibly to just patch "rep movsb; RET" over whatever gets generated
for memcpy_orig (after the two register moves) ?
Then there are neither nops nor a jmp.

David

>
> Hmm?
>
> Linus
>