mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kiryl Shutsemau <kas@kernel.org>
To: Usama Arif <usama.arif@linux.dev>
Cc: 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,
	torvalds@linux-foundation.org,  hannes@cmpxchg.org,
	riel@surriel.com, shakeel.butt@linux.dev, kernel-team@meta.com
Subject: Re: [PATCH] x86/lib: Use REP MOVSB for large memcpy() on ERMS CPUs without FSRM
Date: Wed, 21 Oct 2026 10:54:53 +0100	[thread overview]
Message-ID: <atiKeB-76nOj-ztU@thinkstation> (raw)
In-Reply-To: <20261017192727.2760919-1-usama.arif@linux.dev>

On Sat, Oct 17, 2026 at 12:27:25PM -0700, Usama Arif wrote:
> diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
> index 12a23fa7c44c5..6b3e203b6087c 100644
> --- a/arch/x86/lib/memcpy_64.S
> +++ b/arch/x86/lib/memcpy_64.S
> @@ -31,9 +31,10 @@
>   * which the compiler could/should do much better anyway.
>   */
>  SYM_TYPED_FUNC_START(__memcpy)
> -	ALTERNATIVE "jmp memcpy_orig", "", X86_FEATURE_FSRM
> +	/* The FSRM destination move shares the space used by the ERMS jump. */
> +	ALTERNATIVE_2 "jmp memcpy_orig", "jmp memcpy_erms", X86_FEATURE_ERMS, \
> +		      "movq %rdi, %rax", X86_FEATURE_FSRM
>  
> -	movq %rdi, %rax

Moving MOVQ inside ALTERNATIVE_2 is ugly...

And it only turns a 5-byte NOP into a 2-byte one on FSRM.
What is the point?

>  	movq %rdx, %rcx
>  	rep movsb
>  	RET
> @@ -171,3 +172,11 @@ SYM_FUNC_START_LOCAL(memcpy_orig)
>  	RET
>  SYM_FUNC_END(memcpy_orig)
>  
> +SYM_FUNC_START_LOCAL(memcpy_erms)
> +	cmpq $2048, %rdx
> +	jb memcpy_orig
> +	movq %rdi, %rax
> +	movq %rdx, %rcx
> +	rep movsb
> +	RET
> +SYM_FUNC_END(memcpy_erms)

Copies below 2048 now take two jumps to reach memcpy_orig() instead of
one, and David's point is that nearly all kernel copies are that small.

Can the check go in memcpy_orig() after the existing 32-byte compare?

-- 
  Kiryl Shutsemau / Kirill A. Shutemov

  reply	other threads:[~2026-10-21  9:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 10:04 Usama Arif
2026-10-15 10:39 ` Kiryl Shutsemau
2026-10-17 19:27   ` Usama Arif
2026-10-21  9:54     ` Kiryl Shutsemau [this message]
2026-10-21 18:18       ` Linus Torvalds
2026-10-22  8:49         ` David Laight
2026-10-17 21:42 ` David Laight

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=atiKeB-76nOj-ztU@thinkstation \
    --to=kas@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dsterba@suse.com \
    --cc=hannes@cmpxchg.org \
    --cc=hpa@zytor.com \
    --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®