This is a note to let you know that I've just added the patch titled riscv: jump_label: Fixup unaligned arch_static_branch function to the 5.15-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: riscv-jump_label-fixup-unaligned-arch_static_branch-function.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 9ddfc3cd806081ce1f6c9c2f988cbb031f35d28f Mon Sep 17 00:00:00 2001 From: Andy Chiu <andy.chiu@xxxxxxxxxx> Date: Mon, 6 Feb 2023 04:04:40 -0500 Subject: riscv: jump_label: Fixup unaligned arch_static_branch function From: Andy Chiu <andy.chiu@xxxxxxxxxx> 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: ebc00dde8a97 ("riscv: Add jump-label implementation") Link: https://lore.kernel.org/linux-riscv/20220913094252.3555240-6-andy.chiu@xxxxxxxxxx/ Reviewed-by: Greentime Hu <greentime.hu@xxxxxxxxxx> Signed-off-by: Andy Chiu <andy.chiu@xxxxxxxxxx> Signed-off-by: Guo Ren <guoren@xxxxxxxxxx> Link: https://lore.kernel.org/r/20230206090440.1255001-1-guoren@xxxxxxxxxx Cc: stable@xxxxxxxxxxxxxxx Signed-off-by: Palmer Dabbelt <palmer@xxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- arch/riscv/include/asm/jump_label.h | 2 ++ 1 file changed, 2 insertions(+) --- a/arch/riscv/include/asm/jump_label.h +++ b/arch/riscv/include/asm/jump_label.h @@ -18,6 +18,7 @@ static __always_inline bool arch_static_ bool branch) { asm_volatile_goto( + " .align 2 \n\t" " .option push \n\t" " .option norelax \n\t" " .option norvc \n\t" @@ -39,6 +40,7 @@ static __always_inline bool arch_static_ bool branch) { asm_volatile_goto( + " .align 2 \n\t" " .option push \n\t" " .option norelax \n\t" " .option norvc \n\t" Patches currently in stable-queue which might be from andy.chiu@xxxxxxxxxx are queue-5.15/riscv-jump_label-fixup-unaligned-arch_static_branch-function.patch