1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright(c) 2016-2020 Intel Corporation. All rights reserved. */
4 #include <linux/linkage.h>
12 * copy_mc_fragile - copy memory with indication if an exception / fault happened
14 * The 'fragile' version is opted into by platform quirks and takes
15 * pains to avoid unrecoverable corner cases like 'fast-string'
16 * instruction sequences, and consuming poison across a cacheline
17 * boundary. The non-fragile version is equivalent to memcpy()
18 * regardless of CPU machine-check-recovery capability.
20 SYM_FUNC_START(copy_mc_fragile)
22 /* Less than 8 bytes? Go to byte copy loop */
25 /* Check for bad alignment of source */
30 /* Copy one byte at a time until source is 8-byte aligned */
36 .L_read_leading_bytes:
38 .L_write_leading_bytes:
43 jnz .L_read_leading_bytes
60 /* Any trailing bytes? */
63 jz .L_done_memcpy_trap
65 /* Copy trailing bytes */
67 .L_read_trailing_bytes:
69 .L_write_trailing_bytes:
74 jnz .L_read_trailing_bytes
76 /* Copy successful. Return zero */
81 SYM_FUNC_END(copy_mc_fragile)
85 * Return number of bytes not copied for any failure. Note that
86 * there is no "tail" handling since the source buffer is 8-byte
87 * aligned and poison is cacheline aligned.
98 * For write fault handling, given the destination is unaligned,
99 * we handle faults on multi-byte writes with a byte-by-byte
100 * copy up to the write-protected page.
106 jmp copy_mc_fragile_handle_tail
110 _ASM_EXTABLE_FAULT(.L_read_leading_bytes, .E_leading_bytes)
111 _ASM_EXTABLE_FAULT(.L_read_words, .E_read_words)
112 _ASM_EXTABLE_FAULT(.L_read_trailing_bytes, .E_trailing_bytes)
113 _ASM_EXTABLE(.L_write_leading_bytes, .E_leading_bytes)
114 _ASM_EXTABLE(.L_write_words, .E_write_words)
115 _ASM_EXTABLE(.L_write_trailing_bytes, .E_trailing_bytes)
116 #endif /* CONFIG_X86_MCE */
119 * copy_mc_enhanced_fast_string - memory copy with exception handling
121 * Fast string copy + fault / exception handling. If the CPU does
122 * support machine check exception recovery, but does not support
123 * recovering from fast-string exceptions then this CPU needs to be
124 * added to the copy_mc_fragile_key set of quirks. Otherwise, absent any
125 * machine check recovery support this version should be no slower than
128 SYM_FUNC_START(copy_mc_enhanced_fast_string)
133 /* Copy successful. Return zero */
136 SYM_FUNC_END(copy_mc_enhanced_fast_string)
138 .section .fixup, "ax"
141 * On fault %rcx is updated such that the copy instruction could
142 * optionally be restarted at the fault position, i.e. it
143 * contains 'bytes remaining'. A non-zero return indicates error
144 * to copy_mc_generic() users, or indicate short transfers to
145 * user-copy routines.
152 _ASM_EXTABLE_FAULT(.L_copy, .E_copy)
153 #endif /* !CONFIG_UML */