From patchwork Mon Sep 18 07:29:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13388970 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 22094CD37B0 for ; Mon, 18 Sep 2023 07:30:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9A1D6B0276; Mon, 18 Sep 2023 03:30:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A23356B0278; Mon, 18 Sep 2023 03:30:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89BD66B0279; Mon, 18 Sep 2023 03:30:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 713CD6B0276 for ; Mon, 18 Sep 2023 03:30:29 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4881116094B for ; Mon, 18 Sep 2023 07:30:29 +0000 (UTC) X-FDA: 81248895378.28.79C1FA9 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf02.hostedemail.com (Postfix) with ESMTP id A411D8001F for ; Mon, 18 Sep 2023 07:30:26 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=n1BsBmpf; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf02.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=1695022226; 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=IkPztNd7bnD91GoOX9u3X5sY7LI8HpPP33/j7zBq9yU=; b=Ynybp5qB/ZIp6S1eMwZ8VB3Y8D3TIO+Ls2kBlr33XJlhbZ0KW9FlKaNffccpLIXwwGIAp4 sI5F4u83UV9Tg2jyYJcJ/9llWIAfNyKSdhtQG5+HwFocUNODK8axJBEMo+hFgndi5JdKuU ufSAnlmFSmJ2QwQADVc8/G1x9YhsFkM= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=n1BsBmpf; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf02.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=1695022226; a=rsa-sha256; cv=none; b=u5KIkcyjp35dEENB/A1djvxRm0+y5f+D5jlaI9aV0BZ5cmqRwjiUeLEyCkHgb4Ybt6pQxM +ccWAgMnI7ZSEtyuJKZuPaIeKldLO2buPRoDVztdUo2RlKjEZFrVXaCGt/+c2wY/WD5zK/ UnNIx6GKH5b8oYGa1m48RZsF+Brp3Cw= 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 6C5CD60E15; Mon, 18 Sep 2023 07:30:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55C0EC43397; Mon, 18 Sep 2023 07:30:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695022224; bh=KSPIxmcvM6pw+gN3UxNfSb/hLNccmDr75av1M8zdRQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n1BsBmpfW3QKK3NJROVE3ZzVUFsmFfDjPKEBn27xuClR0kSquHorXzHaU80koKHjq oZZubDbrJshf2OzAsSW/lYZeiCxCVkNHUyRKf0J25B3oyQqT68RZdj7eYC/N0Cta3F s7s8WnXGl08TzUW7RJcoZTxms2v0q/MjRq68IGaI1IRBqPpLAZ6vaNChPkgshwIF5h 3KnstVmy4jP0LDvFd3KogmLI2XFZUpl0AY5gcnG4Aq2Zy+SxUhV393i/W7f5/3shGG k9UrFYiH9x7//wdEvOIFolwWa2pPRCHkauyGN/FXYwMai04Ht7kCMou6e5Iw71dZtp HuRwsr2VE4kwA== 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 01/13] nios2: define virtual address space for modules Date: Mon, 18 Sep 2023 10:29:43 +0300 Message-Id: <20230918072955.2507221-2-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-Queue-Id: A411D8001F X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 3qxex7hhjuj153f5c1y3pncnukb8gyim X-HE-Tag: 1695022226-671701 X-HE-Meta: U2FsdGVkX19RwcEfRuHa5RRKFUFTkimBmFRcIL4kIKRqskiynVo3gdhq5rdqbaaT3KwM5inRhF9RCTm4sASV21SdtkMT6ZNKVN/RwYG8Zdo+czgunDmp+LvjcThjjn/RmVFYVbOGvB4O+uAIQ9Z+IxOERR/HalNwnJGfgiFSTE4vnI7ScIi7wAdXOPvc+uaDya/hjwE73MEusLmaab265O2C0jBqlauFH9NgVOQ+jbsHfJrSR4Z4G6CfZQ7z3T9eipPP1/tOECE5nvhIIu3OM5KDxG1U3DU0L1h2eca/KNd/e5Mcc3FZHa8T5d96587z3ufvtf0YWzHdFEhwJUfFo5N8jb2awh3wR1ow6W43CqHGOaD9BRxxpHur3YtzBPUSPe66XFKPxWSYAnCXlmo45DJ5V37PxApimVO8FXp8dc6bDsFCLPPLOAlURY+Ug2FNLvCLvVuzIjAa4cUvte9F9mkGod4Q3Bkp8aFUEwt3qJr+Ny6A0aJT1ETNztJWzSv1t8c8JBAmjpCY4ZC/RN6SuaKJRddI4dqABvy7NQAMwYvQ8Gom50MkCANZQhOqGgwSGyFj5a8X/ZeG/56IvYFZFK4NzLDFPRpu6/xDw/Kv3bWojZSUtz3lzUr2UaTjEvslNSOpYATLEyjocD4n2tOgtdo2fjsutTwMFoNSc2WxJGHgjAbooFtvdkNPgnQvt9hYMKmvVFNDMAmAiV8SMo3m/yhJvT63ex04aQ7e/kYMpKotjtMFG7wHEbuGtHi7Jbp5ozO4CQ5mGbZROotxbOc/v9EqNYJUUzlQjBhW1+273ejxterSE24rI7F43jAA1s1aIDFqEfl3CzCOAYe9aOCamXQ1t+lphYCFy/y4prVBcHijySA3UI1RH1fXLmJRTuZNj3i/ejZm1y967UkEVTAcYS3iH/KSs6fTLpnGPhi7J2kMGymeKwEVKW0nWti9O9796pzK309PP04eoFOGMS9 XCtxx5JY ARqNH16DGeus4VmQsrYN0TMbQIZkzZ7rFczJBvCAACw9qN90L3ggaJB6kytwKpHECxf7RA2P9dSEeMjUKMVzlH6sJyFoQn28ofb6ar4R2edqteGBuN51E+JE9sBp76ecDDzwrrXDwMGnSxLrq8hHfu8QpfOj2QewxDn8y+YV9ute9AQJpX5MGsZjTr0XyzaBAygQbbwIBCMcHM1eG8DjbZ0eWxiIxYz2Hx7JikFttPU93ZzgyofNkDEOh+uOxe1HsJSugLJuHToar6O7OiQTccohpU/JERq8lrEV+8rGu7aJIQoKSlRPBBGJp8LyDlvlrPtQHMteCTYNMAJEN+PoMZLCu097fW89IZTVNTvLPEixbe01oLESAHiyz5iso7qsmjMiB83pX4D8bLK9ONFwnFga2JpDCUmX0hQu8PyH0Ye/XegdQqEwx3UYqO7c7kahQq9hL 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)" nios2 uses kmalloc() to implement module_alloc() because CALL26/PCREL26 cannot reach all of vmalloc address space. Define module space as 32MiB below the kernel base and switch nios2 to use vmalloc for module allocations. Suggested-by: Thomas Gleixner Acked-by: Dinh Nguyen Acked-by: Song Liu Signed-off-by: Mike Rapoport (IBM) --- arch/nios2/include/asm/pgtable.h | 5 ++++- arch/nios2/kernel/module.c | 19 ++++--------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/arch/nios2/include/asm/pgtable.h b/arch/nios2/include/asm/pgtable.h index 5144506dfa69..d2fb42fb6db8 100644 --- a/arch/nios2/include/asm/pgtable.h +++ b/arch/nios2/include/asm/pgtable.h @@ -25,7 +25,10 @@ #include #define VMALLOC_START CONFIG_NIOS2_KERNEL_MMU_REGION_BASE -#define VMALLOC_END (CONFIG_NIOS2_KERNEL_REGION_BASE - 1) +#define VMALLOC_END (CONFIG_NIOS2_KERNEL_REGION_BASE - SZ_32M - 1) + +#define MODULES_VADDR (CONFIG_NIOS2_KERNEL_REGION_BASE - SZ_32M) +#define MODULES_END (CONFIG_NIOS2_KERNEL_REGION_BASE - 1) struct mm_struct; diff --git a/arch/nios2/kernel/module.c b/arch/nios2/kernel/module.c index 76e0a42d6e36..9c97b7513853 100644 --- a/arch/nios2/kernel/module.c +++ b/arch/nios2/kernel/module.c @@ -21,23 +21,12 @@ #include -/* - * Modules should NOT be allocated with kmalloc for (obvious) reasons. - * But we do it for now to avoid relocation issues. CALL26/PCREL26 cannot reach - * from 0x80000000 (vmalloc area) to 0xc00000000 (kernel) (kmalloc returns - * addresses in 0xc0000000) - */ void *module_alloc(unsigned long size) { - if (size == 0) - return NULL; - return kmalloc(size, GFP_KERNEL); -} - -/* Free memory returned from module_alloc */ -void module_memfree(void *module_region) -{ - kfree(module_region); + return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, + GFP_KERNEL, PAGE_KERNEL_EXEC, + VM_FLUSH_RESET_PERMS, NUMA_NO_NODE, + __builtin_return_address(0)); } int apply_relocate_add(Elf32_Shdr *sechdrs, const char *strtab,