Skip to content

Commit 66d18db

Browse files
RISC-V: Take text_mutex in ftrace_init_nop()
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 <palmerdabbelt@google.com> Acked-by: Guo Ren <guoren@kernel.org> Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
1 parent d012a71 commit 66d18db

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

arch/riscv/include/asm/ftrace.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ do { \
6666
* Let auipc+jalr be the basic *mcount unit*, so we make it 8 bytes here.
6767
*/
6868
#define MCOUNT_INSN_SIZE 8
69+
70+
#ifndef __ASSEMBLY__
71+
struct dyn_ftrace;
72+
int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
73+
#define ftrace_init_nop ftrace_init_nop
74+
#endif
75+
6976
#endif
7077

7178
#endif /* _ASM_RISCV_FTRACE_H */

arch/riscv/kernel/ftrace.c

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

100+
101+
/*
102+
* This is called early on, and isn't wrapped by
103+
* ftrace_arch_code_modify_{prepare,post_process}() and therefor doesn't hold
104+
* text_mutex, which triggers a lockdep failure. SMP isn't running so we could
105+
* just directly poke the text, but it's simpler to just take the lock
106+
* ourselves.
107+
*/
108+
int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec)
109+
{
110+
int out;
111+
112+
ftrace_arch_code_modify_prepare();
113+
out = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
114+
ftrace_arch_code_modify_post_process();
115+
116+
return out;
117+
}
118+
100119
int ftrace_update_ftrace_func(ftrace_func_t func)
101120
{
102121
int ret = __ftrace_modify_call((unsigned long)&ftrace_call,

0 commit comments

Comments
 (0)