xref: /openbmc/linux/arch/riscv/kernel/ftrace.c (revision 5927145e)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2013 Linaro Limited
4  * Author: AKASHI Takahiro <takahiro.akashi@linaro.org>
5  * Copyright (C) 2017 Andes Technology Corporation
6  */
7 
8 #include <linux/ftrace.h>
9 
10 /*
11  * Most of this file is copied from arm64.
12  */
13 void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
14 			   unsigned long frame_pointer)
15 {
16 	unsigned long return_hooker = (unsigned long)&return_to_handler;
17 	unsigned long old;
18 	struct ftrace_graph_ent trace;
19 	int err;
20 
21 	if (unlikely(atomic_read(&current->tracing_graph_pause)))
22 		return;
23 
24 	/*
25 	 * We don't suffer access faults, so no extra fault-recovery assembly
26 	 * is needed here.
27 	 */
28 	old = *parent;
29 
30 	trace.func = self_addr;
31 	trace.depth = current->curr_ret_stack + 1;
32 
33 	if (!ftrace_graph_entry(&trace))
34 		return;
35 
36 	err = ftrace_push_return_trace(old, self_addr, &trace.depth,
37 				       frame_pointer, NULL);
38 	if (err == -EBUSY)
39 		return;
40 	*parent = return_hooker;
41 }
42