hw_breakpoint: Let the user choose not to build it (and perf too)
Subsystems (7)
cover hw_breakpoint: Let the user choose not to build it (and perf too)
Hi,
Until now, x86 and superh32 had to always build hw_breakpoint and perf. And powerpc and arm were always building hw_breakpoints when perf was enabled.
After this patchset, one can simply disable hw_breakpoints if he selected CONFIG_EXPERT. Afterward the user is free to select perf or not. Except on SH unfortunately because that would require a bit of change in ptrace to support singlestep failures.
Frederic Weisbecker (6):
hw_breakpoints: Split hardware breakpoints config
hw_breakpoints: Migrate breakpoint conditional build under new config
x86: Allow the user not to build hw_breakpoints
hw_breakpoints: Breakpoints arch ability don't need perf events
hw_breakpoints: Only force perf events if breakpoints are selected
hw_breakpoints: Drop remaining misplaced dependency on perf
arch/Kconfig | 1 - arch/arm/Kconfig | 2 +- arch/arm/include/asm/hw_breakpoint.h | 4 +- arch/arm/include/asm/processor.h | 2 +- arch/arm/kernel/Makefile | 2 +- arch/arm/kernel/entry-header.S | 2 +- arch/arm/kernel/ptrace.c | 4 +- arch/powerpc/Kconfig | 2 +- arch/powerpc/include/asm/cputable.h | 4 +- arch/powerpc/include/asm/hw_breakpoint.h | 6 ++-- arch/powerpc/include/asm/processor.h | 4 +- arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/kernel/process.c | 18 ++++++++-------- arch/powerpc/kernel/ptrace.c | 12 +++++----- arch/powerpc/lib/Makefile | 2 +- arch/sh/Kconfig | 2 +- arch/sh/kernel/Makefile | 2 +- arch/sh/kernel/cpu/sh4a/Makefile | 2 +- arch/x86/Kconfig | 3 +- arch/x86/include/asm/debugreg.h | 33 ++++++++++++++++++++++++++++- arch/x86/kernel/Makefile | 3 +- arch/x86/kernel/process.c | 1 + arch/x86/kernel/ptrace.c | 17 +++++++++++++++ include/linux/hw_breakpoint.h | 6 ++-- include/linux/perf_event.h | 4 +- init/Kconfig | 11 ++++++++++ kernel/Makefile | 2 +- kernel/perf_event.c | 4 +- samples/Kconfig | 2 +- 29 files changed, 108 insertions(+), 51 deletions(-)
Signature · 1 line
1.7.3.2
PATCH 2/6 hw_breakpoints: Migrate breakpoint conditional build under new config
Migrate conditional hw_breakpoint code compilation under the new config to prepare for letting the user chose whether or not to build this feature
--- arch/arm/include/asm/hw_breakpoint.h | 4 ++-- arch/arm/include/asm/processor.h | 2 +- arch/arm/kernel/Makefile | 2 +- arch/arm/kernel/entry-header.S | 2 +- arch/arm/kernel/ptrace.c | 4 ++-- arch/powerpc/include/asm/cputable.h | 4 ++-- arch/powerpc/include/asm/hw_breakpoint.h | 6 +++--- arch/powerpc/include/asm/processor.h | 4 ++-- arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/kernel/process.c | 18 +++++++++--------- arch/powerpc/kernel/ptrace.c | 12 ++++++------ arch/powerpc/lib/Makefile | 2 +- arch/sh/kernel/Makefile | 2 +- arch/sh/kernel/cpu/sh4a/Makefile | 2 +- include/linux/hw_breakpoint.h | 6 +++--- include/linux/perf_event.h | 4 ++-- kernel/Makefile | 2 +- kernel/perf_event.c | 4 ++-- samples/Kconfig | 2 +- 19 files changed, 42 insertions(+), 42 deletions(-)
arch/arm/include/asm/hw_breakpoint.h +2 -2
@@ -5,7 +5,7 @@struct task_struct ; -#ifdef CONFIG_HAVE_HW_BREAKPOINT +#ifdef CONFIG_HW_BREAKPOINT struct arch_hw_breakpoint_ctrl { u32 __reserved : 9,
@@ -128,6 +128,6 @@ int hw_breakpoint_slots(int type);#else static inline void clear_ptrace_hw_breakpoint (struct task_struct *tsk) {} -#endif /* CONFIG_HAVE_HW_BREAKPOINT */ +#endif /* CONFIG_HW_BREAKPOINT */ #endif /* __KERNEL__ */ #endif /* _ARM_HW_BREAKPOINT_H */
arch/arm/include/asm/processor.h +1 -1
@@ -30,7 +30,7 @@#endif struct debug_info { -#ifdef CONFIG_HAVE_HW_BREAKPOINT +#ifdef CONFIG_HW_BREAKPOINT struct perf_event *hbp[ARM_MAX_HBP_SLOTS ];#endif };
arch/arm/kernel/Makefile +1 -1
@@ -47,7 +47,7 @@ obj-$(CONFIG_HAVE_TCM) += tcm.o obj-$(CONFIG_CRASH_DUMP) += crash_dump.o obj-$(CONFIG_SWP_EMULATE) += swp_emulate.o CFLAGS_swp_emulate.o := -Wa,-march=armv7-a -obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o +obj-$(CONFIG_HW_BREAKPOINT) += hw_breakpoint.o obj-$(CONFIG_CRUNCH) += crunch.o crunch-bits.o AFLAGS_crunch-bits.o := -Wa,-mcpu=ep9312
arch/arm/kernel/entry-header.S +1 -1
@@ -171,7 +171,7 @@ @ we can access the debug registers safely. @ .macro debug_entry, fsr -#if defined(CONFIG_HAVE_HW_BREAKPOINT) && defined(CONFIG_PREEMPT) +#if defined(CONFIG_HW_BREAKPOINT) && defined(CONFIG_PREEMPT) ldr r4, =0x40f @ mask out fsr.fs and r5, r4, \fsr cmp r5, #2 @ debug exception
arch/arm/kernel/ptrace.c +2 -2
@@ -468,7 +468,7 @@ static int ptrace_setvfpregs(struct task_struct *tsk, void __user *data) }#endif -#ifdef CONFIG_HAVE_HW_BREAKPOINT +#ifdef CONFIG_HW_BREAKPOINT /* * Convert a virtual register number into an index for a thread_info * breakpoint array. Breakpoints are identified using positive numbers
@@ -765,7 +765,7 @@ long arch_ptrace(struct task_struct *child, long request,break ;#endif -#ifdef CONFIG_HAVE_HW_BREAKPOINT +#ifdef CONFIG_HW_BREAKPOINT case PTRACE_GETHBPREGS : ret =ptrace_gethbpregs (child, addr, (unsigned long __user *)data);
arch/powerpc/include/asm/cputable.h +2 -2
@@ -538,9 +538,9 @@ static inline int cpu_has_feature(unsigned long feature) & feature); } -#ifdef CONFIG_HAVE_HW_BREAKPOINT +#ifdef CONFIG_HW_BREAKPOINT #define HBP_NUM 1 -#endif /* CONFIG_HAVE_HW_BREAKPOINT */ +#endif /* CONFIG_HW_BREAKPOINT */ #endif /* !__ASSEMBLY__ */
arch/powerpc/include/asm/hw_breakpoint.h +3 -3
@@ -24,7 +24,7 @@#define _PPC_BOOK3S_64_HW_BREAKPOINT_H #ifdef __KERNEL__ -#ifdef CONFIG_HAVE_HW_BREAKPOINT +#ifdef CONFIG_HW_BREAKPOINT struct arch_hw_breakpoint { bool extraneous_interrupt;
@@ -65,10 +65,10 @@ static inline void hw_breakpoint_disable(void) }extern void thread_change_pc (struct task_struct *tsk,struct pt_regs *regs); -#else /* CONFIG_HAVE_HW_BREAKPOINT */ +#else /* CONFIG_HW_BREAKPOINT */ static inline void hw_breakpoint_disable (void ) { }static inline void thread_change_pc (struct task_struct *tsk,struct pt_regs *regs) { } -#endif /* CONFIG_HAVE_HW_BREAKPOINT */ +#endif /* CONFIG_HW_BREAKPOINT */ #endif /* __KERNEL__ */ #endif /* _PPC_BOOK3S_64_HW_BREAKPOINT_H */
arch/powerpc/include/asm/processor.h +2 -2
@@ -207,14 +207,14 @@ 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 */ -#ifdef CONFIG_HAVE_HW_BREAKPOINT +#ifdef CONFIG_HW_BREAKPOINT struct perf_event *ptrace_bps[HBP_NUM ];/* * Helps identify source of single-step exception and subsequent * hw-breakpoint enablement */ struct perf_event *last_hit_ubp; -#endif /* CONFIG_HAVE_HW_BREAKPOINT */ +#endif /* CONFIG_HW_BREAKPOINT */ #endif unsigned long dabr;/* Data address breakpoint register */ #ifdef CONFIG_ALTIVEC
arch/powerpc/kernel/Makefile +1 -1
@@ -36,7 +36,7 @@ obj-y := cputable.o ptrace.o syscalls.o \ obj-$(CONFIG_PPC64) += setup_64.o sys_ppc32.o \ signal_64.o ptrace32.o \ paca.o nvram_64.o firmware.o -obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o +obj-$(CONFIG_HW_BREAKPOINT) += hw_breakpoint.o obj-$(CONFIG_PPC_BOOK3S_64) += cpu_setup_ppc970.o cpu_setup_pa6t.o obj64-$(CONFIG_RELOCATABLE) += reloc_64.o obj-$(CONFIG_PPC_BOOK3E_64) += exceptions-64e.o idle_book3e.o
arch/powerpc/kernel/process.c +9 -9
@@ -353,7 +353,7 @@ static void switch_booke_debug_regs(struct thread_struct *new_thread) prime_debug_regs(new_thread); } #else /* !CONFIG_PPC_ADV_DEBUG_REGS */ -#ifndef CONFIG_HAVE_HW_BREAKPOINT +#ifndef CONFIG_HW_BREAKPOINT static void set_debug_reg_defaults(struct thread_struct *thread) { if (thread->dabr) {
@@ -361,7 +361,7 @@ static void set_debug_reg_defaults(struct thread_struct *thread)set_dabr (0 ); } } -#endif /* !CONFIG_HAVE_HW_BREAKPOINT */ +#endif /* !CONFIG_HW_BREAKPOINT */ #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ int set_dabr (unsigned long dabr)
@@ -469,10 +469,10 @@ struct task_struct *__switch_to(struct task_struct *prev,* For PPC_BOOK3S_64, we use the hw-breakpoint interfaces that would * schedule DABR */ -#ifndef CONFIG_HAVE_HW_BREAKPOINT +#ifndef CONFIG_HW_BREAKPOINT if (unlikely (__get_cpu_var (current_dabr) != new->thread.dabr))set_dabr (new->thread.dabr); -#endif /* CONFIG_HAVE_HW_BREAKPOINT */ +#endif /* CONFIG_HW_BREAKPOINT */ #endif
@@ -672,11 +672,11 @@ void flush_thread(void) {discard_lazy_cpu_state (); -#ifdef CONFIG_HAVE_HW_BREAKPOINT +#ifdef CONFIG_HW_BREAKPOINT flush_ptrace_hw_breakpoint (current); -#else /* CONFIG_HAVE_HW_BREAKPOINT */ +#else /* CONFIG_HW_BREAKPOINT */ set_debug_reg_defaults (¤t->thread); -#endif /* CONFIG_HAVE_HW_BREAKPOINT */ +#endif /* CONFIG_HW_BREAKPOINT */ }void
@@ -694,9 +694,9 @@ void prepare_to_copy(struct task_struct *tsk)flush_altivec_to_thread (current);flush_vsx_to_thread (current);flush_spe_to_thread (current); -#ifdef CONFIG_HAVE_HW_BREAKPOINT +#ifdef CONFIG_HW_BREAKPOINT flush_ptrace_hw_breakpoint (tsk); -#endif /* CONFIG_HAVE_HW_BREAKPOINT */ +#endif /* CONFIG_HW_BREAKPOINT */ }/*
arch/powerpc/kernel/ptrace.c +6 -6
@@ -877,7 +877,7 @@ void user_disable_single_step(struct task_struct *task)clear_tsk_thread_flag (task,TIF_SINGLESTEP ); } -#ifdef CONFIG_HAVE_HW_BREAKPOINT +#ifdef CONFIG_HW_BREAKPOINT void ptrace_triggered (struct perf_event *bp,int nmi,struct perf_sample_data *data,struct pt_regs *regs) {
@@ -893,17 +893,17 @@ void ptrace_triggered(struct perf_event *bp, int nmi, attr.disabled = true; modify_user_hw_breakpoint(bp, &attr); } -#endif /* CONFIG_HAVE_HW_BREAKPOINT */ +#endif /* CONFIG_HW_BREAKPOINT */ int ptrace_set_debugreg (struct task_struct *task,unsigned long addr,unsigned long data) { -#ifdef CONFIG_HAVE_HW_BREAKPOINT +#ifdef CONFIG_HW_BREAKPOINT int ret;struct thread_struct *thread = &(task->thread);struct perf_event *bp;struct perf_event_attr attr; -#endif /* CONFIG_HAVE_HW_BREAKPOINT */ +#endif /* CONFIG_HW_BREAKPOINT */ /* 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
@@ -932,7 +932,7 @@ int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,/* Ensure breakpoint translation bit is set */ if (data && !(data &DABR_TRANSLATION ))return -EIO ; -#ifdef CONFIG_HAVE_HW_BREAKPOINT +#ifdef CONFIG_HW_BREAKPOINT bp = thread->ptrace_bps[0 ];if ((!data) || !(data & (DABR_DATA_WRITE |DABR_DATA_READ ))) {if (bp) {
@@ -968,7 +968,7 @@ int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, return PTR_ERR(bp); } -#endif /* CONFIG_HAVE_HW_BREAKPOINT */ +#endif /* CONFIG_HW_BREAKPOINT */ /* Move contents to the DABR register */ task->thread.dabr = data;
arch/powerpc/lib/Makefile +1 -1
@@ -19,7 +19,7 @@ obj-$(CONFIG_PPC64) += copypage_64.o copyuser_64.o \ checksum_wrappers_64.o hweight_64.o obj-$(CONFIG_XMON) += sstep.o ldstfp.o obj-$(CONFIG_KPROBES) += sstep.o ldstfp.o -obj-$(CONFIG_HAVE_HW_BREAKPOINT) += sstep.o ldstfp.o +obj-$(CONFIG_HW_BREAKPOINT) += sstep.o ldstfp.o ifeq ($(CONFIG_PPC64),y) obj-$(CONFIG_SMP) += locks.o
arch/sh/kernel/Makefile +1 -1
@@ -45,7 +45,7 @@ obj-$(CONFIG_HIBERNATION) += swsusp.o obj-$(CONFIG_DWARF_UNWINDER) += dwarf.o obj-$(CONFIG_PERF_EVENTS) += perf_event.o perf_callchain.o -obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o +obj-$(CONFIG_HW_BREAKPOINT) += hw_breakpoint.o obj-$(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) += localtimer.o ccflags-y := -Werror
arch/sh/kernel/cpu/sh4a/Makefile +1 -1
@@ -46,4 +46,4 @@ obj-y += $(clock-y) obj-$(CONFIG_SMP) += $(smp-y) obj-$(CONFIG_GENERIC_GPIO) += $(pinmux-y) obj-$(CONFIG_PERF_EVENTS) += perf_event.o -obj-$(CONFIG_HAVE_HW_BREAKPOINT) += ubc.o +obj-$(CONFIG_HW_BREAKPOINT) += ubc.o
include/linux/hw_breakpoint.h +3 -3
@@ -31,7 +31,7 @@ enum bp_type_idx {#include <linux/perf_event.h> -#ifdef CONFIG_HAVE_HW_BREAKPOINT +#ifdef CONFIG_HW_BREAKPOINT extern int __init init_hw_breakpoint (void );
@@ -108,7 +108,7 @@ static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp) return &bp->hw.info; } -#else /* !CONFIG_HAVE_HW_BREAKPOINT */ +#else /* !CONFIG_HW_BREAKPOINT */ static inline int __init init_hw_breakpoint (void ) {return 0 ; }
@@ -144,7 +144,7 @@ static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)return NULL ; } -#endif /* CONFIG_HAVE_HW_BREAKPOINT */ +#endif /* CONFIG_HW_BREAKPOINT */ #endif /* __KERNEL__ */ #endif /* _LINUX_HW_BREAKPOINT_H */
include/linux/perf_event.h +2 -2
@@ -489,7 +489,7 @@ struct perf_guest_info_callbacks {unsigned long (*get_guest_ip) (void ); }; -#ifdef CONFIG_HAVE_HW_BREAKPOINT +#ifdef CONFIG_HW_BREAKPOINT #include <asm/hw_breakpoint.h> #endif
@@ -554,7 +554,7 @@ struct hw_perf_event {struct {/* software */ struct hrtimer hrtimer; }; -#ifdef CONFIG_HAVE_HW_BREAKPOINT +#ifdef CONFIG_HW_BREAKPOINT struct { /* breakpoint */ struct arch_hw_breakpoint info; struct list_head bp_list;
kernel/Makefile +1 -1
@@ -104,7 +104,7 @@ obj-$(CONFIG_TRACEPOINTS) += trace/ obj-$(CONFIG_SMP) += sched_cpupri.o obj-$(CONFIG_IRQ_WORK) += irq_work.o obj-$(CONFIG_PERF_EVENTS) += perf_event.o -obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o +obj-$(CONFIG_HW_BREAKPOINT) += hw_breakpoint.o obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o obj-$(CONFIG_PADATA) += padata.o obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
kernel/perf_event.c +2 -2
@@ -5616,7 +5616,7 @@ static void perf_event_free_filter(struct perf_event *event)#endif /* CONFIG_EVENT_TRACING */ -#ifdef CONFIG_HAVE_HW_BREAKPOINT +#ifdef CONFIG_HW_BREAKPOINT void perf_bp_event (struct perf_event *bp,void *data) {struct perf_sample_data sample;
@@ -6207,7 +6207,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,if (task) { event->attach_state =PERF_ATTACH_TASK ; -#ifdef CONFIG_HAVE_HW_BREAKPOINT +#ifdef CONFIG_HW_BREAKPOINT /* * hw_breakpoint is a bit difficult here.. */
samples/Kconfig +1 -1
@@ -40,7 +40,7 @@ config SAMPLE_KRETPROBES config SAMPLE_HW_BREAKPOINT tristate "Build kernel hardware breakpoint examples -- loadable module only" - depends on HAVE_HW_BREAKPOINT && m + depends on HW_BREAKPOINT && m help This builds kernel hardware breakpoint example modules.
Signature · 1 line
1.7.3.2
PATCH 5/6 hw_breakpoints: Only force perf events if breakpoints are selected
In reply to Frederic WeisbeckerPreviously, arch were forced to always build perf events if they supported hw_breakpoints.
Now that the user can choose not to build hw_breakpoints, let only force perf events if hw_breakpoints are selected.
--- arch/sh/Kconfig | 1 - arch/x86/Kconfig | 1 - init/Kconfig | 1 + 3 files changed, 1 insertions(+), 2 deletions(-)
arch/sh/Kconfig +0 -1
@@ -46,7 +46,6 @@ config SUPERH32 select HAVE_HW_BREAKPOINT select HW_BREAKPOINT select HAVE_MIXED_BREAKPOINTS_REGS - select PERF_EVENTS select ARCH_HIBERNATION_POSSIBLE if MMU select SPARSE_IRQ
arch/x86/Kconfig +0 -1
@@ -55,7 +55,6 @@ config X86 select HAVE_KERNEL_LZO select HAVE_HW_BREAKPOINT select HAVE_MIXED_BREAKPOINTS_REGS - select PERF_EVENTS select HAVE_PERF_EVENTS_NMI select ANON_INODES select HAVE_ARCH_KMEMCHECK
init/Kconfig +1 -0
@@ -927,6 +927,7 @@ menuconfig EXPERT config HW_BREAKPOINT bool "Hardware breakpoints" if EXPERT depends on HAVE_HW_BREAKPOINT + select PERF_EVENTS default y help Hardware breakpoints are a feature implemented by most CPUs
Signature · 1 line
1.7.3.2
PATCH 6/6 hw_breakpoints: Drop remaining misplaced dependency on perf
In reply to Frederic WeisbeckerPowerpc and Arm select breakpoint support ability only if Perf is built. This is not necessary anymore now that we enable perf once breakpoints support is selected.
--- arch/arm/Kconfig | 2 +- arch/powerpc/Kconfig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/Kconfig +1 -1
@@ -24,7 +24,7 @@ config ARM select HAVE_PERF_EVENTS select PERF_USE_VMALLOC select HAVE_REGS_AND_STACK_ACCESS_API - select HAVE_HW_BREAKPOINT if (PERF_EVENTS && (CPU_V6 || CPU_V6K || CPU_V7)) + select HAVE_HW_BREAKPOINT if (CPU_V6 || CPU_V6K || CPU_V7) select HAVE_C_RECORDMCOUNT select HAVE_GENERIC_HARDIRQS select HAVE_SPARSE_IRQ
arch/powerpc/Kconfig +1 -1
@@ -134,7 +134,7 @@ config PPC select HAVE_IRQ_WORK select HAVE_PERF_EVENTS select HAVE_REGS_AND_STACK_ACCESS_API - select HAVE_HW_BREAKPOINT if PERF_EVENTS && PPC_BOOK3S_64 + select HAVE_HW_BREAKPOINT if PPC_BOOK3S_64 select HAVE_GENERIC_HARDIRQS select HAVE_SPARSE_IRQ select IRQ_PER_CPU
Signature · 1 line
1.7.3.2
PATCH 4/6 hw_breakpoints: Breakpoints arch ability don't need perf events
In reply to Frederic WeisbeckerThe breakpoint support ability in an arch is not related to the fact perf events is built or not. HAVE_HW_BREAKPOINT only shows an ability so this dependency makes no sense anymore. Archs that select HAVE_HW_BREAKPOINT already ensure that perf event is built.
Remove that dependency.
--- arch/Kconfig | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
arch/Kconfig +0 -1
@@ -149,7 +149,6 @@ config HAVE_DEFAULT_NO_SPIN_MUTEXES config HAVE_HW_BREAKPOINT bool - depends on PERF_EVENTS config HAVE_MIXED_BREAKPOINTS_REGS bool
Signature · 1 line
1.7.3.2
PATCH 3/6 x86: Allow the user not to build hw_breakpoints
In reply to Frederic WeisbeckerSo that hw_breakpoints and perf can be not built on specific embedded systems.
--- arch/x86/Kconfig | 3 +-- arch/x86/include/asm/debugreg.h | 33 +++++++++++++++++++++++++++++++-- arch/x86/kernel/Makefile | 3 ++- arch/x86/kernel/process.c | 1 + arch/x86/kernel/ptrace.c | 17 +++++++++++++++++ 5 files changed, 52 insertions(+), 5 deletions(-)
arch/x86/Kconfig +1 -2
@@ -41,7 +41,7 @@ config X86 select HAVE_FTRACE_NMI_ENTER if DYNAMIC_FTRACE select HAVE_SYSCALL_TRACEPOINTS select HAVE_KVM - select HAVE_ARCH_KGDB + select HAVE_ARCH_KGDB if HW_BREAKPOINT select HAVE_ARCH_TRACEHOOK select HAVE_GENERIC_DMA_COHERENT if X86_32 select HAVE_EFFICIENT_UNALIGNED_ACCESS
@@ -54,7 +54,6 @@ config X86 select HAVE_KERNEL_XZ select HAVE_KERNEL_LZO select HAVE_HW_BREAKPOINT - select HW_BREAKPOINT select HAVE_MIXED_BREAKPOINTS_REGS select PERF_EVENTS select HAVE_PERF_EVENTS_NMI
arch/x86/include/asm/debugreg.h +31 -2
@@ -78,8 +78,6 @@*/ #ifdef __KERNEL__ -DECLARE_PER_CPU(unsigned long, cpu_dr7); -static inline void hw_breakpoint_disable (void ) {/* Zero the control register for HW Breakpoint */
@@ -92,6 +90,10 @@ static inline void hw_breakpoint_disable(void)set_debugreg (0UL ,3 ); } +#ifdef CONFIG_HW_BREAKPOINT + +DECLARE_PER_CPU(unsigned long, cpu_dr7); +static inline int hw_breakpoint_active (void ) {return __this_cpu_read (cpu_dr7) &DR_GLOBAL_ENABLE_MASK ;
@@ -100,6 +102,33 @@ static inline int hw_breakpoint_active(void)extern void aout_dump_debugregs (struct user *dump);extern void hw_breakpoint_restore (void ); +#else +static inline int hw_breakpoint_active (void ) +{ +return 0 ; +} + +static inline void hw_breakpoint_restore (void ) +{ +set_debugreg (0UL ,0 ); +set_debugreg (0UL ,1 ); +set_debugreg (0UL ,2 ); +set_debugreg (0UL ,3 ); +set_debugreg (current->thread.debugreg6,6 ); +set_debugreg (0UL ,7 ); +} + +static inline void aout_dump_debugregs (struct user *dump) +{ +int i; + +for (i =0 ; i <6 ; i++) + dump->u_debugreg[i] =0 ; + + dump->u_debugreg[6 ] = current->thread.debugreg6; + dump->u_debugreg[7 ] =0 ; +} +#endif /* CONFIG_HW_BREAKPOINT */ #endif /* __KERNEL__ */
arch/x86/kernel/Makefile +2 -1
@@ -42,7 +42,7 @@ obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o obj-$(CONFIG_X86_64) += syscall_64.o vsyscall_64.o obj-y += bootflag.o e820.o obj-y += pci-dma.o quirks.o topology.o kdebugfs.o -obj-y += alternative.o i8253.o pci-nommu.o hw_breakpoint.o +obj-y += alternative.o i8253.o pci-nommu.o obj-y += tsc.o io_delay.o rtc.o obj-y += pci-iommu_table.o obj-y += resource.o
@@ -51,6 +51,7 @@ obj-y += trampoline.o trampoline_$(BITS).o obj-y += process.o obj-y += i387.o xsave.o obj-y += ptrace.o +obj-$(CONFIG_HW_BREAKPOINT) += hw_breakpoint.o obj-$(CONFIG_X86_32) += tls.o obj-$(CONFIG_IA32_EMULATION) += tls.o obj-y += step.o
arch/x86/kernel/process.c +1 -0
@@ -22,6 +22,7 @@#include <asm/uaccess.h> #include <asm/i387.h> #include <asm/debugreg.h> +#include <asm/kdebug.h> struct kmem_cache *task_xstate_cachep;EXPORT_SYMBOL_GPL (task_xstate_cachep);
arch/x86/kernel/ptrace.c +17 -0
@@ -528,6 +528,7 @@ static int genregs_set(struct task_struct *target,return ret; } +#ifdef CONFIG_HW_BREAKPOINT static void ptrace_triggered (struct perf_event *bp,int nmi,struct perf_sample_data *data,struct pt_regs *regs)
@@ -761,6 +762,22 @@ ret_path: return rc; } +#else /* !CONFIG_HW_BREAKPOINT */ + +static inline unsigned long +ptrace_get_debugreg (struct task_struct *tsk,int n) +{ +return -ENOSYS ; +} + +static inline +int ptrace_set_debugreg (struct task_struct *tsk,int n,unsigned long val) +{ +return -ENOSYS ; +} + +#endif /* CONFIG_HW_BREAKPOINT */ +/* * These access the current or another (stopped) task's io permission * bitmap for debugging or core dump.
Signature · 1 line
1.7.3.2
PATCH 1/6 hw_breakpoints: Split hardware breakpoints config
In reply to Frederic WeisbeckerThe hardware breakpoint config is only made of an ability. An arch that support this feature selects HAVE_HW_BREAKPOINT. If so, the feature is definetly built-in, the user can't decide to turn it off. As hw_breakpoints depend on perf, it also makes perf a mandatory feature. The whole is quite a piece of code and may not be desired on some embedded systems.
In order to prepare to make this optable by the user, split the config into the more traditional couple (ability, user choice) by providing a new HW_BREAKPOINT config. It is default on and depends on CONFIG_EXPERT because breakpoint ptrace requests are part of the usual user ABI. The user must know what he's doing before turning that off.
For now, only the archs that already implemented a conditional HAVE_HW_BREAKPOINT can turn off HW_BREAKPOINT. x86 and sh have it always selected because they need more background work to support this new modularity.
--- arch/sh/Kconfig | 1 + arch/x86/Kconfig | 1 + init/Kconfig | 10 ++++++++++ 3 files changed, 12 insertions(+), 0 deletions(-)
arch/sh/Kconfig +1 -0
@@ -44,6 +44,7 @@ config SUPERH32 select HAVE_FUNCTION_GRAPH_TRACER select HAVE_ARCH_KGDB select HAVE_HW_BREAKPOINT + select HW_BREAKPOINT select HAVE_MIXED_BREAKPOINTS_REGS select PERF_EVENTS select ARCH_HIBERNATION_POSSIBLE if MMU
arch/x86/Kconfig +1 -0
@@ -54,6 +54,7 @@ config X86 select HAVE_KERNEL_XZ select HAVE_KERNEL_LZO select HAVE_HW_BREAKPOINT + select HW_BREAKPOINT select HAVE_MIXED_BREAKPOINTS_REGS select PERF_EVENTS select HAVE_PERF_EVENTS_NMI
init/Kconfig +10 -0
@@ -924,6 +924,16 @@ menuconfig EXPERT environments which can tolerate a "non-standard" kernel. Only use this if you really know what you are doing. +config HW_BREAKPOINT + bool "Hardware breakpoints" if EXPERT + depends on HAVE_HW_BREAKPOINT + default y + help + Hardware breakpoints are a feature implemented by most CPUs + to trigger an event when an instruction or data fetch + matches a given pattern. This is typically used by ptrace + and perf events. + config EMBEDDED bool "Embedded system" select EXPERT
Signature · 1 line
1.7.3.2
Quoted 11 lines · Frederic Weisbecker
Hi,
Until now, x86 and superh32 had to always build
hw_breakpointand perf. And powerpc and arm were always buildinghw_breakpointswhen perf was enabled.After this patchset, one can simply disable
hw_breakpointsif he selectedCONFIG_EXPERT. Afterward the user is free to select perf or not. Except on SH unfortunately because that would require a bit of change in ptrace to support singlestep failures.
Quoted 7 lines
Frederic Weisbecker (6):
hw_breakpoints: Split hardware breakpoints config
hw_breakpoints: Migrate breakpoint conditional build under new config
x86: Allow the user not to buildhw_breakpoints
hw_breakpoints: Breakpoints arch ability don't need perf events
hw_breakpoints: Only force perf events if breakpoints are selected
hw_breakpoints: Drop remaining misplaced dependency on perf
Ah, and every !x86 archs touched by this patchset have been compile tested only.
H. Peter Anvin
reviewerRe: [PATCH 3/6] x86: Allow the user not to build hw_breakpoints
In reply to Frederic WeisbeckerQuoted 2 lines · Frederic Weisbecker
So that
hw_breakpointsand perf can be not built on specific embedded systems.
How big of a win, if any, is this, really?
-hpa
Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
Re: [PATCH 3/6] x86: Allow the user not to build hw_breakpoints
Quoted 7 lines · H. Peter Anvin
Quoted 2 lines · Frederic Weisbecker
So that
hw_breakpointsand perf can be not built on specific embedded systems.How big of a win, if any, is this, really?
-hpa
That's pretty significant, because if you can disable breakpoints, then you can disable perf. Together they make quite a chunk.
breakpoints + perf:
text data bss dec hex filename
1567422 348628 511680 2427730 250b52 vmlinux
none:
text data bss dec hex filename
1478031 333220 508256 2319507 236493 vmlinux
Re: [PATCH 3/6] x86: Allow the user not to build hw_breakpoints
Quoted 6 lines · Frederic Weisbecker
Quoted 2 lines · H. Peter Anvin
How big of a win, if any, is this, really?
That's pretty significant, because if you can disable breakpoints, then you can disable perf. Together they make quite a chunk.
Another advantage is the ability to disable these features for kernel bringup on new targets and kernel versions. Recently in v2.6.38 hw_breakpoints were broken in ARM. A change like this would have saved me a hack to the Kconfig at the least.
Mike
Signature · 2 lines
Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
Re: [PATCH 3/6] x86: Allow the user not to build hw_breakpoints
In reply to a message not in the archiveQuoted 1 line · H. Peter Anvin
Why do you have to be able to disable breakpoints to disable perf? That seems seriously backwards, especially since we had breakpoints long before perf...
That started when we implemented breakpoints as counters. Then we realized that ptrace had its own scheduling that was somehow duplicating what perf was doing. So we have finally unified that under perf. The good point is that archs don't need to care much about ptrace breakpoints tracking, just the interface.
But yeah the bad point is that dependency.
Quoted 1 line · Frederic Weisbecker
Hi,
Hi Frederic,
Quoted 8 lines
Until now, x86 and superh32 had to always build
hw_breakpointand perf. And powerpc and arm were always buildinghw_breakpointswhen perf was enabled.After this patchset, one can simply disable
hw_breakpointsif he selectedCONFIG_EXPERT. Afterward the user is free to select perf or not. Except on SH unfortunately because that would require a bit of change in ptrace to support singlestep failures.
For the ARM bits:
Cheers,
Will
H. Peter Anvin
reviewerRe: [PATCH 3/6] x86: Allow the user not to build hw_breakpoints
In reply to Frederic WeisbeckerQuoted 9 lines · Frederic Weisbecker
Quoted 1 line · H. Peter Anvin
Why do you have to be able to disable breakpoints to disable perf? That seems seriously backwards, especially since we had breakpoints long before perf...
That started when we implemented breakpoints as counters. Then we realized that ptrace had its own scheduling that was somehow duplicating what perf was doing. So we have finally unified that under perf. The good point is that archs don't need to care much about ptrace breakpoints tracking, just the interface.
But yeah the bad point is that dependency.
It really is very bad... without breakpoints, you lose almost all debugging support.
-hpa
Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
Re: [PATCH 3/6] x86: Allow the user not to build hw_breakpoints
Quoted 9 lines · H. Peter Anvin
Quoted 8 lines · Frederic Weisbecker
Quoted 1 line · H. Peter Anvin
Why do you have to be able to disable breakpoints to disable perf? That seems seriously backwards, especially since we had breakpoints long before perf...
That started when we implemented breakpoints as counters. Then we realized that ptrace had its own scheduling that was somehow duplicating what perf was doing. So we have finally unified that under perf. The good point is that archs don't need to care much about ptrace breakpoints tracking, just the interface.
Quoted 4 lines
Quoted 1 line
But yeah the bad point is that dependency.
It really is very bad... without breakpoints, you lose almost all debugging support.
Right, so it should be fine for embedded environment to disable breakpoints. It depends on CONFIG_EXPERT now.
H. Peter Anvin
reviewerRe: [PATCH 3/6] x86: Allow the user not to build hw_breakpoints
Quoted 6 lines · Frederic Weisbecker
Quoted 3 lines
It really is very bad... without breakpoints, you lose almost all debugging support.
Right, so it should be fine for embedded environment to disable breakpoints. It depends on
CONFIG_EXPERTnow.
Uh... even embedded environments need to be able to debug.
-hpa
Re: [PATCH 3/6] x86: Allow the user not to build hw_breakpoints
Quoted 9 lines · H. Peter Anvin
Quoted 6 lines · Frederic Weisbecker
Quoted 3 lines
It really is very bad... without breakpoints, you lose almost all debugging support.
Right, so it should be fine for embedded environment to disable breakpoints. It depends on
CONFIG_EXPERTnow.Uh... even embedded environments need to be able to debug.
For development yeah, but is it needed for production evironments?
May be sometimes. But even though, the main functionalities of ptrace are still available since instruction breakpoints are implemented through int3 and not debugreg in ptrace. Only data breakpoints would be unusable, but I believe they are a minor use compared to instruction breakpoints. I rarely make use of them for debugging personally.
That's really deemed for specific cases where people know what they are doing.
H. Peter Anvin
reviewerRe: [PATCH 3/6] x86: Allow the user not to build hw_breakpoints
Quoted 6 lines · Frederic Weisbecker
Quoted 5 lines · H. Peter Anvin
Quoted 4 lines · Frederic Weisbecker
Quoted 3 lines
It really is very bad... without breakpoints, you lose almost all debugging support.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Right, so it should be fine for embedded environment to disable breakpoints. It depends on
CONFIG_EXPERTnow.Uh... even embedded environments need to be able to debug.
For development yeah, but is it needed for production evironments?
Most of the time people don't want to debug something other than they're going to ship.
-hpa
Re: [PATCH 3/6] x86: Allow the user not to build hw_breakpoints
Quoted 10 lines · H. Peter Anvin
Quoted 9 lines · Frederic Weisbecker
Quoted 8 lines · H. Peter Anvin
Quoted 6 lines · Frederic Weisbecker
Quoted 3 lines
It really is very bad... without breakpoints, you lose almost all debugging support.
Right, so it should be fine for embedded environment to disable breakpoints. It depends on
CONFIG_EXPERTnow.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Uh... even embedded environments need to be able to debug.
For development yeah, but is it needed for production evironments?
Most of the time people don't want to debug something other than they're going to ship.
Well, it's like systems that don't care about having BUG(), sysctl, futexes, etc... support in the kernel, or whatever standard feature that makes sense most of the time but sometimes you simply don't need it.
Also consider that as a first step to be able to build a !CONFIG_PERF_EVENTS kernel. If people show strong interest in beeing able to build a kernel with breakpoints but without perf events, then I'll invest more efforts in breaking the dependency.