Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3156018rwe; Mon, 29 Aug 2022 06:50:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR7cNxhdb6Yl76iFHBUXPZfyThqSauOAR/MWHIFeNl4JAbZ6ea4RXhmX2kgWxNnsuaQR4hI5 X-Received: by 2002:a65:6202:0:b0:41d:5906:2165 with SMTP id d2-20020a656202000000b0041d59062165mr14026059pgv.320.1661781005833; Mon, 29 Aug 2022 06:50:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661781005; cv=none; d=google.com; s=arc-20160816; b=stGT/puYNPYAOdb4dPb9cVTO6BwTAeXz/RTM5Akk0WL0cR4deKd/w6+Pq2HFXHWQYL HYD14AUUsk4unf/uV4xCNnJLR+27BIHq61Jx0YmpaA6rhp6t2lssLmOYFsZkdbZ4IxjL JuqL+mpPeD7yJiItoyz7pnuSlHz5x53z8pXYztighyaQkqX9FXrIL60/2aeY9hwUbKUw LGLdPP0J7GzOxj/MK+84SXN/W+Ldf7zIS7D66uveJdJif8L0UNex/u/niqKKTYJ3jOnM HIZy0pC60jJe6X36fQNoVOGRsev1p4lUFRtRWnlSaq0XwJEY/l3ShLD+js31YmXNsBlc KtDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MC/dJaiMmPzaZzb1s/uWm/gGOB1gtMoAJS61/GDBhLc=; b=GbDH9bFTt9gtlimfFWtnD8YNuL+Sy1vxo3MfhnruoaXLdFvzp9DWLU8x7Emo5+v/R3 uZENqW1ZFJjGnB6DoOOYkmgZyUERJFWcyxbJ9kusT9R/6CfqU0ok+nUfOfJspoKHaz7W 6kQYg9XpgY2yTTOyO76GUjyNd8dR3AZGtGO2AjsAUT+VszSDtaKVhyFqDyNIM1MA9APm M98S/pY9DkwXME0T/5wauSvJUYgdPLlKOcxKLJKlOQTZsCok+qdmul5fRdqRfQDmf+s9 YtQ18lOYisJEt98kgqtog3WAhvMNou6gqVa5/dh4F2bybjNmVRRPtqnR7NoVBUOp6juu B4GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=gPriV1sn; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g16-20020a056a0023d000b0052ee2647e0esi9947113pfc.146.2022.08.29.06.49.54; Mon, 29 Aug 2022 06:50:05 -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; dkim=pass header.i=@xry111.site header.s=default header.b=gPriV1sn; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229949AbiH2NfX (ORCPT + 99 others); Mon, 29 Aug 2022 09:35:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229909AbiH2NfT (ORCPT ); Mon, 29 Aug 2022 09:35:19 -0400 Received: from xry111.site (xry111.site [89.208.246.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 132904DB7A for ; Mon, 29 Aug 2022 06:35:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1661780115; bh=TwdAnZTgoj4EYEJwsRSSBSF3le/kWOA9MA+6UkrMJuo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gPriV1snZWAJnOMBQq3lW6JNaPqN66GxTiKaq8D6a7q+9clLZ+x/AOWezXdsBluAB u7XrsElOvTmUXqxuDD4peuLrcadeobkIb2/ndMK8jwsUYSV9ksdsiVre8BEMEQuKo1 puenuWwYkUxIvNDjV66pnQGz7q79LpdYuHDIXIfg= Received: from xry111-x57s1.. (unknown [IPv6:240e:358:11dd:1900:dc73:854d:832e:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id A7BF866905; Mon, 29 Aug 2022 09:35:09 -0400 (EDT) From: Xi Ruoyao To: loongarch@lists.linux.dev Cc: linux-kernel@vger.kernel.org, WANG Xuerui , Huacai Chen , Youling Tang , Jinyang He , Xi Ruoyao Subject: [PATCH v6 3/6] LoongArch: Use model("extreme") attribute for per-CPU variables in module if CONFIG_AS_HAS_EXPLICIT_RELOCS Date: Mon, 29 Aug 2022 21:31:43 +0800 Message-Id: <20220829133146.15236-4-xry111@xry111.site> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829133146.15236-1-xry111@xry111.site> References: <20220829133146.15236-1-xry111@xry111.site> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD, PDS_OTHER_BAD_TLD,SPF_HELO_PASS,SPF_PASS,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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On LoongArch, The "address" of a per-CPU variable symbol is actually an offset from $r21. The value is nearing the loading address of main kernel image, but far from the address of modules. We need to tell the compiler that a PC-relative addressing with 32-bit offset is not sufficient for local per-CPU variables. After some discussion with GCC maintainers, we implemented this attribute to indicate that a PC-relative addressing with 64-bit offset should be used. This attribute should be available in GCC 13 release. Some early GCC 13 snapshots may support -mexplicit-relocs but lack this attribute, we simply reject them. Signed-off-by: Xi Ruoyao Link: https://gcc.gnu.org/r13-2199 --- arch/loongarch/Makefile | 3 +++ arch/loongarch/include/asm/percpu.h | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile index 1563747c4fa8..593818a61741 100644 --- a/arch/loongarch/Makefile +++ b/arch/loongarch/Makefile @@ -53,6 +53,9 @@ LDFLAGS_vmlinux += -G0 -static -n -nostdlib # combination of a "new" assembler and "old" compiler is not supported. Either # upgrade the compiler or downgrade the assembler. ifdef CONFIG_AS_HAS_EXPLICIT_RELOCS +ifeq ($(shell echo '__has_attribute(model)' | $(CC) -E -P - 2> /dev/null), 0) +$(error "C compiler must support model attribute if using explicit relocs") +endif cflags-y += -mexplicit-relocs else cflags-y += $(call cc-option,-mno-explicit-relocs) diff --git a/arch/loongarch/include/asm/percpu.h b/arch/loongarch/include/asm/percpu.h index 0bd6b0110198..dd7fcc553efa 100644 --- a/arch/loongarch/include/asm/percpu.h +++ b/arch/loongarch/include/asm/percpu.h @@ -8,6 +8,14 @@ #include #include +#if defined(MODULE) && defined(CONFIG_AS_HAS_EXPLICIT_RELOCS) +/* The "address" (in fact, offset from $r21) of a per-CPU variable is close + * to the load address of main kernel image, but far from where the modules are + * loaded. Tell the compiler this fact. + */ +# define PER_CPU_ATTRIBUTES __attribute__((model("extreme"))) +#endif + /* Use r21 for fast access */ register unsigned long __my_cpu_offset __asm__("$r21"); -- 2.37.0