Skip to content

Commit 14e4ec9

Browse files
committed
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 thus 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. Reported-by: Daniel Verkamp <dverkamp@chromium.org> Reported-by: Jiri Slaby <jirislaby@kernel.org> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/Y/yK0dyzI0MMdTie@zn.tnic
1 parent 270a69c commit 14e4ec9

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

arch/x86/lib/memmove_64.S

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ SYM_FUNC_START(__memmove)
3838
cmp %rdi, %r8
3939
jg 2f
4040

41-
/* FSRM implies ERMS => no length checks, do the copy directly */
41+
#define CHECK_LEN cmp $0x20, %rdx; jb 1f
42+
#define MEMMOVE_BYTES movq %rdx, %rcx; rep movsb; RET
4243
.Lmemmove_begin_forward:
43-
ALTERNATIVE "cmp $0x20, %rdx; jb 1f", "", X86_FEATURE_FSRM
44-
ALTERNATIVE "", "jmp .Lmemmove_erms", X86_FEATURE_ERMS
44+
ALTERNATIVE_2 __stringify(CHECK_LEN), \
45+
__stringify(CHECK_LEN; MEMMOVE_BYTES), X86_FEATURE_ERMS, \
46+
__stringify(MEMMOVE_BYTES), X86_FEATURE_FSRM
4547

4648
/*
4749
* movsq instruction have many startup latency
@@ -207,11 +209,6 @@ SYM_FUNC_START(__memmove)
207209
movb %r11b, (%rdi)
208210
13:
209211
RET
210-
211-
.Lmemmove_erms:
212-
movq %rdx, %rcx
213-
rep movsb
214-
RET
215212
SYM_FUNC_END(__memmove)
216213
EXPORT_SYMBOL(__memmove)
217214

0 commit comments

Comments
 (0)