PPC64-HWBKPT: Prepare the PowerPC platform for HW Breakpoint infrastructure
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): 20090903183306.875398457@xyz
PATCH 1/6 PPC64-HWBKPT: Prepare the PowerPC platform for HW Breakpoint infrastructure
Prepare the PowerPC code for HW Breakpoint infrastructure patches by including relevant constant definitions and function declarations.
--- arch/powerpc/include/asm/hw_breakpoint.h | 61 +++++++++++++++++++++++++++++++ arch/powerpc/include/asm/processor.h | 1 arch/powerpc/include/asm/reg.h | 3 + arch/powerpc/include/asm/thread_info.h | 2 + 4 files changed, 67 insertions(+)
arch/powerpc/include/asm/hw_breakpoint.h new file +61 -0
@@ -0,0 +1,61 @@ +#ifndef _PPC64_HW_BREAKPOINT_H +#define _PPC64_HW_BREAKPOINT_H + +#ifdef __KERNEL__ +#define __ARCH_HW_BREAKPOINT_H +#ifdef CONFIG_PPC64 + +struct arch_hw_breakpoint { +int type; +char *name;/* Contains name of the symbol to set bkpt */ +unsigned long address; +unsigned long symbolsize; +}; + +#include <linux/kdebug.h> +#include <asm/reg.h> +#include <asm-generic/hw_breakpoint.h> + +#define HW_BREAKPOINT_READ DABR_DATA_READ +#define HW_BREAKPOINT_WRITE DABR_DATA_WRITE +#define HW_BREAKPOINT_RW (DABR_DATA_READ | DABR_DATA_WRITE) + +#define HW_BREAKPOINT_ALIGN 0x7 +/* Maximum permissible length of any HW Breakpoint */ +#define HW_BREAKPOINT_LEN 0x8 + +extern struct hw_breakpoint *hbp_kernel[HBP_NUM ]; +DECLARE_PER_CPU(struct hw_breakpoint*, this_hbp_kernel[HBP_NUM]); +extern unsigned int hbp_user_refcount[HBP_NUM ]; + +extern void arch_install_thread_hw_breakpoint (struct task_struct *tsk); +extern void arch_uninstall_thread_hw_breakpoint (void ); +extern int arch_validate_hwbkpt_settings (struct hw_breakpoint *bp, +struct task_struct *tsk); +extern void arch_update_user_hw_breakpoint (int pos,struct task_struct *tsk); +extern void arch_flush_thread_hw_breakpoint (struct task_struct *tsk); +extern void arch_update_kernel_hw_breakpoint (void *); +extern void arch_disable_hw_breakpoint (void ); +extern int hw_breakpoint_exceptions_notify (struct notifier_block *unused, +unsigned long val,void *data); + +extern void flush_thread_hw_breakpoint (struct task_struct *tsk); +extern int copy_thread_hw_breakpoint (struct task_struct *tsk, +struct task_struct *child,unsigned long clone_flags); +extern void load_debug_registers (void ); +extern void ptrace_triggered (struct hw_breakpoint *bp,struct pt_regs *regs); + +static inline void hw_breakpoint_disable (void ) +{ +set_dabr (0 ); +} + +#else +static inline void hw_breakpoint_disable (void ) +{ +/* Function is defined only on PPC64 for now */ +} +#endif /* CONFIG_PPC64 */ +#endif /* __KERNEL__ */ +#endif /* _PPC64_HW_BREAKPOINT_H */ +
arch/powerpc/include/asm/processor.h +1 -0
@@ -177,6 +177,7 @@ struct thread_struct {#ifdef CONFIG_PPC64 unsigned long start_tb;/* Start purr when proc switched in */ unsigned long accum_tb;/* Total accumilated purr for process */ +struct hw_breakpoint *hbp[HBP_NUM ];#endif unsigned long dabr;/* Data address breakpoint register */ #ifdef CONFIG_ALTIVEC
arch/powerpc/include/asm/reg.h +3 -0
@@ -26,6 +26,8 @@#include <asm/reg_8xx.h> #endif /* CONFIG_8xx */ +#define INSTRUCTION_LEN 4/* Length of any instruction */ +#define MSR_SF_LG 63/* Enable 64 bit mode */ #define MSR_ISF_LG 61/* Interrupt 64b mode valid on 630 */ #define MSR_HV_LG 60/* Hypervisor state */
@@ -184,6 +186,7 @@#define CTRL_TE 0x00c00000/* thread enable */ #define CTRL_RUNLATCH 0x1#define SPRN_DABR 0x3F5/* Data Address Breakpoint Register */ +#define HBP_NUM 1/* Number of physical HW breakpoint registers */ #define DABR_TRANSLATION (1UL << 2)#define DABR_DATA_WRITE (1UL << 1)#define DABR_DATA_READ (1UL << 0)
arch/powerpc/include/asm/thread_info.h +2 -0
@@ -112,6 +112,7 @@ static inline struct thread_info *curren#define TIF_FREEZE 14/* Freezing for suspend */ #define TIF_RUNLATCH 15/* Is the runlatch enabled? */ #define TIF_ABI_PENDING 16/* 32/64 bit switch needed */ +#define TIF_DEBUG 17/* uses debug registers */ /* as above, but as bit values */ #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
@@ -130,6 +131,7 @@ static inline struct thread_info *curren#define _TIF_FREEZE (1<<TIF_FREEZE)#define _TIF_RUNLATCH (1<<TIF_RUNLATCH)#define _TIF_ABI_PENDING (1<<TIF_ABI_PENDING) +#define _TIF_DEBUG (1<<TIF_DEBUG)#define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP)#define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
PATCH 2/6 PPC64-HWBKPT: Introduce PPC64 specific Hardware Breakpoint interfaces
In reply to a message not in the archiveIntroduce PPC64 implementation for the generic hardware breakpoint interfaces defined in kernel/hw_breakpoint.c. Enable the HAVE_HW_BREAKPOINT flag and the Makefile.
--- arch/powerpc/Kconfig | 1 arch/powerpc/kernel/Makefile | 2 arch/powerpc/kernel/hw_breakpoint.c | 342 ++++++++++++++++++++++++++++++++++++ arch/powerpc/kernel/ptrace.c | 4 4 files changed, 348 insertions(+), 1 deletion(-)
arch/powerpc/Kconfig +1 -0
@@ -126,6 +126,7 @@ config PPC select HAVE_SYSCALL_WRAPPERS if PPC64 select GENERIC_ATOMIC64 if PPC32 select HAVE_PERF_COUNTERS + select HAVE_HW_BREAKPOINT if PPC64 config EARLY_PRINTK bool
arch/powerpc/kernel/Makefile +1 -1
@@ -35,7 +35,7 @@ obj-$(CONFIG_PPC64) += setup_64.o sys_p signal_64.o ptrace32.o \ paca.o cpu_setup_ppc970.o \ cpu_setup_pa6t.o \ - firmware.o nvram_64.o + firmware.o nvram_64.o hw_breakpoint.o obj64-$(CONFIG_RELOCATABLE) += reloc_64.o obj-$(CONFIG_PPC64) += vdso64/ obj-$(CONFIG_ALTIVEC) += vecemu.o
arch/powerpc/kernel/hw_breakpoint.c new file +342 -0
342 lines not on this page · raw message
arch/powerpc/kernel/ptrace.c +4 -0
@@ -755,6 +755,10 @@ void user_disable_single_step(struct tasclear_tsk_thread_flag (task,TIF_SINGLESTEP ); } +void ptrace_triggered (struct hw_breakpoint *bp,struct pt_regs *regs) +{ +} +int ptrace_set_debugreg (struct task_struct *task,unsigned long addr,unsigned long data) {
PATCH 3/6 PPC64-HWBKPT: Modify ptrace code to use Hardware Breakpoint interfaces
In reply to a message not in the archiveModify the ptrace code to use the hardware breakpoint interfaces for user-space.
--- arch/powerpc/kernel/ptrace.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
arch/powerpc/kernel/ptrace.c +43 -0
@@ -37,6 +37,7 @@#include <asm/page.h> #include <asm/pgtable.h> #include <asm/system.h> +#include <asm/hw_breakpoint.h> /* * does not yet catch signals sent when the child dies.
@@ -757,11 +758,24 @@ void user_disable_single_step(struct tasvoid ptrace_triggered (struct hw_breakpoint *bp,struct pt_regs *regs) { +/* +* Unregister the breakpoint request here since ptrace has defined a +* one-shot behaviour for breakpoint exceptions in PPC64. +* The SIGTRAP signal is generated automatically for us in do_dabr(). +* We don't have to do anything here +*/ +unregister_user_hw_breakpoint (current, bp); +kfree (bp); }int ptrace_set_debugreg (struct task_struct *task,unsigned long addr,unsigned long data) { +#ifdef CONFIG_PPC64 +struct thread_struct *thread = &(task->thread); +struct hw_breakpoint *bp; +int ret; +#endif /* For ppc64 we support one DABR and no IABR's at the moment (ppc64). * For embedded processors we support one DAC and no IAC's at the * moment.
@@ -791,6 +805,35 @@ int ptrace_set_debugreg(struct task_struif (data && !(data &DABR_TRANSLATION ))return -EIO ; +#ifdef CONFIG_PPC64 + bp = thread->hbp[0 ]; +if (data ==0 ) { +if (bp) { +unregister_user_hw_breakpoint (task, bp); +kfree (bp); + } +return 0 ; + } + +if (bp) { + bp->info.type = data &HW_BREAKPOINT_RW ; + task->thread.dabr = bp->info.address = data; +return modify_user_hw_breakpoint (task, bp); + } + bp =kzalloc (sizeof (struct hw_breakpoint ),GFP_KERNEL ); +if (!bp) +return -ENOMEM ; + +/* Store the type of breakpoint */ + bp->info.type = data &HW_BREAKPOINT_RW ; + bp->triggered = ptrace_triggered; + task->thread.dabr = bp->info.address = data; + + ret =register_user_hw_breakpoint (task, bp); +if (ret) +return ret; +#endif /* CONFIG_PPC64 */ +/* Move contents to the DABR register */ task->thread.dabr = data;
PATCH 4/6 PPC64-HWBKPT: Modify process/processor code to recognise hardware debug registers
In reply to a message not in the archiveModify process handling code to recognise hardware debug registers during copy and flush operations. Introduce a new TIF_DEBUG task flag to indicate a process's use of debug register. Load the debug register values into a new CPU during initialisation.
--- arch/powerpc/kernel/process.c | 15 +++++++++++++++ arch/powerpc/kernel/smp.c | 2 ++ 2 files changed, 17 insertions(+)
arch/powerpc/kernel/process.c +15 -0
@@ -50,6 +50,7 @@#include <asm/syscalls.h> #ifdef CONFIG_PPC64 #include <asm/firmware.h> +#include <asm/hw_breakpoint.h> #endif #include <linux/kprobes.h> #include <linux/kdebug.h>
@@ -254,8 +255,10 @@ void do_dabr(struct pt_regs *regs, unsig 11, SIGSEGV) == NOTIFY_STOP)return ; +#ifndef CONFIG_PPC64 if (debugger_dabr_match (regs))return ; +#endif /* Clear the DAC and struct entries. One shot trigger */ #if defined(CONFIG_BOOKE )
@@ -372,8 +375,13 @@ struct task_struct *__switch_to(struct t#endif /* CONFIG_SMP */ +#ifdef CONFIG_PPC64 +if (unlikely (test_tsk_thread_flag (new,TIF_DEBUG ))) +arch_install_thread_hw_breakpoint (new); +#else if (unlikely (__get_cpu_var (current_dabr) != new->thread.dabr))set_dabr (new->thread.dabr); +#endif /* CONFIG_PPC64 */ #if defined(CONFIG_BOOKE )/* If new thread DAC (HW breakpoint) is the same then leave it */
@@ -550,6 +558,10 @@ void show_regs(struct pt_regs * regs)void exit_thread (void ) {discard_lazy_cpu_state (); +#ifdef CONFIG_PPC64 +if (unlikely (test_tsk_thread_flag (current,TIF_DEBUG ))) +flush_thread_hw_breakpoint (current); +#endif /* CONFIG_PPC64 */ }void flush_thread (void )
@@ -672,6 +684,9 @@ int copy_thread(unsigned long clone_flag* function. */ kregs->nip = *((unsigned long *)ret_from_fork); + +if (unlikely (test_tsk_thread_flag (current,TIF_DEBUG ))) +copy_thread_hw_breakpoint (current, p, clone_flags);#else kregs->nip = (unsigned long )ret_from_fork;#endif
arch/powerpc/kernel/smp.c +2 -0
@@ -48,6 +48,7 @@#include <asm/vdso_datapage.h> #ifdef CONFIG_PPC64 #include <asm/paca.h> +#include <asm/hw_breakpoint.h> #endif #ifdef DEBUG
@@ -537,6 +538,7 @@ int __devinit start_secondary(void *unuslocal_irq_enable (); +load_debug_registers ();cpu_idle ();return 0 ; }
PATCH 5/6 PPC64-HWBKPT: Modify Data storage exception code to recognise DABR match first
In reply to a message not in the archiveModify Data storage exception code to first lookout for a DABR match before recognising a kprobe or xmon exception.
--- arch/powerpc/mm/fault.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
arch/powerpc/mm/fault.c +6 -8
@@ -137,6 +137,12 @@ int __kprobes do_page_fault(struct pt_re error_code &=0x48200000 ; else is_write = error_code &DSISR_ISSTORE ; + +if (error_code &DSISR_DABRMATCH ) { +/* DABR match */ +do_dabr (regs, address, error_code); +return 0 ; + }#else is_write = error_code &ESR_DST ;#endif /* CONFIG_4xx || CONFIG_BOOKE */
@@ -151,14 +157,6 @@ int __kprobes do_page_fault(struct pt_reif (!user_mode (regs) && (address >=TASK_SIZE ))return SIGSEGV ; -#if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE )) -if (error_code &DSISR_DABRMATCH ) { -/* DABR match */ -do_dabr (regs, address, error_code); -return 0 ; - } -#endif /* !(CONFIG_4xx || CONFIG_BOOKE)*/ -if (in_atomic () || mm ==NULL ) {if (!user_mode (regs))return SIGSEGV ;
PATCH 6/6 PPC64-HWBKPT: Adapt kexec and samples code to recognise PPC64 hw-breakpoint
In reply to a message not in the archiveModify kexec code to disable DABR registers before a reboot. Adapt the samples code to populate PPC64-arch specific fields.
--- arch/powerpc/kernel/machine_kexec_64.c | 3 +++ samples/hw_breakpoint/data_breakpoint.c | 4 ++++ 2 files changed, 7 insertions(+)
arch/powerpc/kernel/machine_kexec_64.c +3 -0
@@ -24,6 +24,7 @@#include <asm/sections.h> /* _end */ #include <asm/prom.h> #include <asm/smp.h> +#include <asm/hw_breakpoint.h> int default_machine_kexec_prepare (struct kimage *image) {
@@ -214,6 +215,7 @@ static void kexec_prepare_cpus(void)put_cpu ();local_irq_disable (); + hw_breakpoint_disable(); }#else /* ! SMP */
@@ -233,6 +235,7 @@ static void kexec_prepare_cpus(void)if (ppc_md.kexec_cpu_down) ppc_md.kexec_cpu_down (0 ,0 );local_irq_disable (); + hw_breakpoint_disable(); }#endif /* SMP */
samples/hw_breakpoint/data_breakpoint.c +4 -0
@@ -54,6 +54,10 @@ static int __init hw_break_module_init(v sample_hbp.info.type =HW_BREAKPOINT_WRITE ; sample_hbp.info.len =HW_BREAKPOINT_LEN_4 ;#endif /* CONFIG_X86 */ +#ifdef CONFIG_PPC64 + sample_hbp.info.name = ksym_name; + sample_hbp.info.type =HW_BREAKPOINT_WRITE ; +#endif /* CONFIG_PPC64 */ sample_hbp.triggered = (void *)sample_hbp_handler;