Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Naveen N. Rao and committed by
Michael Ellerman
7cd01b08 b4d16ab5

+37
+1
arch/powerpc/Kconfig
··· 190 190 select HAVE_EBPF_JIT if PPC64 191 191 select HAVE_EFFICIENT_UNALIGNED_ACCESS if !(CPU_LITTLE_ENDIAN && POWER7_CPU) 192 192 select HAVE_FTRACE_MCOUNT_RECORD 193 + select HAVE_FUNCTION_ERROR_INJECTION 193 194 select HAVE_FUNCTION_GRAPH_TRACER 194 195 select HAVE_FUNCTION_TRACER 195 196 select HAVE_GCC_PLUGINS if GCC_VERSION >= 50200 # plugin support on gcc <= 5.1 is buggy on PPC
+13
arch/powerpc/include/asm/error-injection.h
··· 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 */
+5
arch/powerpc/include/asm/ptrace.h
··· 133 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 141 #ifdef __powerpc64__ 137 142 #define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1) 138 143 #else
+2
arch/powerpc/lib/Makefile
··· 12 12 13 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 17 # See corresponding test in arch/powerpc/Makefile 16 18 # 64-bit linker creates .sfpr on demand for final link (vmlinux), 17 19 # so it is only needed for modules, and only for older linkers which
+16
arch/powerpc/lib/error-inject.c
··· 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);