Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp566611lqh; Tue, 7 May 2024 07:38:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWTSN7FHMRI1tih6lViFpvbJYD/kBefGM5cCFiYfXDqSb2AyfonqdGvM6VZZFgM3DnVTdU0BKU98TAseTUlbi/IBgajs3d7nWiQl1V7kg== X-Google-Smtp-Source: AGHT+IGV8uLJ7T/95nyDH7YxdnBtn0+EUgyrx4jRQGPxJ8GO4FWLv5zRYNSILYgefCwTboL6leSc X-Received: by 2002:a05:6a21:918a:b0:1af:abef:c620 with SMTP id tp10-20020a056a21918a00b001afabefc620mr9765113pzb.35.1715092707964; Tue, 07 May 2024 07:38:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715092707; cv=pass; d=google.com; s=arc-20160816; b=MGWALSGHNhN2qbWjEZHuVagnWgw1zhK8AEmOesUXhWF2nsafH/gmsEcuK751f8LEOK usp5XkzG53yCx+Rr3Af1S4yCm62HPhscPUi/op3A81q8ENoTsTS1uLuohY5p8qvHULme AC/VM8KTp6inyjgvdz84gkY81iEiXIs9HEHQL+JUj94Nh+xpmrfEepgqu3PkQ8/KR6ND U3uXqt7LsMgiBPf5j57MCNGE3+eOQnv8kTdsL91cvoN9d7pZtJ9uJk9vaOLusL7oH99F kPz3X/B/MBhiDUAaOk3WhG61ysm99kGSBc+I5e4iMgSMkEHKtwnxIO0aICZdOw6fm84a GHjQ== 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=xtL+YrIcoLu11C2tmm/w4cuE7pUzl5XPBQgNf49ghFo=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=nX6TsYAQEPNNzMmTQXwA7lR4mynm+BeXsZVnSTqE5MbQdHg4XEjItHDd3ll+hfQ11f 1LVQpT725Ll+3g/aR4PGUcrEQx0fhfKUEH2TsTQuBQOz9Yb9zDIhh6IH/xxYAonzia0S vcsGzSyAoubL/brqL7CBUFFl9/tIV3twYiocHH6LXDiY5mksKKvh8Jumafv/DCVDRtyw LA4tTA+wSUfNgkKdnQGR7J3FPHtY+OEu0jhXogG85J8i5x8Wef3qfYDdcCvLMP5D4EWp Lo56zpfhuX2VXyEVIyw/rAsD9hc+APj6ymyr+zDC0oALShoAYsnrAx5yY2nNNtbPkbn8 uzpg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tc0i0AZ8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171513-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171513-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id u6-20020a637906000000b0062e4ca9219esi491857pgc.165.2024.05.07.07.38.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 07:38:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171513-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tc0i0AZ8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171513-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171513-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 78373B2ADAD for ; Tue, 7 May 2024 14:10:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA36F16078B; Tue, 7 May 2024 14:09:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tc0i0AZ8" 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 D8D4515FA84; Tue, 7 May 2024 14:09:40 +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=1715090981; cv=none; b=CBjdFl2VIxBYzlGlZRbtcbPsyWhfiiwd6YVDpfy9S809dGkgczbjh6hDyjmGtZXpUWq7Kcpg45eYBZU751d4UPFftqSFaKSjgt6QMsCM7CA9WA+z7Rn+N/5ck2Q5/lH5x1Ptz6KNsFkD1ooq+r5PnKYAzfuGIf9/3OvL7AUj5hc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715090981; c=relaxed/simple; bh=8cshOLCkgmf2wPL42uvM4lxZyiYR1ZHAwelzPteEqz4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=rEJhjrDiaZ4iDiyTYfFabzyXsVaFjwO1qCPz1h9FAekyMPGbAV47/h+OK6Tdu9Q2Arcz2cH4u7bQkxpiuX9Hx1zvl5cBz1p4YvQNGokGORsoTnULj7BTZmgYGxF8ZJ+e2nTIB3be2qRYyTyvGCYBSR5dvaosZN68SMpFfMiOfYg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tc0i0AZ8; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D528C3277B; Tue, 7 May 2024 14:09:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715090980; bh=8cshOLCkgmf2wPL42uvM4lxZyiYR1ZHAwelzPteEqz4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tc0i0AZ86gcqFE3S2/J1OceyArBgBZ52W9h9/kC3/iUlaJWOw8lI6s/76ONE62e3R P/aXoSfS+UY+WLl+P5gB6snRg1qi+QfbrgHu3CD71tYIRC+7lvJ2y6925yHzy1BglI QXanp4kRCoIAYT8XVa4oMrofmatr/BFVlqW3RVIUceKXUDn7w5PkWVAen/Io+TH6bb +cCPtX3RP8ivGnxsLasIzagnef4+vfiNSk2MEOKsWFiHbVKV4CEn5sNUydnHFJDu80 FjFT2pth920E/ZAwt3KJaQKneIvZrYY5JYSoWDG2XkD2WNoMOKjkcxCG5d3KOu5Epi /iKDrOUXwcY+g== 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 08/36] function_graph: Remove logic around ftrace_graph_entry and return Date: Tue, 7 May 2024 23:09:34 +0900 Message-Id: <171509097408.162236.17387844142114638932.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: Steven Rostedt (VMware) The function pointers ftrace_graph_entry and ftrace_graph_return are no longer called via the function_graph tracer. Instead, an array structure is now used that will allow for multiple users of the function_graph infrastructure. The variables are still used by the architecture code for non dynamic ftrace configs, where a test is made against them to see if they point to the default stub function or not. This is how the static function tracing knows to call into the function graph tracer infrastructure or not. Two new stub functions are made. entry_run() and return_run(). The ftrace_graph_entry and ftrace_graph_return are set to them respectively when the function graph tracer is enabled, and this will trigger the architecture specific function graph code to be executed. This also requires checking the global_ops hash for all calls into the function_graph tracer. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Fix typo and make lines shorter than 76 chars in the description. - Remove unneeded return from return_run() function. --- kernel/trace/fgraph.c | 67 +++++++++------------------------------- kernel/trace/ftrace.c | 2 - kernel/trace/ftrace_internal.h | 2 - 3 files changed, 15 insertions(+), 56 deletions(-) diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index 6b06962657fe..c50edd1344e5 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -143,6 +143,17 @@ add_fgraph_index_bitmap(struct task_struct *t, int offset, unsigned long bitmap) t->ret_stack[offset] |= (bitmap << FGRAPH_INDEX_SHIFT); } +/* ftrace_graph_entry set to this to tell some archs to run function graph */ +static int entry_run(struct ftrace_graph_ent *trace) +{ + return 0; +} + +/* ftrace_graph_return set to this to tell some archs to run function graph */ +static void return_run(struct ftrace_graph_ret *trace) +{ +} + /* * @offset: The offset into @t->ret_stack to find the ret_stack entry * @frame_offset: Where to place the offset into @t->ret_stack of that entry @@ -673,7 +684,6 @@ extern void ftrace_stub_graph(struct ftrace_graph_ret *); /* The callbacks that hook a function */ trace_func_graph_ret_t ftrace_graph_return = ftrace_stub_graph; trace_func_graph_ent_t ftrace_graph_entry = ftrace_graph_entry_stub; -static trace_func_graph_ent_t __ftrace_graph_entry = ftrace_graph_entry_stub; /* Try to assign a return stack array on FTRACE_RETSTACK_ALLOC_SIZE tasks. */ static int alloc_retstack_tasklist(unsigned long **ret_stack_list) @@ -756,46 +766,6 @@ ftrace_graph_probe_sched_switch(void *ignore, bool preempt, } } -static int ftrace_graph_entry_test(struct ftrace_graph_ent *trace) -{ - if (!ftrace_ops_test(&global_ops, trace->func, NULL)) - return 0; - return __ftrace_graph_entry(trace); -} - -/* - * The function graph tracer should only trace the functions defined - * by set_ftrace_filter and set_ftrace_notrace. If another function - * tracer ops is registered, the graph tracer requires testing the - * function against the global ops, and not just trace any function - * that any ftrace_ops registered. - */ -void update_function_graph_func(void) -{ - struct ftrace_ops *op; - bool do_test = false; - - /* - * The graph and global ops share the same set of functions - * to test. If any other ops is on the list, then - * the graph tracing needs to test if its the function - * it should call. - */ - do_for_each_ftrace_op(op, ftrace_ops_list) { - if (op != &global_ops && op != &graph_ops && - op != &ftrace_list_end) { - do_test = true; - /* in double loop, break out with goto */ - goto out; - } - } while_for_each_ftrace_op(op); - out: - if (do_test) - ftrace_graph_entry = ftrace_graph_entry_test; - else - ftrace_graph_entry = __ftrace_graph_entry; -} - static DEFINE_PER_CPU(unsigned long *, idle_ret_stack); static void @@ -937,18 +907,12 @@ int register_ftrace_graph(struct fgraph_ops *gops) ftrace_graph_active--; goto out; } - - ftrace_graph_return = gops->retfunc; - /* - * Update the indirect function to the entryfunc, and the - * function that gets called to the entry_test first. Then - * call the update fgraph entry function to determine if - * the entryfunc should be called directly or not. + * Some archs just test to see if these are not + * the default function */ - __ftrace_graph_entry = gops->entryfunc; - ftrace_graph_entry = ftrace_graph_entry_test; - update_function_graph_func(); + ftrace_graph_return = return_run; + ftrace_graph_entry = entry_run; ret = ftrace_startup(&graph_ops, FTRACE_START_FUNC_RET); } @@ -984,7 +948,6 @@ void unregister_ftrace_graph(struct fgraph_ops *gops) if (!ftrace_graph_active) { ftrace_graph_return = ftrace_stub_graph; ftrace_graph_entry = ftrace_graph_entry_stub; - __ftrace_graph_entry = ftrace_graph_entry_stub; ftrace_shutdown(&graph_ops, FTRACE_STOP_FUNC_RET); unregister_pm_notifier(&ftrace_suspend_notifier); unregister_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL); diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index da1710499698..fef833f63647 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -235,8 +235,6 @@ static void update_ftrace_function(void) func = ftrace_ops_list_func; } - update_function_graph_func(); - /* If there's no change, then do nothing more here */ if (ftrace_trace_function == func) return; diff --git a/kernel/trace/ftrace_internal.h b/kernel/trace/ftrace_internal.h index 5012c04f92c0..19eddcb91584 100644 --- a/kernel/trace/ftrace_internal.h +++ b/kernel/trace/ftrace_internal.h @@ -42,10 +42,8 @@ ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip, void *regs) #ifdef CONFIG_FUNCTION_GRAPH_TRACER extern int ftrace_graph_active; -void update_function_graph_func(void); #else /* !CONFIG_FUNCTION_GRAPH_TRACER */ # define ftrace_graph_active 0 -static inline void update_function_graph_func(void) { } #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ #else /* !CONFIG_FUNCTION_TRACER */