mirror of
https://github.com/torvalds/linux.git
synced 2024-12-17 16:43:08 +00:00
24f1e32c60
This patch rebase the implementation of the breakpoints API on top of perf events instances. Each breakpoints are now perf events that handle the register scheduling, thread/cpu attachment, etc.. The new layering is now made as follows: ptrace kgdb ftrace perf syscall \ | / / \ | / / / Core breakpoint API / / | / | / Breakpoints perf events | | Breakpoints PMU ---- Debug Register constraints handling (Part of core breakpoint API) | | Hardware debug registers Reasons of this rewrite: - Use the centralized/optimized pmu registers scheduling, implying an easier arch integration - More powerful register handling: perf attributes (pinned/flexible events, exclusive/non-exclusive, tunable period, etc...) Impact: - New perf ABI: the hardware breakpoints counters - Ptrace breakpoints setting remains tricky and still needs some per thread breakpoints references. Todo (in the order): - Support breakpoints perf counter events for perf tools (ie: implement perf_bpcounter_event()) - Support from perf tools Changes in v2: - Follow the perf "event " rename - The ptrace regression have been fixed (ptrace breakpoint perf events weren't released when a task ended) - Drop the struct hw_breakpoint and store generic fields in perf_event_attr. - Separate core and arch specific headers, drop asm-generic/hw_breakpoint.h and create linux/hw_breakpoint.h - Use new generic len/type for breakpoint - Handle off case: when breakpoints api is not supported by an arch Changes in v3: - Fix broken CONFIG_KVM, we need to propagate the breakpoint api changes to kvm when we exit the guest and restore the bp registers to the host. Changes in v4: - Drop the hw_breakpoint_restore() stub as it is only used by KVM - EXPORT_SYMBOL_GPL hw_breakpoint_restore() as KVM can be built as a module - Restore the breakpoints unconditionally on kvm guest exit: TIF_DEBUG_THREAD doesn't anymore cover every cases of running breakpoints and vcpu->arch.switch_db_regs might not always be set when the guest used debug registers. (Waiting for a reliable optimization) Changes in v5: - Split-up the asm-generic/hw-breakpoint.h moving to linux/hw_breakpoint.h into a separate patch - Optimize the breakpoints restoring while switching from kvm guest to host. We only want to restore the state if we have active breakpoints to the host, otherwise we don't care about messed-up address registers. - Add asm/hw_breakpoint.h to Kbuild - Fix bad breakpoint type in trace_selftest.c Changes in v6: - Fix wrong header inclusion in trace.h (triggered a build error with CONFIG_FTRACE_SELFTEST Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Prasad <prasad@linux.vnet.ibm.com> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Ingo Molnar <mingo@elte.hu> Cc: Jan Kiszka <jan.kiszka@web.de> Cc: Jiri Slaby <jirislaby@gmail.com> Cc: Li Zefan <lizf@cn.fujitsu.com> Cc: Avi Kivity <avi@redhat.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Masami Hiramatsu <mhiramat@redhat.com> Cc: Paul Mundt <lethal@linux-sh.org>
74 lines
1.9 KiB
C
74 lines
1.9 KiB
C
#ifndef _I386_HW_BREAKPOINT_H
|
|
#define _I386_HW_BREAKPOINT_H
|
|
|
|
#ifdef __KERNEL__
|
|
#define __ARCH_HW_BREAKPOINT_H
|
|
|
|
/*
|
|
* The name should probably be something dealt in
|
|
* a higher level. While dealing with the user
|
|
* (display/resolving)
|
|
*/
|
|
struct arch_hw_breakpoint {
|
|
char *name; /* Contains name of the symbol to set bkpt */
|
|
unsigned long address;
|
|
u8 len;
|
|
u8 type;
|
|
};
|
|
|
|
#include <linux/kdebug.h>
|
|
#include <linux/percpu.h>
|
|
#include <linux/list.h>
|
|
|
|
/* Available HW breakpoint length encodings */
|
|
#define X86_BREAKPOINT_LEN_1 0x40
|
|
#define X86_BREAKPOINT_LEN_2 0x44
|
|
#define X86_BREAKPOINT_LEN_4 0x4c
|
|
#define X86_BREAKPOINT_LEN_EXECUTE 0x40
|
|
|
|
#ifdef CONFIG_X86_64
|
|
#define X86_BREAKPOINT_LEN_8 0x48
|
|
#endif
|
|
|
|
/* Available HW breakpoint type encodings */
|
|
|
|
/* trigger on instruction execute */
|
|
#define X86_BREAKPOINT_EXECUTE 0x80
|
|
/* trigger on memory write */
|
|
#define X86_BREAKPOINT_WRITE 0x81
|
|
/* trigger on memory read or write */
|
|
#define X86_BREAKPOINT_RW 0x83
|
|
|
|
/* Total number of available HW breakpoint registers */
|
|
#define HBP_NUM 4
|
|
|
|
struct perf_event;
|
|
struct pmu;
|
|
|
|
extern int arch_check_va_in_userspace(unsigned long va, u8 hbp_len);
|
|
extern int arch_validate_hwbkpt_settings(struct perf_event *bp,
|
|
struct task_struct *tsk);
|
|
extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused,
|
|
unsigned long val, void *data);
|
|
|
|
|
|
int arch_install_hw_breakpoint(struct perf_event *bp);
|
|
void arch_uninstall_hw_breakpoint(struct perf_event *bp);
|
|
void hw_breakpoint_pmu_read(struct perf_event *bp);
|
|
void hw_breakpoint_pmu_unthrottle(struct perf_event *bp);
|
|
|
|
extern void
|
|
arch_fill_perf_breakpoint(struct perf_event *bp);
|
|
|
|
unsigned long encode_dr7(int drnum, unsigned int len, unsigned int type);
|
|
int decode_dr7(unsigned long dr7, int bpnum, unsigned *len, unsigned *type);
|
|
|
|
extern int arch_bp_generic_fields(int x86_len, int x86_type,
|
|
int *gen_len, int *gen_type);
|
|
|
|
extern struct pmu perf_ops_bp;
|
|
|
|
#endif /* __KERNEL__ */
|
|
#endif /* _I386_HW_BREAKPOINT_H */
|
|
|