Skip to content

Commit d576aec

Browse files
mhiramatrostedt
authored andcommitted
fgraph: Get ftrace recursion lock in function_graph_enter
Get the ftrace recursion lock in the generic function_graph_enter() instead of each architecture code. This changes all function_graph tracer callbacks running in non-preemptive state. On x86 and powerpc, this is by default, but on the other architecutres, this will be new. Cc: Alexei Starovoitov <[email protected]> Cc: Florent Revest <[email protected]> Cc: Martin KaFai Lau <[email protected]> Cc: bpf <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Alan Maguire <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Nicholas Piggin <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: Naveen N Rao <[email protected]> Cc: Madhavan Srinivasan <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Dave Hansen <[email protected]> Cc: [email protected] Cc: "H. Peter Anvin" <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Link: https://lore.kernel.org/173379653720.973433.18438622234884980494.stgit@devnote2 Signed-off-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 1d95fd9 commit d576aec

File tree

4 files changed

+7
-20
lines changed

4 files changed

+7
-20
lines changed

arch/powerpc/kernel/trace/ftrace.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -658,22 +658,16 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
658658
struct ftrace_ops *op, struct ftrace_regs *fregs)
659659
{
660660
unsigned long sp = arch_ftrace_regs(fregs)->regs.gpr[1];
661-
int bit;
662661

663662
if (unlikely(ftrace_graph_is_dead()))
664663
goto out;
665664

666665
if (unlikely(atomic_read(&current->tracing_graph_pause)))
667666
goto out;
668667

669-
bit = ftrace_test_recursion_trylock(ip, parent_ip);
670-
if (bit < 0)
671-
goto out;
672-
673668
if (!function_graph_enter(parent_ip, ip, 0, (unsigned long *)sp))
674669
parent_ip = ppc_function_entry(return_to_handler);
675670

676-
ftrace_test_recursion_unlock(bit);
677671
out:
678672
arch_ftrace_regs(fregs)->regs.link = parent_ip;
679673
}

arch/powerpc/kernel/trace/ftrace_64_pg.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -790,24 +790,18 @@ static unsigned long
790790
__prepare_ftrace_return(unsigned long parent, unsigned long ip, unsigned long sp)
791791
{
792792
unsigned long return_hooker;
793-
int bit;
794793

795794
if (unlikely(ftrace_graph_is_dead()))
796795
goto out;
797796

798797
if (unlikely(atomic_read(&current->tracing_graph_pause)))
799798
goto out;
800799

801-
bit = ftrace_test_recursion_trylock(ip, parent);
802-
if (bit < 0)
803-
goto out;
804-
805800
return_hooker = ppc_function_entry(return_to_handler);
806801

807802
if (!function_graph_enter(parent, ip, 0, (unsigned long *)sp))
808803
parent = return_hooker;
809804

810-
ftrace_test_recursion_unlock(bit);
811805
out:
812806
return parent;
813807
}

arch/x86/kernel/ftrace.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,6 @@ void prepare_ftrace_return(unsigned long ip, unsigned long *parent,
615615
unsigned long frame_pointer)
616616
{
617617
unsigned long return_hooker = (unsigned long)&return_to_handler;
618-
int bit;
619618

620619
/*
621620
* When resuming from suspend-to-ram, this function can be indirectly
@@ -635,14 +634,8 @@ void prepare_ftrace_return(unsigned long ip, unsigned long *parent,
635634
if (unlikely(atomic_read(&current->tracing_graph_pause)))
636635
return;
637636

638-
bit = ftrace_test_recursion_trylock(ip, *parent);
639-
if (bit < 0)
640-
return;
641-
642637
if (!function_graph_enter(*parent, ip, frame_pointer, parent))
643638
*parent = return_hooker;
644-
645-
ftrace_test_recursion_unlock(bit);
646639
}
647640

648641
#ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS

kernel/trace/fgraph.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,13 @@ int function_graph_enter(unsigned long ret, unsigned long func,
650650
struct ftrace_graph_ent trace;
651651
unsigned long bitmap = 0;
652652
int offset;
653+
int bit;
653654
int i;
654655

656+
bit = ftrace_test_recursion_trylock(func, ret);
657+
if (bit < 0)
658+
return -EBUSY;
659+
655660
trace.func = func;
656661
trace.depth = ++current->curr_ret_depth;
657662

@@ -697,12 +702,13 @@ int function_graph_enter(unsigned long ret, unsigned long func,
697702
* flag, set that bit always.
698703
*/
699704
set_bitmap(current, offset, bitmap | BIT(0));
700-
705+
ftrace_test_recursion_unlock(bit);
701706
return 0;
702707
out_ret:
703708
current->curr_ret_stack -= FGRAPH_FRAME_OFFSET + 1;
704709
out:
705710
current->curr_ret_depth--;
711+
ftrace_test_recursion_unlock(bit);
706712
return -EBUSY;
707713
}
708714

0 commit comments

Comments
 (0)