Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2200545rdd; Fri, 12 Jan 2024 02:26:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSVpPW2frrQuFld0UcI0Y5wZJxsIl5kFMydPadj6uQyjtMpLTZPjCDCiwjW1RJ2O8ibFea X-Received: by 2002:a05:6808:22a1:b0:3bd:1f27:fe6a with SMTP id bo33-20020a05680822a100b003bd1f27fe6amr891456oib.60.1705055210224; Fri, 12 Jan 2024 02:26:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705055210; cv=none; d=google.com; s=arc-20160816; b=ekHreDqWKle+O08AIqR7hYiet5v9vezMhp2oMaVuxla2eDGPuaHjBqkPE5QKF2pi8G /UZiTUr46k6PY1XkuH6mLaRmUdC399TOQgw2Hn+SDa+tJvmnaGjuLaVGIsxFapCVLtwm yYwD78czKmB6tEKS+OEspqIOplajTMn5mTXbgt9p2HDP8KC70Z9dNcEmXnRpDa0fOJAo 4t1ZnRovYEFYYeGpaGIhTb6kCYIjNXUyi0fq5/G7zJLkUYjT4pe1ZNlHH6GoRfRmwuO1 437SKHOJW4rYR5N3Blqs/Kn65xr/7YWtvV9G00Xw1C0RnatXhYVrg3XlOPC8B/o4PnD9 YZjg== 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=pE+0E6T3RjMx/4hyfR4ROm3ukE1Xf259LCsoEx6OOXG1MU9uCWcZiARkgy0tPLc5VN +KqmpKSOAEGIhCea/XVb3iRWC4WXdAYPQ1rpB0DzyPJ+XuAWDD0iCxrzwIn9G9yATRBM 3mWn9brvK4bfc0n4jT2qr9S4sF00M2LG9Tuy9OXbVoEZ0/KMcgiyrJ7KwIS/FPzBtd1l P0+I3+ncNa2zDsxzNWx0x9cWVFiLH648G4LMEm6tYE3Rw5v4lnklDFL4hDHCOTixzT57 bK9HR3A/3IO+wkufAHxyIajEcdYkkCVT/o8LUVkbPhUoe30o6rREWcu9Dntb/bhhA4Si Dh7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VXpG45fs; spf=pass (google.com: domain of linux-kernel+bounces-24573-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24573-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id c32-20020a631c20000000b0059779ae58a0si3042167pgc.465.2024.01.12.02.26.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 02:26:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24573-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VXpG45fs; spf=pass (google.com: domain of linux-kernel+bounces-24573-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24573-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 214CE28DFF1 for ; Fri, 12 Jan 2024 10:19:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 727AB60EF1; Fri, 12 Jan 2024 10:15:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VXpG45fs" 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 9FF095DF1F; Fri, 12 Jan 2024 10:15:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9669C433F1; Fri, 12 Jan 2024 10:15:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705054551; bh=Tv6V79hvaGG+hzXn9p0p+FTonUg+dTMFhQaVZNAc9e0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VXpG45fs15/T3CetNIg6DF7mB7CoAitb1sqPFlt6+9dUtMxj/aZcxcZ43Fjx5eJpp 7DwuRXg1FyXYNhNNtTrSEkee8s1iFanU3Hd8whyXcj/lK7Xnfu5bcUrg85RkC+7k7T 3s5gD4UvyxvXJXamqeV06K6nEqrlUfwnh921uOmR4o7mmmB+mOWHf7F1kxOKulRBph 6HKuI+t+2lurBLOoExGa1dfuifCuqXIDjpimZOGRrDZS/E2BX6asedi24r+RWKC5jx JqX9Ech9Y3eDI7p2KJ8aesP703YQ8WPTGXLVM93SLqjFK7ebcfq61Hf+Me2c/VxCxK lJYENoKp64uHw== 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 v6 25/36] arm64: ftrace: Enable HAVE_FUNCTION_GRAPH_FREGS Date: Fri, 12 Jan 2024 19:15:45 +0900 Message-Id: <170505454553.459169.17513084336482780988.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170505424954.459169.10630626365737237288.stgit@devnote2> References: <170505424954.459169.10630626365737237288.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 */