Re: [PATCH v2] x86/lib: Use REP MOVSB for large memcpy() on ERMS CPUs without FSRM
From: Linus Torvalds
Date: Tue Nov 10 2026 - 16:00:57 EST
On Tue, 10 Nov 2026 at 12:18, H. Peter Anvin <hpa@xxxxxxxxx> wrote:
>
> On November 10, 2026 9:53:07 AM PST, Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
> >Let's not do that.
> >
> >Putting magic things like RET in alternatives is just a bad bad idea.
> >
> > Linus
>
> Why is that, *given that it is in assembly*?
It's assembly, but it's assembly that potentially gets rewritten.
objtool already knows about __x86_return_thunk being special (although
I think it's the _target_, not the call site, it cares about).
I would like to not have magic in stuff that is in the alternatives
section. We've had issues with relocations etc before.
That said, grepping a bit for this, it turns out we already seem to be
doing that in memmove_64.S, although it was hidden from my first grep:
#define CHECK_LEN cmp $0x20, %rdx; jb 1f
#define MEMMOVE_BYTES movq %rdx, %rcx; rep movsb; RET
.Lmemmove_begin_forward:
ALTERNATIVE_2 __stringify(CHECK_LEN), \
__stringify(CHECK_LEN; MEMMOVE_BYTES), X86_FEATURE_ERMS, \
__stringify(MEMMOVE_BYTES), X86_FEATURE_FSRM
which is pretty disgusting. But I guess that train has passed..
Linus