Skip to content

Commit

Permalink
hw-breakpoints: ftrace plugin for kernel symbol tracing using HW Brea…
Browse files Browse the repository at this point in the history
…kpoint interfaces

This patch adds an ftrace plugin to detect and profile memory access over kernel
variables. It uses HW Breakpoint interfaces to 'watch memory addresses.

Signed-off-by: K.Prasad <prasad@linux.vnet.ibm.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
  • Loading branch information
K.Prasad authored and Frederic Weisbecker committed Jun 2, 2009
1 parent 4320399 commit 0722db0
Show file tree
Hide file tree
Showing 5 changed files with 623 additions and 0 deletions.
21 changes: 21 additions & 0 deletions kernel/trace/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,27 @@ config POWER_TRACER
power management decisions, specifically the C-state and P-state
behavior.

config KSYM_TRACER
bool "Trace read and write access on kernel memory locations"
depends on HAVE_HW_BREAKPOINT
select TRACING
help
This tracer helps find read and write operations on any given kernel
symbol i.e. /proc/kallsyms.

config PROFILE_KSYM_TRACER
bool "Profile all kernel memory accesses on 'watched' variables"
depends on KSYM_TRACER
help
This tracer profiles kernel accesses on variables watched through the
ksym tracer ftrace plugin. Depending upon the hardware, all read
and write operations on kernel variables can be monitored for
accesses.

The results will be displayed in:
/debugfs/tracing/profile_ksym

Say N if unsure.

config STACK_TRACER
bool "Trace max stack"
Expand Down
1 change: 1 addition & 0 deletions kernel/trace/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ obj-$(CONFIG_EVENT_TRACING) += trace_export.o
obj-$(CONFIG_FTRACE_SYSCALLS) += trace_syscalls.o
obj-$(CONFIG_EVENT_PROFILE) += trace_event_profile.o
obj-$(CONFIG_EVENT_TRACING) += trace_events_filter.o
obj-$(CONFIG_KSYM_TRACER) += trace_ksym.o

libftrace-y := ftrace.o
23 changes: 23 additions & 0 deletions kernel/trace/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include <linux/trace_seq.h>
#include <linux/ftrace_event.h>

#ifdef CONFIG_KSYM_TRACER
#include <asm/hw_breakpoint.h>
#endif

enum trace_type {
__TRACE_FIRST_TYPE = 0,

Expand All @@ -40,6 +44,7 @@ enum trace_type {
TRACE_KMEM_FREE,
TRACE_POWER,
TRACE_BLK,
TRACE_KSYM,

__TRACE_LAST_TYPE,
};
Expand Down Expand Up @@ -207,6 +212,21 @@ struct syscall_trace_exit {
unsigned long ret;
};

#define KSYM_SELFTEST_ENTRY "ksym_selftest_dummy"
extern int process_new_ksym_entry(char *ksymname, int op, unsigned long addr);

struct trace_ksym {
struct trace_entry ent;
struct hw_breakpoint *ksym_hbp;
unsigned long ksym_addr;
unsigned long ip;
#ifdef CONFIG_PROFILE_KSYM_TRACER
unsigned long counter;
#endif
struct hlist_node ksym_hlist;
char ksym_name[KSYM_NAME_LEN];
char p_name[TASK_COMM_LEN];
};

/*
* trace_flag_type is an enumeration that holds different
Expand Down Expand Up @@ -323,6 +343,7 @@ extern void __ftrace_bad_type(void);
TRACE_SYSCALL_ENTER); \
IF_ASSIGN(var, ent, struct syscall_trace_exit, \
TRACE_SYSCALL_EXIT); \
IF_ASSIGN(var, ent, struct trace_ksym, TRACE_KSYM); \
__ftrace_bad_type(); \
} while (0)

Expand Down Expand Up @@ -540,6 +561,8 @@ extern int trace_selftest_startup_branch(struct tracer *trace,
struct trace_array *tr);
extern int trace_selftest_startup_hw_branches(struct tracer *trace,
struct trace_array *tr);
extern int trace_selftest_startup_ksym(struct tracer *trace,
struct trace_array *tr);
#endif /* CONFIG_FTRACE_STARTUP_TEST */

extern void *head_page(struct trace_array_cpu *data);
Expand Down
Loading

0 comments on commit 0722db0

Please sign in to comment.