Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp553438lqh; Tue, 7 May 2024 07:18:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWbaJP//yRcRKC3idJTRzdbBlicdI/Mu2VXUW4EQHP2bUidC4p6kb7lJQA5JHSP/CPNIu6mihLHG6ZrB5n0wR/RjbPo7+eRWQAz4a6WLw== X-Google-Smtp-Source: AGHT+IHv7JgqfHwwSkw+7pLV0XNS1AnSxj8U9RNLjmPD0q7CzAy0CzqN1BWdaZ7W0pcTt6TzogMb X-Received: by 2002:a17:903:4d1:b0:1ec:53de:a51d with SMTP id jm17-20020a17090304d100b001ec53dea51dmr14313939plb.69.1715091515016; Tue, 07 May 2024 07:18:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715091515; cv=pass; d=google.com; s=arc-20160816; b=z9ep2eyQwH+wF2RLQ6MI85pLXjqJbXl9l8XfMsyNpbMRxhUu4KSXfpQE3RXEQx+TCA BRfXNmJLbccw9rbWP/t+psk6IXz03GxWZoFJNT35ql/BxRqaZETpDQ17H36CC3TDyfMB qr+Xnq3e7CkT+yIbtcyHEERzX1h8iW36PG4P1NkvgHOlJiUYt8VgqboIAlFkXnVuLVko 90rBdZgckyg/oB7fgL2ta9GsJCaqlNl7KoTWQYs+oop/jVZbNgpoiJS/EjtWdev64OSI WgjZ/JNlGQcJzhNbLXzEA8ODrJEtc87FGEAOi1C9g6IMURL7UQGhsPuCoVUrbNp7zuAJ tl9Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=7PjutEMmMCJY8d+Q3MnS8v4dL5+oKI/DjPJMrBzBfC4=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=ld9GiIH53/oiynIiG23ZvwegeEDEPPJjRXfQYlE1AKpH9ukadtvtmyZHL/afBAOzUm js3KrvWQ6UcztbebfJXg7hobm2BldVbQct2hEcn5guYpQ9KSc0v4bxccu4yc5Y/4d7wD VOPr2RsNAfI+ezzpsAAHodHnSlNLGzK+XGPymQJASN1vS1NjudE7R+CV/U2J9TTN70mc aC8aGB8/d1gaMUM9kOUWxAzgDY8IDNL5hrisSm+CmC+NH14XoX8ScRRvnROdKwKBu1cQ WwMmk4EQfPvBeHv6iw1GDiK/LrYq12z1+N2cJcTGvzdYOEdHnB7GA5SDO0ZA2cIXyRpt fitg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=maEZLGAq; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171528-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171528-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u4-20020a17090341c400b001e4ea3583ffsi10439997ple.552.2024.05.07.07.18.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 07:18:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171528-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=maEZLGAq; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171528-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171528-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 45624283687 for ; Tue, 7 May 2024 14:15:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EB88615FA71; Tue, 7 May 2024 14:12:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="maEZLGAq" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D85EC16ABF7; Tue, 7 May 2024 14:12:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715091157; cv=none; b=gAgmZ+HTBB6bv7nBL03dr2YaL6mJeTzg4IMgIC206kLC/xvtniObjumpd1Uv80gOP8+oy7PcjOVfbN5pz8B8px7QMkU+isgv+8wSpgtHgg5aOpUEIWGNe82ylrmnDg+Ne3MVVcKycvnkdFFjOLBrfPHOvRL8ISOlr3JKnE5xpds= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715091157; c=relaxed/simple; bh=IypJUXdfLDMzh2Zc7SJIn01pmChcGms8ypnAXt1TbyA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=fTd22/DFar2Gw3FICZOBqv9MAPSOOjiUYSCjy/dkrDFzDrugCgNossVa7voG3jWOu4yWe+IYgUHP5Ck7Fz9E22Mg7jCkht4mYPkEfYT2JR+v5zFOfwMglchExQt9VXXBayx9Qnc4Yw0Mi6aXoN4ZCBa2v+pN5eIwmSyhzMI+avM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=maEZLGAq; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E01FC2BBFC; Tue, 7 May 2024 14:12:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715091156; bh=IypJUXdfLDMzh2Zc7SJIn01pmChcGms8ypnAXt1TbyA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=maEZLGAq+5jvWRbFFHYPm3X9mGYEklIN8qGtTsOvr6FRQRL6x05AJrAgmaBv7vfBU 1qPFvtzYyVWXQuFFBvv50I4JMjZZ5cQvHsaO4K7HGwpU9BpUNB4RlrD5q/CIB7xKHf ujhxJSKwIRY9e4RHQXnIQFSFd8I1m33AfQ8CUJt/ZgGjNJNIDl3p65hmgmPoX1Aunk dDwghsaTVGZ2zNq+d6Z84l4AX9nQ3w/dsJgAnDnZklF48BMeNs6aW4R3g2nQT4SAwj 9EDjh31kzwmrtEGX8zNd7FEccVvqPJ/Th/7LdRZGTxd1WI82oN4MLbBkNrn9byCONS e/gGjB4O2zr+Q== From: "Masami Hiramatsu (Google)" To: Alexei Starovoitov , Steven Rostedt , Florent Revest Cc: linux-trace-kernel@vger.kernel.org, LKML , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Mark Rutland , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: [PATCH v10 23/36] function_graph: Pass ftrace_regs to retfunc Date: Tue, 7 May 2024 23:12:30 +0900 Message-Id: <171509115030.162236.4328110181248913864.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <171509088006.162236.7227326999861366050.stgit@devnote2> References: <171509088006.162236.7227326999861366050.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit From: Masami Hiramatsu (Google) Pass ftrace_regs to the fgraph_ops::retfunc(). If ftrace_regs is not available, it passes a NULL instead. User callback function can access some registers (including return address) via this ftrace_regs. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v8: - Pass ftrace_regs to retfunc, instead of adding retregfunc. Changes in v6: - update to use ftrace_regs_get_return_value() because of reordering patches. Changes in v3: - Update for new multiple fgraph. - Save the return address to instruction pointer in ftrace_regs. --- include/linux/ftrace.h | 3 ++- kernel/trace/fgraph.c | 14 ++++++++++---- kernel/trace/ftrace.c | 3 ++- kernel/trace/trace.h | 3 ++- kernel/trace/trace_functions_graph.c | 7 ++++--- kernel/trace/trace_irqsoff.c | 3 ++- kernel/trace/trace_sched_wakeup.c | 3 ++- kernel/trace/trace_selftest.c | 3 ++- 8 files changed, 26 insertions(+), 13 deletions(-) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 0af83b115886..1c185fefd932 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -1067,7 +1067,8 @@ struct fgraph_ops; /* Type of the callback handlers for tracing function graph*/ typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *, - struct fgraph_ops *); /* return */ + struct fgraph_ops *, + struct ftrace_regs *); /* return */ typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *, struct fgraph_ops *, struct ftrace_regs *); /* entry */ diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index d520b2b78918..40f47fcbc6c3 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -264,7 +264,8 @@ static int entry_run(struct ftrace_graph_ent *trace, struct fgraph_ops *ops, } /* ftrace_graph_return set to this to tell some archs to run function graph */ -static void return_run(struct ftrace_graph_ret *trace, struct fgraph_ops *ops) +static void return_run(struct ftrace_graph_ret *trace, struct fgraph_ops *ops, + struct ftrace_regs *fregs) { } @@ -455,7 +456,8 @@ int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace, } static void ftrace_graph_ret_stub(struct ftrace_graph_ret *trace, - struct fgraph_ops *gops) + struct fgraph_ops *gops, + struct ftrace_regs *fregs) { } @@ -799,6 +801,9 @@ __ftrace_return_to_handler(struct ftrace_regs *fregs, unsigned long frame_pointe } trace.rettime = trace_clock_local(); + if (fregs) + ftrace_regs_set_instruction_pointer(fregs, ret); + #ifdef CONFIG_FUNCTION_GRAPH_RETVAL trace.retval = ftrace_regs_get_return_value(fregs); #endif @@ -812,7 +817,7 @@ __ftrace_return_to_handler(struct ftrace_regs *fregs, unsigned long frame_pointe if (gops == &fgraph_stub) continue; - gops->retfunc(&trace, gops); + gops->retfunc(&trace, gops, fregs); } /* @@ -976,7 +981,8 @@ void ftrace_graph_sleep_time_control(bool enable) * Simply points to ftrace_stub, but with the proper protocol. * Defined by the linker script in linux/vmlinux.lds.h */ -void ftrace_stub_graph(struct ftrace_graph_ret *trace, struct fgraph_ops *gops); +void ftrace_stub_graph(struct ftrace_graph_ret *trace, struct fgraph_ops *gops, + struct ftrace_regs *fregs); /* The callbacks that hook a function */ trace_func_graph_ret_t ftrace_graph_return = ftrace_stub_graph; diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 5377a0b22ec9..e869258efc52 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -835,7 +835,8 @@ static int profile_graph_entry(struct ftrace_graph_ent *trace, } static void profile_graph_return(struct ftrace_graph_ret *trace, - struct fgraph_ops *gops) + struct fgraph_ops *gops, + struct ftrace_regs *fregs) { struct ftrace_ret_stack *ret_stack; struct ftrace_profile_stat *stat; diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 8221b6febb51..81cb2a90cbda 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -681,7 +681,8 @@ void trace_latency_header(struct seq_file *m); void trace_default_header(struct seq_file *m); void print_trace_header(struct seq_file *m, struct trace_iterator *iter); -void trace_graph_return(struct ftrace_graph_ret *trace, struct fgraph_ops *gops); +void trace_graph_return(struct ftrace_graph_ret *trace, struct fgraph_ops *gops, + struct ftrace_regs *fregs); int trace_graph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops, struct ftrace_regs *fregs); diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c index b9785fc919c9..241407000109 100644 --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c @@ -240,7 +240,7 @@ void __trace_graph_return(struct trace_array *tr, } void trace_graph_return(struct ftrace_graph_ret *trace, - struct fgraph_ops *gops) + struct fgraph_ops *gops, struct ftrace_regs *fregs) { unsigned long *task_var = fgraph_get_task_var(gops); struct trace_array *tr = gops->private; @@ -270,7 +270,8 @@ void trace_graph_return(struct ftrace_graph_ret *trace, } static void trace_graph_thresh_return(struct ftrace_graph_ret *trace, - struct fgraph_ops *gops) + struct fgraph_ops *gops, + struct ftrace_regs *fregs) { ftrace_graph_addr_finish(gops, trace); @@ -283,7 +284,7 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace, (trace->rettime - trace->calltime < tracing_thresh)) return; else - trace_graph_return(trace, gops); + trace_graph_return(trace, gops, fregs); } static struct fgraph_ops funcgraph_ops = { diff --git a/kernel/trace/trace_irqsoff.c b/kernel/trace/trace_irqsoff.c index ad739d76fc86..504de7a05498 100644 --- a/kernel/trace/trace_irqsoff.c +++ b/kernel/trace/trace_irqsoff.c @@ -208,7 +208,8 @@ static int irqsoff_graph_entry(struct ftrace_graph_ent *trace, } static void irqsoff_graph_return(struct ftrace_graph_ret *trace, - struct fgraph_ops *gops) + struct fgraph_ops *gops, + struct ftrace_regs *fregs) { struct trace_array *tr = irqsoff_trace; struct trace_array_cpu *data; diff --git a/kernel/trace/trace_sched_wakeup.c b/kernel/trace/trace_sched_wakeup.c index 23360a2700de..9ffbd9326898 100644 --- a/kernel/trace/trace_sched_wakeup.c +++ b/kernel/trace/trace_sched_wakeup.c @@ -144,7 +144,8 @@ static int wakeup_graph_entry(struct ftrace_graph_ent *trace, } static void wakeup_graph_return(struct ftrace_graph_ret *trace, - struct fgraph_ops *gops) + struct fgraph_ops *gops, + struct ftrace_regs *fregs) { struct trace_array *tr = wakeup_trace; struct trace_array_cpu *data; diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c index 5edbf09844d9..4e6dff831407 100644 --- a/kernel/trace/trace_selftest.c +++ b/kernel/trace/trace_selftest.c @@ -807,7 +807,8 @@ static __init int store_entry(struct ftrace_graph_ent *trace, } static __init void store_return(struct ftrace_graph_ret *trace, - struct fgraph_ops *gops) + struct fgraph_ops *gops, + struct ftrace_regs *fregs) { struct fgraph_fixture *fixture = container_of(gops, struct fgraph_fixture, gops); const char *type = fixture->store_type_name;