Skip to content

Commit 9be12f9

Browse files
committed
sparc64: Add proper dynamic ftrace support.
Signed-off-by: David S. Miller <davem@davemloft.net> Acked-by: Steven Rostedt <rostedt@goodmis.org> Acked-by: Ingo Molnar <mingo@elte.hu>
1 parent 949e827 commit 9be12f9

4 files changed

Lines changed: 65 additions & 15 deletions

File tree

‎arch/sparc/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ config SPARC64
3737
select HAVE_KPROBES
3838
select HAVE_LMB
3939
select HAVE_SYSCALL_WRAPPERS
40+
select HAVE_DYNAMIC_FTRACE
41+
select HAVE_FTRACE_MCOUNT_RECORD
4042
select USE_GENERIC_SMP_HELPERS if SMP
4143
select RTC_DRV_CMOS
4244
select RTC_DRV_BQ4802

‎arch/sparc/include/asm/ftrace.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,15 @@ extern void _mcount(void);
1111

1212
#endif
1313

14+
#ifdef CONFIG_DYNAMIC_FTRACE
15+
/* reloction of mcount call site is the same as the address */
16+
static inline unsigned long ftrace_call_adjust(unsigned long addr)
17+
{
18+
return addr;
19+
}
20+
21+
struct dyn_arch_ftrace {
22+
};
23+
#endif /* CONFIG_DYNAMIC_FTRACE */
24+
1425
#endif /* _ASM_SPARC64_FTRACE */

‎arch/sparc/kernel/ftrace.c‎

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,22 @@
77

88
#include <asm/ftrace.h>
99

10+
#ifdef CONFIG_DYNAMIC_FTRACE
1011
static const u32 ftrace_nop = 0x01000000;
1112

12-
unsigned char *ftrace_nop_replace(void)
13-
{
14-
return (char *)&ftrace_nop;
15-
}
16-
17-
unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
13+
static u32 ftrace_call_replace(unsigned long ip, unsigned long addr)
1814
{
1915
static u32 call;
2016
s32 off;
2117

2218
off = ((s32)addr - (s32)ip);
2319
call = 0x40000000 | ((u32)off >> 2);
2420

25-
return (unsigned char *) &call;
21+
return call;
2622
}
2723

28-
int
29-
ftrace_modify_code(unsigned long ip, unsigned char *old_code,
30-
unsigned char *new_code)
24+
static int ftrace_modify_code(unsigned long ip, u32 old, u32 new)
3125
{
32-
u32 old = *(u32 *)old_code;
33-
u32 new = *(u32 *)new_code;
3426
u32 replaced;
3527
int faulted;
3628

@@ -59,18 +51,43 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code,
5951
return faulted;
6052
}
6153

54+
int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, unsigned long addr)
55+
{
56+
unsigned long ip = rec->ip;
57+
u32 old, new;
58+
59+
old = ftrace_call_replace(ip, addr);
60+
new = ftrace_nop;
61+
return ftrace_modify_code(ip, old, new);
62+
}
63+
64+
int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
65+
{
66+
unsigned long ip = rec->ip;
67+
u32 old, new;
68+
69+
old = ftrace_nop;
70+
new = ftrace_call_replace(ip, addr);
71+
return ftrace_modify_code(ip, old, new);
72+
}
73+
6274
int ftrace_update_ftrace_func(ftrace_func_t func)
6375
{
6476
unsigned long ip = (unsigned long)(&ftrace_call);
65-
unsigned char old[MCOUNT_INSN_SIZE], *new;
77+
u32 old, new;
6678

67-
memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
79+
old = *(u32 *) &ftrace_call;
6880
new = ftrace_call_replace(ip, (unsigned long)func);
6981
return ftrace_modify_code(ip, old, new);
7082
}
7183

7284
int __init ftrace_dyn_arch_init(void *data)
7385
{
74-
ftrace_mcount_set(data);
86+
unsigned long *p = data;
87+
88+
*p = 0;
89+
7590
return 0;
7691
}
92+
#endif
93+

‎scripts/recordmcount.pl‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,26 @@
226226
if ($is_module eq "0") {
227227
$cc .= " -mconstant-gp";
228228
}
229+
} elsif ($arch eq "sparc64") {
230+
# In the objdump output there are giblets like:
231+
# 0000000000000000 <igmp_net_exit-0x18>:
232+
# As there's some data blobs that get emitted into the
233+
# text section before the first instructions and the first
234+
# real symbols. We don't want to match that, so to combat
235+
# this we use '\w' so we'll match just plain symbol names,
236+
# and not those that also include hex offsets inside of the
237+
# '<>' brackets. Actually the generic function_regex setting
238+
# could safely use this too.
239+
$function_regex = "^([0-9a-fA-F]+)\\s+<(\\w*?)>:";
240+
241+
# Sparc64 calls '_mcount' instead of plain 'mcount'.
242+
$mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$";
243+
244+
$alignment = 8;
245+
$type = ".xword";
246+
$ld .= " -m elf64_sparc";
247+
$cc .= " -m64";
248+
$objcopy .= " -O elf64-sparc";
229249
} else {
230250
die "Arch $arch is not supported with CONFIG_FTRACE_MCOUNT_RECORD";
231251
}

0 commit comments

Comments
 (0)