x86/lib: Add fast-short-rep-movs check to copy_user_enhanced_fast_string()
authorTony Luck <tony.luck@intel.com>
Thu, 16 Dec 2021 17:24:31 +0000 (09:24 -0800)
committerBorislav Petkov <bp@suse.de>
Wed, 29 Dec 2021 12:46:02 +0000 (13:46 +0100)
Commit

  f444a5ff95dc ("x86/cpufeatures: Add support for fast short REP; MOVSB")

fixed memmove() with an ALTERNATIVE that will use REP MOVSB for all
string lengths.

copy_user_enhanced_fast_string() has a similar run time check to avoid
using REP MOVSB for copies less that 64 bytes.

Add an ALTERNATIVE to patch out the short length check and always use
REP MOVSB on X86_FEATURE_FSRM CPUs.

Signed-off-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lore.kernel.org/r/20211216172431.1396371-1-tony.luck@intel.com
arch/x86/lib/copy_user_64.S

index 2797e630b9b1ccc31326a042d1facc3c8ea98fda..1c429f0489ddcb5891812739e354bf4ca67b90c3 100644 (file)
@@ -200,8 +200,8 @@ EXPORT_SYMBOL(copy_user_generic_string)
  */
 SYM_FUNC_START(copy_user_enhanced_fast_string)
        ASM_STAC
-       cmpl $64,%edx
-       jb .L_copy_short_string /* less then 64 bytes, avoid the costly 'rep' */
+       /* CPUs without FSRM should avoid rep movsb for short copies */
+       ALTERNATIVE "cmpl $64, %edx; jb .L_copy_short_string", "", X86_FEATURE_FSRM
        movl %edx,%ecx
 1:     rep
        movsb