Skip to contentSkip to conversation

ARM: support function error injection

PATCH New Kefeng Wang 1 participant 1 message Dec 2, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: support function error injection

This enables HAVE_FUNCTION_ERROR_INJECTION by adding necessary regs_set_return_value() and override_function_with_return().

Simply tested according to Documentation/fault-injection/fault-injection.rst.

---
 arch/arm/Kconfig              |  1 +
 arch/arm/include/asm/ptrace.h |  4 ++++
 arch/arm/lib/Makefile         |  2 ++
 arch/arm/lib/error-inject.c   | 10 ++++++++++
 4 files changed, 17 insertions(+)
 create mode 100644 arch/arm/lib/error-inject.c
arch/arm/Kconfig +1 -0
index a08c9d092a33..9092b68541f1 100644
@@ -95,6 +95,7 @@ config ARM
 	select HAVE_EXIT_THREAD
 	select HAVE_FAST_GUP if ARM_LPAE
 	select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
+	select HAVE_FUNCTION_ERROR_INJECTION
 	select HAVE_FUNCTION_GRAPH_TRACER
 	select HAVE_FUNCTION_TRACER if !XIP_KERNEL
 	select HAVE_GCC_PLUGINS
arch/arm/include/asm/ptrace.h +4 -0
index 1408a6a15d0e..483b8ddfcb82 100644
@@ -163,6 +163,10 @@ static inline unsigned long user_stack_pointer(struct pt_regs *regs)
 		((current_stack_pointer | (THREAD_SIZE - 1)) - 7) - 1;	\
 })
 
+static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc)
+{
+	regs->ARM_r0 = rc;
+}
 
 /*
  * Update ITSTATE after normal execution of an IT block instruction.
arch/arm/lib/Makefile +2 -0
index 6d2ba454f25b..f2c2ef94b74d 100644
@@ -48,3 +48,5 @@ ifeq ($(CONFIG_KERNEL_MODE_NEON),y)
   CFLAGS_xor-neon.o		+= $(NEON_FLAGS)
   obj-$(CONFIG_XOR_BLOCKS)	+= xor-neon.o
 endif
+
+obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
arch/arm/lib/error-inject.c new file +10 -0
new file mode 100644
index 000000000000..5a5b405792ba
@@ -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->ARM_lr);
+}
+NOKPROBE_SYMBOL(override_function_with_return);
Signature · 7 lines
2.27.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel