Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6110052rwd; Mon, 19 Jun 2023 02:24:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4oC6vR2K6pLdsF0aDCqMBjNu4FIkGvAGmtQm4VLaVsM+RRilVzcL2hliRziVeeElNhlS6n X-Received: by 2002:a17:903:2593:b0:1b3:e90b:93e1 with SMTP id jb19-20020a170903259300b001b3e90b93e1mr10030814plb.36.1687166698169; Mon, 19 Jun 2023 02:24:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687166698; cv=none; d=google.com; s=arc-20160816; b=XZy7szjvllbRGH+6GYnkIFdhyeqJuUpxB5bzsQv1BB5mjZ4MmCPw5iUYLUQS2y8fXb 52giHJ2woI9Dq3yEtzhC9VhrFOGqoibUpvn9/iLEccQZiFPfMvLB/G9obdmwcKmf3qXP KhU+LKqRcsCTvsiLfmLQY5mmf0eiv3kprfnjFQW/KtCRSv4jMYKmS4rd6anzFstN+U8S 7VOj9AQAXTtxfkgox/hfAgPiWT7jJtI9GGUGzRBx8Lk1x59E/ZkSZSqLJcGSWJa+B9eT OvBBU5nFI95vcSkeeF/iAtGrrZqFD38K87X0MazKeKoBZ005Notxg6FD1hGnurj3zh4+ L45g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=dRCO0t2N2FpSJZyw9v3UZz248rKf5deSA5g97VI74o8=; b=fXL+WHpaINtTf9eenLvZvo5cttM4DxI/k/BmBRw3OmyZNsG1PB3ZP0M2Vu07uaXQ02 s1NumiX6HLhKaBwC8DnPo9pwfmQl4a7uxXuq/1zn0cAhPslECwOplPJKRkJ9TmMooJer DL1b+pxrlwh+HLXwehqulgzKsW/2bD/M7nn/hiX+8D9toqlnr9wLwGQ+uJjjPSaYdUlf SsRTl+TgN3316LvEQdPxzC40qTT4aMQly73aOwaTbWR8mU0jIsgPtDnRG/D84dqag8vW mfRxj0qC+eBn1nemOl1c9qvIwHQewQFFtN8NEQt25r+9wGeep77ZI684IuaKllLtI3lD q18A== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a14-20020a170902ecce00b001b3cd3e0533si7905269plh.607.2023.06.19.02.24.44; Mon, 19 Jun 2023 02:24:58 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230151AbjFSJTK (ORCPT + 99 others); Mon, 19 Jun 2023 05:19:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229618AbjFSJTH (ORCPT ); Mon, 19 Jun 2023 05:19:07 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 92DBA83; Mon, 19 Jun 2023 02:19:05 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 279F612FC; Mon, 19 Jun 2023 02:19:49 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.28.22]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8B0053F64C; Mon, 19 Jun 2023 02:19:03 -0700 (PDT) Date: Mon, 19 Jun 2023 10:19:00 +0100 From: Mark Rutland To: Kent Overstreet Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-bcachefs@vger.kernel.org, Kent Overstreet , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , linux-mm@kvack.org, Kees Cook , Andy Lutomirski Subject: Re: [PATCH 07/32] mm: Bring back vmalloc_exec Message-ID: References: <20230509165657.1735798-1-kent.overstreet@linux.dev> <20230509165657.1735798-8-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230509165657.1735798-8-kent.overstreet@linux.dev> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,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: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 09, 2023 at 12:56:32PM -0400, Kent Overstreet wrote: > From: Kent Overstreet > > This is needed for bcachefs, which dynamically generates per-btree node > unpack functions. Much like Kees and Andy, I have concerns with adding new code generators to the kernel. Even ignoring the actual code generation, there are a bunch of subtle ordering/maintenance/synchronization concerns across architectures, and we already have a fair amount of pain with the existing cases. Can you share more detail on how you want to use this? From a quick scan of your gitweb for the bcachefs-for-upstream branch I couldn't spot the relevant patches. Thanks, Mark. > > Signed-off-by: Kent Overstreet > Cc: Andrew Morton > Cc: Uladzislau Rezki > Cc: Christoph Hellwig > Cc: linux-mm@kvack.org > --- > include/linux/vmalloc.h | 1 + > kernel/module/main.c | 4 +--- > mm/nommu.c | 18 ++++++++++++++++++ > mm/vmalloc.c | 21 +++++++++++++++++++++ > 4 files changed, 41 insertions(+), 3 deletions(-) > > diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h > index 69250efa03..ff147fe115 100644 > --- a/include/linux/vmalloc.h > +++ b/include/linux/vmalloc.h > @@ -145,6 +145,7 @@ extern void *vzalloc(unsigned long size) __alloc_size(1); > extern void *vmalloc_user(unsigned long size) __alloc_size(1); > extern void *vmalloc_node(unsigned long size, int node) __alloc_size(1); > extern void *vzalloc_node(unsigned long size, int node) __alloc_size(1); > +extern void *vmalloc_exec(unsigned long size, gfp_t gfp_mask) __alloc_size(1); > extern void *vmalloc_32(unsigned long size) __alloc_size(1); > extern void *vmalloc_32_user(unsigned long size) __alloc_size(1); > extern void *__vmalloc(unsigned long size, gfp_t gfp_mask) __alloc_size(1); > diff --git a/kernel/module/main.c b/kernel/module/main.c > index d3be89de70..9eaa89e84c 100644 > --- a/kernel/module/main.c > +++ b/kernel/module/main.c > @@ -1607,9 +1607,7 @@ static void dynamic_debug_remove(struct module *mod, struct _ddebug_info *dyndbg > > void * __weak module_alloc(unsigned long size) > { > - return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END, > - GFP_KERNEL, PAGE_KERNEL_EXEC, VM_FLUSH_RESET_PERMS, > - NUMA_NO_NODE, __builtin_return_address(0)); > + return vmalloc_exec(size, GFP_KERNEL); > } > > bool __weak module_init_section(const char *name) > diff --git a/mm/nommu.c b/mm/nommu.c > index 57ba243c6a..8d9ab19e39 100644 > --- a/mm/nommu.c > +++ b/mm/nommu.c > @@ -280,6 +280,24 @@ void *vzalloc_node(unsigned long size, int node) > } > EXPORT_SYMBOL(vzalloc_node); > > +/** > + * vmalloc_exec - allocate virtually contiguous, executable memory > + * @size: allocation size > + * > + * Kernel-internal function to allocate enough pages to cover @size > + * the page level allocator and map them into contiguous and > + * executable kernel virtual space. > + * > + * For tight control over page level allocator and protection flags > + * use __vmalloc() instead. > + */ > + > +void *vmalloc_exec(unsigned long size, gfp_t gfp_mask) > +{ > + return __vmalloc(size, gfp_mask); > +} > +EXPORT_SYMBOL_GPL(vmalloc_exec); > + > /** > * vmalloc_32 - allocate virtually contiguous memory (32bit addressable) > * @size: allocation size > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index 31ff782d36..2ebb9ea7f0 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -3401,6 +3401,27 @@ void *vzalloc_node(unsigned long size, int node) > } > EXPORT_SYMBOL(vzalloc_node); > > +/** > + * vmalloc_exec - allocate virtually contiguous, executable memory > + * @size: allocation size > + * > + * Kernel-internal function to allocate enough pages to cover @size > + * the page level allocator and map them into contiguous and > + * executable kernel virtual space. > + * > + * For tight control over page level allocator and protection flags > + * use __vmalloc() instead. > + * > + * Return: pointer to the allocated memory or %NULL on error > + */ > +void *vmalloc_exec(unsigned long size, gfp_t gfp_mask) > +{ > + return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END, > + gfp_mask, PAGE_KERNEL_EXEC, VM_FLUSH_RESET_PERMS, > + NUMA_NO_NODE, __builtin_return_address(0)); > +} > +EXPORT_SYMBOL_GPL(vmalloc_exec); > + > #if defined(CONFIG_64BIT) && defined(CONFIG_ZONE_DMA32) > #define GFP_VMALLOC32 (GFP_DMA32 | GFP_KERNEL) > #elif defined(CONFIG_64BIT) && defined(CONFIG_ZONE_DMA) > -- > 2.40.1 > >