From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 213BE17565; Sun, 14 Apr 2024 07:28:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713079683; cv=none; b=ekIp91v3s3LBHAb2WunZcXrjH4xV3xGCu+c6oWltHqyO/V7ICXpHU7SFrr9NaxZu6OCYlp3u1+MZsxen3cNlwzBzpYU8k/j+Z5/7qoVjgTf8av2a1ickI3nlBiVyab0RNknvZV/Z1KU4m4IYjvdxuZHAMrCHC9NhD2YLRBTf7LE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713079683; c=relaxed/simple; bh=7UcAoz/SHZJ9dQ0bgxdPwC8jDXsqkfxw4nZlv0SLw5o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qbtxOfhZcaHsLD9jYrV2UIUzMCUE9EUXt1oaTpBMKzUZn1goQjZB8pC3+WRqLnjsOZnjz5GFc1H0/VPGjPGUY5yL3HHcR6uudTMBBTuF9XHxapMb6wL1ZZxvPcrwVX7L6g+IAnkXJRbzpuc2X1Q9qW95KlpFG4HTyJ5E5ImdaFE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mSn3bFIT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mSn3bFIT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 759F8C072AA; Sun, 14 Apr 2024 07:27:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713079682; bh=7UcAoz/SHZJ9dQ0bgxdPwC8jDXsqkfxw4nZlv0SLw5o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mSn3bFITK7eYlJdTFbScch0ThBeU+CtfVZynIF2TKYAjwpfIWpT9mvprRtl/vRdi+ PWs0IudDlFW6Beno7xjDAiW1ip7pL/FGhEaTkCamfUxQ5eDkHTs4QkNm97zhVJccwv UxX9+hkJgUV7GSohwVI620vdp0JYtwTWKKysZvcjBk9t6kUNPFg5Eeatgn84u8vivs 7On6vy8KLlD97z5wp8DI0bLXFhxIaSTkHjS//iWFuOPg7CQ+rJyeDYDISTJa6W6AFc TXNbcHaOhhepqyuh8BUKoPaV89wZMsoGzWH9gtBjUYYSDb1AqF+wsfY3ZeQjYF2dQ5 tmillpYns8epg== Date: Sun, 14 Apr 2024 10:26:47 +0300 From: Mike Rapoport To: Sam Ravnborg Cc: linux-kernel@vger.kernel.org, Alexandre Ghiti , Andrew Morton , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Luis Chamberlain , Mark Rutland , Michael Ellerman , Nadav Amit , Palmer Dabbelt , Puranjay Mohan , Rick Edgecombe , Russell King , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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: Re: [PATCH v4 06/15] mm/execmem, arch: convert simple overrides of module_alloc to execmem Message-ID: References: <20240411160051.2093261-1-rppt@kernel.org> <20240411160051.2093261-7-rppt@kernel.org> <20240411205346.GA66667@ravnborg.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240411205346.GA66667@ravnborg.org> On Thu, Apr 11, 2024 at 10:53:46PM +0200, Sam Ravnborg wrote: > Hi Mike. > > On Thu, Apr 11, 2024 at 07:00:42PM +0300, Mike Rapoport wrote: > > From: "Mike Rapoport (IBM)" > > > > Several architectures override module_alloc() only to define address > > range for code allocations different than VMALLOC address space. > > > > Provide a generic implementation in execmem that uses the parameters for > > address space ranges, required alignment and page protections provided > > by architectures. > > > > The architectures must fill execmem_info structure and implement > > execmem_arch_setup() that returns a pointer to that structure. This way the > > execmem initialization won't be called from every architecture, but rather > > from a central place, namely a core_initcall() in execmem. > > > > The execmem provides execmem_alloc() API that wraps __vmalloc_node_range() > > with the parameters defined by the architectures. If an architecture does > > not implement execmem_arch_setup(), execmem_alloc() will fall back to > > module_alloc(). > > > > Signed-off-by: Mike Rapoport (IBM) > > --- > > This code snippet could be more readable ... > > diff --git a/arch/sparc/kernel/module.c b/arch/sparc/kernel/module.c > > index 66c45a2764bc..b70047f944cc 100644 > > --- a/arch/sparc/kernel/module.c > > +++ b/arch/sparc/kernel/module.c > > @@ -14,6 +14,7 @@ > > #include > > #include > > #include > > +#include > > > > #include > > #include > > @@ -21,34 +22,26 @@ > > > > #include "entry.h" > > > > +static struct execmem_info execmem_info __ro_after_init = { > > + .ranges = { > > + [EXECMEM_DEFAULT] = { > > #ifdef CONFIG_SPARC64 > > - > > -#include > > - > > -static void *module_map(unsigned long size) > > -{ > > - if (PAGE_ALIGN(size) > MODULES_LEN) > > - return NULL; > > - return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, > > - GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE, > > - __builtin_return_address(0)); > > -} > > + .start = MODULES_VADDR, > > + .end = MODULES_END, > > #else > > -static void *module_map(unsigned long size) > > + .start = VMALLOC_START, > > + .end = VMALLOC_END, > > +#endif > > + .alignment = 1, > > + }, > > + }, > > +}; > > + > > +struct execmem_info __init *execmem_arch_setup(void) > > { > > - return vmalloc(size); > > -} > > -#endif /* CONFIG_SPARC64 */ > > - > > -void *module_alloc(unsigned long size) > > -{ > > - void *ret; > > - > > - ret = module_map(size); > > - if (ret) > > - memset(ret, 0, size); > > + execmem_info.ranges[EXECMEM_DEFAULT].pgprot = PAGE_KERNEL; > > > > - return ret; > > + return &execmem_info; > > } > > > > /* Make generic code ignore STT_REGISTER dummy undefined symbols. */ > > ... if the following was added: > > diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h > index 9e85d57ac3f2..62bcafe38b1f 100644 > --- a/arch/sparc/include/asm/pgtable_32.h > +++ b/arch/sparc/include/asm/pgtable_32.h > @@ -432,6 +432,8 @@ static inline int io_remap_pfn_range(struct vm_area_struct *vma, > > #define VMALLOC_START _AC(0xfe600000,UL) > #define VMALLOC_END _AC(0xffc00000,UL) > +#define MODULES_VADDR VMALLOC_START > +#define MODULES_END VMALLOC_END > > > Then the #ifdef CONFIG_SPARC64 could be dropped and the code would be > the same for 32 and 64 bits. Yeah, the #ifdef there can be dropped even regardless of execmem. I'll add a patch for that. > Just a drive-by comment. > > Sam > -- Sincerely yours, Mike. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C1BFCC4345F for ; Sun, 14 Apr 2024 07:28:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MiI5mptaRT6E6ob9jIp1uMP4Xa+13tYQBDNAUqVJKeM=; b=26nVC/24LImPvL i9SFv5ys8eGW3MXmgPJpnuKkXMrDwuINKj8hLTgWFkNFjP9ZFcYIG1GBmYAdigGPBKGKdh17tV+TU 6vTHhoDHcJb0CY6KtAQRhDa7bQ1/X2eE5QyKSjf2AvWz8hFU57euIHcEKl7f6vhzOrv6KVNnZLD75 LlCbCBHjTlpFPBohrTJKv2qqvq6cOpwuESmalypHPwWoDmTsxJrPAY5p3hhOaiIJRPhhZCCRgQUxV Pc08W4wFy99tisUgLWeileYB3Iq/ZyYXErWpRh7xs/t4QNXQFlAA0Y10QHoURpqfldNsDfugPnQ5z xqWd2SlVMpL1G96oHh1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvuHb-00000004t46-0l1M; Sun, 14 Apr 2024 07:28:11 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvuHW-00000004t1C-2KWD; Sun, 14 Apr 2024 07:28:07 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0AE1B6091C; Sun, 14 Apr 2024 07:28:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 759F8C072AA; Sun, 14 Apr 2024 07:27:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713079682; bh=7UcAoz/SHZJ9dQ0bgxdPwC8jDXsqkfxw4nZlv0SLw5o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mSn3bFITK7eYlJdTFbScch0ThBeU+CtfVZynIF2TKYAjwpfIWpT9mvprRtl/vRdi+ PWs0IudDlFW6Beno7xjDAiW1ip7pL/FGhEaTkCamfUxQ5eDkHTs4QkNm97zhVJccwv UxX9+hkJgUV7GSohwVI620vdp0JYtwTWKKysZvcjBk9t6kUNPFg5Eeatgn84u8vivs 7On6vy8KLlD97z5wp8DI0bLXFhxIaSTkHjS//iWFuOPg7CQ+rJyeDYDISTJa6W6AFc TXNbcHaOhhepqyuh8BUKoPaV89wZMsoGzWH9gtBjUYYSDb1AqF+wsfY3ZeQjYF2dQ5 tmillpYns8epg== Date: Sun, 14 Apr 2024 10:26:47 +0300 From: Mike Rapoport To: Sam Ravnborg Cc: linux-kernel@vger.kernel.org, Alexandre Ghiti , Andrew Morton , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Luis Chamberlain , Mark Rutland , Michael Ellerman , Nadav Amit , Palmer Dabbelt , Puranjay Mohan , Rick Edgecombe , Russell King , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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: Re: [PATCH v4 06/15] mm/execmem, arch: convert simple overrides of module_alloc to execmem Message-ID: References: <20240411160051.2093261-1-rppt@kernel.org> <20240411160051.2093261-7-rppt@kernel.org> <20240411205346.GA66667@ravnborg.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240411205346.GA66667@ravnborg.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240414_002806_698971_79CB2364 X-CRM114-Status: GOOD ( 29.82 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Thu, Apr 11, 2024 at 10:53:46PM +0200, Sam Ravnborg wrote: > Hi Mike. > > On Thu, Apr 11, 2024 at 07:00:42PM +0300, Mike Rapoport wrote: > > From: "Mike Rapoport (IBM)" > > > > Several architectures override module_alloc() only to define address > > range for code allocations different than VMALLOC address space. > > > > Provide a generic implementation in execmem that uses the parameters for > > address space ranges, required alignment and page protections provided > > by architectures. > > > > The architectures must fill execmem_info structure and implement > > execmem_arch_setup() that returns a pointer to that structure. This way the > > execmem initialization won't be called from every architecture, but rather > > from a central place, namely a core_initcall() in execmem. > > > > The execmem provides execmem_alloc() API that wraps __vmalloc_node_range() > > with the parameters defined by the architectures. If an architecture does > > not implement execmem_arch_setup(), execmem_alloc() will fall back to > > module_alloc(). > > > > Signed-off-by: Mike Rapoport (IBM) > > --- > > This code snippet could be more readable ... > > diff --git a/arch/sparc/kernel/module.c b/arch/sparc/kernel/module.c > > index 66c45a2764bc..b70047f944cc 100644 > > --- a/arch/sparc/kernel/module.c > > +++ b/arch/sparc/kernel/module.c > > @@ -14,6 +14,7 @@ > > #include > > #include > > #include > > +#include > > > > #include > > #include > > @@ -21,34 +22,26 @@ > > > > #include "entry.h" > > > > +static struct execmem_info execmem_info __ro_after_init = { > > + .ranges = { > > + [EXECMEM_DEFAULT] = { > > #ifdef CONFIG_SPARC64 > > - > > -#include > > - > > -static void *module_map(unsigned long size) > > -{ > > - if (PAGE_ALIGN(size) > MODULES_LEN) > > - return NULL; > > - return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, > > - GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE, > > - __builtin_return_address(0)); > > -} > > + .start = MODULES_VADDR, > > + .end = MODULES_END, > > #else > > -static void *module_map(unsigned long size) > > + .start = VMALLOC_START, > > + .end = VMALLOC_END, > > +#endif > > + .alignment = 1, > > + }, > > + }, > > +}; > > + > > +struct execmem_info __init *execmem_arch_setup(void) > > { > > - return vmalloc(size); > > -} > > -#endif /* CONFIG_SPARC64 */ > > - > > -void *module_alloc(unsigned long size) > > -{ > > - void *ret; > > - > > - ret = module_map(size); > > - if (ret) > > - memset(ret, 0, size); > > + execmem_info.ranges[EXECMEM_DEFAULT].pgprot = PAGE_KERNEL; > > > > - return ret; > > + return &execmem_info; > > } > > > > /* Make generic code ignore STT_REGISTER dummy undefined symbols. */ > > ... if the following was added: > > diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h > index 9e85d57ac3f2..62bcafe38b1f 100644 > --- a/arch/sparc/include/asm/pgtable_32.h > +++ b/arch/sparc/include/asm/pgtable_32.h > @@ -432,6 +432,8 @@ static inline int io_remap_pfn_range(struct vm_area_struct *vma, > > #define VMALLOC_START _AC(0xfe600000,UL) > #define VMALLOC_END _AC(0xffc00000,UL) > +#define MODULES_VADDR VMALLOC_START > +#define MODULES_END VMALLOC_END > > > Then the #ifdef CONFIG_SPARC64 could be dropped and the code would be > the same for 32 and 64 bits. Yeah, the #ifdef there can be dropped even regardless of execmem. I'll add a patch for that. > Just a drive-by comment. > > Sam > -- Sincerely yours, Mike. _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7830AC001CC for ; Sun, 14 Apr 2024 07:28:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=A0UllMhZoNZbEauhY9OFzfTZ1dQVDktU6HQV6ZFqUhc=; b=3PehXwvpflitTL fR5xtREaPnsKzCS+J476uUin8kfLYkl5MC+YgTiMAamXozJT7HMH/ujyfY1h5NpRKYdhxddpcBDwv B/g932OwLq4xzHZxY5dmXj8yA+42VcP0aVERlbeki3GatMTwufNGclt6DRqgkk68IZj4Z2xOv2Af7 OLLGJC/C7vyRec+oGdG302jKO9vqAxFXQMX726tqyH4czHbcyksd7bBtobK4K3npyHr9btHrDKbwP Ey7q7xq07Cf9GLQg8wyteCSfaUBpr0ULPAdekpVIBIX+8h0vvhrp4ksnoteWu7HLnRaEduc5abMJh AU9cwL/qszzKjJZUMDJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvuHa-00000004t3O-12Yg; Sun, 14 Apr 2024 07:28:10 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvuHW-00000004t1C-2KWD; Sun, 14 Apr 2024 07:28:07 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0AE1B6091C; Sun, 14 Apr 2024 07:28:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 759F8C072AA; Sun, 14 Apr 2024 07:27:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713079682; bh=7UcAoz/SHZJ9dQ0bgxdPwC8jDXsqkfxw4nZlv0SLw5o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mSn3bFITK7eYlJdTFbScch0ThBeU+CtfVZynIF2TKYAjwpfIWpT9mvprRtl/vRdi+ PWs0IudDlFW6Beno7xjDAiW1ip7pL/FGhEaTkCamfUxQ5eDkHTs4QkNm97zhVJccwv UxX9+hkJgUV7GSohwVI620vdp0JYtwTWKKysZvcjBk9t6kUNPFg5Eeatgn84u8vivs 7On6vy8KLlD97z5wp8DI0bLXFhxIaSTkHjS//iWFuOPg7CQ+rJyeDYDISTJa6W6AFc TXNbcHaOhhepqyuh8BUKoPaV89wZMsoGzWH9gtBjUYYSDb1AqF+wsfY3ZeQjYF2dQ5 tmillpYns8epg== Date: Sun, 14 Apr 2024 10:26:47 +0300 From: Mike Rapoport To: Sam Ravnborg Cc: linux-kernel@vger.kernel.org, Alexandre Ghiti , Andrew Morton , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Luis Chamberlain , Mark Rutland , Michael Ellerman , Nadav Amit , Palmer Dabbelt , Puranjay Mohan , Rick Edgecombe , Russell King , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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: Re: [PATCH v4 06/15] mm/execmem, arch: convert simple overrides of module_alloc to execmem Message-ID: References: <20240411160051.2093261-1-rppt@kernel.org> <20240411160051.2093261-7-rppt@kernel.org> <20240411205346.GA66667@ravnborg.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240411205346.GA66667@ravnborg.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240414_002806_698971_79CB2364 X-CRM114-Status: GOOD ( 29.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Apr 11, 2024 at 10:53:46PM +0200, Sam Ravnborg wrote: > Hi Mike. > > On Thu, Apr 11, 2024 at 07:00:42PM +0300, Mike Rapoport wrote: > > From: "Mike Rapoport (IBM)" > > > > Several architectures override module_alloc() only to define address > > range for code allocations different than VMALLOC address space. > > > > Provide a generic implementation in execmem that uses the parameters for > > address space ranges, required alignment and page protections provided > > by architectures. > > > > The architectures must fill execmem_info structure and implement > > execmem_arch_setup() that returns a pointer to that structure. This way the > > execmem initialization won't be called from every architecture, but rather > > from a central place, namely a core_initcall() in execmem. > > > > The execmem provides execmem_alloc() API that wraps __vmalloc_node_range() > > with the parameters defined by the architectures. If an architecture does > > not implement execmem_arch_setup(), execmem_alloc() will fall back to > > module_alloc(). > > > > Signed-off-by: Mike Rapoport (IBM) > > --- > > This code snippet could be more readable ... > > diff --git a/arch/sparc/kernel/module.c b/arch/sparc/kernel/module.c > > index 66c45a2764bc..b70047f944cc 100644 > > --- a/arch/sparc/kernel/module.c > > +++ b/arch/sparc/kernel/module.c > > @@ -14,6 +14,7 @@ > > #include > > #include > > #include > > +#include > > > > #include > > #include > > @@ -21,34 +22,26 @@ > > > > #include "entry.h" > > > > +static struct execmem_info execmem_info __ro_after_init = { > > + .ranges = { > > + [EXECMEM_DEFAULT] = { > > #ifdef CONFIG_SPARC64 > > - > > -#include > > - > > -static void *module_map(unsigned long size) > > -{ > > - if (PAGE_ALIGN(size) > MODULES_LEN) > > - return NULL; > > - return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, > > - GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE, > > - __builtin_return_address(0)); > > -} > > + .start = MODULES_VADDR, > > + .end = MODULES_END, > > #else > > -static void *module_map(unsigned long size) > > + .start = VMALLOC_START, > > + .end = VMALLOC_END, > > +#endif > > + .alignment = 1, > > + }, > > + }, > > +}; > > + > > +struct execmem_info __init *execmem_arch_setup(void) > > { > > - return vmalloc(size); > > -} > > -#endif /* CONFIG_SPARC64 */ > > - > > -void *module_alloc(unsigned long size) > > -{ > > - void *ret; > > - > > - ret = module_map(size); > > - if (ret) > > - memset(ret, 0, size); > > + execmem_info.ranges[EXECMEM_DEFAULT].pgprot = PAGE_KERNEL; > > > > - return ret; > > + return &execmem_info; > > } > > > > /* Make generic code ignore STT_REGISTER dummy undefined symbols. */ > > ... if the following was added: > > diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h > index 9e85d57ac3f2..62bcafe38b1f 100644 > --- a/arch/sparc/include/asm/pgtable_32.h > +++ b/arch/sparc/include/asm/pgtable_32.h > @@ -432,6 +432,8 @@ static inline int io_remap_pfn_range(struct vm_area_struct *vma, > > #define VMALLOC_START _AC(0xfe600000,UL) > #define VMALLOC_END _AC(0xffc00000,UL) > +#define MODULES_VADDR VMALLOC_START > +#define MODULES_END VMALLOC_END > > > Then the #ifdef CONFIG_SPARC64 could be dropped and the code would be > the same for 32 and 64 bits. Yeah, the #ifdef there can be dropped even regardless of execmem. I'll add a patch for that. > Just a drive-by comment. > > Sam > -- Sincerely yours, Mike. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 562D7C4345F for ; Sun, 14 Apr 2024 07:28:47 +0000 (UTC) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=mSn3bFIT; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VHMNs621Fz3dXF for ; Sun, 14 Apr 2024 17:28:45 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=mSn3bFIT; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=139.178.84.217; helo=dfw.source.kernel.org; envelope-from=rppt@kernel.org; receiver=lists.ozlabs.org) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4VHMN502T9z3cHN for ; Sun, 14 Apr 2024 17:28:04 +1000 (AEST) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0AE1B6091C; Sun, 14 Apr 2024 07:28:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 759F8C072AA; Sun, 14 Apr 2024 07:27:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713079682; bh=7UcAoz/SHZJ9dQ0bgxdPwC8jDXsqkfxw4nZlv0SLw5o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mSn3bFITK7eYlJdTFbScch0ThBeU+CtfVZynIF2TKYAjwpfIWpT9mvprRtl/vRdi+ PWs0IudDlFW6Beno7xjDAiW1ip7pL/FGhEaTkCamfUxQ5eDkHTs4QkNm97zhVJccwv UxX9+hkJgUV7GSohwVI620vdp0JYtwTWKKysZvcjBk9t6kUNPFg5Eeatgn84u8vivs 7On6vy8KLlD97z5wp8DI0bLXFhxIaSTkHjS//iWFuOPg7CQ+rJyeDYDISTJa6W6AFc TXNbcHaOhhepqyuh8BUKoPaV89wZMsoGzWH9gtBjUYYSDb1AqF+wsfY3ZeQjYF2dQ5 tmillpYns8epg== Date: Sun, 14 Apr 2024 10:26:47 +0300 From: Mike Rapoport To: Sam Ravnborg Subject: Re: [PATCH v4 06/15] mm/execmem, arch: convert simple overrides of module_alloc to execmem Message-ID: References: <20240411160051.2093261-1-rppt@kernel.org> <20240411160051.2093261-7-rppt@kernel.org> <20240411205346.GA66667@ravnborg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240411205346.GA66667@ravnborg.org> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , x86@kernel.org, Catalin Marinas , linux-mips@vger.kernel.org, Song Liu , Donald Dutile , Luis Chamberlain , sparclinux@vger.kernel.org, linux-riscv@lists.infradead.org, Nadav Amit , linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, Helge Deller , Huacai Chen , Russell King , linux-trace-kernel@vger.kernel.org, Alexandre Ghiti , Will Deacon , Heiko Carstens , Steven Rostedt , loongarch@lists.linux.dev, Thomas Gleixner , bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Thomas Bogendoerfer , linux-parisc@vger.kernel.org, Puranjay Mohan , linux-mm@kvack.org, netdev@vger.kernel.org, Kent Overstreet , linux-kernel@vger.kernel.org, Dinh Nguyen , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Eric Chanudet , Palmer Dabbelt , Andrew Morton , Rick Edgecombe , linuxppc-dev@lists.ozlabs.org, "David S. Miller" , linux-modules@vger.kernel.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Thu, Apr 11, 2024 at 10:53:46PM +0200, Sam Ravnborg wrote: > Hi Mike. > > On Thu, Apr 11, 2024 at 07:00:42PM +0300, Mike Rapoport wrote: > > From: "Mike Rapoport (IBM)" > > > > Several architectures override module_alloc() only to define address > > range for code allocations different than VMALLOC address space. > > > > Provide a generic implementation in execmem that uses the parameters for > > address space ranges, required alignment and page protections provided > > by architectures. > > > > The architectures must fill execmem_info structure and implement > > execmem_arch_setup() that returns a pointer to that structure. This way the > > execmem initialization won't be called from every architecture, but rather > > from a central place, namely a core_initcall() in execmem. > > > > The execmem provides execmem_alloc() API that wraps __vmalloc_node_range() > > with the parameters defined by the architectures. If an architecture does > > not implement execmem_arch_setup(), execmem_alloc() will fall back to > > module_alloc(). > > > > Signed-off-by: Mike Rapoport (IBM) > > --- > > This code snippet could be more readable ... > > diff --git a/arch/sparc/kernel/module.c b/arch/sparc/kernel/module.c > > index 66c45a2764bc..b70047f944cc 100644 > > --- a/arch/sparc/kernel/module.c > > +++ b/arch/sparc/kernel/module.c > > @@ -14,6 +14,7 @@ > > #include > > #include > > #include > > +#include > > > > #include > > #include > > @@ -21,34 +22,26 @@ > > > > #include "entry.h" > > > > +static struct execmem_info execmem_info __ro_after_init = { > > + .ranges = { > > + [EXECMEM_DEFAULT] = { > > #ifdef CONFIG_SPARC64 > > - > > -#include > > - > > -static void *module_map(unsigned long size) > > -{ > > - if (PAGE_ALIGN(size) > MODULES_LEN) > > - return NULL; > > - return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, > > - GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE, > > - __builtin_return_address(0)); > > -} > > + .start = MODULES_VADDR, > > + .end = MODULES_END, > > #else > > -static void *module_map(unsigned long size) > > + .start = VMALLOC_START, > > + .end = VMALLOC_END, > > +#endif > > + .alignment = 1, > > + }, > > + }, > > +}; > > + > > +struct execmem_info __init *execmem_arch_setup(void) > > { > > - return vmalloc(size); > > -} > > -#endif /* CONFIG_SPARC64 */ > > - > > -void *module_alloc(unsigned long size) > > -{ > > - void *ret; > > - > > - ret = module_map(size); > > - if (ret) > > - memset(ret, 0, size); > > + execmem_info.ranges[EXECMEM_DEFAULT].pgprot = PAGE_KERNEL; > > > > - return ret; > > + return &execmem_info; > > } > > > > /* Make generic code ignore STT_REGISTER dummy undefined symbols. */ > > ... if the following was added: > > diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h > index 9e85d57ac3f2..62bcafe38b1f 100644 > --- a/arch/sparc/include/asm/pgtable_32.h > +++ b/arch/sparc/include/asm/pgtable_32.h > @@ -432,6 +432,8 @@ static inline int io_remap_pfn_range(struct vm_area_struct *vma, > > #define VMALLOC_START _AC(0xfe600000,UL) > #define VMALLOC_END _AC(0xffc00000,UL) > +#define MODULES_VADDR VMALLOC_START > +#define MODULES_END VMALLOC_END > > > Then the #ifdef CONFIG_SPARC64 could be dropped and the code would be > the same for 32 and 64 bits. Yeah, the #ifdef there can be dropped even regardless of execmem. I'll add a patch for that. > Just a drive-by comment. > > Sam > -- Sincerely yours, Mike.