linux/arch/loongarch/lib
Tiezhu Yang 8b5ee2c66d LoongArch: Add support for function error injection
Inspired by the commit 42d038c4fb ("arm64: Add support for function
error injection") and the commit ee55ff803b ("riscv: Add support for
function error injection"), this patch supports function error injection
for LoongArch.

Mainly implement two functions:
(1) regs_set_return_value() which is used to overwrite the return value,
(2) override_function_with_return() which is used to override the probed
function returning and jump to its caller.

Here is a simple test under CONFIG_FUNCTION_ERROR_INJECTION and
CONFIG_FAIL_FUNCTION:

  # echo sys_clone > /sys/kernel/debug/fail_function/inject
  # echo 100 > /sys/kernel/debug/fail_function/probability
  # dmesg
  bash: fork: Invalid argument
  # dmesg
  ...
  FAULT_INJECTION: forcing a failure.
  name fail_function, interval 1, probability 100, space 0, times 1
  ...
  Call Trace:
  [<90000000002238f4>] show_stack+0x5c/0x180
  [<90000000012e384c>] dump_stack_lvl+0x60/0x88
  [<9000000000b1879c>] should_fail_ex+0x1b0/0x1f4
  [<900000000032ead4>] fei_kprobe_handler+0x28/0x6c
  [<9000000000230970>] kprobe_breakpoint_handler+0xf0/0x118
  [<90000000012e3e60>] do_bp+0x2c4/0x358
  [<9000000002241924>] exception_handlers+0x1924/0x10000
  [<900000000023b7d0>] sys_clone+0x0/0x4
  [<90000000012e4744>] do_syscall+0x7c/0x94
  [<9000000000221e44>] handle_syscall+0xc4/0x160

Tested-by: Hengqi Chen <hengqi.chen@gmail.com>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2023-05-01 17:19:52 +08:00
..
clear_user.S LoongArch: Optimize memory ops (memset/memcpy/memmove) 2023-05-01 17:19:43 +08:00
copy_user.S LoongArch: Optimize memory ops (memset/memcpy/memmove) 2023-05-01 17:19:43 +08:00
csum.c LoongArch: Add checksum optimization for 64-bit system 2023-05-01 17:19:43 +08:00
delay.c LoongArch: Remove useless header compiler.h 2022-07-29 18:22:32 +08:00
dump_tlb.c LoongArch: Improve dump_tlb() output messages 2022-09-03 18:01:27 +08:00
error-inject.c LoongArch: Add support for function error injection 2023-05-01 17:19:52 +08:00
Makefile LoongArch: Add support for function error injection 2023-05-01 17:19:52 +08:00
memcpy.S LoongArch: Optimize memory ops (memset/memcpy/memmove) 2023-05-01 17:19:43 +08:00
memmove.S LoongArch: Optimize memory ops (memset/memcpy/memmove) 2023-05-01 17:19:43 +08:00
memset.S LoongArch: Optimize memory ops (memset/memcpy/memmove) 2023-05-01 17:19:43 +08:00
unaligned.S LoongArch: Add unaligned access support 2022-12-14 08:36:11 +08:00