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

From: Borislav Petkov

Date: Tue Nov 10 2026 - 21:13:26 EST


On November 10, 2026 8:59:02 PM UTC, Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>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

Yah, I never liked this piece of gunk. Lemme give it a fresh look when things relax a bit...
--
Small device. Typos and formatting crap