Skip to content

Commit 67ccddf

Browse files
iii-ihcahca
authored andcommitted
ftrace: Introduce ftrace_need_init_nop()
Implementing live patching on s390 requires each function's prologue to contain a very special kind of nop, which gcc and clang don't generate. However, the current code assumes that if CC_USING_NOP_MCOUNT is defined, then whatever the compiler generates is good enough. Move the CC_USING_NOP_MCOUNT check into the new ftrace_need_init_nop() macro, that the architectures can override. An alternative solution is to disable using -mnop-mcount in the Makefile, however, this makes the build logic (even) more complicated and forces the arch-specific code to deal with the useless __fentry__ symbol. Signed-off-by: Ilya Leoshkevich <[email protected]> Reviewed-by: Steven Rostedt (VMware) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Heiko Carstens <[email protected]>
1 parent d80d3ea commit 67ccddf

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

include/linux/ftrace.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,22 @@ static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
643643
extern int ftrace_make_nop(struct module *mod,
644644
struct dyn_ftrace *rec, unsigned long addr);
645645

646+
/**
647+
* ftrace_need_init_nop - return whether nop call sites should be initialized
648+
*
649+
* Normally the compiler's -mnop-mcount generates suitable nops, so we don't
650+
* need to call ftrace_init_nop() if the code is built with that flag.
651+
* Architectures where this is not always the case may define their own
652+
* condition.
653+
*
654+
* Return must be:
655+
* 0 if ftrace_init_nop() should be called
656+
* Nonzero if ftrace_init_nop() should not be called
657+
*/
658+
659+
#ifndef ftrace_need_init_nop
660+
#define ftrace_need_init_nop() (!__is_defined(CC_USING_NOP_MCOUNT))
661+
#endif
646662

647663
/**
648664
* ftrace_init_nop - initialize a nop call site

kernel/trace/ftrace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3100,6 +3100,7 @@ ops_references_rec(struct ftrace_ops *ops, struct dyn_ftrace *rec)
31003100

31013101
static int ftrace_update_code(struct module *mod, struct ftrace_page *new_pgs)
31023102
{
3103+
bool init_nop = ftrace_need_init_nop();
31033104
struct ftrace_page *pg;
31043105
struct dyn_ftrace *p;
31053106
u64 start, stop;
@@ -3138,8 +3139,7 @@ static int ftrace_update_code(struct module *mod, struct ftrace_page *new_pgs)
31383139
* Do the initial record conversion from mcount jump
31393140
* to the NOP instructions.
31403141
*/
3141-
if (!__is_defined(CC_USING_NOP_MCOUNT) &&
3142-
!ftrace_nop_initialize(mod, p))
3142+
if (init_nop && !ftrace_nop_initialize(mod, p))
31433143
break;
31443144

31453145
update_cnt++;

0 commit comments

Comments
 (0)