From patchwork Sun Sep 24 13:36:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 144080 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp668431vqu; Sun, 24 Sep 2023 06:38:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEdnKrMNFs+0CugxT0V5/+riQmSD68zoqezaNKeNhdmSqFGVPDNdi3MTlHROcNM+SlfNwX5 X-Received: by 2002:a05:6a00:e88:b0:68a:48e7:9deb with SMTP id bo8-20020a056a000e8800b0068a48e79debmr10272528pfb.2.1695562680072; Sun, 24 Sep 2023 06:38:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695562680; cv=none; d=google.com; s=arc-20160816; b=Q3R5X/DdPSeeEz9wdNyH4mLIWh/juCJo/O2VbDZHnJLPtiZQFmfUtt0rhW/66C53oI cYmJDWPA1A5uc5yWRPNyVbhLpoqbE1hCtuRPnLmjosXm6QMNlyMzQ7/qQT3dTLJ3ee91 1fgWOmvLF4FiPMe8+snBuBcM6ghiX8ySolnkgGNRo00WKATPR6Vzyh9DM6mf8RcbLt0I umZvf57kwYTe/k9vMYVEcpdSpaKYvY/PwZB1RgS7ODclxITv8trwtgM/O6MYRWaGAwQ9 B9awLsUsQwfVkJjCfRxcFLXAPjQGrvjdZZUMy/jYsAnRYMM9qEK4jUKuZmKwytJHMdse 1IOA== 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=jhYorJE2G0psM9CoW8dsq2y1A4ADt9ByWQJxukzZmKo=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=AyjNggJtarO85Z8oSE9lNyb42sWaey7KpIguHKAV+CCD9UhPmgiixjQJtPHsv+Mhr3 oZF3RyPK/z2mcPhncNzDwHqgxWhWPx+mpDAyBACojBIXW8RV3coydG9rOY+jWdcitv3X gQW372pgtdC6RegC5L/fTo7ZTh5g5LfR8w1MsBiGVF2/pIc3R957HYkFmvLWRFHOCwh2 l6dNkLV8Qm+uyLTM4HzffXGCwIQQxWJV9FhXFznL3Q7AyNsqyyKV6LRXN3kQF8ocDC// nj/9mGJZ5LLSiZm3fcObIXRCLxMMw1xgGh3emMFLHd1jzRahG+b401LHKvRSqflJ1dUC 6CoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AQRxpZ9U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id f20-20020a637554000000b00565dd3fbfdfsi7637587pgn.214.2023.09.24.06.37.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:38:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AQRxpZ9U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 6252F8313006; Sun, 24 Sep 2023 06:37:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231237AbjIXNh5 (ORCPT + 30 others); Sun, 24 Sep 2023 09:37:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231235AbjIXNhk (ORCPT ); Sun, 24 Sep 2023 09:37:40 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 486171717 for ; Sun, 24 Sep 2023 06:36:55 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27DC8C433C7; Sun, 24 Sep 2023 13:36:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695562614; bh=jmHWZoJzNc7w2WNK0aSXMKcROawBX8r9FSb7vj/g9k4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AQRxpZ9URRHAkZC5HdJ8I8W4mys6wynoEVlftisU26BNvb9oiXK0Ro0PXYd9qLB2l UL3C0Oy+xI57Izrd/yxuWzsvG4CXpOxOGRD78wJxDt02xtJijhUFSWR7QcUorUwFdx O5hf0wkh9BjAh382ei6TnpnBPotUpzDvkt+JUKJwJnCdDi+nKlNZVymAvIk54keZYY BW4+MqOrdmXmTAfaZXd8nd359ake5zpaQynZsXrSQENdGQz9VryIndwLRoYQVqp8+n R/DUZZZ+mgL/oGSxsVqdK92HPyXr6YtPOR6dFKfl+Ty7MWFdnNNnzqBRbH37eg1mOI eDmk2HLeM2faQ== 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 v5 05/12] tracing: Expose ftrace_regs regardless of CONFIG_FUNCTION_TRACER Date: Sun, 24 Sep 2023 22:36:48 +0900 Message-Id: <169556260811.146934.12334081780807613682.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169556254640.146934.5654329452696494756.stgit@devnote2> References: <169556254640.146934.5654329452696494756.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Sun, 24 Sep 2023 06:37:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777926332738843383 X-GMAIL-MSGID: 1777926332738843383 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) Acked-by: Florent Revest --- Changes in v3: - arch/s390/include/asm/ftrace.h: hide ftrace_regs parts if CONFIG_FUNCTION_TRACER=n to avoid conflict. - Fixed typo. - Define accessor macros only if HAVE_REGS_AND_STACK_ACCESS_API=y --- arch/s390/include/asm/ftrace.h | 4 +++ include/linux/ftrace.h | 51 +++++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/arch/s390/include/asm/ftrace.h b/arch/s390/include/asm/ftrace.h index 5a82b08f03cd..6de3bf4d0092 100644 --- a/arch/s390/include/asm/ftrace.h +++ b/arch/s390/include/asm/ftrace.h @@ -41,6 +41,8 @@ static inline unsigned long ftrace_call_adjust(unsigned long addr) return addr; } +#ifdef CONFIG_FUNCTION_TRACER + struct ftrace_regs { struct pt_regs regs; }; @@ -97,6 +99,8 @@ ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs, #define ftrace_regs_query_register_offset(name) \ regs_query_register_offset(name) +#endif /* CONFIG_FUNCTION_TRACER */ + #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS /* * When an ftrace registered caller is tracing a function that is diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 5da70f238645..15f4865a4083 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 disables function + * tracer, define the default(pt_regs compatible) ftrace_regs. + */ +#if !defined(CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS) || !defined(CONFIG_FUNCTION_TRACER) /* * The ftrace_regs will be just a wrapper of the pt_regs if @@ -131,13 +131,33 @@ struct ftrace_regs { }; #define arch_ftrace_get_regs(fregs) (&(fregs)->regs) +#ifdef CONFIG_HAVE_REGS_AND_STACK_ACCESS_API + /* * ftrace_regs_set_instruction_pointer() is to be defined by the architecture * if to allow setting of the instruction pointer from the ftrace_regs when * HAVE_DYNAMIC_FTRACE_WITH_ARGS is set and it supports live kernel patching. */ #define ftrace_regs_set_instruction_pointer(fregs, ip) do { } while (0) -#endif /* 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 /* CONFIG_HAVE_REGS_AND_STACK_ACCESS_API */ + +#endif /* !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS || !CONFIG_FUNCTION_TRACER */ static __always_inline struct pt_regs *ftrace_get_regs(struct ftrace_regs *fregs) { @@ -159,22 +179,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);