From patchwork Mon Dec 18 13:16:11 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: 180402 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1235690dyi; Mon, 18 Dec 2023 05:24:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IE2FBQFV7TAhJ8qXmIKGdHn8evCx0KKazsPQu2/XwNb9ngUF2c9OPI27PuKFFrPLPpzbJJu X-Received: by 2002:a05:6512:ac8:b0:50e:2bf3:3781 with SMTP id n8-20020a0565120ac800b0050e2bf33781mr2057527lfu.75.1702905863532; Mon, 18 Dec 2023 05:24:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702905863; cv=none; d=google.com; s=arc-20160816; b=lERQ3mAd6C1/oT4LjMQDQKu8HjQM+dgw6zhaKnnPY0u/2U7v5LGJxe2nSzlUcpA+O/ kiNqH8J/8ZBMuY++NSWD2T9vR90jAq3ndcVUJ3y60kw8N9XBg4/wZYaSvRGYWS5ocMP7 x+6+NcdKAgklZQ3t+l3kFk6Jhm6ecVdcICLA8GlDYscg0lE6Nmav9vYvMAP7Sc5COYaf SLlhNMDInBh6fGOlhdXgwJcIKSzcF/+PAXXM5TlD0T2BhGi2Byvp9KyVVv//pPBd7Lb1 VKcqEM79e2wKV1HXeK2BPfO7a26UKlDz2I1WDV5UE89452Bk0HCfWvEYzL2iA1j8G6zg Rfag== ARC-Message-Signature: i=1; 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=gyhDufMlqWYyit6UVacrM1UC8KltlsDNU7U2cyRBaIc=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=nFjvw/TRWhmkHFNRGDyiWlano5McBCQQpjETL7Vc/vW1gUZMHZ8s9f8/0PGevgku1u Ny4UrnXU7P5FL8r00rFvkVjfdkX3fVtsPRKh3fpi8x++3eEGx26cKNm/LZ7Bu9u9uMp/ 7np1Bmqj8aGFdVsg5boLbpZLOjhDJr3XhuPDrTmm4umvN9t9KQ4wOCwwIhLI+3621epN gt+ScyuUZIPQq4vxCm1KUVDG9aRYngUr/5SjFFDe28vDPAfrXPTujHdwlo61INhiajfB F3cxQWJmRoX3koNxks4vb2MBDnluFPBRbLYjL28DAFegcW1cJJIyBmIR3XMJhCLp2h+c BAiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JjI065Ws; spf=pass (google.com: domain of linux-kernel+bounces-3729-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3729-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id y5-20020a17090668c500b00a234b6ee26dsi1213121ejr.370.2023.12.18.05.24.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 05:24:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3729-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JjI065Ws; spf=pass (google.com: domain of linux-kernel+bounces-3729-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3729-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id D14561F233CF for ; Mon, 18 Dec 2023 13:23:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CF133740AA; Mon, 18 Dec 2023 13:16:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JjI065Ws" X-Original-To: linux-kernel@vger.kernel.org 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 1FB0149888; Mon, 18 Dec 2023 13:16:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41FA1C433C8; Mon, 18 Dec 2023 13:16:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702905377; bh=Tv6V79hvaGG+hzXn9p0p+FTonUg+dTMFhQaVZNAc9e0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JjI065WsV+UuVFNbwe/MkVeNOSTeLN25SiPe0I4+BQ/TeG8MlgP6A7Q82MqSx0irQ ywMUs3Eh1ogGIUj0LK4ISd21lyMh3wyUYBNuY0YfwLdVpVlGEjCXnheW6+RnPrboWc TSJN6i6CEAMwbBuDVMJrGAUUTkRn5ItfJWmUhLHD8a+wvEZ02nCGTPh1VNk9YEvqCR stz34976yYKUfGNimfPXmtBGQDVgk/TXNMgUadk2HpPAGG4BZ+GtK6nYZeeZzfOA8o X1b4qazpRaeFUUb6mLhjGuz4aQ4Cs57PV2C1jpr0MJaGY/lH70f2wdq5Z8wwKaUvKc oNHnayZF57dEg== 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 23/34] arm64: ftrace: Enable HAVE_FUNCTION_GRAPH_FREGS Date: Mon, 18 Dec 2023 22:16:11 +0900 Message-Id: <170290537121.220107.6547455713086067597.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170290509018.220107.1347127510564358608.stgit@devnote2> References: <170290509018.220107.1347127510564358608.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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785626218800950766 X-GMAIL-MSGID: 1785626218800950766 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 7b071a00425d..beebc724dcae 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 */