Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1872035imn; Mon, 1 Aug 2022 03:23:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR6dnqXzQGDkoz8qjEYxTGtntlbRZnYJhD1t1LaoxZfow83CorU2ACi+p0Wy4eYfNXeelqtc X-Received: by 2002:a17:902:cece:b0:16e:ea30:6287 with SMTP id d14-20020a170902cece00b0016eea306287mr4654388plg.104.1659349430381; Mon, 01 Aug 2022 03:23:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659349430; cv=none; d=google.com; s=arc-20160816; b=g5BeDE30feQLC9T5mZAAAjewxBQuJ50b/68PE4ry0SH81tYL5euP46SqScIRGMkixM EwGhVb5X1tPLprHoQS0nyOYW4UhbyDp0kD4C9TRYFD7mo/GILYxZT9RRo0WNfSzM/YHl lenm+mIH7mlSIHAQUNbAnzNfI+2LVg/u0ERI3W1rQIsPoyIPixt9GwGG98WNDUb/z5kQ nSX/EPAVFfTtcF0kaPvMvUgljNsoaeUbZmSzhx2SRGRgFAM2Vy4BMPAvmVizBo7bE8fV auut6qbc/WZkTVlF7Y/9VCKoquRlzvKV1Y59PkqbO6qpbRGVcsVZB3b4+WtuSxyHtAXq wZxw== 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=f1nSjRmaMf4jOB746M7xHMojJEObrXcT+ZgpBH/Nsdg=; b=xeQlYaLItaHRWhgjAZ9JAlKlSBG5kSiCgRwxLpY+SkUszGVJUGsYbVNU2rHvRwLtPe oZmSduNLCvohKR6be2RqiSJlinrg7gy8fHJ3LXYh/C768g7M+SBo9UnA7MCgkC8jljOY XtVO1kHm7MlNGHq1uEOyQMDLY4wyP/R0qgFDdgzFZGli0+yCxPOhKkLusDIGrs3h6lwP 5B9OyOVuDRCPyO3ljarxVWoYcKCik9TCEpNxA2Wu4ynE5S7HPhYwmUB/m3hSiliuaYaN 40BrUlVBKjb1dNpqQgu0a189YQEXmiahSrp+q48yhs2uoROXQH8ZGcRNrQhZ/4/w0WoC SM4g== 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 c10-20020a170902d48a00b0016d6c3dbc81si186907plg.463.2022.08.01.03.23.35; Mon, 01 Aug 2022 03:23:50 -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 S230128AbiHAKIy (ORCPT + 99 others); Mon, 1 Aug 2022 06:08:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229818AbiHAKIv (ORCPT ); Mon, 1 Aug 2022 06:08:51 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 75C6D17E3A for ; Mon, 1 Aug 2022 03:08:49 -0700 (PDT) Received: from localhost.localdomain (unknown [111.9.175.10]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dx4M4tpudi3BcAAA--.489S3; Mon, 01 Aug 2022 18:08:47 +0800 (CST) Subject: Re: [PATCH v4 0/4] LoongArch: Support new relocation types To: Xi Ruoyao , Huacai Chen , Youling Tang References: <32a74a218c76611f897fd1df1ad0059068621133.camel@xry111.site> <0179679b736aea7258981dec2d83107cce74dfc1.camel@xry111.site> <6b5d2188f93ed72b67a4bbb7116113f833fe1ee5.camel@xry111.site> <7cad6e78014168a8906e130e1cf3809077d2bda7.camel@xry111.site> <1d0783b87bda3e454a111862fcc5b5faffcb16b0.camel@xry111.site> <00eede4b1380888a500f74b1e818bb25a550632b.camel@xry111.site> <7512ae16-b171-d072-674f-a6b9a5e764d6@loongson.cn> <10751c9af5d45fea741e0bbed6c818ddb9db3ac3.camel@xry111.site> Cc: loongarch@lists.linux.dev, LKML , WANG Xuerui , Lulu Cheng From: Jinyang He Message-ID: <7b1f9813-85fc-acfd-8e24-7e01469ded3a@loongson.cn> Date: Mon, 1 Aug 2022 18:08:45 +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: <10751c9af5d45fea741e0bbed6c818ddb9db3ac3.camel@xry111.site> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID: AQAAf9Dx4M4tpudi3BcAAA--.489S3 X-Coremail-Antispam: 1UD129KBjvJXoWxJFW3ur43Zw1rXw17GF15Jwb_yoWrGr1DpF Z7GFWUKr4kJr1Fyanrtw18uFyjvws8Jry7Xw15tryUZFyqvr93Gr4xtw1ruF9Fqr1kG3WU JrW7A34xXrWrZw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkC14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvEwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc7I2V7IY0VAS07AlzVAY IcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14 v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkG c2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6rW3Jr0E3s1lIxAIcVC2z280aVAFwI0_Jr0_ Gr1lIxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjfUoOJ5UU UUU X-CM-SenderInfo: pkhmx0p1dqwqxorr0wxvrqhubq/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_PASS,SPF_PASS 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 On 08/01/2022 05:55 PM, Xi Ruoyao wrote: > On Mon, 2022-08-01 at 10:34 +0800, Huacai Chen wrote: >> Hi, all, >> >> On Mon, Aug 1, 2022 at 10:16 AM Youling Tang >> wrote: >>> Hi, Ruoyao >>> >>> On 07/30/2022 10:52 AM, Xi Ruoyao wrote: >>>> On Sat, 2022-07-30 at 10:24 +0800, Xi Ruoyao wrote: >>>>> On Sat, 2022-07-30 at 01:55 +0800, Xi Ruoyao wrote: >>>>>> On Fri, 2022-07-29 at 20:19 +0800, Youling Tang wrote: >>>>>> >>>>>>> On 07/29/2022 07:45 PM, Xi Ruoyao wrote: >>>>>>>> Hmm... The problem is the "addresses" of per-cpu symbols >>>>>>>> are >>>>>>>> faked: they >>>>>>>> are actually offsets from $r21. So we can't just load >>>>>>>> such an >>>>>>>> offset >>>>>>>> with PCALA addressing. >>>>>>>> >>>>>>>> It looks like we'll need to introduce an attribute for GCC >>>>>>>> to >>>>>>>> make >>>>>>>> an >>>>>>>> variable "must be addressed via GOT", and add the >>>>>>>> attribute into >>>>>>>> PER_CPU_ATTRIBUTES. >>>>>>> Yes, we need a GCC attribute to specify the per-cpu >>>>>>> variable. >>>>>> GCC patch adding "addr_global" attribute for LoongArch: >>>>>> https://gcc.gnu.org/pipermail/gcc-patches/2022-July/599064.html >>>>>> >>>>>> An experiment to use it: >>>>>> https://github.com/xry111/linux/commit/c1d5d70 >>>>> Correction: https://github.com/xry111/linux/commit/c1d5d708 >>>>> >>>>> It seems 7-bit SHA is not enough for kernel repo. >>>> If addr_global is rejected or not implemented (for example, >>>> building the >>>> kernel with GCC 12), *I expect* the following hack to work (I've >>>> not >>>> tested it because I'm AFK now). Using visibility in kernel seems >>>> strange, but I think it may make some sense because the modules >>>> are some >>>> sort of similar to an ELF shared object being dlopen()'ed, and our >>>> way >>>> to inject per-CPU symbols is analog to ELF interposition. >>>> >>>> arch/loongarch/include/asm/percpu.h: >>>> >>>> #if !__has_attribute(__addr_global__) && defined(MODULE) >>>> /* Magically remove "static" for per-CPU variables. */ >>>> # define ARCH_NEEDS_WEAK_PER_CPU >>>> /* Force GOT-relocation for per-CPU variables. */ >>>> # define PER_CPU_ATTRIBUTES >>>> __attribute__((__visibility__("default"))) >>>> #endif >>>> >>>> arch/loongarch/Makefile: >>>> >>>> # Hack for per-CPU variables, see PER_CPU_ATTRIBUTES in >>>> # include/asm/percpu.h >>>> if (call gcc-does-not-support-addr-global) >>>> KBUILD_CFLAGS_MODULE += -fPIC -fvisibility=hidden >>>> endif >>>> >>> Using the old toolchain (GCC 12) can successfully load the >>> nf_tables.ko >>> module after applying the above patch. >> I don't like such a hack..., can we consider using old relocation >> types when building by old toolchains? > > I don't like the hack too. I only developed it as an intellectual game. > > We need to consider multiple combinations: > > (1) Old GCC + old Binutils. We need -mla-local-with-abs for > KBUILD_CFLAGS_MODULE. > > (2) Old GCC + new Binutils. We need -mla-local-with-abs for > KBUILD_CFLAGS_MODULE, *and* adding the support for > R_LARCH_ABS{_HI20,_LO12,64_LO20,64_HI12} in the kernel module loader. > > (3) New GCC + old Binutils. As new GCC should support our new attribute > (I now intend to send V2 patch to gcc-patches using "movable" as the > attribute name), no special action is needed. > > Basically, we need: > > (1) Handle R_LARCH_ABS{_HI20,_LO12,64_LO20,64_HI12} in the kernel module > loader. > (2) Add -Wa,-mla-local-with-abs into KBUILD_CFLAGS_MODULE if GCC version > is <= 12. Actually, I really hope kernel image is in the XKVRANGE, rather than being in XKPRANGE. So that we can limit kernel and modules be in 4GB range. I think it will make all work normally. :-(