From patchwork Fri Jun 16 08:50:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13282250 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 9EC1AEB64DA for ; Fri, 16 Jun 2023 08:51:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43CD06B0075; Fri, 16 Jun 2023 04:51:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C3368E0001; Fri, 16 Jun 2023 04:51:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2651D6B0080; Fri, 16 Jun 2023 04:51:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 13B2D6B0075 for ; Fri, 16 Jun 2023 04:51:51 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D3A6CC0B2D for ; Fri, 16 Jun 2023 08:51:50 +0000 (UTC) X-FDA: 80907993180.27.F332818 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf20.hostedemail.com (Postfix) with ESMTP id 0D4821C001F for ; Fri, 16 Jun 2023 08:51:48 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YZTtvWhb; spf=pass (imf20.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686905509; a=rsa-sha256; cv=none; b=hUFsfipF+mtn7+ZWIXOASFx4aD9A1GQrGgzb9LwzKlh+vb/BEDCC55Om3uqnkH6cdgdAJo 5wc7oRAKRmN8VWzCdu4FU2jQeMMquQL2PNS7JDoXIVbiijimWR1OtrL8oP+kZsXqk1d/oU JTvDMjkZJBPxPF5GrCMrNEcMf96vceA= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YZTtvWhb; spf=pass (imf20.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686905509; 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=1+X/wLrqa0k/PTb6X1vDO2TMZO595dDD2xmuNqovnIU=; b=CaO0BlBPIczZ4PMpsB1Bb83IjEGmJnpSiY++xeoG2TtP3JHqmJQkLQJTeNJwSHfaCp9S+g e9qtgt1wRSq+1f9WpJPGpbIftwxd/enfskEwAqdF0MPL9qTsKMHkYJHkti/6Pq22KP/u91 z7lrLGBOqeyCsfqlnoea25KKgQYNkmo= 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 377A16313B; Fri, 16 Jun 2023 08:51:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B963C433C9; Fri, 16 Jun 2023 08:51:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686905508; bh=+07oFke3TwadZ0sZEEllL+tiiID3wwgy+CrUkcKlMys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YZTtvWhbmreCzC2jgCquzt+akv8T+7MJ+bE0l+X2tLA+SnHISSyAy2Tvsr5WGGhE9 PuxrPjU24hrqUElx9XIEe9OyVQwg8nfQOaWtcLSYFmDhH2hsz+RrgGpGDBvno1MJtS 2dr6uCCG1OnS/I52oIBnBqiFHwI2oUJTpHL6w/UriQdmHLxKHJQLhBNcM3/brxCTUA ACvH3XIoNfEusFqphqtAr2BDJawpGKGEbVMGV6vtFFym/zFgSP2FCRRnNSuK6n3h8a Eg2cl4gg22X2neXvj/JGEpds4aDGlaDuDSPceA7hFbFtWVJrgB3b1RFzCh5PamK893 93VQ7ENRp/0cg== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Andrew Morton , 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 v2 05/12] modules, execmem: drop module_alloc Date: Fri, 16 Jun 2023 11:50:31 +0300 Message-Id: <20230616085038.4121892-6-rppt@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230616085038.4121892-1-rppt@kernel.org> References: <20230616085038.4121892-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-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fJLCIU5Me8YKu4 jbdlv/Px sBDNSX8PHyTIMbjdY+cy73L/sv/vq6mwFW+gfytnUSuBTSh7MdHfvCbxUzqj5E1cvYhqP7wh14aEckUxjFUv++sm8A+aJbKcNIeG3TFhFIthaaH1KT+0tT6lBgtaAUo82Y//zm+etbM16fYs0OzCVK5OZxkmT7QS/7mbOCd3i005EIsQCu6o9yiM+4ctJHgyvwed69zNSYUVAPkYnZ+UtTbK5/yIaQ7pnEEsidsw5YIF7NcDaCpqLVuh17sd0JZmjsK+KmsiJtT1KJ9N6KsAcXx2JjKyL2FNvfvD7jJWTzI/j5j/Iztfx6Wd2lHp24mNVCcxXugqsgiRtZXSNNWFsvGcHWaxNTL85B97BUMPzkCR7U+bK9go4Ijy9v7VVhwIRfgQ5Du+muek7wjVqpT6cq3DXqEWdnPC/TBCHfa9G/x2vnFJCjCteCpuOJKLwB4nW9u7/X7P3oVLGaDM= 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 architecure 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) Acked-by: Song Liu --- 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 68b2bfc79993..b9a97fcdf3c5 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 + /** * struct execmem_range - definition of a memory range suitable for code and * related data allocations diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h index b3374342f7af..4321682fe849 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). */ @@ -113,12 +109,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 43810a3bdb81..b445c5ad863a 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -1600,13 +1600,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 2fe36dcc7bdf..a67acd75ffef 100644 --- a/mm/execmem.c +++ b/mm/execmem.c @@ -59,9 +59,6 @@ void *execmem_text_alloc(size_t size) unsigned long fallback_end = execmem_params.modules.text.fallback_end; bool kasan = execmem_params.modules.flags & EXECMEM_KASAN_SHADOW; - if (!execmem_params.modules.text.start) - return module_alloc(size); - return execmem_alloc(size, start, end, align, pgprot, fallback_start, fallback_end, kasan); } @@ -108,8 +105,15 @@ void __init execmem_init(void) { struct execmem_params *p = execmem_arch_params(); - if (!p) + if (!p) { + p = &execmem_params; + p->modules.text.start = VMALLOC_START; + p->modules.text.end = VMALLOC_END; + p->modules.text.pgprot = PAGE_KERNEL_EXEC; + p->modules.text.alignment = 1; + return; + } if (!execmem_validate_params(p)) return;