Skip to content

Commit ea73179

Browse files
rnavmpe
authored andcommitted
powerpc/ftrace: Ignore ftrace locations in exit text sections
Michael reported that we are seeing an ftrace bug on bootup when KASAN is enabled and we are using -fpatchable-function-entry: ftrace: allocating 47780 entries in 18 pages ftrace-powerpc: 0xc0000000020b3d5c: No module provided for non-kernel address ------------[ ftrace bug ]------------ ftrace faulted on modifying [<c0000000020b3d5c>] 0xc0000000020b3d5c Initializing ftrace call sites ftrace record flags: 0 (0) expected tramp: c00000000008cef4 ------------[ cut here ]------------ WARNING: CPU: 0 PID: 0 at kernel/trace/ftrace.c:2180 ftrace_bug+0x3c0/0x424 Modules linked in: CPU: 0 PID: 0 Comm: swapper Not tainted 6.5.0-rc3-00120-g0f71dcfb4aef torvalds#860 Hardware name: IBM pSeries (emulated by qemu) POWER9 (raw) 0x4e1202 0xf000005 of:SLOF,HEAD hv:linux,kvm pSeries NIP: c0000000003aa81c LR: c0000000003aa818 CTR: 0000000000000000 REGS: c0000000033cfab0 TRAP: 0700 Not tainted (6.5.0-rc3-00120-g0f71dcfb4aef) MSR: 8000000002021033 <SF,VEC,ME,IR,DR,RI,LE> CR: 28028240 XER: 00000000 CFAR: c0000000002781a8 IRQMASK: 3 ... NIP [c0000000003aa81c] ftrace_bug+0x3c0/0x424 LR [c0000000003aa818] ftrace_bug+0x3bc/0x424 Call Trace: ftrace_bug+0x3bc/0x424 (unreliable) ftrace_process_locs+0x5f4/0x8a0 ftrace_init+0xc0/0x1d0 start_kernel+0x1d8/0x484 With CONFIG_FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY=y and CONFIG_KASAN=y, compiler emits nops in functions that it generates for registering and unregistering global variables (unlike with -pg and -mprofile-kernel where calls to _mcount() are not generated in those functions). Those functions then end up in INIT_TEXT and EXIT_TEXT respectively. We don't expect to see any profiled functions in EXIT_TEXT, so ftrace_init_nop() assumes that all addresses that aren't in the core kernel text belongs to a module. Since these functions do not match that criteria, we see the above bug. Address this by having ftrace ignore all locations in the text exit sections of vmlinux. Fixes: 0f71dcf ("powerpc/ftrace: Add support for -fpatchable-function-entry") Cc: [email protected] # v6.6+ Reported-by: Michael Ellerman <[email protected]> Signed-off-by: Naveen N Rao <[email protected]> Reviewed-by: Benjamin Gray <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://msgid.link/[email protected]
1 parent eb6d871 commit ea73179

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

arch/powerpc/include/asm/ftrace.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@
2020
#ifndef __ASSEMBLY__
2121
extern void _mcount(void);
2222

23-
static inline unsigned long ftrace_call_adjust(unsigned long addr)
24-
{
25-
if (IS_ENABLED(CONFIG_ARCH_USING_PATCHABLE_FUNCTION_ENTRY))
26-
addr += MCOUNT_INSN_SIZE;
27-
28-
return addr;
29-
}
30-
3123
unsigned long prepare_ftrace_return(unsigned long parent, unsigned long ip,
3224
unsigned long sp);
3325

@@ -142,8 +134,10 @@ static inline u8 this_cpu_get_ftrace_enabled(void) { return 1; }
142134
#ifdef CONFIG_FUNCTION_TRACER
143135
extern unsigned int ftrace_tramp_text[], ftrace_tramp_init[];
144136
void ftrace_free_init_tramp(void);
137+
unsigned long ftrace_call_adjust(unsigned long addr);
145138
#else
146139
static inline void ftrace_free_init_tramp(void) { }
140+
static inline unsigned long ftrace_call_adjust(unsigned long addr) { return addr; }
147141
#endif
148142
#endif /* !__ASSEMBLY__ */
149143

arch/powerpc/include/asm/sections.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ typedef struct func_desc func_desc_t;
1414

1515
extern char __head_end[];
1616
extern char __srwx_boundary[];
17+
extern char __exittext_begin[], __exittext_end[];
1718

1819
/* Patch sites */
1920
extern s32 patch__call_flush_branch_caches1;

arch/powerpc/kernel/trace/ftrace.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,22 @@
2727
#include <asm/ftrace.h>
2828
#include <asm/syscall.h>
2929
#include <asm/inst.h>
30+
#include <asm/sections.h>
3031

3132
#define NUM_FTRACE_TRAMPS 2
3233
static unsigned long ftrace_tramps[NUM_FTRACE_TRAMPS];
3334

35+
unsigned long ftrace_call_adjust(unsigned long addr)
36+
{
37+
if (addr >= (unsigned long)__exittext_begin && addr < (unsigned long)__exittext_end)
38+
return 0;
39+
40+
if (IS_ENABLED(CONFIG_ARCH_USING_PATCHABLE_FUNCTION_ENTRY))
41+
addr += MCOUNT_INSN_SIZE;
42+
43+
return addr;
44+
}
45+
3446
static ppc_inst_t ftrace_create_branch_inst(unsigned long ip, unsigned long addr, int link)
3547
{
3648
ppc_inst_t op;

arch/powerpc/kernel/trace/ftrace_64_pg.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
#define NUM_FTRACE_TRAMPS 8
3838
static unsigned long ftrace_tramps[NUM_FTRACE_TRAMPS];
3939

40+
unsigned long ftrace_call_adjust(unsigned long addr)
41+
{
42+
return addr;
43+
}
44+
4045
static ppc_inst_t
4146
ftrace_call_replace(unsigned long ip, unsigned long addr, int link)
4247
{

arch/powerpc/kernel/vmlinux.lds.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ SECTIONS
281281
* to deal with references from __bug_table
282282
*/
283283
.exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
284+
__exittext_begin = .;
284285
EXIT_TEXT
286+
__exittext_end = .;
285287
}
286288

287289
. = ALIGN(PAGE_SIZE);

0 commit comments

Comments
 (0)