Skip to content

Commit 71e193d

Browse files
committed
csky: Add support for function error injection
Inspired by the commit 42d038c ("arm64: Add support for function error injection"), this patch supports function error injection for csky. This patch mainly support two functions: one is regs_set_return_value() which is used to overwrite the return value; the another function is override_function_with_return() which is to override the probed function returning and jump to its caller. Test log: cd /sys/kernel/debug/fail_function/ echo sys_clone > inject echo 100 > probability echo 1 > interval ls / [ 108.644163] FAULT_INJECTION: forcing a failure. [ 108.644163] name fail_function, interval 1, probability 100, space 0, times 1 [ 108.647799] CPU: 0 PID: 104 Comm: sh Not tainted 5.8.0-rc5+ #46 [ 108.648384] Call Trace: [ 108.649339] [<8005eed4>] walk_stackframe+0x0/0xf0 [ 108.649679] [<8005f16a>] show_stack+0x32/0x5c [ 108.649927] [<8040f9d2>] dump_stack+0x6e/0x9c [ 108.650271] [<80406f7e>] should_fail+0x15e/0x1ac [ 108.650720] [<80118ba8>] fei_kprobe_handler+0x28/0x5c [ 108.651519] [<80754110>] kprobe_breakpoint_handler+0x144/0x1cc [ 108.652289] [<8005d6da>] trap_c+0x8e/0x110 [ 108.652816] [<8005ce8c>] csky_trap+0x5c/0x70 -sh: can't fork: Invalid argument Signed-off-by: Guo Ren <[email protected]> Cc: Arnd Bergmann <[email protected]>
1 parent a5447fb commit 71e193d

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

arch/csky/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ config CSKY
4545
select HAVE_DYNAMIC_FTRACE_WITH_REGS
4646
select HAVE_FUNCTION_TRACER
4747
select HAVE_FUNCTION_GRAPH_TRACER
48+
select HAVE_FUNCTION_ERROR_INJECTION
4849
select HAVE_FTRACE_MCOUNT_RECORD
4950
select HAVE_KERNEL_GZIP
5051
select HAVE_KERNEL_LZO

arch/csky/include/asm/ptrace.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
5252
return regs->a0;
5353
}
5454

55+
static inline void regs_set_return_value(struct pt_regs *regs,
56+
unsigned long val)
57+
{
58+
regs->a0 = val;
59+
}
60+
5561
/* Valid only for Kernel mode traps. */
5662
static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
5763
{

arch/csky/lib/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
lib-y := usercopy.o delay.o
3+
obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o

arch/csky/lib/error-inject.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/error-injection.h>
4+
#include <linux/kprobes.h>
5+
6+
void override_function_with_return(struct pt_regs *regs)
7+
{
8+
instruction_pointer_set(regs, regs->lr);
9+
}
10+
NOKPROBE_SYMBOL(override_function_with_return);

0 commit comments

Comments
 (0)