Skip to content

Commit 69e4908

Browse files
ahunter6Peter Zijlstra
authored andcommitted
kprobes: Add perf ksymbol events for kprobe insn pages
Symbols are needed for tools to describe instruction addresses. Pages allocated for kprobe's purposes need symbols to be created for them. Add such symbols to be visible via perf ksymbol events. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Masami Hiramatsu <mhiramat@kernel.org> Link: https://lkml.kernel.org/r/20200512121922.8997-5-adrian.hunter@intel.com
1 parent d002b8b commit 69e4908

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎include/uapi/linux/perf_event.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,11 @@ enum perf_event_type {
10491049
enum perf_record_ksymbol_type {
10501050
PERF_RECORD_KSYMBOL_TYPE_UNKNOWN = 0,
10511051
PERF_RECORD_KSYMBOL_TYPE_BPF = 1,
1052+
/*
1053+
* Out of line code such as kprobe-replaced instructions or optimized
1054+
* kprobes.
1055+
*/
1056+
PERF_RECORD_KSYMBOL_TYPE_OOL = 2,
10521057
PERF_RECORD_KSYMBOL_TYPE_MAX /* non-ABI */
10531058
};
10541059

‎kernel/kprobes.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/ftrace.h>
3636
#include <linux/cpu.h>
3737
#include <linux/jump_label.h>
38+
#include <linux/perf_event.h>
3839

3940
#include <asm/sections.h>
4041
#include <asm/cacheflush.h>
@@ -184,6 +185,10 @@ kprobe_opcode_t *__get_insn_slot(struct kprobe_insn_cache *c)
184185
kip->cache = c;
185186
list_add_rcu(&kip->list, &c->pages);
186187
slot = kip->insns;
188+
189+
/* Record the perf ksymbol register event after adding the page */
190+
perf_event_ksymbol(PERF_RECORD_KSYMBOL_TYPE_OOL, (unsigned long)kip->insns,
191+
PAGE_SIZE, false, c->sym);
187192
out:
188193
mutex_unlock(&c->mutex);
189194
return slot;
@@ -202,6 +207,13 @@ static int collect_one_slot(struct kprobe_insn_page *kip, int idx)
202207
* next time somebody inserts a probe.
203208
*/
204209
if (!list_is_singular(&kip->list)) {
210+
/*
211+
* Record perf ksymbol unregister event before removing
212+
* the page.
213+
*/
214+
perf_event_ksymbol(PERF_RECORD_KSYMBOL_TYPE_OOL,
215+
(unsigned long)kip->insns, PAGE_SIZE, true,
216+
kip->cache->sym);
205217
list_del_rcu(&kip->list);
206218
synchronize_rcu();
207219
kip->cache->free(kip->insns);

0 commit comments

Comments
 (0)