Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp946550pxp; Wed, 16 Mar 2022 22:14:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzt+YD/VF8RLtlAw2CO9ifKRCUTdBC6Au/1wMR4ROyUxbino62OOFpZ+JDRCwYZiXJpwh5g X-Received: by 2002:a17:90b:1b06:b0:1c1:171b:cc7a with SMTP id nu6-20020a17090b1b0600b001c1171bcc7amr3302866pjb.231.1647494092527; Wed, 16 Mar 2022 22:14:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647494092; cv=none; d=google.com; s=arc-20160816; b=uZS6Ph6scq0Ih+pCeFNlHvCtYfw9q9zQgzFEEsNoCzkLGvJyWZvk3DAmm4OuGV1+QD Q+pMYkKArmnBaUvtdrqh/407Sr3USsVWLy1oQQIG7Dfe2knJj9XTVNvcQz0sfTP8Itk/ HnaPrqcQYKJiIq/JLxyfhwa4yaAYp33nwRjMA2wxP6PCilBbtRKjoUsSPtRigh5Uuvww u6V/AWkVdz7kgU2WmlYXz7vHkI4CNwv9gTRlc9ECU+uupvxg5+bZk/gdio0/WTCrUO9O hEcHuoeVjTSiflUgPTc4RHsWlIwH0OCBadZlJtnAHPSObEgYl2Z6Vv3AFA9z3hHVRTuG fP7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from; bh=phjszPJmO8RA3wKGUk++RI+xySo/9X9v0IKH0FhBe+0=; b=KEATRWnksthQ9a9NN58UnCOePGByVExpEcPYSSKKv4N2/nH7+j9HoCn+yU5EVKKZf0 dyEkpxJRGue5ZgLZTAV15u8aiisrw62O6GEnQCk4tTr0S+CtqLXJoJ/K+X7GK6hc/p6E zZGK1Bdz5af6iOdzPN78v73wQ8mL8HDKpRMnUsLjQmXoRE9yMCBVc5wgeH/j7N1LLTkN UUxEcbgDsEAwOx06lYxXe/nmAQjgswVLTNkqSJohAvmkjOGenUiY6qFbWy+JzCWvA2vb k0+GJSBq/j6X6ZBrWuIa9jbide7kya7A2M0QYRk6S7I8z0xKM6G8ETZ5QLqeddpf/+KH 4Drg== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k13-20020a056a00134d00b004f7550f7f55si4300070pfu.225.2022.03.16.22.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 22:14:52 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2010A1E3765; Wed, 16 Mar 2022 21:23:30 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355011AbiCPJxP (ORCPT + 99 others); Wed, 16 Mar 2022 05:53:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354994AbiCPJxK (ORCPT ); Wed, 16 Mar 2022 05:53:10 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC10E606E3 for ; Wed, 16 Mar 2022 02:51:56 -0700 (PDT) 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 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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 */ /* -- 2.25.1