![Michael Ellerman](/assets/img/avatar_default.png)
On powerpc we can build the kernel with two different ABIs for mcount(), which
is used by ftrace. Kernels built with one ABI do not know how to load modules
built with the other ABI. The new style ABI is called "mprofile-kernel", for
want of a better name.
Currently if we build a module using the old style ABI, and the kernel with
mprofile-kernel, when we load the module we'll oops something like:
# insmod autofs4-no-mprofile-kernel.ko
ftrace-powerpc: Unexpected instruction f8810028 around bl _mcount
------------[ cut here ]------------
WARNING: CPU: 6 PID: 3759 at ../kernel/trace/ftrace.c:2024 ftrace_bug+0x2b8/0x3c0
CPU: 6 PID: 3759 Comm: insmod Not tainted 4.11.0-rc3-gcc-5.4.1-00017-g5a61ef74f269 #11
...
NIP [c0000000001eaa48] ftrace_bug+0x2b8/0x3c0
LR [c0000000001eaff8] ftrace_process_locs+0x4a8/0x590
Call Trace:
alloc_pages_current+0xc4/0x1d0 (unreliable)
ftrace_process_locs+0x4a8/0x590
load_module+0x1c8c/0x28f0
SyS_finit_module+0x110/0x140
system_call+0x38/0xfc
...
ftrace failed to modify
[<d000000002a31024>] 0xd000000002a31024
actual: 35:65:00:48
We can avoid this by including in the vermagic whether the kernel/module was
built with mprofile-kernel. Which results in:
# insmod autofs4-pg.ko
autofs4: version magic
'4.11.0-rc3-gcc-5.4.1-00017-g5a61ef74f269 SMP mod_unload modversions '
should be
'4.11.0-rc3-gcc-5.4.1-00017-g5a61ef74f269-dirty SMP mod_unload modversions mprofile-kernel'
insmod: ERROR: could not insert module autofs4-pg.ko: Invalid module format
Fixes: 8c50b72a3b
("powerpc/ftrace: Add Kconfig & Make glue for mprofile-kernel")
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Acked-by: Balbir Singh <bsingharora@gmail.com>
Acked-by: Jessica Yu <jeyu@redhat.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
99 lines
2.5 KiB
C
99 lines
2.5 KiB
C
#ifndef _ASM_POWERPC_MODULE_H
|
|
#define _ASM_POWERPC_MODULE_H
|
|
#ifdef __KERNEL__
|
|
|
|
/*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version
|
|
* 2 of the License, or (at your option) any later version.
|
|
*/
|
|
|
|
#include <linux/list.h>
|
|
#include <asm/bug.h>
|
|
#include <asm-generic/module.h>
|
|
|
|
|
|
#ifdef CC_USING_MPROFILE_KERNEL
|
|
#define MODULE_ARCH_VERMAGIC "mprofile-kernel"
|
|
#endif
|
|
|
|
#ifndef __powerpc64__
|
|
/*
|
|
* Thanks to Paul M for explaining this.
|
|
*
|
|
* PPC can only do rel jumps += 32MB, and often the kernel and other
|
|
* modules are further away than this. So, we jump to a table of
|
|
* trampolines attached to the module (the Procedure Linkage Table)
|
|
* whenever that happens.
|
|
*/
|
|
|
|
struct ppc_plt_entry {
|
|
/* 16 byte jump instruction sequence (4 instructions) */
|
|
unsigned int jump[4];
|
|
};
|
|
#endif /* __powerpc64__ */
|
|
|
|
|
|
struct mod_arch_specific {
|
|
#ifdef __powerpc64__
|
|
unsigned int stubs_section; /* Index of stubs section in module */
|
|
unsigned int toc_section; /* What section is the TOC? */
|
|
bool toc_fixed; /* Have we fixed up .TOC.? */
|
|
#ifdef CONFIG_DYNAMIC_FTRACE
|
|
unsigned long toc;
|
|
unsigned long tramp;
|
|
#endif
|
|
|
|
#else /* powerpc64 */
|
|
/* Indices of PLT sections within module. */
|
|
unsigned int core_plt_section;
|
|
unsigned int init_plt_section;
|
|
#ifdef CONFIG_DYNAMIC_FTRACE
|
|
unsigned long tramp;
|
|
#endif
|
|
#endif /* powerpc64 */
|
|
|
|
/* List of BUG addresses, source line numbers and filenames */
|
|
struct list_head bug_list;
|
|
struct bug_entry *bug_table;
|
|
unsigned int num_bugs;
|
|
};
|
|
|
|
/*
|
|
* Select ELF headers.
|
|
* Make empty section for module_frob_arch_sections to expand.
|
|
*/
|
|
|
|
#ifdef __powerpc64__
|
|
# ifdef MODULE
|
|
asm(".section .stubs,\"ax\",@nobits; .align 3; .previous");
|
|
# endif
|
|
#else
|
|
# ifdef MODULE
|
|
asm(".section .plt,\"ax\",@nobits; .align 3; .previous");
|
|
asm(".section .init.plt,\"ax\",@nobits; .align 3; .previous");
|
|
# endif /* MODULE */
|
|
#endif
|
|
|
|
#ifdef CONFIG_DYNAMIC_FTRACE
|
|
# ifdef MODULE
|
|
asm(".section .ftrace.tramp,\"ax\",@nobits; .align 3; .previous");
|
|
# endif /* MODULE */
|
|
#endif
|
|
|
|
int module_trampoline_target(struct module *mod, unsigned long trampoline,
|
|
unsigned long *target);
|
|
|
|
#ifdef CONFIG_DYNAMIC_FTRACE
|
|
int module_finalize_ftrace(struct module *mod, const Elf_Shdr *sechdrs);
|
|
#else
|
|
static inline int module_finalize_ftrace(struct module *mod, const Elf_Shdr *sechdrs)
|
|
{
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
#endif /* __KERNEL__ */
|
|
#endif /* _ASM_POWERPC_MODULE_H */
|