Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp2565252rwb; Sun, 4 Sep 2022 19:33:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR57UOSLTTL1y01dab3Y2CZhg5SXRu38mcn+qPJpLUbsMs5LkqYWk2slfRuCDjj3SIEk5VnS X-Received: by 2002:a17:906:cc5a:b0:741:5240:d91a with SMTP id mm26-20020a170906cc5a00b007415240d91amr27936386ejb.500.1662345214533; Sun, 04 Sep 2022 19:33:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662345214; cv=none; d=google.com; s=arc-20160816; b=mBHeGdSVIdFjTL/b4oLLd5pNDdHm8AqA3FVd5eVIQYU3RCwJjvxMtFmvbD6kaR5eiW v8GZsi0icZmZIIzqdDsB5Uew6Tz+PJemC4l8HR7G7z8V+1C2do5EpC/+wn/c1IyyK3pM JylYlOQzRK+BqQs1z4+McNzVRVoqRk3JCvFUSuVK36WM6I+6vLwABOK+wcrU7Rb+9GF4 BGL4Wpm+09/E2tL4QtttUZ0VV6yAzbNG117tcUJNBslWogjenyVsQnWvxrC3DVrZNyOg LZ+SrJjjvgyjp97+wTXfgX7+OKbr9PRiok6Cz3g4LfMdDzzXnEH3d1ly9TC3m+bM8XtR kW0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=KeI2K+vpJxKz2joPpgzHPvssxm0ytCAkQ81Z6vZdx1w=; b=hCv80p9t6sbF3JK5SGwRzxgODP8xevBtrUdtzELQELJIoCxN+WS2JrBK+rK4TRkwKf 6tQrOweXHmQ3RwNfNTX5VH0dmijoEevAwi0YIbfDBrAQthWlTz5/Tj+Bm6TbyoQg65yL 9PrwsruPwne9TG2EZbqef0wbTudv5NQxo0p6zDUdlm99cjk666yLhKFHmIKy2ZlxHrSs 1wjj8GVvRTxkKg0JxWUiosGiIJ7vgnozxlcOtBoegeVmRWyHssoxJFAFsUhlBBjdIP3+ RToB1kV2IILikcE4bQHrq3bL74ZAFSZXz2/DaKpPsgCyJVgslvQz+mcsVZbh7+y0ofnZ BuuA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd14-20020a1709076e0e00b007417a742974si7671525ejc.610.2022.09.04.19.33.09; Sun, 04 Sep 2022 19:33:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235438AbiIEBwe (ORCPT + 99 others); Sun, 4 Sep 2022 21:52:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235432AbiIEBwa (ORCPT ); Sun, 4 Sep 2022 21:52:30 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DC18926555 for ; Sun, 4 Sep 2022 18:52:28 -0700 (PDT) Received: from [10.130.0.193] (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxYOJUVhVjeVsRAA--.7257S3; Mon, 05 Sep 2022 09:52:21 +0800 (CST) Subject: Re: [PATCH 1/3] LoongArch: tools: Add relocs tool support To: Jinyang He , Xi Ruoyao , Huacai Chen References: <1662113335-14282-1-git-send-email-tangyouling@loongson.cn> <1662113335-14282-2-git-send-email-tangyouling@loongson.cn> <4df8a26c49a35c1fce36d80c370f738fa71a2bef.camel@xry111.site> <78a4a6b0970c309daa336a2329e69d28df486552.camel@xry111.site> Cc: linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, Xuerui Wang , Jiaxun Yang From: Youling Tang Message-ID: Date: Mon, 5 Sep 2022 09:52:20 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID: AQAAf8CxYOJUVhVjeVsRAA--.7257S3 X-Coremail-Antispam: 1UD129KBjvJXoWxXrW8Cw18Kr1DCryxWFyDWrg_yoW5CFWxpr W7KF4UKa1kGr1xZa1jqwnYgFyFg3y8WryfWrW5tryFv3Z09Fn3XF18ta1UuFy7Crn2yr1Y vFWSyFn7Zr4YyFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvl14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r 4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2Wl Yx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbV WUJVW8JwACjcxG0xvEwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc7I2V7IY0VAS07Al zVAYIcxG8wCY02Avz4vE14v_KwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJV W8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF 1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6x IIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvE x4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvj DU0xZFpf9x0JUHpB-UUUUU= X-CM-SenderInfo: 5wdqw5prxox03j6o00pqjv00gofq/ X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Jinyang Thank you very much for some ideas. On 09/04/2022 12:23 AM, Jinyang He wrote: > On 2022/9/3 18:49, Xi Ruoyao wrote: > >> On Sat, 2022-09-03 at 09:57 +0800, Youling Tang wrote: >>>>> Unlike (pre-r6) MIPS, LoongArch has a complete support for PIC, and >>>>> currently LoongArch toolchain always produces PIC (except, if >>>>> -Wa,-mla- >>>>> {local,global}-with-abs or la.abs macros are used explicitly). >>>>> >>>>> So would it be easier to review and correct the uses of "la.abs" in >>>>> the >>>>> code, and make the main kernel image a real PIE? Then we can load it >>>>> everywhere w/o any need to do relocation at load time. >>> At the beginning I also wanted to make the main kernel image a real PIE >>> and tried it, some of the "la.abs" can be modified, but I encountered >>> difficulties in modifying the exception handling code part, the kernel >>> will not boot after modification :(, I will continue to work hard try. >> I just tried the same thing and get the same result :(. Will spend >> several hours reading the LoongArch manual about exception... >> > Hi, > > The following ideas are based on experience, without validation. Patches > show that three types of relocation are needed to be done. > 1, GOT is generated by toolchain, so I think eliminating them by > toolchain is better. > 2, Ex_table is generated but striped relocation info. We can plays pcrel > way to resolve this problem. One of ways like follows, (pseudo-code) > > arch/loongarch/copy_user.S > ... > .macro fixup_ex from, to, offset, fix > .if \fix > .section .fixup, "ax" > \to: addi.d a0, a2, \offset > jr ra > .previous > .endif > .section __ex_table, "a" > PTR \from\()b, \to\()b - \from\()b # fixup use pcrel > .previous > .endm > ... > ... > > arch/loongarch/mm/extable.c > ... > unsigned long era = exception_era(regs); > fixup = search_exception_tables(era - relocate_offset); // > Search by orig value > if (fixup) { > regs->csr_era = fixup->fixup + era; // Fixup fixup address. > return 1; > } > > ... Yes, we might be able to make the exception table consists of pairs of relative offsets, like arm64 and riscv do. Thanks, Youling. > > 3, The left is the processed relocation table. It collect the relocation > type R_LARCH_ABS* (R_LARCH_MARK_LA?) and R_LARCH_64. Just do > as this patch does. The la.abs is used because of the different exception > entry on each CPUs and better NUMA performance IMHO. We can > do follows way to avoid R_LARCH_ABS* and produce R_LARCH_64, (data in text) > > .text > la.pcrel t0,999f > ld.d t0,t0,0 > ... > PTR do_vint > ... > > *Not* important. For me, I really wish a bootstrap relocation while this > patch is KALSR. The bootstrap relocation meaning is the boot cpu enter > kernel_entry, check the real address itself, parse the cmdline whether > do kaslr, and then relocate itself. Then kdump capture process is easier. > Some past info links, > https://lore.kernel.org/loongarch/3002b2b3-2c2c-e32e-c474-d3876d3ef9b7@loongson.cn/ > > https://patchwork.kernel.org/project/linux-mips/patch/1618230494-6207-6-git-send-email-hejinyang@loongson.cn/ > > >