]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
RISC-V: Take text_mutex in ftrace_init_nop()
authorPalmer Dabbelt <palmerdabbelt@google.com>
Tue, 25 Aug 2020 00:21:22 +0000 (17:21 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 1 Oct 2020 11:18:14 +0000 (13:18 +0200)
[ Upstream commit 66d18dbda8469a944dfec6c49d26d5946efba218 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/riscv/include/asm/ftrace.h
arch/riscv/kernel/ftrace.c

index c6dcc5291f972ab74fd534436be003ed8e2b308d..02fbc175142e29847ff673d8a37cd0f13663b124 100644 (file)
@@ -63,4 +63,11 @@ do {                                                                 \
  * Let auipc+jalr be the basic *mcount unit*, so we make it 8 bytes here.
  */
 #define MCOUNT_INSN_SIZE 8
+
+#ifndef __ASSEMBLY__
+struct dyn_ftrace;
+int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
+#define ftrace_init_nop ftrace_init_nop
+#endif
+
 #endif
index c40fdcdeb950a59f48f1be56ff8776253883bf90..291c579e12457ef5f0b53742c7143b4cb4313401 100644 (file)
@@ -88,6 +88,25 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec,
        return __ftrace_modify_call(rec->ip, addr, false);
 }
 
+
+/*
+ * This is called early on, and isn't wrapped by
+ * ftrace_arch_code_modify_{prepare,post_process}() and therefor doesn't hold
+ * text_mutex, which triggers a lockdep failure.  SMP isn't running so we could
+ * just directly poke the text, but it's simpler to just take the lock
+ * ourselves.
+ */
+int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec)
+{
+       int out;
+
+       ftrace_arch_code_modify_prepare();
+       out = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
+       ftrace_arch_code_modify_post_process();
+
+       return out;
+}
+
 int ftrace_update_ftrace_func(ftrace_func_t func)
 {
        int ret = __ftrace_modify_call((unsigned long)&ftrace_call,