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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D6D4C433EF for ; Mon, 29 Nov 2021 01:42:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235161AbhK2Bpw (ORCPT ); Sun, 28 Nov 2021 20:45:52 -0500 Received: from szxga02-in.huawei.com ([45.249.212.188]:27307 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236804AbhK2Bnv (ORCPT ); Sun, 28 Nov 2021 20:43:51 -0500 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4J2Sj71rd9zbj2N; Mon, 29 Nov 2021 09:40:27 +0800 (CST) Received: from kwepemm600003.china.huawei.com (7.193.23.202) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 29 Nov 2021 09:40:32 +0800 Received: from [10.67.102.185] (10.67.102.185) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 29 Nov 2021 09:40:31 +0800 Subject: Re: [PATCH v4 2/2] arm64: kprobe: Enable OPTPROBE for arm64 To: Masami Hiramatsu CC: Mark Rutland , , , , , , , , , , , , References: <20210818073336.59678-1-liuqi115@huawei.com> <20210818073336.59678-3-liuqi115@huawei.com> <20210824105001.GA96738@C02TD0UTHF1T.local> <20211127212302.f71345c34e5a62e5e779adb2@kernel.org> From: "liuqi (BA)" Message-ID: <4998f219-eb47-a07c-b3ed-c2ae46a77230@huawei.com> Date: Mon, 29 Nov 2021 09:40:30 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20211127212302.f71345c34e5a62e5e779adb2@kernel.org> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.102.185] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/11/27 20:23, Masami Hiramatsu wrote: > On Fri, 26 Nov 2021 18:31:06 +0800 > "liuqi (BA)" wrote: > >> >> >> On 2021/8/24 18:50, Mark Rutland wrote: >>>> diff --git a/arch/arm64/kernel/probes/optprobe_trampoline.S b/arch/arm64/kernel/probes/optprobe_trampoline.S >>>> new file mode 100644 >>>> index 000000000000..24d713d400cd >>>> --- /dev/null >>>> +++ b/arch/arm64/kernel/probes/optprobe_trampoline.S >>>> @@ -0,0 +1,37 @@ >>>> +/* SPDX-License-Identifier: GPL-2.0 */ >>>> +/* >>>> + * trampoline entry and return code for optprobes. >>>> + */ >>>> + >>>> +#include >>>> +#include >>>> +#include >>>> + >>>> + .global optprobe_template_entry >>>> +optprobe_template_entry: >>> Please use SYM_*(); see arch/arm64/kernel/entry-ftrace.S for examples of >>> how to use that for trampolines. >>> >>> This should be: >>> >>> SYM_CODE_START(optprobe_template) >>> >> Hi all, >> >> I meet a problem when I use SYM_CODE_START(optprobe_template) to replace >> optprobe_template_entry. >> >> If SYM_CODE_START is used, all optprobe will share one trampoline space. >> Under this circumstances, if user register two optprobes, trampoline >> will be overwritten by the newer one, and this will cause kernel panic >> when the old optprobe is trigger. > > Hm, this is curious, because the template should be copied to the > trampoline buffer for each optprobe and be modified. > >> >> Using optprobe_template_entry will not have this problem, as each >> optprobe has its own trampoline space (alloced in get_opinsn_slot()). > > Yes, it is designed to do so. > > Thank you, > Hi Masami, Thanks for your reply. But I also met a problem when using get_opinsn_slot() to alloc trampoline buffer. As module_alloc(like x86) is used to alloc buffer, trampoline is in module space, so if origin insn is in kernel space, the range between origin insn and trampoline is out of 128M. As module PLT cannot used here, I have no idea to achieve long jump in this situation. Do you have any good idea? Thanks, Qi >> >> So how to reuse SYM_CODE_START in this situation, does anyone has a >> good idea? >> >> Thanks, >> Qi >>> ... and note the matching end below. >>> >>>> + sub sp, sp, #PT_REGS_SIZE >>>> + save_all_base_regs >>>> + /* Get parameters to optimized_callback() */ >>>> + ldr x0, 1f >>>> + mov x1, sp >>>> + /* Branch to optimized_callback() */ >>>> + .global optprobe_template_call >>>> +optprobe_template_call: >>> SYM_INNER_LABEL(optprobe_template_call, SYM_L_GLOBAL) >>> >>> ...and likewise for all the other labels. >>> >>>> + nop >>>> + restore_all_base_regs >>>> + ldr lr, [sp, #S_LR] >>>> + add sp, sp, #PT_REGS_SIZE >>>> + .global optprobe_template_restore_orig_insn >>>> +optprobe_template_restore_orig_insn: >>>> + nop >>>> + .global optprobe_template_restore_end >>>> +optprobe_template_restore_end: >>>> + nop >>>> + .global optprobe_template_end >>>> +optprobe_template_end: >>>> + .global optprobe_template_val >>>> +optprobe_template_val: >>>> + 1: .long 0 >>>> + .long 0 >>>> + .global optprobe_template_max_length >>>> +optprobe_template_max_length: >>> SYM_INNER_LABEL(optprobe_template_end, SYM_L_GLOBAL) >>> SYM_CODE_END(optprobe_template) >>> >>> Thanks, >>> Mark. >>> >>>> -- > > 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 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 F05C4C433F5 for ; Mon, 29 Nov 2021 01:42:08 +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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:CC:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=XfQahlYWDGdOwfdDJPbjYD8YiYZXdtjYRsMO/iU4+Ww=; b=VPmoY5wtezp+/XlyqCsUPzEmnB 3FDVcdN6ZK66uTbcthnySmeiebFAzDdY2UESYhHfUwHb1eI/hmr4Lka5JMfkp4jqEtnYU25Qo0Ba3 9L+RfzPdIjlx5upRuXptyGzNyaLYWe39U+l5Jbu0SYhrO3HsUOIp1hTUmWB+i61stXFNTzsC8qc/c QdP6HkVs0lJdx26bg9QQUmQ5htmuxCONKpY7Ed6eLuUELnxPrR9JjJeyG6KEOUkRIwUA+zhd4GsYQ +mAKTvFTIkItWhQsSKCRZdan2SKDsNR0Z/oFPj0woeh8qd/I+cuEk6ceKjRUAqqPCUlRIvybb0ngc GUxboWtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mrVet-00H3Ps-9N; Mon, 29 Nov 2021 01:40:43 +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 1mrVep-00H3Om-7R for linux-arm-kernel@lists.infradead.org; Mon, 29 Nov 2021 01:40:41 +0000 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4J2Sj71rd9zbj2N; Mon, 29 Nov 2021 09:40:27 +0800 (CST) Received: from kwepemm600003.china.huawei.com (7.193.23.202) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 29 Nov 2021 09:40:32 +0800 Received: from [10.67.102.185] (10.67.102.185) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Mon, 29 Nov 2021 09:40:31 +0800 Subject: Re: [PATCH v4 2/2] arm64: kprobe: Enable OPTPROBE for arm64 To: Masami Hiramatsu CC: Mark Rutland , , , , , , , , , , , , References: <20210818073336.59678-1-liuqi115@huawei.com> <20210818073336.59678-3-liuqi115@huawei.com> <20210824105001.GA96738@C02TD0UTHF1T.local> <20211127212302.f71345c34e5a62e5e779adb2@kernel.org> From: "liuqi (BA)" Message-ID: <4998f219-eb47-a07c-b3ed-c2ae46a77230@huawei.com> Date: Mon, 29 Nov 2021 09:40:30 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20211127212302.f71345c34e5a62e5e779adb2@kernel.org> Content-Language: en-GB X-Originating-IP: [10.67.102.185] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211128_174039_663200_39EDA16C X-CRM114-Status: GOOD ( 22.57 ) 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: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2021/11/27 20:23, Masami Hiramatsu wrote: > On Fri, 26 Nov 2021 18:31:06 +0800 > "liuqi (BA)" wrote: > >> >> >> On 2021/8/24 18:50, Mark Rutland wrote: >>>> diff --git a/arch/arm64/kernel/probes/optprobe_trampoline.S b/arch/arm64/kernel/probes/optprobe_trampoline.S >>>> new file mode 100644 >>>> index 000000000000..24d713d400cd >>>> --- /dev/null >>>> +++ b/arch/arm64/kernel/probes/optprobe_trampoline.S >>>> @@ -0,0 +1,37 @@ >>>> +/* SPDX-License-Identifier: GPL-2.0 */ >>>> +/* >>>> + * trampoline entry and return code for optprobes. >>>> + */ >>>> + >>>> +#include >>>> +#include >>>> +#include >>>> + >>>> + .global optprobe_template_entry >>>> +optprobe_template_entry: >>> Please use SYM_*(); see arch/arm64/kernel/entry-ftrace.S for examples of >>> how to use that for trampolines. >>> >>> This should be: >>> >>> SYM_CODE_START(optprobe_template) >>> >> Hi all, >> >> I meet a problem when I use SYM_CODE_START(optprobe_template) to replace >> optprobe_template_entry. >> >> If SYM_CODE_START is used, all optprobe will share one trampoline space. >> Under this circumstances, if user register two optprobes, trampoline >> will be overwritten by the newer one, and this will cause kernel panic >> when the old optprobe is trigger. > > Hm, this is curious, because the template should be copied to the > trampoline buffer for each optprobe and be modified. > >> >> Using optprobe_template_entry will not have this problem, as each >> optprobe has its own trampoline space (alloced in get_opinsn_slot()). > > Yes, it is designed to do so. > > Thank you, > Hi Masami, Thanks for your reply. But I also met a problem when using get_opinsn_slot() to alloc trampoline buffer. As module_alloc(like x86) is used to alloc buffer, trampoline is in module space, so if origin insn is in kernel space, the range between origin insn and trampoline is out of 128M. As module PLT cannot used here, I have no idea to achieve long jump in this situation. Do you have any good idea? Thanks, Qi >> >> So how to reuse SYM_CODE_START in this situation, does anyone has a >> good idea? >> >> Thanks, >> Qi >>> ... and note the matching end below. >>> >>>> + sub sp, sp, #PT_REGS_SIZE >>>> + save_all_base_regs >>>> + /* Get parameters to optimized_callback() */ >>>> + ldr x0, 1f >>>> + mov x1, sp >>>> + /* Branch to optimized_callback() */ >>>> + .global optprobe_template_call >>>> +optprobe_template_call: >>> SYM_INNER_LABEL(optprobe_template_call, SYM_L_GLOBAL) >>> >>> ...and likewise for all the other labels. >>> >>>> + nop >>>> + restore_all_base_regs >>>> + ldr lr, [sp, #S_LR] >>>> + add sp, sp, #PT_REGS_SIZE >>>> + .global optprobe_template_restore_orig_insn >>>> +optprobe_template_restore_orig_insn: >>>> + nop >>>> + .global optprobe_template_restore_end >>>> +optprobe_template_restore_end: >>>> + nop >>>> + .global optprobe_template_end >>>> +optprobe_template_end: >>>> + .global optprobe_template_val >>>> +optprobe_template_val: >>>> + 1: .long 0 >>>> + .long 0 >>>> + .global optprobe_template_max_length >>>> +optprobe_template_max_length: >>> SYM_INNER_LABEL(optprobe_template_end, SYM_L_GLOBAL) >>> SYM_CODE_END(optprobe_template) >>> >>> Thanks, >>> Mark. >>> >>>> -- > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel