aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt (Red Hat) <rostedt@goodmis.org>2014-05-06 21:34:14 -0400
committerSteven Rostedt <rostedt@goodmis.org>2014-05-14 11:37:29 -0400
commit7413af1fb70e7efa6dbc7f27663e7a5126b3aa33 (patch)
treec3060be62f4f8a6d94cfe1f390c12e2d0285435e
parent94792ea07ce2cceef48803c4df3cb5efacb21c9a (diff)
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 <rostedt@goodmis.org>
-rw-r--r--arch/x86/kernel/ftrace.c36
-rw-r--r--include/linux/ftrace.h2
-rw-r--r--kernel/trace/ftrace.c36
3 files changed, 43 insertions, 31 deletions
diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index 4b3c195d4133..5ef43ce8492f 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -349,38 +349,12 @@ static int add_brk_on_nop(struct dyn_ftrace *rec)
349 return add_break(rec->ip, old); 349 return add_break(rec->ip, old);
350} 350}
351 351
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 */
357static 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 */
370static 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
378static int add_breakpoints(struct dyn_ftrace *rec, int enable) 352static int add_breakpoints(struct dyn_ftrace *rec, int enable)
379{ 353{
380 unsigned long ftrace_addr; 354 unsigned long ftrace_addr;
381 int ret; 355 int ret;
382 356
383 ftrace_addr = get_ftrace_old_addr(rec); 357 ftrace_addr = ftrace_get_addr_curr(rec);
384 358
385 ret = ftrace_test_record(rec, enable); 359 ret = ftrace_test_record(rec, enable);
386 360
@@ -438,14 +412,14 @@ static int remove_breakpoint(struct dyn_ftrace *rec)
438 * If not, don't touch the breakpoint, we make just create 412 * If not, don't touch the breakpoint, we make just create
439 * a disaster. 413 * a disaster.
440 */ 414 */
441 ftrace_addr = get_ftrace_addr(rec); 415 ftrace_addr = ftrace_get_addr_new(rec);
442 nop = ftrace_call_replace(ip, ftrace_addr); 416 nop = ftrace_call_replace(ip, ftrace_addr);
443 417
444 if (memcmp(&ins[1], &nop[1], MCOUNT_INSN_SIZE - 1) == 0) 418 if (memcmp(&ins[1], &nop[1], MCOUNT_INSN_SIZE - 1) == 0)
445 goto update; 419 goto update;
446 420
447 /* Check both ftrace_addr and ftrace_old_addr */ 421 /* Check both ftrace_addr and ftrace_old_addr */
448 ftrace_addr = get_ftrace_old_addr(rec); 422 ftrace_addr = ftrace_get_addr_curr(rec);
449 nop = ftrace_call_replace(ip, ftrace_addr); 423 nop = ftrace_call_replace(ip, ftrace_addr);
450 424
451 if (memcmp(&ins[1], &nop[1], MCOUNT_INSN_SIZE - 1) != 0) 425 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)
489 463
490 ret = ftrace_test_record(rec, enable); 464 ret = ftrace_test_record(rec, enable);
491 465
492 ftrace_addr = get_ftrace_addr(rec); 466 ftrace_addr = ftrace_get_addr_new(rec);
493 467
494 switch (ret) { 468 switch (ret) {
495 case FTRACE_UPDATE_IGNORE: 469 case FTRACE_UPDATE_IGNORE:
@@ -536,7 +510,7 @@ static int finish_update(struct dyn_ftrace *rec, int enable)
536 510
537 ret = ftrace_update_record(rec, enable); 511 ret = ftrace_update_record(rec, enable);
538 512
539 ftrace_addr = get_ftrace_addr(rec); 513 ftrace_addr = ftrace_get_addr_new(rec);
540 514
541 switch (ret) { 515 switch (ret) {
542 case FTRACE_UPDATE_IGNORE: 516 case FTRACE_UPDATE_IGNORE:
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
index f0ff2c2453e7..2f8cbffecd3d 100644
--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -400,6 +400,8 @@ int ftrace_update_record(struct dyn_ftrace *rec, int enable);
400int ftrace_test_record(struct dyn_ftrace *rec, int enable); 400int ftrace_test_record(struct dyn_ftrace *rec, int enable);
401void ftrace_run_stop_machine(int command); 401void ftrace_run_stop_machine(int command);
402unsigned long ftrace_location(unsigned long ip); 402unsigned long ftrace_location(unsigned long ip);
403unsigned long ftrace_get_addr_new(struct dyn_ftrace *rec);
404unsigned long ftrace_get_addr_curr(struct dyn_ftrace *rec);
403 405
404extern ftrace_func_t ftrace_trace_function; 406extern ftrace_func_t ftrace_trace_function;
405 407
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 98fa931b6864..e825fded435d 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -1755,6 +1755,42 @@ int ftrace_test_record(struct dyn_ftrace *rec, int enable)
1755 return ftrace_check_record(rec, enable, 0); 1755 return ftrace_check_record(rec, enable, 0);
1756} 1756}
1757 1757
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 */
1768unsigned 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 */
1786unsigned 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
1758static int 1794static int
1759__ftrace_replace_code(struct dyn_ftrace *rec, int enable) 1795__ftrace_replace_code(struct dyn_ftrace *rec, int enable)
1760{ 1796{