From nobody Sat Jul 25 01:25:38 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 85DAC3C1404 for ; Tue, 21 Jul 2026 09:06:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784624780; cv=none; b=jfCtVf0zEI091TWAxAsvkM2GWrHK0eWl0ed/6uTfz1AdtKBBodC3d4ogqUCfIK040SRojs7e32/AJyBLiUsRwFQIBNlmFK+Vrv+dkeHo12L3NSm7giK0Ui8p2vaQPXYqrlYHu4nj949JRRCizyZCvqeFa7IChKenA/P/l1Pt22g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784624780; c=relaxed/simple; bh=p0lkgSry27wiwao79AF6pts01/8WmlkMsYsp66GzW44=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LQwQczZ6JfzjyfdzItRWgxl2dIwdthOZJWsUQgV95cvYVf6SC2Xxp/Rcq0l/il/9V4Ms0ipm3FNDjke9vdy+brE5bcQqaq+KS3uvFSCbItv5I5uvxPipO+EHfFLlFO7SDv0tge29+Wd5N0Mk+20i76AMaG+4XfgA88jIX/xxFe0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8Axx+qBNl9qJpMFAA--.22059S3; Tue, 21 Jul 2026 17:06:09 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowJBxb8d_Nl9qdssTAA--.39236S3; Tue, 21 Jul 2026 17:06:08 +0800 (CST) From: Tiezhu Yang To: Huacai Chen Cc: linux-mm@kvack.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, Andrew Morton , Mike Rapoport Subject: [PATCH v2 1/2] LoongArch: Expand module virtual address space to 2GB Date: Tue, 21 Jul 2026 17:06:05 +0800 Message-ID: <20260721090606.8982-2-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20260721090606.8982-1-yangtiezhu@loongson.cn> References: <20260721090606.8982-1-yangtiezhu@loongson.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJBxb8d_Nl9qdssTAA--.39236S3 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW7tF13Xw18ur4UXw4fJFyUtwc_yoW8Ar4UpF sxC3s8tFW8Wr1fCFWvywsrWF1aya97GFWIga15Wry8Cr9xW3WkXFs7t3s8XFykZan7C3WI vFyS9w13ZaykA3XCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9Yb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q 6rW5McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64 vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_ Jrv_JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1V AY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAI cVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42 IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIev Ja73UjIFyTuYvjxU4miiDUUUU Content-Type: text/plain; charset="utf-8" The current 256MB module virtual address space is easily exhausted when loading massive graphics drivers such as amdgpu along with the large unstripped symbol tables, resulting in allocation failures of "execmem: unable to allocate memory". Thus, expand the module virtual address space to 2GB while keeping the current normal code model '-mcmodel=3Dnormal', rather than using the medium code model '-mcmodel=3Dmedium'. This approach avoids the extra performance overhead and larger binary size of forcing every function call into a 2-instruction sequence of 'pcaddu18i + jirl'. Given that individual module code segments rarely exceed 128MB, most jumps remain fast direct calls by using the bl instruction. For the long-distance jumps exceeding the 128MB limit, apply_r_larch_b26() emits PLT entries, while signed_imm_check() guarantees the run-time safety by rejecting any out-of-bound instruction offsets. Signed-off-by: Tiezhu Yang --- arch/loongarch/include/asm/pgtable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/= asm/pgtable.h index 223528c04d73..e5952ecd6a73 100644 --- a/arch/loongarch/include/asm/pgtable.h +++ b/arch/loongarch/include/asm/pgtable.h @@ -96,7 +96,7 @@ struct vm_area_struct; #ifdef CONFIG_64BIT =20 #define MODULES_VADDR (vm_map_base + PCI_IOSIZE + (2 * PAGE_SIZE)) -#define MODULES_END (MODULES_VADDR + SZ_256M) +#define MODULES_END (MODULES_VADDR + SZ_2G) =20 #ifdef CONFIG_KFENCE #define KFENCE_AREA_SIZE (((CONFIG_KFENCE_NUM_OBJECTS + 1) * 2 + 2) * PAGE= _SIZE) --=20 2.42.0 From nobody Sat Jul 25 01:25:38 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 945633C140D for ; Tue, 21 Jul 2026 09:06:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784624779; cv=none; b=QeOlKIEIn6D9rBVd+QbOOIuc1YVVK8gHHneIZZhFPqSoqc3kA8RtgZwQuTJOSrtSfEldoBrtp1msy8bwEWivwO5jJatZWJx8ykufx5Mir0TDFyWLfUxRvKwUtCYZXQmcbKDsHsrNsK6Zuy1RcfHSPgtoS7PnRuP7TEupS6dWtjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784624779; c=relaxed/simple; bh=6hnBbVGYNLzPEo64qDSzGAeZsF8r3FudhQWYUFXijLQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OUWqK3gVHbj90yXrgoueEOgnKbdp1AUMBK3c9cHCzIgX4AP8hgvc2kLTZLAsUTMDkTY7ezLVoHXJS6+Yjd3U0sXylO5uiSzF3px/HGuTbm5GNjKh9d9jr16NVOCnmgcjaDqEZWNKsp4gRGP4v1D166DTVRKYMxTNnc/dLhTYNUg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8AxCOuCNl9qK5MFAA--.22052S3; Tue, 21 Jul 2026 17:06:10 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by front1 (Coremail) with SMTP id qMiowJBxb8d_Nl9qdssTAA--.39236S4; Tue, 21 Jul 2026 17:06:09 +0800 (CST) From: Tiezhu Yang To: Huacai Chen Cc: linux-mm@kvack.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, Andrew Morton , Mike Rapoport Subject: [PATCH v2 2/2] LoongArch: Skip address pairing for non-exec sections Date: Tue, 21 Jul 2026 17:06:06 +0800 Message-ID: <20260721090606.8982-3-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20260721090606.8982-1-yangtiezhu@loongson.cn> References: <20260721090606.8982-1-yangtiezhu@loongson.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJBxb8d_Nl9qdssTAA--.39236S4 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW7CrW8Zr18tryxKw4kKrWfJFc_yoW8CFWkpr sxCws5Zr48GrnxJws5J3WkWa4UGaykWw4aqF95J3s2yFsxXF9Yy3Z3KrnxXayUuw4rAw10 qryFqwn8Z3WUCFbCm3ZEXasCq-sJn29KB7ZKAUJUUUU7529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUB2b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q 6rW5McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64 vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_ Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8Gjc xK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0 cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E 14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUxhiSDUUUU Content-Type: text/plain; charset="utf-8" The module loader currently runs expensive address pairing logic for all sections blindly during relocation. For massive modules like amdgpu, this causes the loader to waste lots of CPU cycles analyzing non-exec sections. Furthermore, there is an inconsistency since module_frob_arch_sections() already ignores non-exec sections during the counting phase. Check the SHF_EXECINSTR flag in apply_relocate_add(). If the section is non-exec, skip address pairing and then jump to normal relocation. This eliminates redundant search loops to improve module loading efficiency. Signed-off-by: Tiezhu Yang --- arch/loongarch/kernel/module.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/loongarch/kernel/module.c b/arch/loongarch/kernel/module.c index 7d4d571ee55e..c84ac1546dc6 100644 --- a/arch/loongarch/kernel/module.c +++ b/arch/loongarch/kernel/module.c @@ -484,6 +484,7 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *s= trtab, Elf_Addr v; Elf_Sym *sym; Elf_Rela *rel =3D (void *) sechdrs[relsec].sh_addr; + Elf_Shdr *dst_sec =3D sechdrs + sechdrs[relsec].sh_info; =20 pr_debug("%s: Applying relocate section %u to %u\n", __func__, relsec, sechdrs[relsec].sh_info); @@ -522,6 +523,10 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *= strtab, =20 v =3D sym->st_value + rel[i].r_addend; =20 + /* Skip address pairing for non-exec sections */ + if (!(dst_sec->sh_flags & SHF_EXECINSTR)) + goto apply_normal; + if (type =3D=3D R_LARCH_PCADD_LO12 || type =3D=3D R_LARCH_GOT_PCADD_LO12= ) { bool found =3D false; unsigned int j =3D idx; @@ -562,6 +567,7 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *s= trtab, idx =3D j; /* Record the previous j-loop end index */ } =20 +apply_normal: switch (type) { case R_LARCH_B26: err =3D apply_r_larch_b26(mod, sechdrs, location, --=20 2.42.0