From patchwork Mon Sep 18 07:29:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13388974 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 B1D5CCD37B0 for ; Mon, 18 Sep 2023 07:31:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 431AF6B0281; Mon, 18 Sep 2023 03:31:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BADB6B0283; Mon, 18 Sep 2023 03:31:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 234F76B0284; Mon, 18 Sep 2023 03:31:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0E8716B0281 for ; Mon, 18 Sep 2023 03:31:07 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D5A101CA7F0 for ; Mon, 18 Sep 2023 07:31:06 +0000 (UTC) X-FDA: 81248896932.06.F566075 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id 2824B8002A for ; Mon, 18 Sep 2023 07:31:04 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ojfgNgsu; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf30.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695022265; 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=D67hK1WK/glEPsWwRha4zs/WTd3TgpZNhVD7Yn+lGNM=; b=u76w6QBEGmwX0lK2IG0P1p0o0uSGDagFmNEsI0QKbWcl4+MPiTV4M+pggbU0mUk+dw39xC XgnOSndRcLfmq9wIoWKnzxQiuhKJNNqBBvErEDlmB+cCSml9v8ajy39mmH7Gv/yi3iMTNv lS8OnLcqnTyTq4FPSvROgdVeIfdMS1g= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ojfgNgsu; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf30.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695022265; a=rsa-sha256; cv=none; b=MMahGRyqBqE+LBGbjR6RMFPhG4DHLdWPERxoKhNxkkso1sGdZxEpVBSMPRRx8K8qgwO8cU 9z58dKbsXJOk0InwyisS7aS22ZLWpeBGzBNvfWLbDQHXv3jRPW3JGyNzWRS/aJoW/CzjS8 kaCXh57JTGpYzHWHkSMOl8XOe1etxxA= 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 44E2A60E15; Mon, 18 Sep 2023 07:31:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68ED7C433C8; Mon, 18 Sep 2023 07:30:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695022263; bh=mbiiTE+Ax/Si/BZxcJVEdVXi15nThNmQlUqiyILb0zo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ojfgNgsup07S+iaZErkHdPn6pFXvUxpfd0rqcJ0g/fFjdgDTdp5RCwZChtRwqs+hU 358zdLhiRZXyw3aIFuKwPq3ciyzug59B+euqQg31hDJF2IYAsE+6D264chrRpy0JCv lIJDaEg0ezBhP+IOLDXi95uXUolbh37QjiMgyCp6vToq0/niAQX3TSUJ4+A3chXFuR Fz6pQnaNxbhFzVVMJL+/JI6h0Va38Wr9Y8Zzq0rWzkuGOl0+j0c7QpIR3g6g0WJ4vh Na6tomyrzTQLlYxetqXYeBzvBjSJ3J7TMO8PQeFVdg4iyOutejtYTgrDjMGzC7l/J1 0uZomhqve3rWw== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBl?= =?utf-8?b?bA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Luis Chamberlain , Mark Rutland , Michael Ellerman , Mike Rapoport , Nadav Amit , "Naveen N. Rao" , Palmer Dabbelt , Puranjay Mohan , Rick Edgecombe , Russell King , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , 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 v3 05/13] modules, execmem: drop module_alloc Date: Mon, 18 Sep 2023 10:29:47 +0300 Message-Id: <20230918072955.2507221-6-rppt@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918072955.2507221-1-rppt@kernel.org> References: <20230918072955.2507221-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 2824B8002A X-Stat-Signature: 8cdza1m3jrm3xb3qoi6e3fjha849zauf X-Rspam-User: X-HE-Tag: 1695022264-667032 X-HE-Meta: U2FsdGVkX1+vxaAmgjAUc/ake5ryVirAUWdXf2s7Nlhan6Vv8veH71MSCxaYJorKWyoPnFacxogiZGGyYF9LsC52FJ+yTRmnGfRyvKmVm16bzVk9UxkvJkDeqNH4Y5CyQ11usdtnp9ZLBV+CiSyZNrBeUhaS/maqmP8HA9IBMZPsz6py0K9Vx2XNSqDyDG3etotxqEUacQKpvPmo5aioHbl16hhdLBTu8JsLG1RydGgQSEOb6i6zMr/pFAPKEUh5Omnl21h8jCXMgfMCIxmnWI3gVRpQaN87Sd1xRY3KuRhRf62hiX8ZvG+Mxo66fA2hsmn2BkWDpcaFx2Ym+ECUfIblx+Z14t0g2OuRGCIMU1NkWPgqjb2vaNGB0Ja8hrrdPHrKk9iHhyg0PT0LnFBs0S0lIBNH6Xbyixh0c7vEFIFmB1XZx1rSUtYrtbT1f6IEQcmGafEy/bpwpNoyxCkgbj5d1ka+n64IBBHVU1lM1eXzDZvyc9akzS+OKEpd6R1Z1LS9cE/tFYXvb7gHNoEYGerRbXeTGDtNDeFTnKAXmL3rp5gpnbTPu8vgTp/c+aQts7kAtE4YcZD4O9chCASv3Fp27XfbzUNTxV2VuGpwC2JKM/66J43SY1+49rgJHq96pwVu2489JqBMJ/OF6wUHq+Js4025x3nsC5KIrDTQo8ctKIKW1JIh2FN+SirRH1vQuNtvDw3hba0Qcr6jLaoNmTYbyjNKlNcNK0HAI9feVhPx8B430tIM73VzmqDuDuDowrUtZBjC0XsLbdDnjWwpIEqysPDtyx4uvC0Kl9dpiyGLO74xMudm+O8wvhoGJXeSLwku4+DUTLsiZGI9jiLrO9GrIgGz3AQnhXykJzYF43q/+eUszj0lF+MeuE6Re2rfn9Rd6qK/r+9W5+acWBjsUt9P/mvvT1HQnNWUENwbUOegpRLb4BRYbGg3U/BTvYcbRGDA4gHzWsOHoF52gfe eRtmZMrm jYVC/OtP/4Li5cMfNq40ki8xUYzy/gdCc17lNefO0jjTyAIIq8XeUuKQ+OqzzExtpVsEMA8sOpkU2jupOYzNMEAi3kw7mbvIdaHr0+x+scYh3uWe1MurAHf5QNy12H03Tv+1RgMT/GPdqjng1CnQktE0Hh3+AeNmJoT0oPtsFnYe5c4hiH3UTGZEMSbGpN3Fntf5lg272ZAZAmtQJrvO0xshgNCCeFexoao8pTKjZ/l65abLzmnP0kPLSeAc7x3Gld1YLxCapjhQwMhNA7OtOqZSaVXWtsZ2Ys/Spc6s+saTevLh2M9Y7YNWtsM0JPWarKa+du0szRAL47EHQ0Ngb3nXIf/h8PmmA7EAf0ak7FMKDwJBhZplzF9Vqyb59Eb8soamwkIXPagG4RAy6/t631jbJXv7xRZ/Lk72BJelPaKJIgJNsrImpL3U8xPLQRmY0HS6QCy6DN1C30CA= 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: "Mike Rapoport (IBM)" Define default parameters for address range for code allocations using the current values in module_alloc() and make execmem_text_alloc() use these defaults when an architecture does not supply its specific parameters. With this, execmem_text_alloc() implements memory allocation in a way compatible with module_alloc() and can be used as a replacement for module_alloc(). Signed-off-by: Mike Rapoport (IBM) --- include/linux/execmem.h | 8 ++++++++ include/linux/moduleloader.h | 12 ------------ kernel/module/main.c | 7 ------- mm/execmem.c | 12 ++++++++---- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/include/linux/execmem.h b/include/linux/execmem.h index 806ad1a0088d..519bdfdca595 100644 --- a/include/linux/execmem.h +++ b/include/linux/execmem.h @@ -4,6 +4,14 @@ #include +#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ + !defined(CONFIG_KASAN_VMALLOC) +#include +#define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT) +#else +#define MODULE_ALIGN PAGE_SIZE +#endif + /** * enum execmem_type - types of executable memory ranges * diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h index a23718aa2f4d..8c81f389117d 100644 --- a/include/linux/moduleloader.h +++ b/include/linux/moduleloader.h @@ -25,10 +25,6 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, /* Additional bytes needed by arch in front of individual sections */ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section); -/* Allocator used for allocating struct module, core sections and init - sections. Returns NULL on failure. */ -void *module_alloc(unsigned long size); - /* Determines if the section name is an init section (that is only used during * module loading). */ @@ -118,12 +114,4 @@ void module_arch_cleanup(struct module *mod); /* Any cleanup before freeing mod->module_init */ void module_arch_freeing_init(struct module *mod); -#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ - !defined(CONFIG_KASAN_VMALLOC) -#include -#define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT) -#else -#define MODULE_ALIGN PAGE_SIZE -#endif - #endif diff --git a/kernel/module/main.c b/kernel/module/main.c index 4ec982cc943c..c4146bfcd0a7 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -1601,13 +1601,6 @@ static void free_modinfo(struct module *mod) } } -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)); -} - bool __weak module_init_section(const char *name) { return strstarts(name, ".init"); diff --git a/mm/execmem.c b/mm/execmem.c index a8c2f44d0133..abcbd07e05ac 100644 --- a/mm/execmem.c +++ b/mm/execmem.c @@ -55,9 +55,6 @@ static void *execmem_alloc(size_t size, struct execmem_range *range) void *execmem_text_alloc(enum execmem_type type, size_t size) { - if (!execmem_params.ranges[type].start) - return module_alloc(size); - return execmem_alloc(size, &execmem_params.ranges[type]); } @@ -111,8 +108,15 @@ void __init execmem_init(void) { struct execmem_params *p = execmem_arch_params(); - if (!p) + if (!p) { + p = &execmem_params; + p->ranges[EXECMEM_DEFAULT].start = VMALLOC_START; + p->ranges[EXECMEM_DEFAULT].end = VMALLOC_END; + p->ranges[EXECMEM_DEFAULT].pgprot = PAGE_KERNEL_EXEC; + p->ranges[EXECMEM_DEFAULT].alignment = 1; + return; + } if (!execmem_validate_params(p)) return;