From patchwork Wed Mar 16 10:01:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wangshaobo (bobo)" X-Patchwork-Id: 12782485 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 DD14CC433FE for ; Wed, 16 Mar 2022 09:53:32 +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: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:In-Reply-To:References: List-Owner; bh=cx7PJArpsmFjltT5Ab8U/nLDjf9HJRC/sixL02RN3rw=; b=egj9EhwsSi9g/t XGdnHFATRcjICUcUcgDSK32tkC6Q3ikENek+KAVXCV+cZPpjfPoNk2Wc0PSzyBBhroyi6n8Ngx7w1 4K6vRBoZ4yuo1xvj8PeCWR+grv/TdzUuJrH8R8szSSVLSTeZX5ex7+2hpyLpHXXIdTZp1zEsXWXj0 XqG8FL62NxlkLXOOnVS1oxaIWxc94SnP0+JhhsVvQSTM6qOmDvQiPifVmkY0fKpyB5AFo8jbnMiM5 y8x79aD736Vpbkf9XP38+y1+VA9AEM1BJc59Hw2sroNurZlALLNFUjLS79K5fI1IV5y8YO106OgVu L/dEnWrRTQAUAp+xyx3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUQKQ-00CMpx-EE; Wed, 16 Mar 2022 09:52:26 +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-00CMiA-F3 for linux-arm-kernel@lists.infradead.org; Wed, 16 Mar 2022 09:52:05 +0000 Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KJQVS2hVpzCqpY; Wed, 16 Mar 2022 17:49:52 +0800 (CST) Received: from dggpemm500015.china.huawei.com (7.185.36.181) by dggpemm500020.china.huawei.com (7.185.36.49) 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:53 +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:52 +0800 From: Wang ShaoBo To: CC: , , , , , , , , , , , Subject: [RFC PATCH -next v2 0/4] arm64/ftrace: support dynamic trampoline Date: Wed, 16 Mar 2022 18:01:28 +0800 Message-ID: <20220316100132.244849-1-bobo.shaobowang@huawei.com> X-Mailer: git-send-email 2.25.1 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_871709_29D1E728 X-CRM114-Status: UNSURE ( 8.16 ) 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 This implements dynamic trampoline in ARM64, as reference said, we complete whole design of supporting long jump in dynamic trampoline: .text section: funcA: | funcA(): funcB():| `-> +-----+ | | ... mov x9 | | ... | | | adrp <- bl <> | | nop | | | mov | nop | | | br x16 ---+ funcB | nop | | | ftrace_(regs_)caller_tramp: `-> +-----+ | `--> +---------------------+ | nop | | | ... | | nop | | ftrace callsite +---------------------+ | ... | | `-----> | PLT entry: | | nop | | | adrp | | nop | | | add | funcC: | nop | | ftrace graph callsite | br x16 | `-> +-----+ | `-----> +---------------------+ | nop | | | ... | | nop | | +---------------------+ But there is still a tricky problem that is how to adjust tracing ip, waiting to be solved: For ARM64, somecases there may be extra instructions inserted into the head of tracable functions(but not all) by compiler, for instance BTI[1]. This dump vmlinux with CONFIG_BTI=y: (1) function gic_handle_irq has bti in its head, so we adjust rec->ip+=5 to last nop ffffffc0080100e0: d53cd042 mrs x2, tpidr_el2 ... ffffffc0080100f0: d503201f nop //__mcount_loc tells the rec->ip ffffffc0080100f4: d503201f nop ffffffc0080100f8: d503201f nop ffffffc0080100fc : ffffffc0080100fc: d503245f bti c ffffffc008010100: d503201f nop ffffffc008010104: d503201f nop //we adjust origin rec->ip+5 to here ffffffc008010108: d503233f paciasp (2) name_to_dev_t.part.0 do not has bti in its head, so we should adjust rec->ip+=4 to last nop ffff8000080137d4: d503201f nop ffff8000080137d8: d503201f nop ffff8000080137dc: d503201f nop ffff8000080137e0 : ffff8000080137e0: d503201f nop ffff8000080137e4: d503201f nop ffff8000080137e8: d503233f paciasp So at this time we have no idea to identify rec->ip for each tracable function. we are looking forward to follow-up discussions. References: [1] https://developer.arm.com/documentation/100076/0100/a64-instruction-set-reference/a64-general-instructions/bti [2] https://lore.kernel.org/linux-arm-kernel/20200109142736.1122-1-cj.chengjian@huawei.com/ Cheng Jian (4): arm64: introduce aarch64_insn_gen_load_literal arm64/ftrace: introduce ftrace dynamic trampoline entrances arm64/ftrace: support dynamically allocated trampolines arm64/ftrace: implement long jump for dynamic trampolines arch/arm64/Makefile | 2 +- arch/arm64/include/asm/ftrace.h | 10 +- arch/arm64/include/asm/insn.h | 6 + arch/arm64/include/asm/module.h | 9 + arch/arm64/kernel/entry-ftrace.S | 88 ++++++-- arch/arm64/kernel/ftrace.c | 366 ++++++++++++++++++++++++++++--- arch/arm64/kernel/module-plts.c | 50 +++++ arch/arm64/lib/insn.c | 49 +++++ 8 files changed, 532 insertions(+), 48 deletions(-)