From patchwork Mon Nov 27 13:57:40 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: 170161 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3135581vqx; Mon, 27 Nov 2023 06:03:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IFF7eJz/IVXWb8kJrjCc4rxwzC4zWg8QjmUKZeBg+XYMvOg+EvntKFLiDQY2n5w61fkUQif X-Received: by 2002:a17:90b:4b0f:b0:281:8e9:7b86 with SMTP id lx15-20020a17090b4b0f00b0028108e97b86mr10495247pjb.23.1701093809548; Mon, 27 Nov 2023 06:03:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701093809; cv=none; d=google.com; s=arc-20160816; b=egdSIqXOPkypL7mHKkwqabRCP0vrdFM3dk9A/8Izv5K9bpewJgzkyotaO2fxTvRy4k M3AixqOxUBL9Em2sMMMoNNHu/5wBFZkiA1XnII1zwzDlOPOKzraF6nPU3YsgKxvEDGuT TkCyLxsbdsqAF55Luo0lQJ697Fcg2t/vsyYfQz+OOSgXroNutcQgjtZlsmABpsWZSA4w FCIox7EUyznjOXsyGaTSPA0u8TKc7TtoF0ulj3srTlW4zmfpxRzvRYuZHZ6e325FRwFz Hmopo//JZaj6jPSrdGdhmo6JcXw5jiovGE5zERlQz8LPYpe5upVKV6mt3QO4Iv1MVYhL eRoQ== 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=fZ0jd+o/ZSLrIRQfuGu+aLWmGpes0zoYvq3h/cU5EhE=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=qTdq52mevttVXcUeUZRG7Qbduj0zyCJOjvq8BVVDXAr+Nn9ajzL3WwjgCZ/zdGDIky bljuQjgaiWQryMJX2ICd+vYE4kmOZ03/TLi5wStHXtHMko9nRFDLcbx5z4ePoFvYLCBm 5Q7EzrL9MKQWAAo2p0kjrp9BSzpPNf97jB2zsFb9Kp3HI50iclFPzxDN1jF53klsag3z fXoqCNMeeBmL03pi0C6To5o7zcFXye1ieHnPH3vo0lpsBRW4aAk5/tSlDo4PDbX0r0ol svYkDctCWKp8WGdzvJ3M4LyCfiIbSLjC719iS70kai0hnjjQCz6whmRT9fxb9mJqI+et t30w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mjl1gU6E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id in24-20020a17090b439800b0028031f2f450si9648654pjb.22.2023.11.27.06.03.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 06:03:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mjl1gU6E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 95D88809D3CB; Mon, 27 Nov 2023 06:03:23 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233489AbjK0ODO (ORCPT + 99 others); Mon, 27 Nov 2023 09:03:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233524AbjK0OBL (ORCPT ); Mon, 27 Nov 2023 09:01:11 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ECAE2D40 for ; Mon, 27 Nov 2023 05:57:47 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4BF8C433C7; Mon, 27 Nov 2023 13:57:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701093466; bh=laXiPq6pCZezVsgqy2AbYoST02LKOiIN00hspmTWaV4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mjl1gU6E/H4SivudDYeoneFcQjDJLVwxkwxIB9sH92a8mwKwj4fGQiTQNOHHDC3tu J0P+AoSuDghoMThhLLoWMMxQw5jaEWhi5zj8N9bzLZy2IFSwzFhzFZqhU+BWNR2zfi mCQme+LXphmTC9L6W+akPXsWajpZfajpiqNsSPHl/W2PhMPyI0i2nhsjV/Qcvp4S/v qsNYBw3iHERLhrXwbdiLtqXY+/dZqDGRnQPxA4L+LMVNYcDaq23KhbVNja/lpr7SWK 9kXStCyPUn1fmeQMOG6iRXO62PL3tWoN9iOJEY5WkHAMp81fPUZdA+DJXBUDCtfc0A kpQ3oqJhOwciA== 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 v3 23/33] arm64: ftrace: Enable HAVE_FUNCTION_GRAPH_FREGS Date: Mon, 27 Nov 2023 22:57:40 +0900 Message-Id: <170109345963.343914.8985762897942714493.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170109317214.343914.4784420430328654397.stgit@devnote2> References: <170109317214.343914.4784420430328654397.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 (snail.vger.email [0.0.0.0]); Mon, 27 Nov 2023 06:03:23 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783726142068459124 X-GMAIL-MSGID: 1783726142068459124 From: Masami Hiramatsu (Google) Enable CONFIG_HAVE_FUNCTION_GRAPH_FREGS on arm64. Note that this depends on HAVE_DYNAMIC_FTRACE_WITH_ARGS which is enabled if the compiler supports "-fpatchable-function-entry=2". If not, it continue to use ftrace_ret_regs. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v3: - Newly added. --- arch/arm64/Kconfig | 2 ++ arch/arm64/include/asm/ftrace.h | 6 ++++++ arch/arm64/kernel/entry-ftrace.S | 28 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 78f20e632712..373f6e113141 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -192,6 +192,8 @@ config ARM64 select HAVE_DYNAMIC_FTRACE select HAVE_DYNAMIC_FTRACE_WITH_ARGS \ if $(cc-option,-fpatchable-function-entry=2) + select HAVE_FUNCTION_GRAPH_FREGS \ + if HAVE_DYNAMIC_FTRACE_WITH_ARGS select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS \ if DYNAMIC_FTRACE_WITH_ARGS && DYNAMIC_FTRACE_WITH_CALL_OPS select HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS \ diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index ab158196480c..efd5dbf74dd6 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -131,6 +131,12 @@ ftrace_regs_set_return_value(struct ftrace_regs *fregs, fregs->regs[0] = ret; } +static __always_inline unsigned long +ftrace_regs_get_frame_pointer(struct ftrace_regs *fregs) +{ + return fregs->fp; +} + static __always_inline void ftrace_override_function_with_return(struct ftrace_regs *fregs) { diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S index f0c16640ef21..d87ccdb9e678 100644 --- a/arch/arm64/kernel/entry-ftrace.S +++ b/arch/arm64/kernel/entry-ftrace.S @@ -328,6 +328,33 @@ SYM_FUNC_END(ftrace_stub_graph) * Run ftrace_return_to_handler() before going back to parent. * @fp is checked against the value passed by ftrace_graph_caller(). */ +#ifdef CONFIG_HAVE_FUNCTION_GRAPH_FREGS +SYM_CODE_START(return_to_handler) + /* save ftrace_regs except for PC */ + sub sp, sp, #FREGS_SIZE + stp x0, x1, [sp, #FREGS_X0] + stp x2, x3, [sp, #FREGS_X2] + stp x4, x5, [sp, #FREGS_X4] + stp x6, x7, [sp, #FREGS_X6] + str x8, [sp, #FREGS_X8] + str x29, [sp, #FREGS_FP] + str x9, [sp, #FREGS_LR] + str x10, [sp, #FREGS_SP] + + mov x0, sp + bl ftrace_return_to_handler // addr = ftrace_return_to_hander(fregs); + mov x30, x0 // restore the original return address + + /* restore return value regs */ + ldp x0, x1, [sp, #FREGS_X0] + ldp x2, x3, [sp, #FREGS_X2] + ldp x4, x5, [sp, #FREGS_X4] + ldp x6, x7, [sp, #FREGS_X6] + add sp, sp, #FREGS_SIZE + + ret +SYM_CODE_END(return_to_handler) +#else /* !CONFIG_HAVE_FUNCTION_GRAPH_FREGS */ SYM_CODE_START(return_to_handler) /* save return value regs */ sub sp, sp, #FGRET_REGS_SIZE @@ -350,4 +377,5 @@ SYM_CODE_START(return_to_handler) ret SYM_CODE_END(return_to_handler) +#endif /* CONFIG_HAVE_FUNCTION_GRAPH_FREGS */ #endif /* CONFIG_FUNCTION_GRAPH_TRACER */