Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <alexei.starovoitov@gmail.com>
Cc: Florent Revest <revest@chromium.org>
Cc: Martin KaFai Lau <martin.lau@linux.dev>
Cc: bpf <bpf@vger.kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alan Maguire <alan.maguire@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Naveen N Rao <naveen@kernel.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: x86@kernel.org
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Link: https://lore.kernel.org/173379653720.973433.18438622234884980494.stgit@devnote2
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Masami Hiramatsu (Google) and committed by
Steven Rostedt (Google)
d576aec2 1d95fd9d

+7 -20
-6
arch/powerpc/kernel/trace/ftrace.c
··· 658 658 struct ftrace_ops *op, struct ftrace_regs *fregs) 659 659 { 660 660 unsigned long sp = arch_ftrace_regs(fregs)->regs.gpr[1]; 661 - int bit; 662 661 663 662 if (unlikely(ftrace_graph_is_dead())) 664 663 goto out; ··· 665 666 if (unlikely(atomic_read(&current->tracing_graph_pause))) 666 667 goto out; 667 668 668 - bit = ftrace_test_recursion_trylock(ip, parent_ip); 669 - if (bit < 0) 670 - goto out; 671 - 672 669 if (!function_graph_enter(parent_ip, ip, 0, (unsigned long *)sp)) 673 670 parent_ip = ppc_function_entry(return_to_handler); 674 671 675 - ftrace_test_recursion_unlock(bit); 676 672 out: 677 673 arch_ftrace_regs(fregs)->regs.link = parent_ip; 678 674 }
-6
arch/powerpc/kernel/trace/ftrace_64_pg.c
··· 790 790 __prepare_ftrace_return(unsigned long parent, unsigned long ip, unsigned long sp) 791 791 { 792 792 unsigned long return_hooker; 793 - int bit; 794 793 795 794 if (unlikely(ftrace_graph_is_dead())) 796 795 goto out; ··· 797 798 if (unlikely(atomic_read(&current->tracing_graph_pause))) 798 799 goto out; 799 800 800 - bit = ftrace_test_recursion_trylock(ip, parent); 801 - if (bit < 0) 802 - goto out; 803 - 804 801 return_hooker = ppc_function_entry(return_to_handler); 805 802 806 803 if (!function_graph_enter(parent, ip, 0, (unsigned long *)sp)) 807 804 parent = return_hooker; 808 805 809 - ftrace_test_recursion_unlock(bit); 810 806 out: 811 807 return parent; 812 808 }
-7
arch/x86/kernel/ftrace.c
··· 615 615 unsigned long frame_pointer) 616 616 { 617 617 unsigned long return_hooker = (unsigned long)&return_to_handler; 618 - int bit; 619 618 620 619 /* 621 620 * When resuming from suspend-to-ram, this function can be indirectly ··· 634 635 if (unlikely(atomic_read(&current->tracing_graph_pause))) 635 636 return; 636 637 637 - bit = ftrace_test_recursion_trylock(ip, *parent); 638 - if (bit < 0) 639 - return; 640 - 641 638 if (!function_graph_enter(*parent, ip, frame_pointer, parent)) 642 639 *parent = return_hooker; 643 - 644 - ftrace_test_recursion_unlock(bit); 645 640 } 646 641 647 642 #ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS
+7 -1
kernel/trace/fgraph.c
··· 650 650 struct ftrace_graph_ent trace; 651 651 unsigned long bitmap = 0; 652 652 int offset; 653 + int bit; 653 654 int i; 655 + 656 + bit = ftrace_test_recursion_trylock(func, ret); 657 + if (bit < 0) 658 + return -EBUSY; 654 659 655 660 trace.func = func; 656 661 trace.depth = ++current->curr_ret_depth; ··· 702 697 * flag, set that bit always. 703 698 */ 704 699 set_bitmap(current, offset, bitmap | BIT(0)); 705 - 700 + ftrace_test_recursion_unlock(bit); 706 701 return 0; 707 702 out_ret: 708 703 current->curr_ret_stack -= FGRAPH_FRAME_OFFSET + 1; 709 704 out: 710 705 current->curr_ret_depth--; 706 + ftrace_test_recursion_unlock(bit); 711 707 return -EBUSY; 712 708 } 713 709