All of lore.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: Peter Zijlstra <peterz@infradead.org>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	mhiramat@kernel.org, kirill.shutemov@linux.intel.com,
	Andrew.Cooper3@citrix.com, jpoimboe@redhat.com,
	Daniel Verkamp <dverkamp@chromium.org>,
	Jiri Slaby <jirislaby@kernel.org>,
	Tony Luck <tony.luck@intel.com>
Subject: [PATCH] x86/lib/memmove: Decouple ERMS from FSRM
Date: Mon, 27 Feb 2023 11:49:53 +0100	[thread overview]
Message-ID: <Y/yK0dyzI0MMdTie@zn.tnic> (raw)
In-Reply-To: <20230208171050.490809180@infradead.org>

On Wed, Feb 08, 2023 at 06:10:50PM +0100, Peter Zijlstra wrote:
> Hi,
> 
> This version is fully tested and includes a few NOP twiddles inspired by the
> objtool patches I'll post separately.
> 
> Also available at:
> 
>   https://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git/log/?h=x86/core

Ontop of the first two:

From: "Borislav Petkov (AMD)" <bp@alien8.de>
Date: Sun, 26 Feb 2023 21:04:26 +0100
Subject: [PATCH] x86/lib/memmove: Decouple ERMS from FSRM

Up until now it was perceived that FSRM is an improvement to ERMS and
thus it was made dependent on latter.

However, there are AMD BIOSes out there which allow for disabling of
either features and this preventing kernels from booting due to the CMP
disappearing and thus breaking the logic in the memmove() function.

Similar observation happens on some VM migration scenarios.

Patch the proper sequences depending on which feature is enabled.

Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reported-by: Daniel Verkamp <dverkamp@chromium.org>
Reported-by: Jiri Slaby <jirislaby@kernel.org>
---
 arch/x86/lib/memmove_64.S | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
index 02661861e5dd..0559b206fb11 100644
--- a/arch/x86/lib/memmove_64.S
+++ b/arch/x86/lib/memmove_64.S
@@ -38,10 +38,12 @@ SYM_FUNC_START(__memmove)
 	cmp %rdi, %r8
 	jg 2f
 
-	/* FSRM implies ERMS => no length checks, do the copy directly */
+#define CHECK_LEN	cmp $0x20, %rdx; jb 1f
+#define MEMMOVE_BYTES	movq %rdx, %rcx; rep movsb; RET
 .Lmemmove_begin_forward:
-	ALTERNATIVE "cmp $0x20, %rdx; jb 1f", "", X86_FEATURE_FSRM
-	ALTERNATIVE "", "jmp .Lmemmove_erms", X86_FEATURE_ERMS
+	ALTERNATIVE_2 __stringify(CHECK_LEN), \
+		      __stringify(CHECK_LEN; MEMMOVE_BYTES), X86_FEATURE_ERMS, \
+		      __stringify(MEMMOVE_BYTES), X86_FEATURE_FSRM
 
 	/*
 	 * movsq instruction have many startup latency
@@ -207,11 +209,6 @@ SYM_FUNC_START(__memmove)
 	movb %r11b, (%rdi)
 13:
 	RET
-
-.Lmemmove_erms:
-	movq %rdx, %rcx
-	rep movsb
-	RET
 SYM_FUNC_END(__memmove)
 EXPORT_SYMBOL(__memmove)
 
-- 
2.35.1


-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

  parent reply	other threads:[~2023-02-27 10:50 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-08 17:10 [PATCH v3 0/4] x86: Fully relocatable alternatives and some NOPs Peter Zijlstra
2023-02-08 17:10 ` [PATCH v3 1/4] x86/alternative: Make debug-alternative selective Peter Zijlstra
2023-02-14 11:48   ` Borislav Petkov
2023-05-13 13:03   ` [tip: x86/alternatives] " tip-bot2 for Peter Zijlstra
2023-02-08 17:10 ` [PATCH v3 2/4] x86/alternative: Support relocations in alternatives Peter Zijlstra
2023-02-17 20:28   ` Borislav Petkov
2023-02-17 22:21   ` Borislav Petkov
2023-05-13 13:03   ` [tip: x86/alternatives] " tip-bot2 for Peter Zijlstra
2023-02-08 17:10 ` [PATCH v3 3/4] x86/alternative: Rewrite optimize_nops() some Peter Zijlstra
2023-02-08 19:52   ` Andrew.Cooper3
2023-02-08 20:29     ` Peter Zijlstra
2023-02-08 20:36       ` Peter Zijlstra
2023-02-08 20:44         ` Peter Zijlstra
2023-02-08 20:45           ` Peter Zijlstra
2023-02-08 21:01           ` Peter Zijlstra
2023-02-08 21:08           ` Peter Zijlstra
2023-02-08 21:21             ` Peter Zijlstra
2023-02-09  1:11               ` Andrew.Cooper3
2023-02-09 22:27                 ` David Laight
2023-02-09  1:33       ` Andrew.Cooper3
2023-02-08 23:04     ` David Laight
2023-05-13 13:03   ` [tip: x86/alternatives] " tip-bot2 for Peter Zijlstra
2023-02-08 17:10 ` [PATCH v3 4/4] x86/alternative: Complicate optimize_nops() some more Peter Zijlstra
2023-05-13 13:03   ` [tip: x86/alternatives] " tip-bot2 for Peter Zijlstra
2023-05-13 16:01     ` [PATCH] x86/alternatives: Fix section mismatch warnings Borislav Petkov
2023-05-13 16:10       ` [tip: x86/alternatives] " tip-bot2 for Borislav Petkov (AMD)
2023-02-27 10:49 ` Borislav Petkov [this message]
2023-04-27  9:22   ` [PATCH TEST] x86/lib/memmove: Decouple ERMS from FSRM Yahu Gao

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=Y/yK0dyzI0MMdTie@zn.tnic \
    --to=bp@alien8.de \
    --cc=Andrew.Cooper3@citrix.com \
    --cc=dverkamp@chromium.org \
    --cc=jirislaby@kernel.org \
    --cc=jpoimboe@redhat.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tony.luck@intel.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.