linux-stable/arch
Joey Gouly 1f1b58ebad arm64: alternatives: mark patch_alternative() as `noinstr`
[ Upstream commit a2c0b0fbe0 ]

The alternatives code must be `noinstr` such that it does not patch itself,
as the cache invalidation is only performed after all the alternatives have
been applied.

Mark patch_alternative() as `noinstr`. Mark branch_insn_requires_update()
and get_alt_insn() with `__always_inline` since they are both only called
through patch_alternative().

Booting a kernel in QEMU TCG with KCSAN=y and ARM64_USE_LSE_ATOMICS=y caused
a boot hang:
[    0.241121] CPU: All CPU(s) started at EL2

The alternatives code was patching the atomics in __tsan_read4() from LL/SC
atomics to LSE atomics.

The following fragment is using LL/SC atomics in the .text section:
  | <__tsan_unaligned_read4+304>:     ldxr    x6, [x2]
  | <__tsan_unaligned_read4+308>:     add     x6, x6, x5
  | <__tsan_unaligned_read4+312>:     stxr    w7, x6, [x2]
  | <__tsan_unaligned_read4+316>:     cbnz    w7, <__tsan_unaligned_read4+304>

This LL/SC atomic sequence was to be replaced with LSE atomics. However since
the alternatives code was instrumentable, __tsan_read4() was being called after
only the first instruction was replaced, which led to the following code in memory:
  | <__tsan_unaligned_read4+304>:     ldadd   x5, x6, [x2]
  | <__tsan_unaligned_read4+308>:     add     x6, x6, x5
  | <__tsan_unaligned_read4+312>:     stxr    w7, x6, [x2]
  | <__tsan_unaligned_read4+316>:     cbnz    w7, <__tsan_unaligned_read4+304>

This caused an infinite loop as the `stxr` instruction never completed successfully,
so `w7` was always 0.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20220405104733.11476-1-joey.gouly@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-04-20 09:36:21 +02:00
..
alpha bitmap patches for 5.17-rc1 2022-01-23 06:20:44 +02:00
arc uaccess: fix type mismatch warnings from access_ok() 2022-04-08 13:58:44 +02:00
arm ARM: dts: spear13xx: Update SPI dma properties 2022-04-08 13:59:03 +02:00
arm64 arm64: alternatives: mark patch_alternative() as `noinstr` 2022-04-20 09:36:21 +02:00
csky uaccess: fix type mismatch warnings from access_ok() 2022-04-08 13:58:44 +02:00
h8300 bitmap patches for 5.17-rc1 2022-01-23 06:20:44 +02:00
hexagon uaccess: fix integer overflow on access_ok() 2022-03-28 10:03:21 +02:00
ia64 ia64: make IA64_MCA_RECOVERY bool instead of tristate 2022-01-30 09:56:58 +02:00
m68k m68k: coldfire/device.c: only build for MCF_EDMA when h/w macros are defined 2022-04-08 13:57:51 +02:00
microblaze uaccess: fix nios2 and microblaze get_user_8() 2022-04-08 13:57:49 +02:00
mips MIPS: ingenic: correct unit node address 2022-04-13 19:27:22 +02:00
nds32 nds32: fix access_ok() checks in get/put_user 2022-03-28 10:03:22 +02:00
nios2 uaccess: fix type mismatch warnings from access_ok() 2022-04-08 13:58:44 +02:00
openrisc bitmap patches for 5.17-rc1 2022-01-23 06:20:44 +02:00
parisc parisc: Fix patch code locking and flushing 2022-04-13 19:27:27 +02:00
powerpc static_call: Properly initialise DEFINE_STATIC_CALL_RET0() 2022-04-20 09:36:21 +02:00
riscv RISC-V: KVM: include missing hwcap.h into vcpu_fp 2022-04-20 09:36:14 +02:00
s390 KVM: s390x: fix SCK locking 2022-04-08 13:57:30 +02:00
sh bitmap patches for 5.17-rc1 2022-01-23 06:20:44 +02:00
sparc uaccess: fix type mismatch warnings from access_ok() 2022-04-08 13:58:44 +02:00
um um: fix and optimize xor select template for CONFIG64 and timetravel mode 2022-04-13 19:27:06 +02:00
x86 static_call: Properly initialise DEFINE_STATIC_CALL_RET0() 2022-04-20 09:36:21 +02:00
xtensa xtensa: fix DTC warning unit_address_format 2022-04-13 19:27:22 +02:00
.gitignore
Kconfig stack: Constrain and fix stack offset randomization with Clang builds 2022-04-08 13:57:34 +02:00