Message ID | 20230616085038.4121892-2-rppt@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1184405vqr; Fri, 16 Jun 2023 02:01:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ZYaVY1q6P5D9586Qc6cgoUbLr9NNpO83AHCt+gq6p9i9BStF693JWZh9qExWoSkn9dW/k X-Received: by 2002:aa7:88d3:0:b0:647:e45f:1a4c with SMTP id k19-20020aa788d3000000b00647e45f1a4cmr1731042pff.11.1686906105909; Fri, 16 Jun 2023 02:01:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686906105; cv=none; d=google.com; s=arc-20160816; b=W9kDG5MoxBwbjBtZHgJvkS/q84mZRGgz4v9JIgC925O39Rs3uO55KZvTcxDo/9IY9s Nh6ysi4Ur0HyYfTiGQ9ZBP3d14hnXDgdSlIzuopfefcXYRA/6rX5zq2ua4CZIUxs0NxM Y87olLmPrpwKryEq8LrN6YeiDLP8I0bNgHfR0Mzt6IJm0ikrXx3lbGpsCK1NbPBe+2XO az/akJR3sv/fiC11cdZCfo9sF1yRMeaNpK64VyiuOAaqAV4mV+iaLiZ5lcTQc/Yaug4J CNCYySNfVkfMe5aUg9mm6R8KM+C2xNEThlkO/sSgQaYU3pOZXrDtT/YzKWV14CqxUWPU TrNQ== 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=L6XOdhPFP9NUFSkCDrsax9hrvyCgIk+n72kqbEz2oa4=; b=wL6O7wYgS1xLlvTBF4QvpFB4faULOaI8VdBK7V3YL/Bet4eVA1kykJD54Kdg8Ls/JR TJW+uC7XySX4K/ACVsEFt/LjDl1Ed6r4aTtpBaTXgDyg7AR2ahVFiGx/oOKxyXIVcAKQ PAK09E6UdGCbcDs9f3hzZvJKnTHCkxJaumslv42dWV8nibYkF9bX9RwJEwO8e2ve6SIn pM1CMVOofskK9Cex/kMTq+n8NAk+gajb+rtv9q11/Gt36elkDGbOwvk/SUHNqznykuz8 EvR4L9Vl+oP2bfEyp/JUVmYN/jo/An7cLfE7engH5+bZwQk7l2OC/LSpv8I20qFYLTEV FMTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KGdNi1Dy; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w185-20020a6262c2000000b0065ee6c40f91si10857155pfb.159.2023.06.16.02.01.33; Fri, 16 Jun 2023 02:01:45 -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=@kernel.org header.s=k20201202 header.b=KGdNi1Dy; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243558AbjFPIvS (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Fri, 16 Jun 2023 04:51:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343793AbjFPIvM (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 16 Jun 2023 04:51:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0EF530CD; Fri, 16 Jun 2023 01:51:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 58CE4628D0; Fri, 16 Jun 2023 08:51:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 416C3C43391; Fri, 16 Jun 2023 08:50:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686905468; bh=VoOzGojCT0s2khtn9U0zehI+G2CTL85NKGZbZioHSD0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KGdNi1DykOpL1nAp8YKmwUQtjmCY/GNdUrUS59wOYcF4YSeSmrHnLBQ1izkZ44N8U HHO3e+TYfMkfqi0szVbZ5zeAc9QeKHM17xDlt8OFJq0dr7xpgPizOgDUQGBudyuu82 ld7wsSBnY8+kktqR9FA0EEr8dMyJJXJ5BDD3M0xH0u+jPEYh/O9MrpHZwSiBGPLOPy 3GS8k19KoDWuq6n3hxMBwWwAyLGYUSGTMaYKta4EnO43cwBG8JuYjGTnnCo8Ak9JVZ t0m+rqOW+OVypCmxh/X1bXMy4dzCVDUgwqQdYYJYURrrYUW3z2v96C4kPFTxM8Oyco sdMiv6KioS9+Q== From: Mike Rapoport <rppt@kernel.org> To: linux-kernel@vger.kernel.org Cc: Andrew Morton <akpm@linux-foundation.org>, Catalin Marinas <catalin.marinas@arm.com>, Christophe Leroy <christophe.leroy@csgroup.eu>, "David S. Miller" <davem@davemloft.net>, Dinh Nguyen <dinguyen@kernel.org>, Heiko Carstens <hca@linux.ibm.com>, Helge Deller <deller@gmx.de>, Huacai Chen <chenhuacai@kernel.org>, Kent Overstreet <kent.overstreet@linux.dev>, Luis Chamberlain <mcgrof@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Michael Ellerman <mpe@ellerman.id.au>, Mike Rapoport <rppt@kernel.org>, Nadav Amit <nadav.amit@gmail.com>, "Naveen N. Rao" <naveen.n.rao@linux.ibm.com>, Palmer Dabbelt <palmer@dabbelt.com>, Puranjay Mohan <puranjay12@gmail.com>, Rick Edgecombe <rick.p.edgecombe@intel.com>, Russell King <linux@armlinux.org.uk>, Song Liu <song@kernel.org>, Steven Rostedt <rostedt@goodmis.org>, Thomas Bogendoerfer <tsbogend@alpha.franken.de>, Thomas Gleixner <tglx@linutronix.de>, Will Deacon <will@kernel.org>, bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev, netdev@vger.kernel.org, sparclinux@vger.kernel.org, x86@kernel.org Subject: [PATCH v2 01/12] nios2: define virtual address space for modules Date: Fri, 16 Jun 2023 11:50:27 +0300 Message-Id: <20230616085038.4121892-2-rppt@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230616085038.4121892-1-rppt@kernel.org> References: <20230616085038.4121892-1-rppt@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768849257387087916?= X-GMAIL-MSGID: =?utf-8?q?1768849257387087916?= |
Series |
mm: jit/text allocator
|
|
Commit Message
Mike Rapoport
June 16, 2023, 8:50 a.m. UTC
From: "Mike Rapoport (IBM)" <rppt@kernel.org> nios2 uses kmalloc() to implement module_alloc() because CALL26/PCREL26 cannot reach all of vmalloc address space. Define module space as 32MiB below the kernel base and switch nios2 to use vmalloc for module allocations. Suggested-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org> Acked-by: Dinh Nguyen <dinguyen@kernel.org> --- arch/nios2/include/asm/pgtable.h | 5 ++++- arch/nios2/kernel/module.c | 19 ++++--------------- 2 files changed, 8 insertions(+), 16 deletions(-)
Comments
On Fri, 2023-06-16 at 11:50 +0300, Mike Rapoport wrote: > void *module_alloc(unsigned long size) > { > - if (size == 0) > - return NULL; > - return kmalloc(size, GFP_KERNEL); > -} > - > -/* Free memory returned from module_alloc */ > -void module_memfree(void *module_region) > -{ > - kfree(module_region); > + return __vmalloc_node_range(size, 1, MODULES_VADDR, > MODULES_END, > + GFP_KERNEL, PAGE_KERNEL_EXEC, > + VM_FLUSH_RESET_PERMS, > NUMA_NO_NODE, > + __builtin_return_address(0)); > } > > int apply_relocate_add(Elf32_Shdr *sechdrs, const char *s I wonder if the (size == 0) check is really needed, but __vmalloc_node_range() will WARN on this case where the old code won't.
On Fri, Jun 16, 2023 at 1:51 AM Mike Rapoport <rppt@kernel.org> wrote: > > From: "Mike Rapoport (IBM)" <rppt@kernel.org> > > nios2 uses kmalloc() to implement module_alloc() because CALL26/PCREL26 > cannot reach all of vmalloc address space. > > Define module space as 32MiB below the kernel base and switch nios2 to > use vmalloc for module allocations. > > Suggested-by: Thomas Gleixner <tglx@linutronix.de> > Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org> > Acked-by: Dinh Nguyen <dinguyen@kernel.org> Acked-by: Song Liu <song@kernel.org> > --- > arch/nios2/include/asm/pgtable.h | 5 ++++- > arch/nios2/kernel/module.c | 19 ++++--------------- > 2 files changed, 8 insertions(+), 16 deletions(-) > > diff --git a/arch/nios2/include/asm/pgtable.h b/arch/nios2/include/asm/pgtable.h > index 0f5c2564e9f5..0073b289c6a4 100644 > --- a/arch/nios2/include/asm/pgtable.h > +++ b/arch/nios2/include/asm/pgtable.h > @@ -25,7 +25,10 @@ > #include <asm-generic/pgtable-nopmd.h> > > #define VMALLOC_START CONFIG_NIOS2_KERNEL_MMU_REGION_BASE > -#define VMALLOC_END (CONFIG_NIOS2_KERNEL_REGION_BASE - 1) > +#define VMALLOC_END (CONFIG_NIOS2_KERNEL_REGION_BASE - SZ_32M - 1) > + > +#define MODULES_VADDR (CONFIG_NIOS2_KERNEL_REGION_BASE - SZ_32M) > +#define MODULES_END (CONFIG_NIOS2_KERNEL_REGION_BASE - 1) > > struct mm_struct; > > diff --git a/arch/nios2/kernel/module.c b/arch/nios2/kernel/module.c > index 76e0a42d6e36..9c97b7513853 100644 > --- a/arch/nios2/kernel/module.c > +++ b/arch/nios2/kernel/module.c > @@ -21,23 +21,12 @@ > > #include <asm/cacheflush.h> > > -/* > - * Modules should NOT be allocated with kmalloc for (obvious) reasons. > - * But we do it for now to avoid relocation issues. CALL26/PCREL26 cannot reach > - * from 0x80000000 (vmalloc area) to 0xc00000000 (kernel) (kmalloc returns > - * addresses in 0xc0000000) > - */ > void *module_alloc(unsigned long size) > { > - if (size == 0) > - return NULL; > - return kmalloc(size, GFP_KERNEL); > -} > - > -/* Free memory returned from module_alloc */ > -void module_memfree(void *module_region) > -{ > - kfree(module_region); > + return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, > + GFP_KERNEL, PAGE_KERNEL_EXEC, > + VM_FLUSH_RESET_PERMS, NUMA_NO_NODE, > + __builtin_return_address(0)); > } > > int apply_relocate_add(Elf32_Shdr *sechdrs, const char *strtab, > -- > 2.35.1 >
On Fri, Jun 16, 2023 at 04:00:19PM +0000, Edgecombe, Rick P wrote: > On Fri, 2023-06-16 at 11:50 +0300, Mike Rapoport wrote: > > void *module_alloc(unsigned long size) > > { > > - if (size == 0) > > - return NULL; > > - return kmalloc(size, GFP_KERNEL); > > -} > > - > > -/* Free memory returned from module_alloc */ > > -void module_memfree(void *module_region) > > -{ > > - kfree(module_region); > > + return __vmalloc_node_range(size, 1, MODULES_VADDR, > > MODULES_END, > > + GFP_KERNEL, PAGE_KERNEL_EXEC, > > + VM_FLUSH_RESET_PERMS, > > NUMA_NO_NODE, > > + __builtin_return_address(0)); > > } > > > > int apply_relocate_add(Elf32_Shdr *sechdrs, const char *s > > I wonder if the (size == 0) check is really needed, but > __vmalloc_node_range() will WARN on this case where the old code won't. module_alloc() should not be called with zero size, so a warning there would be appropriate. Besides, no other module_alloc() had this check.
diff --git a/arch/nios2/include/asm/pgtable.h b/arch/nios2/include/asm/pgtable.h index 0f5c2564e9f5..0073b289c6a4 100644 --- a/arch/nios2/include/asm/pgtable.h +++ b/arch/nios2/include/asm/pgtable.h @@ -25,7 +25,10 @@ #include <asm-generic/pgtable-nopmd.h> #define VMALLOC_START CONFIG_NIOS2_KERNEL_MMU_REGION_BASE -#define VMALLOC_END (CONFIG_NIOS2_KERNEL_REGION_BASE - 1) +#define VMALLOC_END (CONFIG_NIOS2_KERNEL_REGION_BASE - SZ_32M - 1) + +#define MODULES_VADDR (CONFIG_NIOS2_KERNEL_REGION_BASE - SZ_32M) +#define MODULES_END (CONFIG_NIOS2_KERNEL_REGION_BASE - 1) struct mm_struct; diff --git a/arch/nios2/kernel/module.c b/arch/nios2/kernel/module.c index 76e0a42d6e36..9c97b7513853 100644 --- a/arch/nios2/kernel/module.c +++ b/arch/nios2/kernel/module.c @@ -21,23 +21,12 @@ #include <asm/cacheflush.h> -/* - * Modules should NOT be allocated with kmalloc for (obvious) reasons. - * But we do it for now to avoid relocation issues. CALL26/PCREL26 cannot reach - * from 0x80000000 (vmalloc area) to 0xc00000000 (kernel) (kmalloc returns - * addresses in 0xc0000000) - */ void *module_alloc(unsigned long size) { - if (size == 0) - return NULL; - return kmalloc(size, GFP_KERNEL); -} - -/* Free memory returned from module_alloc */ -void module_memfree(void *module_region) -{ - kfree(module_region); + return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, + GFP_KERNEL, PAGE_KERNEL_EXEC, + VM_FLUSH_RESET_PERMS, NUMA_NO_NODE, + __builtin_return_address(0)); } int apply_relocate_add(Elf32_Shdr *sechdrs, const char *strtab,