]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Avoid setting direction flag on EFI platforms
authorMichael Brown <mcb30@ipxe.org>
Tue, 7 Jul 2020 12:49:17 +0000 (13:49 +0100)
committerMichael Brown <mcb30@ipxe.org>
Tue, 7 Jul 2020 13:08:05 +0000 (14:08 +0100)
The only remaining use case in iPXE for the CPU direction flag is in
__memcpy_reverse() where it is set to allow the use of "rep movsb" to
perform the memory copy.  This matches the equivalent functionality in
the EDK2 codebase, which has functions such as InternalMemCopyMem that
also temporarily set the direction flag in order to use "rep movsb".

As noted in commit d2fb317 ("[crypto] Avoid temporarily setting
direction flag in bigint_is_geq()"), some UEFI implementations are
known to have buggy interrupt handlers that may reboot the machine if
a timer interrupt happens to occur while the direction flag is set.

Work around these buggy UEFI implementations by using the
(unoptimised) generic_memcpy_reverse() on i386 or x86_64 UEFI
platforms.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/core/x86_string.c
src/config/defaults/efi.h

index 7d5e4a5f119bac1301fde5e8e495079e973a7982..1a1e79dacc10a743da1505b2b7826282e489bdc4 100644 (file)
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
 #include <string.h>
+#include <config/defaults.h>
+
+/* Use generic_memcpy_reverse() if we cannot safely set the direction flag */
+#ifdef UNSAFE_STD
+#define USE_GENERIC_MEMCPY_REVERSE 1
+#else
+#define USE_GENERIC_MEMCPY_REVERSE 0
+#endif
 
 /**
  * Copy memory area
@@ -77,6 +85,12 @@ void * __attribute__ (( noinline )) __memcpy_reverse ( void *dest,
        const void *esi = ( src + len - 1 );
        int discard_ecx;
 
+       /* Use unoptimised version if we are not permitted to modify
+        * the direction flag.
+        */
+       if ( USE_GENERIC_MEMCPY_REVERSE )
+               return generic_memcpy_reverse ( dest, src, len );
+
        /* Assume memmove() is not performance-critical, and perform a
         * bytewise copy for simplicity.
         */
index 53a7a7b4bd49dbb621754d51121757f7a04d5141..e707dfa6af2f13990d44f61ac97e198573d4c266 100644 (file)
@@ -46,6 +46,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #define IOAPI_X86
 #define NAP_EFIX86
 #define        CPUID_CMD               /* x86 CPU feature detection command */
+#define        UNSAFE_STD              /* Avoid setting direction flag */
 #endif
 
 #if defined ( __arm__ ) || defined ( __aarch64__ )