Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2633621rwb; Mon, 7 Aug 2023 00:18:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE7UY0bHoZqluzGO8RyfpumTF8PdV+hBHP4VFcshpRMY9C8p8HYnlnTvyJBH4+Can13vonO X-Received: by 2002:a17:906:5a45:b0:99c:444c:e4bb with SMTP id my5-20020a1709065a4500b0099c444ce4bbmr7830827ejc.42.1691392684478; Mon, 07 Aug 2023 00:18:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691392684; cv=none; d=google.com; s=arc-20160816; b=m51IOdmNvAq6Ae2Rm8kZKEwLnAJ2rVexvurJpqXXySqBMiMybYV5DTRUiFC2pZsb6b hjsCg0VFGE4d7KBWtgL55/N7cijVBYaY7g/w+qjcB9h3Ck6r8dD9rHteKGzXVdA7oMuO /+wHf3qwq2NqVOnoWNXbl1jUl9Bsnoj5/iV6MZsvUnYjm3TJnV8328+u46Las9enkKmb /rp28GkD/EFbHVHSiPIVwg75EdJs4t7saXAW57cIcx4usIHCEjrJCB7tExBY9Oc3+y/C ow4wpDY4sz6402tqJX/xGCAdjKR92MGvKDjg8/gsBVDf6dN8mBDgcobgmNeXDjiaha2u ZKaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qQJeSXeHZDixpjlDZosMX73sy9QV6u1eC8ahZszaqjY=; fh=nNLeqPmm07c4DrdDej5z+HdJpmx5SqFFnpeka2nrMVM=; b=nkJaFn1YIFz5cJ0HvCUx5l0+vS/Kuucua9iLIvQiI2LjBJj+fUKMWDSVd/W3zNqrra snMdj8uHSyVXN2gdgSWRGiA/A+tiCYMlCf3iaFKlR9xTa1zK5K8SENX4AaQN4nSGhKGo QBMpZc+2V/ZwyWpw89aiJR2JperI1cw2dU12PEjq009AV5tOif2FlHTfOBbKC8ZFIvld KCh/nmuxSw6ohCfHk09YcFyoGgsky7y/bg1Gmjx/CTSfTKaweOyA4HJbEVIOwvldXBe9 KJUf5yXP4MUz8Ebyz0ARxjpawO7vUf79HFZ48d3WfffSz5uUIjtBeKoTYnaqJ93RkwJP BHRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="hP/8bBic"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c18-20020a170906155200b00991f8bce3cbsi5577111ejd.722.2023.08.07.00.17.38; Mon, 07 Aug 2023 00:18:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="hP/8bBic"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231265AbjHGGtA (ORCPT + 99 others); Mon, 7 Aug 2023 02:49:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231158AbjHGGs5 (ORCPT ); Mon, 7 Aug 2023 02:48:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 919301737; Sun, 6 Aug 2023 23:48:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2E30261588; Mon, 7 Aug 2023 06:48:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB7DDC433C7; Mon, 7 Aug 2023 06:48:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691390933; bh=5Wat1ZN9LgqYvlI6WEEnwpes5oBMUfxBgWSRXiQLnnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hP/8bBicWbi8v+hSGI+k4BO2VcLNAotrk4dOJVMcab817b0zRzX8ypsqYLRHJvw7N YO5nrEEe6iHYBxxWCwI06qGbcGuRbU9ZQZN3XHtF0kO0a3Fhamq8F1FcCXoTlAFIHz tKujFeyRbmGt1bYF28QMbBFASfdf6cJaGFAJ/8FHoXZBL20SpO3+Cd/WINNVRJrudF gOdWqXERv5b27aNjbSQlrf+plT8X69i9oHgC8SgsIfZLXx1yKxHdUw+GBc5m1upmHT 7YM2kwz6rHs0O593GxtXHM+55P47G9bbS/uqrV+I2PsAok5p7I0VXPhoKUapsFddOZ EGntGjnWBk7Ow== 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 Subject: [RFC PATCH v2 2/6] tracing: Expose ftrace_regs regardless of CONFIG_FUNCTION_TRACER Date: Mon, 7 Aug 2023 15:48:47 +0900 Message-Id: <169139092722.324433.16681957760325391475.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169139090386.324433.6412259486776991296.stgit@devnote2> References: <169139090386.324433.6412259486776991296.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Masami Hiramatsu (Google) In order to be able to use ftrace_regs even from features unrelated to function tracer (e.g. kretprobe), expose ftrace_regs structures and APIs even if the CONFIG_FUNCTION_TRACER=n. Signed-off-by: Masami Hiramatsu (Google) --- include/linux/ftrace.h | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index ce156c7704ee..3fb94a1a2461 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -112,11 +112,11 @@ static inline int ftrace_mod_get_kallsym(unsigned int symnum, unsigned long *val } #endif -#ifdef CONFIG_FUNCTION_TRACER - -extern int ftrace_enabled; - -#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS +/* + * If the architecture doesn't support FTRACE_WITH_ARGS or disable function + * tracer, define the default(pt_regs compatible) ftrace_regs. + */ +#if !defined(CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS) || !defined(CONFIG_FUNCTION_TRACER) struct ftrace_regs { struct pt_regs regs; @@ -129,6 +129,22 @@ struct ftrace_regs { * HAVE_DYNAMIC_FTRACE_WITH_ARGS is set and it supports live kernel patching. */ #define ftrace_regs_set_instruction_pointer(fregs, ip) do { } while (0) + +#define ftrace_regs_get_instruction_pointer(fregs) \ + instruction_pointer(ftrace_get_regs(fregs)) +#define ftrace_regs_get_argument(fregs, n) \ + regs_get_kernel_argument(ftrace_get_regs(fregs), n) +#define ftrace_regs_get_stack_pointer(fregs) \ + kernel_stack_pointer(ftrace_get_regs(fregs)) +#define ftrace_regs_return_value(fregs) \ + regs_return_value(ftrace_get_regs(fregs)) +#define ftrace_regs_set_return_value(fregs, ret) \ + regs_set_return_value(ftrace_get_regs(fregs), ret) +#define ftrace_override_function_with_return(fregs) \ + override_function_with_return(ftrace_get_regs(fregs)) +#define ftrace_regs_query_register_offset(name) \ + regs_query_register_offset(name) + #endif /* CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS */ static __always_inline struct pt_regs *ftrace_get_regs(struct ftrace_regs *fregs) @@ -151,22 +167,9 @@ static __always_inline bool ftrace_regs_has_args(struct ftrace_regs *fregs) return ftrace_get_regs(fregs) != NULL; } -#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS -#define ftrace_regs_get_instruction_pointer(fregs) \ - instruction_pointer(ftrace_get_regs(fregs)) -#define ftrace_regs_get_argument(fregs, n) \ - regs_get_kernel_argument(ftrace_get_regs(fregs), n) -#define ftrace_regs_get_stack_pointer(fregs) \ - kernel_stack_pointer(ftrace_get_regs(fregs)) -#define ftrace_regs_return_value(fregs) \ - regs_return_value(ftrace_get_regs(fregs)) -#define ftrace_regs_set_return_value(fregs, ret) \ - regs_set_return_value(ftrace_get_regs(fregs), ret) -#define ftrace_override_function_with_return(fregs) \ - override_function_with_return(ftrace_get_regs(fregs)) -#define ftrace_regs_query_register_offset(name) \ - regs_query_register_offset(name) -#endif +#ifdef CONFIG_FUNCTION_TRACER + +extern int ftrace_enabled; typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip, struct ftrace_ops *op, struct ftrace_regs *fregs);