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: Thu, 15 Oct 2026 11:39:10 +0100 [thread overview]
Message-ID: <atCpTMcAALymqADw@thinkstation> (raw)
In-Reply-To: <20261013100442.2658311-1-usama.arif@linux.dev>
On Tue, Oct 13, 2026 at 03:04:42AM -0700, Usama Arif wrote:
> SYM_TYPED_FUNC_START(__memcpy)
> - ALTERNATIVE "jmp memcpy_orig", "", X86_FEATURE_FSRM
> + ALTERNATIVE_2 "jmp memcpy_orig", \
> + "cmpq $512, %rdx; jb memcpy_orig", X86_FEATURE_ERMS, \
> + "", X86_FEATURE_FSRM
This grows the patch site from 2 bytes to 13. On FSRM the replacement is
empty, and 13 bytes is more than ASM_NOP_MAX, so add_nop() puts an
unconditional jump here, executed on every memcpy() call on FSRM
machines. :/
Maybe it is worth moving the patch site into memcpy_orig()? It already
has a 32-byte check. Which brings me to the other question:
Why 512? memmove() uses REP MOVSB from 32 bytes on ERMS. Can we do the
same here? Then we don't need a new branch at all.
--- a/arch/x86/lib/memcpy_64.S
+++ b/arch/x86/lib/memcpy_64.S
@@ -50,6 +50,8 @@
cmpq $0x20, %rdx
jb .Lhandle_tail
+ ALTERNATIVE "", __stringify(movq %rdx, %rcx; rep movsb; RET), X86_FEATURE_ERMS
+
/*
* We check whether memory false dependence could occur,
* then jump to corresponding copy mode.
--
Kiryl Shutsemau / Kirill A. Shutemov
prev parent reply other threads:[~2026-10-15 10:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 10:04 Usama Arif
2026-10-15 10:39 ` Kiryl Shutsemau [this message]
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=atCpTMcAALymqADw@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®