Skip to content

Commit a1326b1

Browse files
committed
module/ftrace: handle patchable-function-entry
When using patchable-function-entry, the compiler will record the callsites into a section named "__patchable_function_entries" rather than "__mcount_loc". Let's abstract this difference behind a new FTRACE_CALLSITE_SECTION, so that architectures don't have to handle this explicitly (e.g. with custom module linker scripts). As parisc currently handles this explicitly, it is fixed up accordingly, with its custom linker script removed. Since FTRACE_CALLSITE_SECTION is only defined when DYNAMIC_FTRACE is selected, the parisc module loading code is updated to only use the definition in that case. When DYNAMIC_FTRACE is not selected, modules shouldn't have this section, so this removes some redundant work in that case. To make sure that this is keep up-to-date for modules and the main kernel, a comment is added to vmlinux.lds.h, with the existing ifdeffery simplified for legibility. I built parisc generic-{32,64}bit_defconfig with DYNAMIC_FTRACE enabled, and verified that the section made it into the .ko files for modules. Signed-off-by: Mark Rutland <[email protected]> Acked-by: Helge Deller <[email protected]> Acked-by: Steven Rostedt (VMware) <[email protected]> Reviewed-by: Ard Biesheuvel <[email protected]> Reviewed-by: Torsten Duwe <[email protected]> Tested-by: Amit Daniel Kachhap <[email protected]> Tested-by: Sven Schnelle <[email protected]> Tested-by: Torsten Duwe <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James E.J. Bottomley <[email protected]> Cc: Jessica Yu <[email protected]> Cc: [email protected]
1 parent fbf6c73 commit a1326b1

File tree

6 files changed

+20
-19
lines changed

6 files changed

+20
-19
lines changed

arch/parisc/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ KBUILD_CFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY=1 \
6060
-DFTRACE_PATCHABLE_FUNCTION_SIZE=$(NOP_COUNT)
6161

6262
CC_FLAGS_FTRACE := -fpatchable-function-entry=$(NOP_COUNT),$(shell echo $$(($(NOP_COUNT)-1)))
63-
KBUILD_LDS_MODULE += $(srctree)/arch/parisc/kernel/module.lds
6463
endif
6564

6665
OBJCOPY_FLAGS =-O binary -R .note -R .comment -S

arch/parisc/kernel/module.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <linux/elf.h>
4444
#include <linux/vmalloc.h>
4545
#include <linux/fs.h>
46+
#include <linux/ftrace.h>
4647
#include <linux/string.h>
4748
#include <linux/kernel.h>
4849
#include <linux/bug.h>
@@ -862,7 +863,7 @@ int module_finalize(const Elf_Ehdr *hdr,
862863
const char *strtab = NULL;
863864
const Elf_Shdr *s;
864865
char *secstrings;
865-
int err, symindex = -1;
866+
int symindex = -1;
866867
Elf_Sym *newptr, *oldptr;
867868
Elf_Shdr *symhdr = NULL;
868869
#ifdef DEBUG
@@ -946,11 +947,13 @@ int module_finalize(const Elf_Ehdr *hdr,
946947
/* patch .altinstructions */
947948
apply_alternatives(aseg, aseg + s->sh_size, me->name);
948949

950+
#ifdef CONFIG_DYNAMIC_FTRACE
949951
/* For 32 bit kernels we're compiling modules with
950952
* -ffunction-sections so we must relocate the addresses in the
951-
*__mcount_loc section.
953+
* ftrace callsite section.
952954
*/
953-
if (symindex != -1 && !strcmp(secname, "__mcount_loc")) {
955+
if (symindex != -1 && !strcmp(secname, FTRACE_CALLSITE_SECTION)) {
956+
int err;
954957
if (s->sh_type == SHT_REL)
955958
err = apply_relocate((Elf_Shdr *)sechdrs,
956959
strtab, symindex,
@@ -962,6 +965,7 @@ int module_finalize(const Elf_Ehdr *hdr,
962965
if (err)
963966
return err;
964967
}
968+
#endif
965969
}
966970
return 0;
967971
}

arch/parisc/kernel/module.lds

Lines changed: 0 additions & 7 deletions
This file was deleted.

include/asm-generic/vmlinux.lds.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,17 @@
110110
#endif
111111

112112
#ifdef CONFIG_FTRACE_MCOUNT_RECORD
113-
#ifdef CC_USING_PATCHABLE_FUNCTION_ENTRY
114-
#define MCOUNT_REC() . = ALIGN(8); \
115-
__start_mcount_loc = .; \
116-
KEEP(*(__patchable_function_entries)) \
117-
__stop_mcount_loc = .;
118-
#else
113+
/*
114+
* The ftrace call sites are logged to a section whose name depends on the
115+
* compiler option used. A given kernel image will only use one, AKA
116+
* FTRACE_CALLSITE_SECTION. We capture all of them here to avoid header
117+
* dependencies for FTRACE_CALLSITE_SECTION's definition.
118+
*/
119119
#define MCOUNT_REC() . = ALIGN(8); \
120120
__start_mcount_loc = .; \
121121
KEEP(*(__mcount_loc)) \
122+
KEEP(*(__patchable_function_entries)) \
122123
__stop_mcount_loc = .;
123-
#endif
124124
#else
125125
#define MCOUNT_REC()
126126
#endif

include/linux/ftrace.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,11 @@ static inline unsigned long get_lock_parent_ip(void)
738738

739739
#ifdef CONFIG_FTRACE_MCOUNT_RECORD
740740
extern void ftrace_init(void);
741+
#ifdef CC_USING_PATCHABLE_FUNCTION_ENTRY
742+
#define FTRACE_CALLSITE_SECTION "__patchable_function_entries"
743+
#else
744+
#define FTRACE_CALLSITE_SECTION "__mcount_loc"
745+
#endif
741746
#else
742747
static inline void ftrace_init(void) { }
743748
#endif

kernel/module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3222,7 +3222,7 @@ static int find_module_sections(struct module *mod, struct load_info *info)
32223222
#endif
32233223
#ifdef CONFIG_FTRACE_MCOUNT_RECORD
32243224
/* sechdrs[0].sh_size is always zero */
3225-
mod->ftrace_callsites = section_objs(info, "__mcount_loc",
3225+
mod->ftrace_callsites = section_objs(info, FTRACE_CALLSITE_SECTION,
32263226
sizeof(*mod->ftrace_callsites),
32273227
&mod->num_ftrace_callsites);
32283228
#endif

0 commit comments

Comments
 (0)