From: guoren@kernel.org
To: guoren@kernel.org, arnd@arndb.de
Cc: linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org,
linux-arch@vger.kernel.org, Guo Ren <guoren@linux.alibaba.com>
Subject: [PATCH 06/13] csky: Add support for function error injection
Date: Sat, 1 Aug 2020 01:14:06 +0000 [thread overview]
Message-ID: <1596244453-98575-7-git-send-email-guoren@kernel.org> (raw)
In-Reply-To: <1596244453-98575-1-git-send-email-guoren@kernel.org>
From: Guo Ren <guoren@linux.alibaba.com>
Inspired by the commit 42d038c4fb00 ("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 <guoren@linux.alibaba.com>
Cc: Arnd Bergmann <arnd@arndb.de>
---
arch/csky/Kconfig | 1 +
arch/csky/include/asm/ptrace.h | 6 ++++++
arch/csky/lib/Makefile | 1 +
arch/csky/lib/error-inject.c | 10 ++++++++++
4 files changed, 18 insertions(+)
create mode 100644 arch/csky/lib/error-inject.c
diff --git a/arch/csky/Kconfig b/arch/csky/Kconfig
index 822362d..c51f64c 100644
--- a/arch/csky/Kconfig
+++ b/arch/csky/Kconfig
@@ -45,6 +45,7 @@ config CSKY
select HAVE_DYNAMIC_FTRACE_WITH_REGS
select HAVE_FUNCTION_TRACER
select HAVE_FUNCTION_GRAPH_TRACER
+ select HAVE_FUNCTION_ERROR_INJECTION
select HAVE_FTRACE_MCOUNT_RECORD
select HAVE_KERNEL_GZIP
select HAVE_KERNEL_LZO
diff --git a/arch/csky/include/asm/ptrace.h b/arch/csky/include/asm/ptrace.h
index bcfb707..82da5e0 100644
--- a/arch/csky/include/asm/ptrace.h
+++ b/arch/csky/include/asm/ptrace.h
@@ -52,6 +52,12 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
return regs->a0;
}
+static inline void regs_set_return_value(struct pt_regs *regs,
+ unsigned long val)
+{
+ regs->a0 = val;
+}
+
/* Valid only for Kernel mode traps. */
static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
{
diff --git a/arch/csky/lib/Makefile b/arch/csky/lib/Makefile
index 078e2d5..7fbdbb2 100644
--- a/arch/csky/lib/Makefile
+++ b/arch/csky/lib/Makefile
@@ -1,2 +1,3 @@
# SPDX-License-Identifier: GPL-2.0-only
lib-y := usercopy.o delay.o
+obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
diff --git a/arch/csky/lib/error-inject.c b/arch/csky/lib/error-inject.c
new file mode 100644
index 00000000..c15fb36
--- /dev/null
+++ b/arch/csky/lib/error-inject.c
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/error-injection.h>
+#include <linux/kprobes.h>
+
+void override_function_with_return(struct pt_regs *regs)
+{
+ instruction_pointer_set(regs, regs->lr);
+}
+NOKPROBE_SYMBOL(override_function_with_return);
--
2.7.4
next prev parent reply other threads:[~2020-08-01 1:15 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-01 1:14 [PATCH 00/13] Update csky subsystem for linux-5.9-rc1 guoren
2020-08-01 1:14 ` [PATCH 01/13] csky: remove unusued thread_saved_pc and *_segments functions/macros guoren
2020-08-01 1:14 ` [PATCH 02/13] csky: Add SECCOMP_FILTER supported guoren
2020-08-01 1:14 ` [PATCH 03/13] csky: Add cpu feature register hint for smp guoren
2020-08-01 1:14 ` [PATCH 04/13] csky: Fixup duplicated restore sp in RESTORE_REGS_FTRACE guoren
2020-08-01 1:14 ` [PATCH 05/13] csky: Fixup kprobes handler couldn't change pc guoren
2020-08-01 1:14 ` guoren [this message]
2020-08-01 1:14 ` [PATCH 07/13] csky: Optimize the trap processing flow guoren
2020-08-01 1:14 ` [PATCH 08/13] csky: Use top-down mmap layout guoren
2020-08-01 1:14 ` [PATCH 09/13] csky: Set CONFIG_NR_CPU 4 as default guoren
2020-08-01 1:14 ` [PATCH 10/13] csky: Fixup warning by EXPORT_SYMBOL(kmap) guoren
2020-08-01 1:14 ` [PATCH 11/13] csky: Add irq_work support guoren
2020-08-01 1:14 ` [PATCH 12/13] csky: Add arch_show_interrupts for IPI interrupts guoren
2020-08-01 1:14 ` [PATCH 13/13] csky: Add context tracking support guoren
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1596244453-98575-7-git-send-email-guoren@kernel.org \
--to=guoren@kernel.org \
--cc=arnd@arndb.de \
--cc=guoren@linux.alibaba.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-csky@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).