From patchwork Wed Mar 16 10:01:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wangshaobo (bobo)" X-Patchwork-Id: 12782486 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 41689C433EF for ; Wed, 16 Mar 2022 09:53:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=t6a5QALiDsF6CN0d+lEj0tOcm2rZfARiLxDO5ZuZlEM=; b=h/kMiDNQ2ZJYaH YAs3oRUeKQ+ipkTxnhLqrDgXUMnM3hnUUsO9zKmB91fxko5Xk18Yh5lNxqgUlLRDTiHEd8QTii9VL 1Ohwb+A7WN4Nw5ss+7CxsdYNL+BVqRf0KNgHiDOp/Mg7UF14o/jDqvW2gbfycB4dHedkKVcsXda7A xjVjvcEHXlDQXoi8W4j7FDCZScWQTnzEhl/IqfO0yRjY3+1qB7YXqrC9SABKqzcq3XOnFUVOM2+22 BxLOAX99ePF+/ZBv5CKM0MYlIqOQQR7XR1Q15iFHVDJhnJ1+CKOjp5FMrCHnOGCZCrnfWoJaUJPnQ deasOZWc4BLCLFvQgX8w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUQKG-00CMnL-Ou; Wed, 16 Mar 2022 09:52:16 +0000 Received: from szxga02-in.huawei.com ([45.249.212.188]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUQK2-00CMiD-Ek for linux-arm-kernel@lists.infradead.org; Wed, 16 Mar 2022 09:52:05 +0000 Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KJQW72NTSzfZ2K; Wed, 16 Mar 2022 17:50:27 +0800 (CST) Received: from dggpemm500015.china.huawei.com (7.185.36.181) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 16 Mar 2022 17:51:54 +0800 Received: from huawei.com (10.175.103.91) by dggpemm500015.china.huawei.com (7.185.36.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.21; Wed, 16 Mar 2022 17:51:54 +0800 From: Wang ShaoBo To: CC: , , , , , , , , , , , Subject: [RFC PATCH -next v2 2/4] arm64/ftrace: introduce ftrace dynamic trampoline entrances Date: Wed, 16 Mar 2022 18:01:30 +0800 Message-ID: <20220316100132.244849-3-bobo.shaobowang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220316100132.244849-1-bobo.shaobowang@huawei.com> References: <20220316100132.244849-1-bobo.shaobowang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggeme707-chm.china.huawei.com (10.1.199.103) To dggpemm500015.china.huawei.com (7.185.36.181) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220316_025202_862614_DB0F950D X-CRM114-Status: UNSURE ( 9.47 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Cheng Jian We introduce two function entrances ftrace_(regs)_caller_tramp for dynamic trampoline use, which are put into Read-Only section and should be entirely copied to the space allocated for trampoline. Signed-off-by: Cheng Jian Signed-off-by: Wang ShaoBo --- arch/arm64/kernel/entry-ftrace.S | 80 +++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 16 deletions(-) diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S index e535480a4069..88462d925446 100644 --- a/arch/arm64/kernel/entry-ftrace.S +++ b/arch/arm64/kernel/entry-ftrace.S @@ -76,6 +76,23 @@ add x29, sp, #S_STACKFRAME .endm + .macro ftrace_regs_restore + /* Restore function arguments */ + ldp x0, x1, [sp] + ldp x2, x3, [sp, #S_X2] + ldp x4, x5, [sp, #S_X4] + ldp x6, x7, [sp, #S_X6] + ldr x8, [sp, #S_X8] + + /* Restore the callsite's FP, LR, PC */ + ldr x29, [sp, #S_FP] + ldr x30, [sp, #S_LR] + ldr x9, [sp, #S_PC] + + /* Restore the callsite's SP */ + add sp, sp, #PT_REGS_SIZE + 16 + .endm + SYM_CODE_START(ftrace_regs_caller) bti c ftrace_regs_entry 1 @@ -108,22 +125,8 @@ SYM_INNER_LABEL(ftrace_graph_call, SYM_L_GLOBAL) // ftrace_graph_caller(); * x19-x29 per the AAPCS, and we created frame records upon entry, so we need * to restore x0-x8, x29, and x30. */ -ftrace_common_return: - /* Restore function arguments */ - ldp x0, x1, [sp] - ldp x2, x3, [sp, #S_X2] - ldp x4, x5, [sp, #S_X4] - ldp x6, x7, [sp, #S_X6] - ldr x8, [sp, #S_X8] - - /* Restore the callsite's FP, LR, PC */ - ldr x29, [sp, #S_FP] - ldr x30, [sp, #S_LR] - ldr x9, [sp, #S_PC] - - /* Restore the callsite's SP */ - add sp, sp, #PT_REGS_SIZE + 16 - +SYM_INNER_LABEL(ftrace_common_return, SYM_L_GLOBAL) + ftrace_regs_restore ret x9 SYM_CODE_END(ftrace_common) @@ -138,6 +141,51 @@ SYM_CODE_START(ftrace_graph_caller) SYM_CODE_END(ftrace_graph_caller) #endif +.pushsection ".rodata", "a" +// ftrace trampoline for ftrace_regs_caller +SYM_CODE_START(ftrace_regs_caller_tramp) + bti c + ftrace_regs_entry 1 // save all regs + + sub x0, x30, #AARCH64_INSN_SIZE // ip (callsite's BL insn) + mov x1, x9 // parent_ip (callsite's LR) +SYM_INNER_LABEL(ftrace_regs_caller_tramp_ops, SYM_L_GLOBAL) + ldr x2, 0 // ops + mov x3, sp // regs +SYM_INNER_LABEL(ftrace_regs_caller_tramp_call, SYM_L_GLOBAL) + nop +#ifdef CONFIG_FUNCTION_GRAPH_TRACER +SYM_INNER_LABEL(ftrace_regs_caller_tramp_graph_call, SYM_L_GLOBAL) + nop // ftrace_graph_caller() +#endif + ftrace_regs_restore +SYM_INNER_LABEL(ftrace_regs_caller_tramp_end, SYM_L_GLOBAL) + ret x9 +SYM_CODE_END(ftrace_regs_caller_tramp) + +// ftrace trampoline for ftrace_caller +SYM_CODE_START(ftrace_caller_tramp) + bti c + ftrace_regs_entry 0 // save all regs + + sub x0, x30, #AARCH64_INSN_SIZE // ip (callsite's BL insn) + mov x1, x9 // parent_ip (callsite's LR) +SYM_INNER_LABEL(ftrace_caller_tramp_ops, SYM_L_GLOBAL) + ldr x2, 0 // ops + mov x3, sp // regs +SYM_INNER_LABEL(ftrace_caller_tramp_call, SYM_L_GLOBAL) + nop +#ifdef CONFIG_FUNCTION_GRAPH_TRACER +SYM_INNER_LABEL(ftrace_caller_tramp_graph_call, SYM_L_GLOBAL) + nop // ftrace_graph_caller() +#endif + ftrace_regs_restore +SYM_INNER_LABEL(ftrace_caller_tramp_end, SYM_L_GLOBAL) + ret x9 +SYM_CODE_END(ftrace_caller_tramp) +.popsection // .rodata + + #else /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ /*