MIPS: Kprobes and Kretprobes Support
cover MIPS: Kprobes and Kretprobes Support
This is a set of 2 patches for adding support of kprobes and kretprobes support on MIPS architecture. All my tests are done on Qemu's MALTA board. If somebody has _real_ MIPS machine, I would appreciate a try on the machine.
---
Himanshu Chauhan (2):
MIPS: KProbes Support
MIPS: Kretprobe support
arch/mips/Kconfig | 14 ++ arch/mips/include/asm/break.h | 2 + arch/mips/include/asm/kdebug.h | 5 + arch/mips/include/asm/kprobes.h | 86 +++++++ arch/mips/kernel/Makefile | 2 + arch/mips/kernel/kprobes.c | 493 +++++++++++++++++++++++++++++++++++++++ arch/mips/kernel/traps.c | 43 ++++- arch/mips/mm/fault.c | 12 +- 8 files changed, 654 insertions(+), 3 deletions(-) create mode 100644 arch/mips/include/asm/kprobes.h create mode 100644 arch/mips/kernel/kprobes.c
PATCH 1/2 MIPS: KProbes Support
This incorporates some of the comments from Daney. Break codes being used are 515 and 516. do_break has been removed and kprobes are handled in do_bp itself.
--- arch/mips/Kconfig | 13 ++ arch/mips/include/asm/break.h | 2 + arch/mips/include/asm/kdebug.h | 5 + arch/mips/include/asm/kprobes.h | 86 +++++++++ arch/mips/kernel/Makefile | 2 + arch/mips/kernel/kprobes.c | 378 +++++++++++++++++++++++++++++++++++++++ arch/mips/kernel/traps.c | 43 +++++- arch/mips/mm/fault.c | 12 +- 8 files changed, 538 insertions(+), 3 deletions(-) create mode 100644 arch/mips/include/asm/kprobes.h create mode 100644 arch/mips/kernel/kprobes.c
arch/mips/Kconfig +13 -0
@@ -2243,6 +2243,19 @@ source "kernel/power/Kconfig" endmenu +menu "Instrumentation Support" + +config KPROBES + bool "MIPS Kprobes Support (Experimental)" + depends on EXPERIMENTAL && MODULES + help + Kprobes allow you to trap at almost any kernel address + and execute a callback function. Kprobes is useful for + kernel debugging, non-intrusive instrumetation and testing. + If in doubt, say N. + +endmenu + source "arch/mips/kernel/cpufreq/Kconfig" source "net/Kconfig"
arch/mips/include/asm/break.h +2 -0
@@ -30,6 +30,8 @@#define BRK_BUG 512/* Used by BUG() */ #define BRK_KDB 513/* Used in KDB_ENTER() */ #define BRK_MEMU 514/* Used by FPU emulator */ +#define BRK_KPRB_BP 515/* Used by Kprobes for pre-handling */ +#define BRK_KPRB_SSTP 516/* Used by Kprobes for post-handling */ #define BRK_MULOVF 1023/* Multiply overflow */ #endif /* __ASM_BREAK_H */
arch/mips/include/asm/kdebug.h +5 -0
@@ -8,6 +8,11 @@ enum die_val {DIE_FP ,DIE_TRAP ,DIE_RI , +#ifdef CONFIG_KPROBES +DIE_PAGE_FAULT , +DIE_BREAK , + DIE_SSTEPBP, +#endif };#endif /* _ASM_MIPS_KDEBUG_H */
arch/mips/include/asm/kprobes.h new file +86 -0
86 lines not on this page · raw message
arch/mips/kernel/Makefile +2 -0
@@ -83,6 +83,7 @@ obj-$(CONFIG_MIPS32_N32) += binfmt_elfn32.o scall64-n32.o signal_n32.o obj-$(CONFIG_MIPS32_O32) += binfmt_elfo32.o scall64-o32.o obj-$(CONFIG_KGDB) += kgdb.o +obj-$(CONFIG_KPROBES) += kprobes.o obj-$(CONFIG_PROC_FS) += proc.o obj-$(CONFIG_64BIT) += cpu-bugs64.o
@@ -95,6 +96,7 @@ obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-$(CONFIG_SPINLOCK_TEST) += spinlock_test.o + CFLAGS_cpu-bugs64.o = $(shell if $(CC) $(KBUILD_CFLAGS) -Wa,-mdaddi -c -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-DHAVE_AS_SET_DADDI"; fi) obj-$(CONFIG_HAVE_STD_PC_SERIAL_PORT) += 8250-platform.o
arch/mips/kernel/kprobes.c new file +378 -0
378 lines not on this page · raw message
arch/mips/kernel/traps.c +42 -1
73 lines not on this page · raw message
arch/mips/mm/fault.c +10 -2
@@ -18,6 +18,8 @@#include <linux/smp.h> #include <linux/vt_kern.h> /* For unblank_screen() */ #include <linux/module.h> +#include <linux/kprobes.h> +#include <linux/kdebug.h> /* notify_die and asm/kdebug.h */ #include <asm/branch.h> #include <asm/mmu_context.h>
@@ -31,8 +33,9 @@* and the problem, and then passes it off to one of the appropriate * routines. */ -asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long write, -unsigned long address) +asmlinkage void __kprobes do_page_fault(struct pt_regs *regs, +unsigned long write, +unsigned long address) {struct vm_area_struct * vma =NULL ;struct task_struct *tsk = current;
@@ -47,6 +50,11 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long write, field, regs->cp0_epc);#endif +/* Notify kprobes fault handler. */ +if (notify_die (DIE_PAGE_FAULT ,"page fault" , + regs,-1 ,SEGV_MAPERR ,SEGV_MAPERR ) ==NOTIFY_STOP ) +return ; + info.si_code =SEGV_MAPERR ;/*
Signature · 1 line
1.7.0.4
PATCH 2/2 MIPS: Kretprobe support
In reply to Himanshu ChauhanThis patch adds support for kretprobes on MIPS architecture.
--- arch/mips/Kconfig | 1 + arch/mips/kernel/kprobes.c | 117 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 117 insertions(+), 1 deletions(-)
arch/mips/Kconfig +1 -0
@@ -2248,6 +2248,7 @@ menu "Instrumentation Support" config KPROBES bool "MIPS Kprobes Support (Experimental)" depends on EXPERIMENTAL && MODULES + select HAVE_KRETPROBES help Kprobes allow you to trap at almost any kernel address and execute a callback function. Kprobes is useful for
arch/mips/kernel/kprobes.c +116 -1
138 lines not on this page · raw message
Signature · 1 line
1.7.0.4