mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Usama Arif <usama.arif@linux.dev>,
	bp@alien8.de, dave.hansen@linux.intel.com, dsterba@suse.com,
	hpa@zytor.com, linux-kernel@vger.kernel.org, mingo@redhat.com,
	terrelln@fb.com, tglx@kernel.org, x86@kernel.org, kas@kernel.org,
	hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev,
	kernel-team@meta.com
Subject: Re: [PATCH v2] x86/lib: Use REP MOVSB for large memcpy() on ERMS CPUs without FSRM
Date: Tue, 10 Nov 2026 19:33:16 +0000	[thread overview]
Message-ID: <20261110193316.7ad9d7bc@pumpkin> (raw)
In-Reply-To: <CAHk-=whPF8CD9zC960jPUi2rMrJ_pq9ytdSYqWoef-R6AHsfXg@mail.gmail.com>

On Tue, 10 Nov 2026 09:53:07 -0800
Linus Torvalds <torvalds@linux-foundation.org> wrote:

> On Wed, 4 Nov 2026 at 14:28, Usama Arif <usama.arif@linux.dev> wrote:
> >
> > +       ALTERNATIVE __stringify(cmpq $0x20, %rcx; jb .Lhandle_tail), \
> > +                   __stringify(rep movsb; RET), X86_FEATURE_FSRM  
> 
> Let's not do that.
> 
> Putting magic things like RET in alternatives is just a bad bad idea.

You'd definitely want the RET in the code itself, and then overwrite
it with something else.
When I suggested it I did wonder whether the code patching really had
the right functionality.

Someone should try to measure it [1], but I actually suspect that the only
cost in following a 'rep movs' with an unconditional 'jmp' would be
for an I-cache load (or, worse, a TLB miss).
I expect the pipeline front end (which handles the jmp) will do all its
work while the setup for rep movs is happening (even for FSRM).

That would mean you could pair the "cmpq $0x20, %rcx; jb .Lhandle_tail"
with "rep movsb; jmps do_RET; nop".

David

[1] I need to dig out my 'rep movs' performance measuring code and run
it on a few different cpu types.
But I not got anything newer than an i7-7 or a zen[1-4].

> 
>                Linus


  reply	other threads:[~2026-11-10 19:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 22:28 Usama Arif
2026-11-05  8:12 ` David Laight
2026-11-05 17:28   ` Usama Arif
2026-11-10 16:25 ` Kiryl Shutsemau
2026-11-10 17:06   ` David Laight
2026-11-10 17:53 ` Linus Torvalds
2026-11-10 19:33   ` David Laight [this message]
2026-11-10 20:17   ` H. Peter Anvin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261110193316.7ad9d7bc@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dsterba@suse.com \
    --cc=hannes@cmpxchg.org \
    --cc=hpa@zytor.com \
    --cc=kas@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=riel@surriel.com \
    --cc=shakeel.butt@linux.dev \
    --cc=terrelln@fb.com \
    --cc=tglx@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=usama.arif@linux.dev \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®