Skip to content

Commit 7413af1

Browse files
committed
ftrace: Make get_ftrace_addr() and get_ftrace_addr_old() global
Move and rename get_ftrace_addr() and get_ftrace_addr_old() to ftrace_get_addr_new() and ftrace_get_addr_curr() respectively. This moves these two helper functions in the generic code out from the arch specific code, and renames them to have a better generic name. This will allow other archs to use them as well as makes it a bit easier to work on getting separate trampolines for different functions. ftrace_get_addr_new() returns the trampoline address that the mcount call address will be converted to. ftrace_get_addr_curr() returns the trampoline address of what the mcount call address currently jumps to. Signed-off-by: Steven Rostedt <[email protected]>
1 parent 94792ea commit 7413af1

File tree

3 files changed

+43
-31
lines changed

3 files changed

+43
-31
lines changed

arch/x86/kernel/ftrace.c

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -349,38 +349,12 @@ static int add_brk_on_nop(struct dyn_ftrace *rec)
349349
return add_break(rec->ip, old);
350350
}
351351

352-
/*
353-
* If the record has the FTRACE_FL_REGS set, that means that it
354-
* wants to convert to a callback that saves all regs. If FTRACE_FL_REGS
355-
* is not not set, then it wants to convert to the normal callback.
356-
*/
357-
static unsigned long get_ftrace_addr(struct dyn_ftrace *rec)
358-
{
359-
if (rec->flags & FTRACE_FL_REGS)
360-
return (unsigned long)FTRACE_REGS_ADDR;
361-
else
362-
return (unsigned long)FTRACE_ADDR;
363-
}
364-
365-
/*
366-
* The FTRACE_FL_REGS_EN is set when the record already points to
367-
* a function that saves all the regs. Basically the '_EN' version
368-
* represents the current state of the function.
369-
*/
370-
static unsigned long get_ftrace_old_addr(struct dyn_ftrace *rec)
371-
{
372-
if (rec->flags & FTRACE_FL_REGS_EN)
373-
return (unsigned long)FTRACE_REGS_ADDR;
374-
else
375-
return (unsigned long)FTRACE_ADDR;
376-
}
377-
378352
static int add_breakpoints(struct dyn_ftrace *rec, int enable)
379353
{
380354
unsigned long ftrace_addr;
381355
int ret;
382356

383-
ftrace_addr = get_ftrace_old_addr(rec);
357+
ftrace_addr = ftrace_get_addr_curr(rec);
384358

385359
ret = ftrace_test_record(rec, enable);
386360

@@ -438,14 +412,14 @@ static int remove_breakpoint(struct dyn_ftrace *rec)
438412
* If not, don't touch the breakpoint, we make just create
439413
* a disaster.
440414
*/
441-
ftrace_addr = get_ftrace_addr(rec);
415+
ftrace_addr = ftrace_get_addr_new(rec);
442416
nop = ftrace_call_replace(ip, ftrace_addr);
443417

444418
if (memcmp(&ins[1], &nop[1], MCOUNT_INSN_SIZE - 1) == 0)
445419
goto update;
446420

447421
/* Check both ftrace_addr and ftrace_old_addr */
448-
ftrace_addr = get_ftrace_old_addr(rec);
422+
ftrace_addr = ftrace_get_addr_curr(rec);
449423
nop = ftrace_call_replace(ip, ftrace_addr);
450424

451425
if (memcmp(&ins[1], &nop[1], MCOUNT_INSN_SIZE - 1) != 0)
@@ -489,7 +463,7 @@ static int add_update(struct dyn_ftrace *rec, int enable)
489463

490464
ret = ftrace_test_record(rec, enable);
491465

492-
ftrace_addr = get_ftrace_addr(rec);
466+
ftrace_addr = ftrace_get_addr_new(rec);
493467

494468
switch (ret) {
495469
case FTRACE_UPDATE_IGNORE:
@@ -536,7 +510,7 @@ static int finish_update(struct dyn_ftrace *rec, int enable)
536510

537511
ret = ftrace_update_record(rec, enable);
538512

539-
ftrace_addr = get_ftrace_addr(rec);
513+
ftrace_addr = ftrace_get_addr_new(rec);
540514

541515
switch (ret) {
542516
case FTRACE_UPDATE_IGNORE:

include/linux/ftrace.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ int ftrace_update_record(struct dyn_ftrace *rec, int enable);
400400
int ftrace_test_record(struct dyn_ftrace *rec, int enable);
401401
void ftrace_run_stop_machine(int command);
402402
unsigned long ftrace_location(unsigned long ip);
403+
unsigned long ftrace_get_addr_new(struct dyn_ftrace *rec);
404+
unsigned long ftrace_get_addr_curr(struct dyn_ftrace *rec);
403405

404406
extern ftrace_func_t ftrace_trace_function;
405407

kernel/trace/ftrace.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,42 @@ int ftrace_test_record(struct dyn_ftrace *rec, int enable)
17551755
return ftrace_check_record(rec, enable, 0);
17561756
}
17571757

1758+
/**
1759+
* ftrace_get_addr_new - Get the call address to set to
1760+
* @rec: The ftrace record descriptor
1761+
*
1762+
* If the record has the FTRACE_FL_REGS set, that means that it
1763+
* wants to convert to a callback that saves all regs. If FTRACE_FL_REGS
1764+
* is not not set, then it wants to convert to the normal callback.
1765+
*
1766+
* Returns the address of the trampoline to set to
1767+
*/
1768+
unsigned long ftrace_get_addr_new(struct dyn_ftrace *rec)
1769+
{
1770+
if (rec->flags & FTRACE_FL_REGS)
1771+
return (unsigned long)FTRACE_REGS_ADDR;
1772+
else
1773+
return (unsigned long)FTRACE_ADDR;
1774+
}
1775+
1776+
/**
1777+
* ftrace_get_addr_curr - Get the call address that is already there
1778+
* @rec: The ftrace record descriptor
1779+
*
1780+
* The FTRACE_FL_REGS_EN is set when the record already points to
1781+
* a function that saves all the regs. Basically the '_EN' version
1782+
* represents the current state of the function.
1783+
*
1784+
* Returns the address of the trampoline that is currently being called
1785+
*/
1786+
unsigned long ftrace_get_addr_curr(struct dyn_ftrace *rec)
1787+
{
1788+
if (rec->flags & FTRACE_FL_REGS_EN)
1789+
return (unsigned long)FTRACE_REGS_ADDR;
1790+
else
1791+
return (unsigned long)FTRACE_ADDR;
1792+
}
1793+
17581794
static int
17591795
__ftrace_replace_code(struct dyn_ftrace *rec, int enable)
17601796
{

0 commit comments

Comments
 (0)