From patchwork Tue May 9 16:56:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 13235992 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C96CBC7EE2D for ; Tue, 9 May 2023 16:57:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1BA886B0075; Tue, 9 May 2023 12:57:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 16B076B0078; Tue, 9 May 2023 12:57:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05A0A6B007B; Tue, 9 May 2023 12:57:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E7D5B6B0075 for ; Tue, 9 May 2023 12:57:21 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 803FF1403DB for ; Tue, 9 May 2023 16:57:21 +0000 (UTC) X-FDA: 80771322282.03.7C91939 Received: from out-16.mta1.migadu.com (out-16.mta1.migadu.com [95.215.58.16]) by imf17.hostedemail.com (Postfix) with ESMTP id 6C5E640016 for ; Tue, 9 May 2023 16:57:18 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=E343AoWg; spf=pass (imf17.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.16 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1683651438; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SY6fXe4pdNkKgId+Z2KcjRoSaHIjUmN9p3hLtNQFQOM=; b=c40qCGhZ7uH0BZuGF73AoHX6mzRlSxWoPbsppGs1FbSM04WFXq+r2owNkQZwBafxGHuv70 mZCmhIHK3EPE7/Bmm+Mpao8ZmV7o/RqzGVXQXDmqayL3IN/iEwcWVhn6B3D/K0bvj1cQMG fAz+97/+yKGQ9TkUm3FqZxKoLA5JQ5Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1683651438; a=rsa-sha256; cv=none; b=dIC2B3SGcRfO1A1aFYxy/wTjXgnJZDMj7Jv0MWWSa4PK7si8rCz5a2UAnN4pOfbzT8SdL0 Mvt+ucmFLJfbyTW7aXc3kWqQxBHAHRB99T4fQx2cdyzIcPjXFAKt1EfycF26SWRX5xz9FJ 5NJpCZxXXh+HDU8Ab/Wvi3bByVIYDPk= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=E343AoWg; spf=pass (imf17.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.16 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev 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 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 6C5E640016 X-Stat-Signature: 9iekuo35twkdo3ed9xbuwxyh4wzdw63b X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1683651438-330518 X-HE-Meta: U2FsdGVkX18zotW5KQjb2BpHP+xAWYhTlU3ZFvI5Q9toOzRoVG0hwRK5caBPG6Df5MFRSU5NeANRpRFafouN7OYjsJHAE/9DhQqhy2p6fBpsLgGq+wtDxGYdlab1rBfFRExBIwZBKv9liRrtYvI4vfKkZiiJGY+FYm/VZLpAGnthAgWNhNsCkatcTmQYgYZjxClNqkt9CbQOkMZK7cL7JoekydmGsEfej1ZAc97dty7BrDFRAz5+iVCVJ/omh002oUynlCE7JhuM4OSNwu5EfdunwwSbeRObSkhxknb2kqgX3ToUSj+RsbjjMEhUAyb3IcOL/tbLzBaXuDYXZI+S1+oPK4KCSVOvdnjs9TvFqQNcYAOpfV0T6n7bF27myRrsHA3tm33EyGoGQKG29sKEnLIXx7zlkDN5VYKQ1FMqU8Y8cAtErorcCAM6foZ/NF1zfThL+COmFk8uzk6LraFS/lxK5VdQoZbuIg2G48NDFFp4LK/mbjWGgkMm+YIQF6FT3Vn1Cx4H//75O1aIxKh+n25v0hw6yAEmLKc0H9+/cS5hLf1+L40dHkO0oBz6Xsiou8p0b6J6tZUhDu4CU7sIZmN0etwkVsuI1i16zeUZZua881D+brfRDa1uo0zoKc+hn4/sEytYkWr1uT0jOygXFFiCDF5ZB16PzXFFBQcn2HE2clF54BHnCln8W4U8p4KkmpnxLRo/zwwHxiZDA2OrjbbtkM/s0gq7gqumc7JdVkoFcMtMZtEr862fvBg3RHpRy8xL47FNhn1MfXH3CtkjtG2pphvrYIMVFXb0pYygoJnMnXvTE6s/qdLG0/7D3XaYPvQpT0fPXAz5DwFLtPlQnpaZoz8K74Rb05ONWfApSqsFk6bCpKYBdXmEty6EaC6X9LLIu7luMX8dd4taLOeQqts+DzpJQxX3dzWTRXS/a9MYUq1QPbPJiRetw82k7EZ8vOVsm1qq4EEOetStahe 1qVvs7NY ddF5cKaIbdBBfInrY7um30BuJ0CY0tVDPECUooc0g2RxPUIzKrTi1waOTuqO0vqvpZaDLrMkK79Mh3iKmX3y2KIy7bPDj+noG6bQVlW5zo2r52zbyWo13Wfl48kYG2eNiZpS1AZ4BLDDSv+AWOcfzo+fHPP9//6mPa+ECykfhC4VWjj7At9joWNi9jm3BdBTxSMEHNpnPc81lkrPVlD/DlPuEPko9PHmAfMkBuDz5+BxT50zGybEs/EoPW6hkdmG153eRAgLtxVw5CFgmVHJwSWphU8L9w++ncxJzzLAQcgSVAU9yOLp2hh/toSiEst4ihB0fFdX4SU99xkznoQBeau0JE1m/iPyYW/cnwlpJLfD2XkLxCrtMTKIQSqN0IBdS6rTJabcHaFyyCJM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Acked-by: Lorenzo Stoakes Nacked-by: Lorenzo Stoakes Signed-off-by: Kent Overstreet Nacked-by: Andy Lutomirski # for x86 --- 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)