Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1425015lqp; Mon, 15 Apr 2024 06:23:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU8O0w4ok0zjBpwltx3BcIxiBjhQDC9CblnAFtutW3ZpbZzUm0JivCqyQ2tkYx14LZv81FAFWommjhTGgzR/eh8etfhVuFXzxw+5sphYg== X-Google-Smtp-Source: AGHT+IFT8vbKh5z/T5b0LEh3I2W07j+UGzkAfBAo69ZL2MqxNHtZYIl8eayuaLS3Xi1HCDGg1zyI X-Received: by 2002:aa7:88c1:0:b0:6ea:d149:c4e with SMTP id k1-20020aa788c1000000b006ead1490c4emr9607154pff.14.1713187386648; Mon, 15 Apr 2024 06:23:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713187386; cv=pass; d=google.com; s=arc-20160816; b=uuT7ZbiuWBXZSV5G3FgyHXYJmj09Y4LfFRNOVPrXCAvrk9OgquNf3eV+ScvGn29QQG QuU7GRxtlAUwqhpwZosT9kt+dD2V+Zg2H97l88XR/bN2JiX4TW8+CAoUYr4xooe5tmN6 Bae67SGM/tZjF6p7TByrWIK43kMQir9FlwsOp9en1XRv7A9Mtym06XnI7qWeXj+sbZRt CIpAucMQb1V8ahNV1SEhVT5YPvxMRnMJPYG7SSWi5qUqceG9gfKaGOIV8llff6QJWAph 1zToIpy3wb5zjeoU4SAc3up8O0F9DQ28AIGd7V4fBh7G+G2qlJS+OkLzEVWoiHNE/MJF Hvcw== 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=VQIb4Rf0aMIztlF3X7TIIulhZNy11oj80du2m/3Ti+M=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=id/Jg1N3uUHNlLPgMuv843SDsQNepgxbLjT+fveTFeSL3aT6VQ11/rBToL8JbUUGYr OtjvyFktCBA2tVF5979GKaOOocRwdtZ9foFQWRt/k+6bFeWzJfpE9oFW8jQ7ylvrIzCl yDALBG8wWMTr2t58JavzELaJX2eW8wIAhTErsflu+1YG9d//85CyAx+Qm74R4jRlDJJD RMXZUoTzjbv75psBruJ49dy86iuXhC72RfxJlYR//umqND/9XxK5EuX+hb4qXOX/itec rYbQUrCfwIYsQjK6Hn7lQ/Wod95m5ndbFX1hxUbVDZbTLexMVtmckMedt8mqrhPTCBLA f62A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ehNU0GHx; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-145187-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145187-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 fh18-20020a056a00391200b006e8f9fc3c54si8221552pfb.95.2024.04.15.06.23.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 06:23:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145187-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=ehNU0GHx; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-145187-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145187-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 5E51228109B for ; Mon, 15 Apr 2024 13:12:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC14713B2B9; Mon, 15 Apr 2024 12:53:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ehNU0GHx" 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 9DA70823DA; Mon, 15 Apr 2024 12:53: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=1713185616; cv=none; b=VaDN4GILrsoU4+tougHObYlGd8OABXAuBJ6Ns5N0oj52zWv66MnW9IidwYXG0lFB76RH7GazbJ/p/Kfj8x+e1znr4ZImwMVp+ip/mjfjcKg0b8ZY9IOOxMc54YPrJ3vBGwWjc4UkPKtPrFwr7LXfoxn3GB4MHPmZfZ7EBw1VOPs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713185616; c=relaxed/simple; bh=M7OiUGVAEwIEIM8KF4/uk7WHPI4GLS3Eg1v6AWJ8GVc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=EaRtUE027AxxousqTVhykMnjj6wlRDtxlgzVVbLncisLBV2AiYs7KjhnWaRVlczekCOSw6TBfmsQZqke957f+NEc5Y1fRFIwsoXpA36RlwB8XNLwZ5COZ+DzMZqOGjC7B6dfZ+siwiZo3fKdq1MetWsKqhAxHkXH8INwel1NBJk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ehNU0GHx; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19FF2C113CC; Mon, 15 Apr 2024 12:53:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713185616; bh=M7OiUGVAEwIEIM8KF4/uk7WHPI4GLS3Eg1v6AWJ8GVc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ehNU0GHxEmmxrWezIgSHjwjGvRJXvJsFn7ZbMdp3sGv9Ni81E8+JuoYLwNDXt3qEK XJYrbddYwHFAxamaiDf68Ep26JuyKTlZAL4GOcnBXfTZJ6TwV1+6UqFo2Uzb8VCDa7 9OfZ+jwn4K1Zpu3flfh/x+n7EGfci4f/4jTLcnZCV3CZPHR72niSWaTQ6Am3lPYLyk tEOgeypKt/hPm9WMpfHcdNQ1C+Ooc/pSbcj+SEW4g2jtgBUqjhe00gsjuD5qgh1zQZ nEkCRrhMXIAmovMCcv9+wkk69dzanEqIVeREJ5D/hpXaatiY7lXmNje+GrwwkNp1CW VOX1iSEQPFlcg== 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 v9 23/36] function_graph: Pass ftrace_regs to retfunc Date: Mon, 15 Apr 2024 21:53:31 +0900 Message-Id: <171318561094.254850.7480253446528564518.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <171318533841.254850.15841395205784342850.stgit@devnote2> References: <171318533841.254850.15841395205784342850.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 0255b95f2d61..54e60dbdb657 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 33be5af4801c..7556fbbae323 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -255,7 +255,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) { } @@ -447,7 +448,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) { } @@ -791,6 +793,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 @@ -804,7 +809,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); } /* @@ -968,7 +973,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;