Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp921667pxp; Wed, 16 Mar 2022 21:23:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK1GRjw90xLYdv/3XlJuvHC4Rdx5OLGH2gTPjdmP9S7ynQDkNl8EDSQipFZYeWkYp9QQKO X-Received: by 2002:aa7:82d9:0:b0:4fa:2c7f:41e with SMTP id f25-20020aa782d9000000b004fa2c7f041emr2569131pfn.1.1647491014635; Wed, 16 Mar 2022 21:23:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647491014; cv=none; d=google.com; s=arc-20160816; b=m8vUkSMOze0ACFi90huuFu3KR0Q9O1FJI07hh8wNnc2rXrcd6LJJqZpuTI59CxUIYW Af+wOgKYEDHJJSVr1l28As3vnRP61Bc8AL2n1XtW1ME5qAeWWjQBonGaQOoNFj4z/zfT w/ezYOydunvosfhS6jlmktScpRdapmNAAACCW1V+CGxpa0mCeAL6S78BG+xonvTn/QZT f2kbeJxuxAAqJUgUJbZ3t5xNkEXaX1KyJ6xtetvLyw1DSrD+08dLRSoHLEwr3Dt822db fdwHUHQQaCH+P0OQYuIHbrcQS0ZADfpg/OrA7oNKVMyXPVy2A0vPA9u8/pa/rofVqHmb yJ6A== 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 :message-id:date:subject:cc:from; bh=pZxKMacp+ddv9jDf0ltzvON837zxHUzK785raxjUIRA=; b=he2LgA4DtKbcgv/KOhqZNDlI4vSgjzQCMQszNqq0PmEgFPx6yNmGotEDWYC5q6oCUM PrLcFB4rUfaFx9vqWb06/UMi8PuEG23RyHL4cqEJLgsZy6mxHyzSaiDGtsAJuGr6QW4v S9WMGRWbeDWC6QlwdmjEymWC/08xviR9TD2ezqTFNb3naXFrdyaaMGW+WpVnxdLyZwQw VNXXkRIiV+J6smAvkiEd27veNkg6rXlfSQk2GXk1Tpz86N2OqxMZIbm8ucz1v8wfCY+h lJT63aO0fffSpg8oCLpcLvc1tBa6uoCqL1mwtcwtpGknDHpBVtr+jzkIphQ9RdxFvCZU ki/Q== 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 c8-20020a6566c8000000b003820429185esi1031272pgw.60.2022.03.16.21.23.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 21:23:34 -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 DCC64E1B76; Wed, 16 Mar 2022 20:56:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354995AbiCPJxL (ORCPT + 99 others); Wed, 16 Mar 2022 05:53:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236931AbiCPJxJ (ORCPT ); Wed, 16 Mar 2022 05:53:09 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ADD7606E3 for ; Wed, 16 Mar 2022 02:51:55 -0700 (PDT) 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 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 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 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(-) -- 2.25.1