Kprobes for PPC32[Booke]
Subsystems (3)
Hi,
This is regarding the kprobes support for ppc32 with BOOKE versions. The attached patch contains this code and there is seperate patch which includes some kernel modules to test the same. This is tested for ebony platform(ppc440_gp).
Kernel Version: 2.6.16.39
Platform: Ebony
But there are some issues which i have noticed while handling debug exception used for single step operation.
1. The single step operation in PPC32 is implemented using debug control register (DBCR) which can be used to generate single step debug exception. This mechanism is used in handling post handler execution of kprobes (see code prepare_single_step)
2. It was noticed that having preempt_disable() at the beginning of kprobe_handler, generates OOPS and kprobes doesnot work. But this is against the original kprobes design implemented in other already working archs (that is, preemption is disabled for the entire duration of pre and post handlers execution). The basic problem noticed is, change in the preempt count after generating single step exception. Even though the preemption is disabled at the beginning of kprobe_handler(), after generating the single step exception, preempt count gets printed as zero in DebugException() handler of traps.c. This causes the problem and system generates OOPS!!
To resolve this problem, we have introduced the preempt_disable
and preempt_enable_no_resched blocks in pre and post handlers exceptions switch case of kprobe_exceptions_notify(), and by this way we found that the preempt count is consistent and pre and post handlers get executed. So why in PPC32 arch, preempt count gets changed between the debug exceptions? Is this problem already noticed or is it because of some other bug in the kprobes code of the attached patch?
3. In PPC32 it is noticed that interrupts are enabled by default and initially i had suspected this as the cause for problem stated in <2>. But it is found that by disabling interrupts, uncommenting the #if 0 blocks in the attached patch, the same problem appears. But this code is still not tested for kprobes reentrancy (by having interrupts enabled). Does anybody see a issue of enabling interrupts while processing kprobes?
4. While executing the fault handler using the test k-004.c in the attached patch, we noticed the following message being printed repeatedly for every pre handler execution where put_user() gets called to generate fault exception.
Debug: sleeping function called from invalid context at /..../k-004.c:39 in_atomic():1, irqs_disabled():1
Even though interrupts are enabled in the code(MSR bits show it as enabled), why the above debug message shows it as disabled? It appears that put_user() will internally call might_sleep() which turns out to be a sleeping function. But this same test didnot report any kind of above message while testing with ARM and MIPS arch even though all interrupts were disabled explicitly. So is it a failure message ? or wrongly printed only in ppc32? After getting this message, the test completes and the system is stable!!!
Since this code is implemented with limited ppc32 arch knowledge, some key things may be missing in this. Can somebody review this and provide some inputs for this code?
(Note:After porting the above patches to 2.6.20, the same above results are noticed!)
Best Regards
Madhvesh
==================
Madhvesh. R. Sulibhavi
Sony India Software Centre
Bangalore
arch/powerpc/lib/Makefile +1 -1
@@ -13,8 +13,8 @@ strcase.o obj-$(CONFIG_PPC_ISERIES) += e2a.o obj-$(CONFIG_XMON) += sstep.o +obj-$(CONFIG_KPROBES) += sstep.o ifeq ($(CONFIG_PPC64),y) obj-$(CONFIG_SMP) += locks.o -obj-$(CONFIG_DEBUG_KERNEL) += sstep.o endif
arch/ppc/Kconfig +14 -0
@@ -1397,3 +1397,17 @@ source "security/Kconfig" source "crypto/Kconfig" + +menu "Instrumentation Support" + +config KPROBES + bool "Kprobes" + depends on DEBUG_KERNEL + help + Kprobes allows you to trap at almost any kernel address and + execute a callback function. register_kprobe() establishes + a probepoint and specifies the callback. Kprobes is useful + for kernel debugging, non-intrusive instrumentation and testing. + If in doubt, say "N". + +endmenu
arch/ppc/kernel/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_PCI) += pci.o obj-$(CONFIG_RAPIDIO) += rio.o obj-$(CONFIG_KGDB) += ppc-stub.o +obj-$(CONFIG_KPROBES) += kprobes.o obj-$(CONFIG_SMP) += smp.o smp-tbsync.o obj-$(CONFIG_TAU) += temp.o ifndef CONFIG_E200
arch/ppc/kernel/kprobes.c new file +387 -0
387 lines not on this page · raw message
arch/ppc/kernel/misc.S +1 -1
@@ -427,7 +427,7 @@ * * __flush_icache_range(unsigned long start, unsigned long stop) */ -_GLOBAL(__flush_icache_range) +_KPROBE(__flush_icache_range) BEGIN_FTR_SECTION blr /* for 601, do nothing */ END_FTR_SECTION_IFCLR(CPU_FTR_SPLIT_ID_CACHE)
arch/ppc/kernel/traps.c +44 -1
87 lines not on this page · raw message
arch/ppc/kernel/vmlinux.lds.S +1 -0
@@ -33,6 +33,7 @@ *(.text) SCHED_TEXT LOCK_TEXT + KPROBES_TEXT *(.fixup) *(.got1) __got2_start = .;
arch/ppc/mm/fault.c +10 -1
@@ -28,6 +28,7 @@#include <linux/interrupt.h> #include <linux/highmem.h> #include <linux/module.h> +#include <linux/kprobes.h> #include <asm/page.h> #include <asm/pgtable.h>
@@ -36,6 +37,7 @@#include <asm/system.h> #include <asm/uaccess.h> #include <asm/tlbflush.h> +#include <asm/kdebug.h> #if defined(CONFIG_XMON ) || defined(CONFIG_KGDB )extern void (*debugger)(struct pt_regs *);
@@ -92,7 +94,7 @@* the error_code parameter is ESR for a data fault, 0 for an instruction * fault. */ -int do_page_fault (struct pt_regs *regs,unsigned long address, +int __kprobes do_page_fault (struct pt_regs *regs,unsigned long address,unsigned long error_code) {struct vm_area_struct * vma;
@@ -116,6 +118,13 @@ is_write = error_code &0x02000000 ;#endif /* CONFIG_4xx || CONFIG_BOOKE */ +#ifdef CONFIG_KPROBES +if (notify_die (DIE_PAGE_FAULT ,"page_fault" , regs, error_code, +11 ,SIGSEGV ) ==NOTIFY_STOP ) { +return 0 ; + } +#endif +#if defined(CONFIG_XMON ) || defined(CONFIG_KGDB )if (debugger_fault_handler &&TRAP (regs) ==0x300 ) {debugger_fault_handler (regs);
include/asm-powerpc/sstep.h +1 -0
@@ -21,6 +21,7 @@*/ #define IS_MTMSRD (instr) (((instr) & 0xfc0007be) == 0x7c000124)#define IS_RFID (instr) (((instr) & 0xfc0007fe) == 0x4c000024) +#define IS_RFI (instr) (((instr) & 0xfc0007fe) == 0x4c000064)/* Emulate instructions that cause a transfer of control. */ extern int emulate_step (struct pt_regs *regs,unsigned int instr);
include/asm-ppc/kdebug.h new file +60 -0
60 lines not on this page · raw message
include/asm-ppc/kprobes.h new file +71 -0
71 lines not on this page · raw message
Makefile +1 -1
@@ -559,7 +559,7 @@ ifeq ($(KBUILD_EXTMOD),) -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ kprobe-tests/ vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
kprobe-tests/Kconfig new file +13 -0
@@ -0,0 +1,13 @@ +# +# Kprobes test modules configuration +# +config KPROBESTEST + tristate "Kprobes test modules" + depends on KPROBES + default m if KPROBES=y + help + This support if enabled, will be used to test the kprobes support. + + To compile this kprobe test support as a module, choose M here: the + module will be called k-00x(x will be any number in 1,2,....9). + If in doubt, say "N"
kprobe-tests/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for the Kprobes test modules kernel. +# +obj-$(CONFIG_KPROBESTEST) += k-001.o k-002.o k-003.o k-004.o k-005.o k-006.o \ + k-007.o k-008.o k-009.o
kprobe-tests/k-001.c new file +91 -0
91 lines not on this page · raw message
kprobe-tests/k-002.c new file +95 -0
95 lines not on this page · raw message
kprobe-tests/k-003.c new file +97 -0
97 lines not on this page · raw message
kprobe-tests/k-004.c new file +124 -0
124 lines not on this page · raw message
kprobe-tests/k-005.c new file +72 -0
72 lines not on this page · raw message
kprobe-tests/k-006.c new file +72 -0
72 lines not on this page · raw message
kprobe-tests/k-007.c new file +80 -0
80 lines not on this page · raw message
kprobe-tests/k-008.c new file +68 -0
68 lines not on this page · raw message
kprobe-tests/k-009.c new file +74 -0
74 lines not on this page · raw message
Documentation/kprobe-tests.txt new file +299 -0
299 lines not on this page · raw message
kprobe-tests/kprobes-test.h new file +101 -0
101 lines not on this page · raw message
arch/ppc/Kconfig +1 -0
@@ -1410,4 +1410,5 @@ for kernel debugging, non-intrusive instrumentation and testing. If in doubt, say "N". +source "kprobe-tests/Kconfig" endmenu