android_kernel_xiaomi_sm8450/arch/riscv
Andy Chiu 285d8390d9 riscv: jump_label: Fixup unaligned arch_static_branch function
commit 9ddfc3cd806081ce1f6c9c2f988cbb031f35d28f upstream.

Runtime code patching must be done at a naturally aligned address, or we
may execute on a partial instruction.

We have encountered problems traced back to static jump functions during
the test. We switched the tracer randomly for every 1~5 seconds on a
dual-core QEMU setup and found the kernel sucking at a static branch
where it jumps to itself.

The reason is that the static branch was 2-byte but not 4-byte aligned.
Then, the kernel would patch the instruction, either J or NOP, with two
half-word stores if the machine does not have efficient unaligned
accesses. Thus, moments exist where half of the NOP mixes with the other
half of the J when transitioning the branch. In our particular case, on
a little-endian machine, the upper half of the NOP was mixed with the
lower part of the J when enabling the branch, resulting in a jump that
jumped to itself. Conversely, it would result in a HINT instruction when
disabling the branch, but it might not be observable.

ARM64 does not have this problem since all instructions must be 4-byte
aligned.

Fixes: ebc00dde8a ("riscv: Add jump-label implementation")
Link: https://lore.kernel.org/linux-riscv/20220913094252.3555240-6-andy.chiu@sifive.com/
Reviewed-by: Greentime Hu <greentime.hu@sifive.com>
Signed-off-by: Andy Chiu <andy.chiu@sifive.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Link: https://lore.kernel.org/r/20230206090440.1255001-1-guoren@kernel.org
Cc: stable@vger.kernel.org
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-03-11 16:40:06 +01:00
..
boot riscv: dts: sifive unleashed: Add PWM controlled LEDs 2022-12-02 17:39:57 +01:00
configs riscv: defconfig: enable gpio support for HiFive Unleashed 2021-01-27 11:55:01 +01:00
include riscv: jump_label: Fixup unaligned arch_static_branch function 2023-03-11 16:40:06 +01:00
kernel RISC-V: time: initialize hrtimer based broadcast clock event device 2023-03-11 16:39:27 +01:00
lib riscv: use memcpy based uaccess for nommu again 2020-10-04 10:27:07 -07:00
mm riscv: Fixup race condition on PG_dcache_clean in flush_icache_pte 2023-02-15 17:22:26 +01:00
net riscv, bpf: Fix potential NULL dereference 2021-11-02 19:48:21 +01:00
Kbuild riscv: Allow device trees to be built into the kernel 2020-05-18 11:38:05 -07:00
Kconfig riscv: topology: fix default topology reporting 2022-10-30 09:41:19 +01:00
Kconfig.debug RISC-V: Remove EARLY_PRINTK support 2018-12-17 10:23:46 -08:00
Kconfig.socs RISC-V: Remove CLINT related code from timer and arch 2020-08-20 10:58:13 -07:00
Makefile riscv: disable generation of unwind tables 2023-02-15 17:22:19 +01:00