Received: by 2002:a05:7412:a9a3:b0:f9:327e:43ab with SMTP id o35csp94104rdh; Mon, 18 Dec 2023 05:28:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IH26c/TuZiznq8A+tPsDJW6aTfFgzAFAJwzZHT/DK1h6vzRBZ12MeDhiM8MPSt68v9q4bnO X-Received: by 2002:a17:902:778c:b0:1d0:aeda:9ad5 with SMTP id o12-20020a170902778c00b001d0aeda9ad5mr7297140pll.34.1702906134473; Mon, 18 Dec 2023 05:28:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702906134; cv=none; d=google.com; s=arc-20160816; b=ZbFpL6LJo03B6XhNISdSL8vYrqVu5pR4pnmxHiP6XKjYlzmsDhuM0kluX5XtLdKewa 6zRMDpz2hEfvIFIFahqXevMviN/QsFsYgrTUidqOmcF20OpSsv4fw8O9O8rHBlRRozAo dFKhlDFgUqp6Ioanxhev198lI+bStF7ylyfU6tTTibrbYXAp/E5B81XQlhOU9VaybSB0 B8+afocgMLomzCRmMWFg5gJuZSRiXFq3vu1/NTnR9bOjdUrL/9+hx+cNLfmqG3lSGXoE 0qdueerYChDcG4ALKlZsi8CbKslbj0dbrGj587ckjeluqv3vZPsoh/wIUIsXaGdyO9to tQPA== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3729-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. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id x24-20020a170902821800b001d3a371cd1dsi3336651pln.3.2023.12.18.05.28.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 05:28:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3729-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3729-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 545DFB24241 for ; Mon, 18 Dec 2023 13:23:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E7BB5498AF; Mon, 18 Dec 2023 13:16:19 +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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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 */