arm64: module/ftrace: intialize PLT at load time
[sfrench/cifs-2.6.git] / arch / arm64 / kernel / module.c
index 763a86d52fef91ba93eaa6792af5eb8f59c5437e..d0692ecb99bb0c8dce7821f3d99e8f8fb1573db3 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <linux/bitops.h>
 #include <linux/elf.h>
+#include <linux/ftrace.h>
 #include <linux/gfp.h>
 #include <linux/kasan.h>
 #include <linux/kernel.h>
@@ -485,24 +486,33 @@ static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
        return NULL;
 }
 
+static int module_init_ftrace_plt(const Elf_Ehdr *hdr,
+                                 const Elf_Shdr *sechdrs,
+                                 struct module *mod)
+{
+#if defined(CONFIG_ARM64_MODULE_PLTS) && defined(CONFIG_DYNAMIC_FTRACE)
+       const Elf_Shdr *s;
+       struct plt_entry *plt;
+
+       s = find_section(hdr, sechdrs, ".text.ftrace_trampoline");
+       if (!s)
+               return -ENOEXEC;
+
+       plt = (void *)s->sh_addr;
+       *plt = get_plt_entry(FTRACE_ADDR, plt);
+       mod->arch.ftrace_trampoline = plt;
+#endif
+       return 0;
+}
+
 int module_finalize(const Elf_Ehdr *hdr,
                    const Elf_Shdr *sechdrs,
                    struct module *me)
 {
        const Elf_Shdr *s;
-
        s = find_section(hdr, sechdrs, ".altinstructions");
        if (s)
                apply_alternatives_module((void *)s->sh_addr, s->sh_size);
 
-#ifdef CONFIG_ARM64_MODULE_PLTS
-       if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE)) {
-               s = find_section(hdr, sechdrs, ".text.ftrace_trampoline");
-               if (!s)
-                       return -ENOEXEC;
-               me->arch.ftrace_trampoline = (void *)s->sh_addr;
-       }
-#endif
-
-       return 0;
+       return module_init_ftrace_plt(hdr, sechdrs, me);
 }