Skip to content

Hardware Breakpoint interfaces

K.Prasad lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest10 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/10Introducing generic hardware breakpoint handler interfacesinclude/asm-generic/hw_breakpoint.h kernel/hw_breakpoint.c+951 -00 replies
2/10x86 architecture implementation of Hardware Breakpoint interfacesarch/x86/kernel/Makefile arch/x86/kernel/hw_breakpoint.c include/asm-x86/hw_breakpoint.h+600 -10 replies
3/10Modifying generic debug exception to use virtual debug registersarch/x86/kernel/traps.c+24 -420 replies
4/10Introduce virtual debug register in thread_struct and wrapper-routines around process related functionsarch/x86/include/asm/debugreg.h arch/x86/include/asm/processor.h+30 -70 replies
5/10Use wrapper routines around debug registers in processor related functionsarch/x86/kernel/smpboot.c arch/x86/power/cpu_32.c arch/x86/power/cpu_64.c+9 -250 replies
6/10Use virtual debug registers in process/thread handling codearch/x86/kernel/process_32.c arch/x86/kernel/process_64.c+49 -350 replies
7/10Modify signal handling code to refrain from re-enabling HW Breakpointsarch/x86/kernel/signal.c+0 -90 replies
8/10Modify Ptrace routines to access breakpoint registersarch/x86/kernel/ptrace.c+152 -760 replies
9/10Cleanup HW Breakpoint registers before kexecarch/x86/kernel/machine_kexec_32.c arch/x86/kernel/machine_kexec_64.c+4 -00 replies
10/10Sample HW breakpoint over kernel data addresssamples/Kconfig samples/Makefile samples/hw_breakpoint/Makefile +1 more+89 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [Patch 0/10] Hardware Breakpoint interfaces

Hi Andrew and all,
Please find the patches that introduce interfaces to access
Hardware Breakpoint (or watchpoint) registers and an arch-specific implementation for x86/x86_64 architecture. Can you consider them for inclusion in -mm tree?

A short description of the framework and interfaces is provided below. Some of the details will be specific to x86/x86_64 architecture and may vary depending upon the support provided by the target processor.

Description
------------

The Hardware Breakpoint registers can be used for tracing changes to a variable or data location (even I/O ports in x86/x86_64) and will be extremely helpful in debugging problems such as memory corruption. While these registers have been used by user-space debuggers for long (through 'ptrace' syscalls), KGDB exploited them for kernel-space addresses.

The proposed framework, introduces interfaces to use them directly on both user- and kernel-space addresses apart from arbitrating requests from various such users for the limited number of registers.

The interfaces are:

int register_kernel_hw_breakpoint(struct hw_breakpoint *); void unregister_kernel_hw_breakpoint(struct hw_breakpoint *bp);

int register_user_hw_breakpoint(struct task_struct *tsk,

                                 struct hw_breakpoint *bp);
void unregister_user_hw_breakpoint(struct task_struct *tsk,
                struct hw_breakpoint *bp);

The 'struct hw_breakpoint' will be the anchor data-structure containing all the necessary information such as name or address, type, length, priority and pointers to handler functions (some of which are arch-specific). More information about the role of each field, the handler functions and their return values can be found in the descriptive comments preceding these functions and in "include/asm-generic/hw_breakpoint.h".

While (un)register_user_hw_breakpoint() isn't exported yet, its worker-routine __register_user-hw_breakpoint() is used by ptrace syscall for all breakpoint register requirements. For the kernel-space, a simple use case to trace 'write' operations on a kernel variable can be found in samples/hw_breakpoint/data_breakpoint.c.

In the current patchset, support is provided only for read and read-write breakpoints on data locations, which can be later expand to include instruction and I/O breakpoints for x86/x86_64.

The patches are based on 2.6.29-rc2 and have been tested on an x86 machine along with concurrent sessions of a kprobe-module and a GDB session using HW breakpoints on the target program.

There is pending integration with 'KGDB' without which mutual exclusion between them (KGDB and HW breakpoint use through above interfaces) needs to be observed.

Several enhancements including support for more architectures and types of breakpoints are contemplated in the revisions to come.

Let me know your thoughts on this.

Thanks,
K.Prasad