Skip to content

Commit 3fa17c3

Browse files
Tony Lucmetcalf-tilera
authored andcommitted
tile: support kprobes on tilegx
This change includes support for Kprobes, Jprobes and Return Probes. Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Signed-off-by: Tony Lu <zlu@tilera.com> Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
1 parent a61fd5e commit 3fa17c3

14 files changed

Lines changed: 718 additions & 5 deletions

File tree

‎arch/tile/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ config TILEGX
125125
select HAVE_FUNCTION_GRAPH_TRACER
126126
select HAVE_DYNAMIC_FTRACE
127127
select HAVE_FTRACE_MCOUNT_RECORD
128+
select HAVE_KPROBES
129+
select HAVE_KRETPROBES
128130

129131
config TILEPRO
130132
def_bool !TILEGX

‎arch/tile/include/asm/Kbuild‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ generic-y += ioctl.h
1515
generic-y += ioctls.h
1616
generic-y += ipcbuf.h
1717
generic-y += irq_regs.h
18-
generic-y += kdebug.h
1918
generic-y += local.h
2019
generic-y += msgbuf.h
2120
generic-y += mutex.h

‎arch/tile/include/asm/kdebug.h‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2012 Tilera Corporation. All Rights Reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation, version 2.
7+
*
8+
* This program is distributed in the hope that it will be useful, but
9+
* WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11+
* NON INFRINGEMENT. See the GNU General Public License for
12+
* more details.
13+
*/
14+
15+
#ifndef _ASM_TILE_KDEBUG_H
16+
#define _ASM_TILE_KDEBUG_H
17+
18+
#include <linux/notifier.h>
19+
20+
enum die_val {
21+
DIE_OOPS = 1,
22+
DIE_BREAK,
23+
DIE_SSTEPBP,
24+
DIE_PAGE_FAULT,
25+
DIE_COMPILED_BPT
26+
};
27+
28+
#endif /* _ASM_TILE_KDEBUG_H */

‎arch/tile/include/asm/kprobes.h‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* arch/tile/include/asm/kprobes.h
3+
*
4+
* Copyright 2012 Tilera Corporation. All Rights Reserved.
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License
8+
* as published by the Free Software Foundation, version 2.
9+
*
10+
* This program is distributed in the hope that it will be useful, but
11+
* WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13+
* NON INFRINGEMENT. See the GNU General Public License for
14+
* more details.
15+
*/
16+
17+
#ifndef _ASM_TILE_KPROBES_H
18+
#define _ASM_TILE_KPROBES_H
19+
20+
#include <linux/types.h>
21+
#include <linux/ptrace.h>
22+
#include <linux/percpu.h>
23+
24+
#include <arch/opcode.h>
25+
26+
#define __ARCH_WANT_KPROBES_INSN_SLOT
27+
#define MAX_INSN_SIZE 2
28+
29+
#define kretprobe_blacklist_size 0
30+
31+
typedef tile_bundle_bits kprobe_opcode_t;
32+
33+
#define flush_insn_slot(p) \
34+
flush_icache_range((unsigned long)p->addr, \
35+
(unsigned long)p->addr + \
36+
(MAX_INSN_SIZE * sizeof(kprobe_opcode_t)))
37+
38+
struct kprobe;
39+
40+
/* Architecture specific copy of original instruction. */
41+
struct arch_specific_insn {
42+
kprobe_opcode_t *insn;
43+
};
44+
45+
struct prev_kprobe {
46+
struct kprobe *kp;
47+
unsigned long status;
48+
unsigned long saved_pc;
49+
};
50+
51+
#define MAX_JPROBES_STACK_SIZE 128
52+
#define MAX_JPROBES_STACK_ADDR \
53+
(((unsigned long)current_thread_info()) + THREAD_SIZE - 32 \
54+
- sizeof(struct pt_regs))
55+
56+
#define MIN_JPROBES_STACK_SIZE(ADDR) \
57+
((((ADDR) + MAX_JPROBES_STACK_SIZE) > MAX_JPROBES_STACK_ADDR) \
58+
? MAX_JPROBES_STACK_ADDR - (ADDR) \
59+
: MAX_JPROBES_STACK_SIZE)
60+
61+
/* per-cpu kprobe control block. */
62+
struct kprobe_ctlblk {
63+
unsigned long kprobe_status;
64+
unsigned long kprobe_saved_pc;
65+
unsigned long jprobe_saved_sp;
66+
struct prev_kprobe prev_kprobe;
67+
struct pt_regs jprobe_saved_regs;
68+
char jprobes_stack[MAX_JPROBES_STACK_SIZE];
69+
};
70+
71+
extern tile_bundle_bits breakpoint2_insn;
72+
extern tile_bundle_bits breakpoint_insn;
73+
74+
void arch_remove_kprobe(struct kprobe *);
75+
76+
extern int kprobe_exceptions_notify(struct notifier_block *self,
77+
unsigned long val, void *data);
78+
79+
#endif /* _ASM_TILE_KPROBES_H */

‎arch/tile/include/asm/ptrace.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ typedef unsigned long pt_reg_t;
3333

3434
#ifndef __ASSEMBLY__
3535

36+
#define regs_return_value(regs) ((regs)->regs[0])
3637
#define instruction_pointer(regs) ((regs)->pc)
3738
#define profile_pc(regs) instruction_pointer(regs)
3839
#define user_stack_pointer(regs) ((regs)->sp)

‎arch/tile/include/uapi/arch/opcode_tilegx.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ typedef tilegx_bundle_bits tile_bundle_bits;
6161
#define TILE_BUNDLE_ALIGNMENT_IN_BYTES TILEGX_BUNDLE_ALIGNMENT_IN_BYTES
6262
#define TILE_LOG2_BUNDLE_ALIGNMENT_IN_BYTES \
6363
TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES
64+
#define TILE_BPT_BUNDLE TILEGX_BPT_BUNDLE
6465

6566
/* 64-bit pattern for a { bpt ; nop } bundle. */
6667
#define TILEGX_BPT_BUNDLE 0x286a44ae51485000ULL

‎arch/tile/include/uapi/arch/opcode_tilepro.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ typedef tilepro_bundle_bits tile_bundle_bits;
7171
#define TILE_BUNDLE_ALIGNMENT_IN_BYTES TILEPRO_BUNDLE_ALIGNMENT_IN_BYTES
7272
#define TILE_LOG2_BUNDLE_ALIGNMENT_IN_BYTES \
7373
TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES
74+
#define TILE_BPT_BUNDLE TILEPRO_BPT_BUNDLE
7475

7576
/* 64-bit pattern for a { bpt ; nop } bundle. */
7677
#define TILEPRO_BPT_BUNDLE 0x400b3cae70166000ULL

‎arch/tile/kernel/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ endif
2828
obj-$(CONFIG_TILE_USB) += usb.o
2929
obj-$(CONFIG_TILE_HVGLUE_TRACE) += hvglue_trace.o
3030
obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o mcount_64.o
31+
obj-$(CONFIG_KPROBES) += kprobes.o
3132

3233
obj-y += vdso/

0 commit comments

Comments
 (0)