From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C0E7C33CA2 for ; Fri, 10 Jan 2020 11:28:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D2B0A2072E for ; Fri, 10 Jan 2020 11:28:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727789AbgAJL2d (ORCPT ); Fri, 10 Jan 2020 06:28:33 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:9152 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727685AbgAJL2c (ORCPT ); Fri, 10 Jan 2020 06:28:32 -0500 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 22CB5E1CF0C553E95238; Fri, 10 Jan 2020 19:28:29 +0800 (CST) Received: from [127.0.0.1] (10.133.217.236) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.439.0; Fri, 10 Jan 2020 19:28:18 +0800 Subject: Re: [RFC PATCH] arm64/ftrace: support dynamically allocated trampolines To: Mark Rutland CC: , , , , , , , "chengjian (D)" References: <20200109142736.1122-1-cj.chengjian@huawei.com> <20200109164858.GH3112@lakrids.cambridge.arm.com> From: "chengjian (D)" Message-ID: Date: Fri, 10 Jan 2020 19:28:17 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 In-Reply-To: <20200109164858.GH3112@lakrids.cambridge.arm.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [10.133.217.236] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Mark     Thanks for your reply. On 2020/1/10 0:48, Mark Rutland wrote: > On Thu, Jan 09, 2020 at 02:27:36PM +0000, Cheng Jian wrote: > > Just how bad is this, and when/where does it matter? > > How much does this patch improve matters? I will have a test about this. >> Known issues : >> If kaslr is enabled, the address of tramp and ftrace call >> may be far away. Therefore, long jump support is required. >> Here I intend to use the same solution as module relocating, >> Reserve enough space for PLT at the end when allocating, can >> use PLT to complete these long jumps. > This can happen both ways; the callsite can also be too far from the > trampoline to be able to branch to it. Yes, that can happen both ways. > I've had issues with that for other reasons, and I think that we might > be able to use -fpatchable-function-entry=N,M to place a PLT immediately > before each function for that. However, I'm wary of doing so because it > makes it much harder to modify the patch site itself. This sounds good. I have no better idea than this now. At least try it first. > >> >> +GLOBAL(ftrace_common_end) >> ret x9 > This doesn't look right. Surely you want the RET, too? I will fix this error, thanks. > +/* > + * ftrace_caller() or ftrace_regs_caller() trampoline > + * +-----------------------+ > + * ftrace_(regs_)caller => | ...... | > + * ftrace_(regs_)caller_end => | b ftrace_common | => nop > + * +-----------------------+ > + * ftrace_common => | ...... | > + * function_trace_op_ptr => | adrp x2, sym | => nop > + * | ldr x2,[x2,:lo12:sym]| => ldr x2 > + * | ...... | > + * ftrace_common_end => | retq | > Copy-paste from x86? arm64 doesn't have a retq instruction. > >> + * +-----------------------+ >> + * ftrace_opt => | ftrace_opt | >> + * +-----------------------+ > Typo: s/opt/ops/ ? Sorry for these scenes. >> + */ >> +static unsigned long create_trampoline(struct ftrace_ops *ops, unsigned int *tramp_size) >> +{ >> + unsigned long start_offset_caller, end_offset_caller, caller_size; >> + unsigned long start_offset_common, end_offset_common, common_size; >> + unsigned long op_offset, offset, size, ip, npages; >> + void *trampoline; >> + unsigned long *ptr; >> + /* ldr x2,