aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm')
-rw-r--r--arch/arm/Kconfig2
-rw-r--r--arch/arm/boot/compressed/Makefile6
-rw-r--r--arch/arm/kernel/Makefile5
-rw-r--r--arch/arm/kernel/armksyms.c5
-rw-r--r--arch/arm/kernel/entry-common.S47
-rw-r--r--arch/arm/kernel/ftrace.c118
-rw-r--r--arch/arm/kernel/kprobes.c2
7 files changed, 184 insertions, 1 deletions
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index b786e68914d4..3845e5c8a34f 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -14,6 +14,8 @@ config ARM
14 select HAVE_OPROFILE 14 select HAVE_OPROFILE
15 select HAVE_KPROBES if (!XIP_KERNEL) 15 select HAVE_KPROBES if (!XIP_KERNEL)
16 select HAVE_KRETPROBES if (HAVE_KPROBES) 16 select HAVE_KRETPROBES if (HAVE_KPROBES)
17 select HAVE_FTRACE if (!XIP_KERNEL)
18 select HAVE_DYNAMIC_FTRACE if (HAVE_FTRACE)
17 help 19 help
18 The ARM series is a line of low-power-consumption RISC chip designs 20 The ARM series is a line of low-power-consumption RISC chip designs
19 licensed by ARM Ltd and targeted at embedded applications and 21 licensed by ARM Ltd and targeted at embedded applications and
diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
index de9d9ee50958..95baac4939e0 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -69,6 +69,12 @@ SEDFLAGS = s/TEXT_START/$(ZTEXTADDR)/;s/BSS_START/$(ZBSSADDR)/
69 69
70targets := vmlinux vmlinux.lds piggy.gz piggy.o font.o font.c \ 70targets := vmlinux vmlinux.lds piggy.gz piggy.o font.o font.c \
71 head.o misc.o $(OBJS) 71 head.o misc.o $(OBJS)
72
73ifeq ($(CONFIG_FTRACE),y)
74ORIG_CFLAGS := $(KBUILD_CFLAGS)
75KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS))
76endif
77
72EXTRA_CFLAGS := -fpic -fno-builtin 78EXTRA_CFLAGS := -fpic -fno-builtin
73EXTRA_AFLAGS := 79EXTRA_AFLAGS :=
74 80
diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile
index ad455ff5aebe..eb9092ca8008 100644
--- a/arch/arm/kernel/Makefile
+++ b/arch/arm/kernel/Makefile
@@ -4,6 +4,10 @@
4 4
5AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET) 5AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
6 6
7ifdef CONFIG_DYNAMIC_FTRACE
8CFLAGS_REMOVE_ftrace.o = -pg
9endif
10
7# Object file lists. 11# Object file lists.
8 12
9obj-y := compat.o entry-armv.o entry-common.o irq.o \ 13obj-y := compat.o entry-armv.o entry-common.o irq.o \
@@ -18,6 +22,7 @@ obj-$(CONFIG_ARTHUR) += arthur.o
18obj-$(CONFIG_ISA_DMA) += dma-isa.o 22obj-$(CONFIG_ISA_DMA) += dma-isa.o
19obj-$(CONFIG_PCI) += bios32.o isa.o 23obj-$(CONFIG_PCI) += bios32.o isa.o
20obj-$(CONFIG_SMP) += smp.o 24obj-$(CONFIG_SMP) += smp.o
25obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o
21obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o 26obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o
22obj-$(CONFIG_KPROBES) += kprobes.o kprobes-decode.o 27obj-$(CONFIG_KPROBES) += kprobes.o kprobes-decode.o
23obj-$(CONFIG_ATAGS_PROC) += atags.o 28obj-$(CONFIG_ATAGS_PROC) += atags.o
diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
index 688b7b1ee416..3b132215cbf8 100644
--- a/arch/arm/kernel/armksyms.c
+++ b/arch/arm/kernel/armksyms.c
@@ -48,6 +48,11 @@ extern void __aeabi_ulcmp(void);
48extern void fpundefinstr(void); 48extern void fpundefinstr(void);
49extern void fp_enter(void); 49extern void fp_enter(void);
50 50
51#ifdef CONFIG_FTRACE
52extern void mcount(void);
53EXPORT_SYMBOL(mcount);
54#endif
55
51/* 56/*
52 * This has a special calling convention; it doesn't 57 * This has a special calling convention; it doesn't
53 * modify any of the usual registers, except for LR. 58 * modify any of the usual registers, except for LR.
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index 597ed00a08d8..8f79a4789ed4 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -99,6 +99,53 @@ ENTRY(ret_from_fork)
99#undef CALL 99#undef CALL
100#define CALL(x) .long x 100#define CALL(x) .long x
101 101
102#ifdef CONFIG_FTRACE
103#ifdef CONFIG_DYNAMIC_FTRACE
104ENTRY(mcount)
105 stmdb sp!, {r0-r3, lr}
106 mov r0, lr
107
108 .globl mcount_call
109mcount_call:
110 bl ftrace_stub
111 ldmia sp!, {r0-r3, pc}
112
113ENTRY(ftrace_caller)
114 stmdb sp!, {r0-r3, lr}
115 ldr r1, [fp, #-4]
116 mov r0, lr
117
118 .globl ftrace_call
119ftrace_call:
120 bl ftrace_stub
121 ldmia sp!, {r0-r3, pc}
122
123#else
124
125ENTRY(mcount)
126 stmdb sp!, {r0-r3, lr}
127 ldr r0, =ftrace_trace_function
128 ldr r2, [r0]
129 adr r0, ftrace_stub
130 cmp r0, r2
131 bne trace
132 ldmia sp!, {r0-r3, pc}
133
134trace:
135 ldr r1, [fp, #-4]
136 mov r0, lr
137 mov lr, pc
138 mov pc, r2
139 ldmia sp!, {r0-r3, pc}
140
141#endif /* CONFIG_DYNAMIC_FTRACE */
142
143 .globl ftrace_stub
144ftrace_stub:
145 mov pc, lr
146
147#endif /* CONFIG_FTRACE */
148
102/*============================================================================= 149/*=============================================================================
103 * SWI handler 150 * SWI handler
104 *----------------------------------------------------------------------------- 151 *-----------------------------------------------------------------------------
diff --git a/arch/arm/kernel/ftrace.c b/arch/arm/kernel/ftrace.c
new file mode 100644
index 000000000000..22f3d6e309f9
--- /dev/null
+++ b/arch/arm/kernel/ftrace.c
@@ -0,0 +1,118 @@
1/*
2 * Dynamic function tracing support.
3 *
4 * Copyright (C) 2008 Abhishek Sagar <sagar.abhishek@gmail.com>
5 *
6 * For licencing details, see COPYING.
7 *
8 * Defines low-level handling of mcount calls when the kernel
9 * is compiled with the -pg flag. When using dynamic ftrace, the
10 * mcount call-sites get patched lazily with NOP till they are
11 * enabled. All code mutation routines here take effect atomically.
12 */
13
14#include <linux/ftrace.h>
15#include <asm/cacheflush.h>
16
17#define INSN_SIZE 4
18#define PC_OFFSET 8
19#define BL_OPCODE 0xeb000000
20#define BL_OFFSET_MASK 0x00ffffff
21
22static unsigned long bl_insn;
23static const unsigned long NOP = 0xe1a00000; /* mov r0, r0 */
24
25unsigned char *ftrace_nop_replace(void)
26{
27 return (char *)&NOP;
28}
29
30/* construct a branch (BL) instruction to addr */
31unsigned char *ftrace_call_replace(unsigned long pc, unsigned long addr)
32{
33 long offset;
34
35 offset = (long)addr - (long)(pc - INSN_SIZE + PC_OFFSET);
36 if (unlikely(offset < -33554432 || offset > 33554428)) {
37 /* Can't generate branches that far (from ARM ARM). Ftrace
38 * doesn't generate branches outside of core kernel text.
39 */
40 WARN_ON_ONCE(1);
41 return NULL;
42 }
43 offset = (offset >> 2) & BL_OFFSET_MASK;
44 bl_insn = BL_OPCODE | offset;
45 return (unsigned char *)&bl_insn;
46}
47
48int ftrace_modify_code(unsigned long pc, unsigned char *old_code,
49 unsigned char *new_code)
50{
51 unsigned long err = 0, replaced = 0, old, new;
52
53 old = *(unsigned long *)old_code;
54 new = *(unsigned long *)new_code;
55 pc -= INSN_SIZE;
56
57 __asm__ __volatile__ (
58 "1: ldr %1, [%2] \n"
59 " cmp %1, %4 \n"
60 "2: streq %3, [%2] \n"
61 " cmpne %1, %3 \n"
62 " movne %0, #2 \n"
63 "3:\n"
64
65 ".section .fixup, \"ax\"\n"
66 "4: mov %0, #1 \n"
67 " b 3b \n"
68 ".previous\n"
69
70 ".section __ex_table, \"a\"\n"
71 " .long 1b, 4b \n"
72 " .long 2b, 4b \n"
73 ".previous\n"
74
75 : "=r"(err), "=r"(replaced)
76 : "r"(pc), "r"(new), "r"(old), "0"(err), "1"(replaced)
77 : "memory");
78
79 if (!err && (replaced == old))
80 flush_icache_range(pc, pc + INSN_SIZE);
81
82 return err;
83}
84
85int ftrace_update_ftrace_func(ftrace_func_t func)
86{
87 int ret;
88 unsigned long pc, old;
89 unsigned char *new;
90
91 pc = (unsigned long)&ftrace_call;
92 pc += INSN_SIZE;
93 memcpy(&old, &ftrace_call, INSN_SIZE);
94 new = ftrace_call_replace(pc, (unsigned long)func);
95 ret = ftrace_modify_code(pc, (unsigned char *)&old, new);
96 return ret;
97}
98
99int ftrace_mcount_set(unsigned long *data)
100{
101 unsigned long pc, old;
102 unsigned long *addr = data;
103 unsigned char *new;
104
105 pc = (unsigned long)&mcount_call;
106 pc += INSN_SIZE;
107 memcpy(&old, &mcount_call, INSN_SIZE);
108 new = ftrace_call_replace(pc, *addr);
109 *addr = ftrace_modify_code(pc, (unsigned char *)&old, new);
110 return 0;
111}
112
113/* run from kstop_machine */
114int __init ftrace_dyn_arch_init(void *data)
115{
116 ftrace_mcount_set(data);
117 return 0;
118}
diff --git a/arch/arm/kernel/kprobes.c b/arch/arm/kernel/kprobes.c
index 5593dd207216..5ee39e10c8d1 100644
--- a/arch/arm/kernel/kprobes.c
+++ b/arch/arm/kernel/kprobes.c
@@ -274,7 +274,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
274 * for kretprobe handlers which should normally be interested in r0 only 274 * for kretprobe handlers which should normally be interested in r0 only
275 * anyway. 275 * anyway.
276 */ 276 */
277static void __attribute__((naked)) __kprobes kretprobe_trampoline(void) 277void __naked __kprobes kretprobe_trampoline(void)
278{ 278{
279 __asm__ __volatile__ ( 279 __asm__ __volatile__ (
280 "stmdb sp!, {r0 - r11} \n\t" 280 "stmdb sp!, {r0 - r11} \n\t"