Skip to content

Commit 66d987b

Browse files
palmer-dabbeltgregkh
authored andcommitted
RISC-V: Take text_mutex in ftrace_init_nop()
[ Upstream commit 66d18db ] Without this we get lockdep failures. They're spurious failures as SMP isn't up when ftrace_init_nop() is called. As far as I can tell the easiest fix is to just take the lock, which also seems like the safest fix. Signed-off-by: Palmer Dabbelt <[email protected]> Acked-by: Guo Ren <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 487e3a1 commit 66d987b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

arch/riscv/include/asm/ftrace.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,11 @@ do { \
6363
* Let auipc+jalr be the basic *mcount unit*, so we make it 8 bytes here.
6464
*/
6565
#define MCOUNT_INSN_SIZE 8
66+
67+
#ifndef __ASSEMBLY__
68+
struct dyn_ftrace;
69+
int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
70+
#define ftrace_init_nop ftrace_init_nop
71+
#endif
72+
6673
#endif

arch/riscv/kernel/ftrace.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec,
8888
return __ftrace_modify_call(rec->ip, addr, false);
8989
}
9090

91+
92+
/*
93+
* This is called early on, and isn't wrapped by
94+
* ftrace_arch_code_modify_{prepare,post_process}() and therefor doesn't hold
95+
* text_mutex, which triggers a lockdep failure. SMP isn't running so we could
96+
* just directly poke the text, but it's simpler to just take the lock
97+
* ourselves.
98+
*/
99+
int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec)
100+
{
101+
int out;
102+
103+
ftrace_arch_code_modify_prepare();
104+
out = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
105+
ftrace_arch_code_modify_post_process();
106+
107+
return out;
108+
}
109+
91110
int ftrace_update_ftrace_func(ftrace_func_t func)
92111
{
93112
int ret = __ftrace_modify_call((unsigned long)&ftrace_call,

0 commit comments

Comments
 (0)