Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6081898rwr; Tue, 9 May 2023 09:59:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4EI6JV0HojN4853Dgsz5G1XjuCgVkpR2oZGQ6lqw/H4FvsDzLIX176hXTfccJcCa4X2rsL X-Received: by 2002:a05:6a00:1409:b0:643:8d7:7bda with SMTP id l9-20020a056a00140900b0064308d77bdamr21113320pfu.21.1683651587743; Tue, 09 May 2023 09:59:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683651587; cv=none; d=google.com; s=arc-20160816; b=QS2nhRJKyxwrJRyJ55fqwFeh3smqnFdTzwpDpAKd7Euc4rj5ThU4BRs8Ldr6A2Qdq+ fIWgLEUrV7Uee3ccgnlarN9P+BFmax26qryH7VkHBFVvYa/eG+n8qpx6Hs08zlM0o56x LbcPyN5gUJhYOzyFeYT/3YSwZNJk3PiMJGJgi/7IUhv3guIsiz/vs4XM4/YCW5s9ShJC oY5LnXbQ915w1AgPGky1skzv78bOLxjXNxxp3HN7ubcYtVW/xioxNBcfI0rqw72OxQT1 pWH8UcMQljISDmD53T9gkL+i4gpwOXRpimSyfnON4IhyNVIVyF6fWilc46vDjHyATW44 AsVw== 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=SY6fXe4pdNkKgId+Z2KcjRoSaHIjUmN9p3hLtNQFQOM=; b=p13RtM2RMcXsrQZB7XvxBMceopg6qUCSkx+8h3SUbAxl91QOBhpwMSVojK+Ca7kPQ+ 6VAfynKUzvYNajl3WA/3c/+rjTBZWc3q4zNZygD+ipcoUouvdEX5QUadB6yBCWTtlrR/ r5z2n3E0B4WVOmK7ySPU58qdbX4vGTULw/rDTeQ1KOWV+WwNY3J18ugqK9KyK0TakpY3 9cK7fYElH75qwFfx7keoVPGLSfwYFj/maKTZBGtYL+nmYMLa+QklVZQ2A0e7XhyqL4Nt 0MtZsXSMCcvbHcpvBewzXgCpNYVzHErRAZIGyZo6tbreiEs9a7BqlhAnrIIUpMXXHt8E 9SYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=E343AoWg; 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=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n20-20020a637214000000b005131739af72si1899812pgc.755.2023.05.09.09.59.35; Tue, 09 May 2023 09:59:47 -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=@linux.dev header.s=key1 header.b=E343AoWg; 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=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234951AbjEIQ6H (ORCPT + 99 others); Tue, 9 May 2023 12:58:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234880AbjEIQ5a (ORCPT ); Tue, 9 May 2023 12:57:30 -0400 Received: from out-8.mta1.migadu.com (out-8.mta1.migadu.com [IPv6:2001:41d0:203:375::8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 131F64C0E for ; Tue, 9 May 2023 09:57:18 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1683651436; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SY6fXe4pdNkKgId+Z2KcjRoSaHIjUmN9p3hLtNQFQOM=; b=E343AoWginlmYA0XNC7JmuE92IbwRHmxwqnCWVBaeQu8jZ05EtSZ5jzp35SoalYgdAyVi2 mGxFIQ5f5mTuLhPjrCK1pmI755V80kOd3XnWhwPE3Gk3/WusCJYaQLjuq0KStuhsVRV+f0 42/iLxS5+Ar2E2XYNjjpc2Zygm9+MFY= From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-bcachefs@vger.kernel.org Cc: Kent Overstreet , Kent Overstreet , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , linux-mm@kvack.org Subject: [PATCH 07/32] mm: Bring back vmalloc_exec Date: Tue, 9 May 2023 12:56:32 -0400 Message-Id: <20230509165657.1735798-8-kent.overstreet@linux.dev> In-Reply-To: <20230509165657.1735798-1-kent.overstreet@linux.dev> References: <20230509165657.1735798-1-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 From: Kent Overstreet This is needed for bcachefs, which dynamically generates per-btree node unpack functions. 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