Skip to content

Commit 589cb22

Browse files
committed
arm64: compat: fix stxr failure case in SWP emulation
If the STXR instruction fails in the SWP emulation code, we leave *data overwritten with the loaded value, therefore corrupting the data written by a subsequent, successful attempt. This patch re-jigs the code so that we only write back to *data once we know that the update has happened. Cc: <stable@vger.kernel.org> Fixes: bd35a4a ("arm64: Port SWP/SWPB emulation support from arm") Reported-by: Shengjiu Wang <shengjiu.wang@freescale.com> Reported-by: Vladimir Murzin <vladimir.murzin@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 32b8819 commit 589cb22

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

arch/arm64/kernel/armv8_deprecated.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,21 +284,23 @@ static void register_insn_emulation_sysctl(struct ctl_table *table)
284284
__asm__ __volatile__( \
285285
ALTERNATIVE("nop", SET_PSTATE_PAN(0), ARM64_HAS_PAN, \
286286
CONFIG_ARM64_PAN) \
287-
" mov %w2, %w1\n" \
288-
"0: ldxr"B" %w1, [%3]\n" \
289-
"1: stxr"B" %w0, %w2, [%3]\n" \
287+
"0: ldxr"B" %w2, [%3]\n" \
288+
"1: stxr"B" %w0, %w1, [%3]\n" \
290289
" cbz %w0, 2f\n" \
291290
" mov %w0, %w4\n" \
291+
" b 3f\n" \
292292
"2:\n" \
293+
" mov %w1, %w2\n" \
294+
"3:\n" \
293295
" .pushsection .fixup,\"ax\"\n" \
294296
" .align 2\n" \
295-
"3: mov %w0, %w5\n" \
296-
" b 2b\n" \
297+
"4: mov %w0, %w5\n" \
298+
" b 3b\n" \
297299
" .popsection" \
298300
" .pushsection __ex_table,\"a\"\n" \
299301
" .align 3\n" \
300-
" .quad 0b, 3b\n" \
301-
" .quad 1b, 3b\n" \
302+
" .quad 0b, 4b\n" \
303+
" .quad 1b, 4b\n" \
302304
" .popsection\n" \
303305
ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN, \
304306
CONFIG_ARM64_PAN) \

0 commit comments

Comments
 (0)