From patchwork Fri Jan 12 10:15:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 187695 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp80371dyc; Fri, 12 Jan 2024 02:25:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IFwYTfxQ3ckUKS3cexTtz7jJGteUkSV7+gY/MTSSI2A1IGNd9Mkt6cV/vE506A8nZf4j8mQ X-Received: by 2002:a05:6808:11c6:b0:3bd:1fdc:eeaa with SMTP id p6-20020a05680811c600b003bd1fdceeaamr910628oiv.55.1705055112185; Fri, 12 Jan 2024 02:25:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705055112; cv=none; d=google.com; s=arc-20160816; b=X95R5J4Dyx4jxAVcjUXLvKB0Zh0YC5uvB3gWa3JgfASSI9tPCDLhWItBC18KkC94zl FQ+yY+sCi+k92wFVT3dehIM0K9q1KkJa52OWDN9TGHzwa88J86wPFwEgnJqRLYHmiO/+ GDqQSYal3pPVoRPuX4bqAoOg19utxHPt02b1StS6SVrbSPoX93jx5VmT8/ZjrIUbMfmE NYS7wVFuDJBs+HRkjXV+IxMeUST9hTo1QR4Phz1Z5VFngzgqVUHgSytgRoyjD7Kos1PA K+9ngg741oJ4btpIoYUweLdAIVKMQ47aaGE5Vr9P64r4bYzo9Rwnay+afoTnpEr8xvjm xFEQ== 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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24573-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id kg16-20020a170903061000b001d5a52386cfsi977589plb.27.2024.01.12.02.25.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 02:25:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24573-ouuuleilei=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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24573-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 3163C28E2A7 for ; Fri, 12 Jan 2024 10:19:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E99764A93; Fri, 12 Jan 2024 10:15:54 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787879868817396895 X-GMAIL-MSGID: 1787879868817396895 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 */