diff options
author | Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> | 2018-06-07 05:52:02 -0400 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2018-10-19 22:26:43 -0400 |
commit | 7cd01b08d35f1b7d55686ed8cd57c94d3406ec8f (patch) | |
tree | ba2112d797cf4e9ba7c690fe9bbe07dad8d5a873 | |
parent | b4d16ab58c41ff0125822464bdff074cebd0fe47 (diff) |
powerpc: Add support for function error injection
We implement regs_set_return_value() and override_function_with_return()
for this purpose.
On powerpc, a return from a function (blr) just branches to the location
contained in the link register. So, we can just update pt_regs rather
than redirecting execution to a dummy function that returns.
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Reviewed-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r-- | arch/powerpc/Kconfig | 1 | ||||
-rw-r--r-- | arch/powerpc/include/asm/error-injection.h | 13 | ||||
-rw-r--r-- | arch/powerpc/include/asm/ptrace.h | 5 | ||||
-rw-r--r-- | arch/powerpc/lib/Makefile | 2 | ||||
-rw-r--r-- | arch/powerpc/lib/error-inject.c | 16 |
5 files changed, 37 insertions, 0 deletions
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 3d008115fe18..076e05ae9b04 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig | |||
@@ -190,6 +190,7 @@ config PPC | |||
190 | select HAVE_EBPF_JIT if PPC64 | 190 | select HAVE_EBPF_JIT if PPC64 |
191 | select HAVE_EFFICIENT_UNALIGNED_ACCESS if !(CPU_LITTLE_ENDIAN && POWER7_CPU) | 191 | select HAVE_EFFICIENT_UNALIGNED_ACCESS if !(CPU_LITTLE_ENDIAN && POWER7_CPU) |
192 | select HAVE_FTRACE_MCOUNT_RECORD | 192 | select HAVE_FTRACE_MCOUNT_RECORD |
193 | select HAVE_FUNCTION_ERROR_INJECTION | ||
193 | select HAVE_FUNCTION_GRAPH_TRACER | 194 | select HAVE_FUNCTION_GRAPH_TRACER |
194 | select HAVE_FUNCTION_TRACER | 195 | select HAVE_FUNCTION_TRACER |
195 | select HAVE_GCC_PLUGINS if GCC_VERSION >= 50200 # plugin support on gcc <= 5.1 is buggy on PPC | 196 | select HAVE_GCC_PLUGINS if GCC_VERSION >= 50200 # plugin support on gcc <= 5.1 is buggy on PPC |
diff --git a/arch/powerpc/include/asm/error-injection.h b/arch/powerpc/include/asm/error-injection.h new file mode 100644 index 000000000000..62fd24739852 --- /dev/null +++ b/arch/powerpc/include/asm/error-injection.h | |||
@@ -0,0 +1,13 @@ | |||
1 | /* SPDX-License-Identifier: GPL-2.0+ */ | ||
2 | |||
3 | #ifndef _ASM_ERROR_INJECTION_H | ||
4 | #define _ASM_ERROR_INJECTION_H | ||
5 | |||
6 | #include <linux/compiler.h> | ||
7 | #include <linux/linkage.h> | ||
8 | #include <asm/ptrace.h> | ||
9 | #include <asm-generic/error-injection.h> | ||
10 | |||
11 | void override_function_with_return(struct pt_regs *regs); | ||
12 | |||
13 | #endif /* _ASM_ERROR_INJECTION_H */ | ||
diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h index 2ba2a1e52291..33196b311964 100644 --- a/arch/powerpc/include/asm/ptrace.h +++ b/arch/powerpc/include/asm/ptrace.h | |||
@@ -133,6 +133,11 @@ static inline long regs_return_value(struct pt_regs *regs) | |||
133 | return -regs->gpr[3]; | 133 | return -regs->gpr[3]; |
134 | } | 134 | } |
135 | 135 | ||
136 | static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc) | ||
137 | { | ||
138 | regs->gpr[3] = rc; | ||
139 | } | ||
140 | |||
136 | #ifdef __powerpc64__ | 141 | #ifdef __powerpc64__ |
137 | #define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1) | 142 | #define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1) |
138 | #else | 143 | #else |
diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile index 703afa1808ed..3bf9fc6fd36c 100644 --- a/arch/powerpc/lib/Makefile +++ b/arch/powerpc/lib/Makefile | |||
@@ -12,6 +12,8 @@ obj-y += string.o alloc.o code-patching.o feature-fixups.o | |||
12 | 12 | ||
13 | obj-$(CONFIG_PPC32) += div64.o copy_32.o crtsavres.o strlen_32.o | 13 | obj-$(CONFIG_PPC32) += div64.o copy_32.o crtsavres.o strlen_32.o |
14 | 14 | ||
15 | obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o | ||
16 | |||
15 | # See corresponding test in arch/powerpc/Makefile | 17 | # See corresponding test in arch/powerpc/Makefile |
16 | # 64-bit linker creates .sfpr on demand for final link (vmlinux), | 18 | # 64-bit linker creates .sfpr on demand for final link (vmlinux), |
17 | # so it is only needed for modules, and only for older linkers which | 19 | # so it is only needed for modules, and only for older linkers which |
diff --git a/arch/powerpc/lib/error-inject.c b/arch/powerpc/lib/error-inject.c new file mode 100644 index 000000000000..407b992fb02f --- /dev/null +++ b/arch/powerpc/lib/error-inject.c | |||
@@ -0,0 +1,16 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0+ | ||
2 | |||
3 | #include <linux/error-injection.h> | ||
4 | #include <linux/kprobes.h> | ||
5 | #include <linux/uaccess.h> | ||
6 | |||
7 | void override_function_with_return(struct pt_regs *regs) | ||
8 | { | ||
9 | /* | ||
10 | * Emulate 'blr'. 'regs' represents the state on entry of a predefined | ||
11 | * function in the kernel/module, captured on a kprobe. We don't need | ||
12 | * to worry about 32-bit userspace on a 64-bit kernel. | ||
13 | */ | ||
14 | regs->nip = regs->link; | ||
15 | } | ||
16 | NOKPROBE_SYMBOL(override_function_with_return); | ||