From patchwork Sun May 5 16:06:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654463 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 23D58C4345F for ; Sun, 5 May 2024 16:07:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 92B646B0083; Sun, 5 May 2024 12:07:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8DA356B0085; Sun, 5 May 2024 12:07:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A3006B0087; Sun, 5 May 2024 12:07:03 -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 5B07E6B0083 for ; Sun, 5 May 2024 12:07:03 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0B7421C08D5 for ; Sun, 5 May 2024 16:07:03 +0000 (UTC) X-FDA: 82084821126.25.4F2EC72 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf22.hostedemail.com (Postfix) with ESMTP id 69FE4C000C for ; Sun, 5 May 2024 16:07:01 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qq9xkaB6; spf=pass (imf22.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=1714925221; 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=xy/onuXdQ30KVEaYuNUZWEt3SxlLWflAgQY6tAjVj70=; b=nDbkNzp3m0bYKqTtVELM6gvcsVQpO9QWjvUPsonlYcvnNsdOCEtxsObrEZnwY2tv37im5L nZEOUkvR9XbGIL0ALXdHp2hIgX5NgKyWNbBOP1+bMcz4Ph4AX8c/x9rWJ9i0+nyP4pv3yh q6R7Fv/YML4R/i1o8xG8u2m5QB4+Sk4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qq9xkaB6; spf=pass (imf22.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=1714925221; a=rsa-sha256; cv=none; b=7f/m8WKJEa/LZjydIsxiAj/KYQvNnNVrfjVo2ArJYiguTSRscIIlKJkFkwtBJ87M4+6+Kv eUlDD73CSWAMDvxwJ3ds6YoYp4u2U3JG/rWtekTQV99H54Df+s948IWaoAipL/zf2DRRGw yHfHphG3g81P5caX071Sn/ikYX2Cqr8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 8666060C90; Sun, 5 May 2024 16:07:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F4F3C4DDE3; Sun, 5 May 2024 16:06:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925220; bh=M6QQiy27Yx7cZTOC0617KB9Ln6pKKwikPWIcgenY/bM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qq9xkaB6DJwbvT6OTP2sGk7b6G6bmDN5GyK5sBXSm32BVbedH8jHvu58xQEar8ba4 uKzUigAgbBAtsz8r5l3mt2L2za5eSKU/+BjQNHwkb8bkk1dSzjGw0MuhLVplgL5ZP8 9+4Xjjkzq/fb5aRZ15hEIYgAO+SLQ3ZdibwPKIo+aOqxO1Wde5HY2qBWwQ/K0irIeT ivaaNIlis9trjR8Xspz86sAH3Biv9Y1hr0lxZc08RADzGXQ7JtgHd1tAb126rA5WHB b8dLhnVtioffkmnpyWBCyjSpVlTprGY0DDKi7/kPoX4BYqxHmygNlAT6hSyOu4Q7Tl 8KyBh8i4EO9TA== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Liviu Dudau , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 RESEND v8 01/16] arm64: module: remove unneeded call to kasan_alloc_module_shadow() Date: Sun, 5 May 2024 19:06:13 +0300 Message-ID: <20240505160628.2323363-2-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 69FE4C000C X-Rspamd-Server: rspam06 X-Stat-Signature: rrheiqkpgz11pqzji4z8y4sejookk1a7 X-HE-Tag: 1714925221-107503 X-HE-Meta: U2FsdGVkX19kRCF6UWe6emthMvk0woRbKwW4gRmeatkNF6D0ujPRYZmE6jMpjI1P/ebCzM3wx0MTs9Kb33U5A8503DJz+pNBUqOVRDG05Os92h9+RjjsTPgnl7yECpRpvsucnfMm7oC9vrsXEZV62YC+is8AoTJGRtv/WAnxzz7b0TbgE5YDugG3JBAROxQN9bD1olbJ+2JSIr/yRg0UqeKt+EGDcTeS939zVgxVMVLlbEV+dgN8IXguyXY0N8tcrGMuOKBIJaY2k4fK5LxQk+hs5dYO5boDdj7BAzJYoUnLG7Dpf0kTXl5GdmJ/2csSY36qpn26JTFv0k5z/G+9Zi1f7/pzyyWCd9t6wNkEKKYLgzIjRE0WohDdMCaOKd+FNTWU8yIe4BtAlA4Az+8Fgn4FTxkO2rrndSY14VguZ4D7Rxa0Io5Op0wN0lbjdTy+WSBCSdR0+KDJcBRX7maxqNkhzi5ChoBr/oE6VhxbYT5zg2Gwzl3Jfy2+0hYZfdMi66wON3sQ4uDFhm9kluKzzFeuit9xJdWhMPjqLxCo4/Mn8f28q3okSvWsigvoADUHlnP6agl7Xij0C8T9SGx1fymmAfYzyRxHV5M24CVcdFyMSvi4rIOYznbPgYc8LSMGWwFzBSTnuq3XWM2MBe/Ii2VHvcS4b7VLzTB8nxjPEXssosf8IQVjW/l00Ei0jrmw2gUzF5JBkOpKQYgj3Ar1s+5iwRPqEH17Y1AUUOKwpR5DWNZSZKJ13lk4TYymouKuOcGwUqwLi5FfXZC9EVQBQ6b3vqJ3/3WQkmHEPGXSaXAv/0L3s/sjHmeSe3llCOZYjaA9Z1MpuYImYDaGx3OT1114zPqLtBGePMiJ5uVLXYHUuOZ/ODNbjDWecQ2eqI4r7/FM/YtEr5B1w+hRKE/KH4d9LLqeTYvX6lrpT5DKWmXVHKwlbTRXQKa8TyWig3LAWhXZky8xhChNmtFYMCa maaYQTtQ WznB1vNxnMfu7pQiu7vAxQN+csHWpXzcKUPZo/HtPjDR5LatlvhVm89wjR2rrQyOt9M/VziXRTIfyNQcCmGIVZpbLdaYfnwZJ+TzHd46cMWFqj8znRx/JWYJcqWyKLwT+hxAsJ3vGPQMV8K/vwKvd9AW4lYAB89PKYelia2w4msNqYhrirxvY05sbMX1YKh3IniyxbtG4U4+hvKd3TTKC2gV8ZjKYVosQBWGVPmR0UaKXOb2KWUXzySO1l/p9qGaU6Lk+3dFkZ1U04x/r8g/cwBXf/LZezC2nD7o954+hJzg2pc4v16b+I+9poEASF5AD383j88NlzLq9yZ2eifQA1RZ3NPxUGIavBZ7Dlx81kAYA4RK7Yp3dxEQMQvIERwouq5LHw9uEcAFRZ6qYXPoYEmUpyFqhs9r+W7I7iWkFh9KzWAg2Nfl0Oiw3jg== 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" Since commit f6f37d9320a1 ("arm64: select KASAN_VMALLOC for SW/HW_TAGS modes") KASAN_VMALLOC is always enabled when KASAN is on. This means that allocations in module_alloc() will be tracked by KASAN protection for vmalloc() and that kasan_alloc_module_shadow() will be always an empty inline and there is no point in calling it. Drop meaningless call to kasan_alloc_module_shadow() from module_alloc(). Signed-off-by: Mike Rapoport (IBM) --- arch/arm64/kernel/module.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c index 47e0be610bb6..e92da4da1b2a 100644 --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c @@ -141,11 +141,6 @@ void *module_alloc(unsigned long size) __func__); } - if (p && (kasan_alloc_module_shadow(p, size, GFP_KERNEL) < 0)) { - vfree(p); - return NULL; - } - /* Memory is intended to be executable, reset the pointer tag. */ return kasan_reset_tag(p); } From patchwork Sun May 5 16:06:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654464 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 3345AC4345F for ; Sun, 5 May 2024 16:07:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB1706B0087; Sun, 5 May 2024 12:07:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A61606B0088; Sun, 5 May 2024 12:07:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9032C6B0089; Sun, 5 May 2024 12:07:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6EC046B0087 for ; Sun, 5 May 2024 12:07:19 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0CDD9C0353 for ; Sun, 5 May 2024 16:07:19 +0000 (UTC) X-FDA: 82084821798.12.4F7AA62 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf14.hostedemail.com (Postfix) with ESMTP id A433B100008 for ; Sun, 5 May 2024 16:07:16 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=QWa5fX+V; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf14.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1714925237; 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=re0M5P5/SqrXTut5ZFqWws3v/3aGFoOhg3MkAMHXQLM=; b=CQbOLQSZ8O3zWf5YDGl5/ElEbTza5uHhikP0ZMJiLb/i6FlbVBrfhFwHRPoxfFCFZYVxpF +iPsKKVdSfC5+UsmD0bRaiy+er1/WLLSSZ5ZvnO0xr9Zb25yKxV1sw/mTP/qO4zumv/Z8z XWHV2ipKGAvBgJFHh9xiX1gb+n1NTg8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=QWa5fX+V; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf14.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714925237; a=rsa-sha256; cv=none; b=hjj+yGNLE/mGV8ss/rUZf3sVw4nGRf4JnEC3ZJElE1B35/mZqlaNTcqg9fOCZaBJ/bM0Gy uuA5vOOE9eyXPmSIvTb7xmPSkYr/NnNG7odBKcrPL+OnCOe1zy1UNvHynwAX2Zpjz40m4l G9qzfLdhZIGMQk7znkHQ0dNcq9Cx2RQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id B697CCE0AB2; Sun, 5 May 2024 16:07:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA2B9C4AF66; Sun, 5 May 2024 16:07:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925232; bh=DCxnhfiOCuZ1vbHkz6N1kzg5vD2Mqvj8bCN8VHj/6O4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QWa5fX+V89TTOP2GlOwvt4twcfdvHMMVPziSmieuPgSBPhWUfbisumxwPB1HxUlJC SghRc/O2IWhq+5uAIL19kBNECjN8Eixj0O+M//1MOzKPjdGEP8/j+8gjwWBR7/8Vtv i7T8kC3S32Mwv38l3PPjKsuGj9NwQptUrFC7qD4hlKFuj2gsb7BzQBL9P1Qxlab7zw t8bDt0pLdKBWzzFTEBo2OuKTmEqM7tos601oUB0a7RFNS6UWZeZpUR1839V3e6YHkl zJMtmY6L2ynGW1NwTp+wFQaP7cjkH15KVcoDbS6MIsORkgjuPaM+IhnyDgczaJyRYq dq0jDZ+sJ6Etw== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Liviu Dudau , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 RESEND v8 02/16] mips: module: rename MODULE_START to MODULES_VADDR Date: Sun, 5 May 2024 19:06:14 +0300 Message-ID: <20240505160628.2323363-3-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Stat-Signature: ytmh8gw14atrtuo5rd358fs688qpdbqi X-Rspamd-Queue-Id: A433B100008 X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1714925236-224198 X-HE-Meta: U2FsdGVkX19HMktiR6gbU5lrC180chbk0k2Z8rT6o9HiJ6zCmguntlXmZfC3J+4PYrBrpGjzF6jpCBRYSHjHbnODFt0Ua8ff2eZiWAluBi3zaF7UUs/nnpLdQwq5ja41d0NvsPJMhMA4SM/vOgn780zpCsAxrAJxyzrqSnFQUOmsUiV0XbYstI6tYQDkHQ7gthToF6Oi5ugSpndT5Wpd7JzFM3WQKSVYM4zAiRsbiwtDhVBZT3hRMh63tiULTK7KdsVQR0bA8t/IWTcVobKD74yGgsSBSNs9Y+K3nyPf2GN9SPJIn1qGFZ1NykQmtlIHBV4dSikBmGvX/uHSaOQyqQlA4+8B1unKCP08ZFHmOMD/SGrMikAJ366GVkPXBONZ6F0ggV6K/g+PakdCqX6kCl2ivn59e/r5lAR9SwOYGMe+jnPqllZgiuw6GKPsVfesy9gOZSSczAV9XZQkBXFcaKz8Z6qZTvSSEby1DJRFs+iicUkPicqTbDoUn58LR1UoTdPjTvOXiAPocd2v8nSi4IwIZjWK9+gpsD9osmYEhFPcnjTr6Q9VLTDAmjzH8ivVfJHfVy4CfggMR1Rtwp7zCrQBUiEOa422Dfn668XC5xS8Lz86Fep8HgcQtrdddK4ui02rrOwPvt6MIGb3ewJMX81tFE5fDBoiT5MQdFEm2Fi/RC94Izj8ic4scoKoJesxOf4s+NFvrXjmIneKbMiB0v4NHOstV6tJ8mHBwdIKdFmpW24/ueIE23MGmNc2XZHLMWbbL9W1R8Tdmn94yPRjzhHNE5pTXp5S1ZUOHFudatXCWW4nrG3H3rpRJQV+N/3WYW1YYKA18aJSAOzlEefd2XBtcXiiJMKka9NoT4zd2kD42B8sQFjAPlCVDD8jLqjNklDCuihtMiqjCs4Twk8QVq6CySXk+rdVaQXU46cpfScfnVBKQeec3tmtNhJwrXp4qUPwrDv+0DgyUS25Grc a0fauyEx /Brk0U6nuqpx+H3ATM15jVM4uSyDZHZXqWPJz0NKNA/7FRMOIezYzxOzC2mCCJUgDWGfm9AHIF2ivsKHpIXW2cvjtuvpr21XA9y4VUZKG0jpdoReRHCJwksEekz0RSSLD8jVlPxgfCxCPr3kjZlLlBl9JqLfPA0iILMuA3c3114kU8aYTSp0RziVdSh6Mc0rk6DWfDUeEt3RfZbBL76Pfcr+mU8kNgaFfr96N4WLV4avys3LwtzSlb6WB0RwMB7gXg2zP4kSXmwDWW6TsHMgbsyr5D0k5RsLqg35mS4cuPNikauYvHaVCGhAMcMROYaH7gRHXoKvqE3qjUXWN27XyXa5NSYmK48fb70Yqi549nHYX7qMAE1GP9dX6ygzsFOp0MxpeVu2xTvvl/FzcimtZdc8aAN9MiznOwiQFMFpkBTX5bE1fYcC6Ql/d9g== 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" and MODULE_END to MODULES_END to match other architectures that define custom address space for modules. Signed-off-by: Mike Rapoport (IBM) --- arch/mips/include/asm/pgtable-64.h | 4 ++-- arch/mips/kernel/module.c | 4 ++-- arch/mips/mm/fault.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/mips/include/asm/pgtable-64.h b/arch/mips/include/asm/pgtable-64.h index 20ca48c1b606..c0109aff223b 100644 --- a/arch/mips/include/asm/pgtable-64.h +++ b/arch/mips/include/asm/pgtable-64.h @@ -147,8 +147,8 @@ #if defined(CONFIG_MODULES) && defined(KBUILD_64BIT_SYM32) && \ VMALLOC_START != CKSSEG /* Load modules into 32bit-compatible segment. */ -#define MODULE_START CKSSEG -#define MODULE_END (FIXADDR_START-2*PAGE_SIZE) +#define MODULES_VADDR CKSSEG +#define MODULES_END (FIXADDR_START-2*PAGE_SIZE) #endif #define pte_ERROR(e) \ diff --git a/arch/mips/kernel/module.c b/arch/mips/kernel/module.c index 7b2fbaa9cac5..9a6c96014904 100644 --- a/arch/mips/kernel/module.c +++ b/arch/mips/kernel/module.c @@ -31,10 +31,10 @@ struct mips_hi16 { static LIST_HEAD(dbe_list); static DEFINE_SPINLOCK(dbe_lock); -#ifdef MODULE_START +#ifdef MODULES_VADDR void *module_alloc(unsigned long size) { - return __vmalloc_node_range(size, 1, MODULE_START, MODULE_END, + return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE, __builtin_return_address(0)); } diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c index aaa9a242ebba..37fedeaca2e9 100644 --- a/arch/mips/mm/fault.c +++ b/arch/mips/mm/fault.c @@ -83,8 +83,8 @@ static void __do_page_fault(struct pt_regs *regs, unsigned long write, if (unlikely(address >= VMALLOC_START && address <= VMALLOC_END)) goto VMALLOC_FAULT_TARGET; -#ifdef MODULE_START - if (unlikely(address >= MODULE_START && address < MODULE_END)) +#ifdef MODULES_VADDR + if (unlikely(address >= MODULES_VADDR && address < MODULES_END)) goto VMALLOC_FAULT_TARGET; #endif From patchwork Sun May 5 16:06:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654465 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 50930C04FFE for ; Sun, 5 May 2024 16:07:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C863A6B0089; Sun, 5 May 2024 12:07:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C36146B008A; Sun, 5 May 2024 12:07:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD6A16B008C; Sun, 5 May 2024 12:07:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8D2366B0089 for ; Sun, 5 May 2024 12:07:30 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1CDBE1A03B9 for ; Sun, 5 May 2024 16:07:30 +0000 (UTC) X-FDA: 82084822260.07.695A99E Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf03.hostedemail.com (Postfix) with ESMTP id C56C820021 for ; Sun, 5 May 2024 16:07:27 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=P4CuvetV; spf=pass (imf03.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1714925248; 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=2feFkw2/DNFlbT2CLv51WDiwJyrr0iuGHxvu/fZCE9Y=; b=hzL3QIc0qIql4A8yaFMGXYukvDC2sYcS24sg/zvWR9xSPMiQgGdtFblsBydTbHzx+Et4In ryZGI+hnMDJlNff3jmlKia+X+qwZXUNzMxsiahwasImt1pJnfTae7D+bOXQej17gVdvx9A kmkLvbLvM8kLUHKdYghbXDlOTsW0/fs= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=P4CuvetV; spf=pass (imf03.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1714925248; a=rsa-sha256; cv=none; b=glMRgTStp5QJvqkbTzWO5HIBHInSni6I4Cen4WFiIS0KToI2JChFa69H9g2U6rXp4S3L1s wvhOVnsAtKoj8Hdt3Xp3acv7omMeaIbyUc3YwCxpvK63eASbAeEqaduAER6s3eZ5NGl59+ p/L58PxMsNcptGBpIAniGepkmNFiv6Q= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 85129CE0AB4; Sun, 5 May 2024 16:07:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88E70C113CC; Sun, 5 May 2024 16:07:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925243; bh=Q5aCDGAMhe9LWjmBOe0KfqvsLthVcLCeaQ3ItO7ykso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P4CuvetVGByVCBaaVxVGGOtA74RDHwFQjjwfPUauzLmoD3wdUW1jd7WI/FNUi9YXr ecSyHliyfMJi2cUpp51ECWceN7DeyR/FktquNEV76UWeLDSX8u5ntplCqdrTZGIyar D+P1a3P3j90UWgY0yEm1lcThQZQ68xgGlJ5P9pQsu+MdqtVgnD2sIkvJCtbHuzGhJY LIv/xEQp3DYvT0pZyyVNtIOhtztKpIuOB81GgZH8ewWLqk/Czr7GNGIJ8tGHZNrj1W kaDVaYV4Oj0AIJ4U/WkvPQlCnuijDIIbENO5+lgHxoBaL30p+JcIdJmJV59oRMq0WW 1ZePgAmim3Bkg== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Liviu Dudau , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 RESEND v8 03/16] nios2: define virtual address space for modules Date: Sun, 5 May 2024 19:06:15 +0300 Message-ID: <20240505160628.2323363-4-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Stat-Signature: bw35tkpit1uhg5d31gnuh4j1bjxrikmx X-Rspam-User: X-Rspamd-Queue-Id: C56C820021 X-Rspamd-Server: rspam05 X-HE-Tag: 1714925247-327595 X-HE-Meta: U2FsdGVkX194Ovdwoyucu0fJpyLfjJ9YMfmoYjdoFtrZ+OdQPZnCWDfgXIVZKiei64zGp0RAZP3g5eccAFr3pHavXoJZj6e/1FBXvAc2oxQXp2vMDW+ul4/FDFB3Vets0aDVWGbSAywXDMKDGiX2sDa0G+i5TKkQYmkYHWRl298Db3KK2thnGiCKLZQQZA9OZbbUYfcb6dysvqhG+pmtgA5py52AddHZ1IEKnwF3UW/gJ2yhcIa0QoFfIHOebEKCxPLqbCDxHReUV5ppH3qAQJQElsbeFaNhuO9L5KyLUY5Kd/7cjgRqQ+tECY8+OpVBBLnhYGTOusSXYE5dvkWMMxTAf4r30lfXdYvCMokCFqDWuhkngqjzR99Lx30hcIkUZyFK7ZkMKP0dWOlvxtHSiSJWJijJCLe8Z5tK9jjRBxDaFx9LVNgNBgPWzhBiRLepb0iie09Ex3KdPYuWuBBkHNi1d+q6d1xD8UK/FFNFjQFzjJJqcjEh6fG7GaIkXok/9KZUruwwpJlXzfkDF4fB4GkqVFSz3rYszIwM+R+jgrO+omx/7aSpJ9yHLcDfYY/YdQW7EuaBSfAwkUu/WoBS82IRAbepmwVfmOw9Ahgl/YGOP6JT6Ljk5zlejpbXDPk3yWelsvZYPv/ii3N4PgxhgoXxbOK53kZgFvXLesPVN8ZtssWrA5QSrxolwZNIeiqGKi9W2ek9kUPq/2S/ZscPGt13XivAqS6LlEaF/CChItZPh60S/pF+Rq9FBxxhGDpwyivmAN2veNN4n4khIPn9b8/MUmuHOrz7+PDk1TJV0Uo1Vpwk9YADmnXGoPlUourHrZ4ajG9Y63avYARQb2COApBldXjRl754b6ZBGr6pvl0JxIg6inuorgRcb9s0+EBHmaYKhd3QKxlEXhLgs4YdgFoz0L5aMWnQKuexVWFspJewOhT1PATuhiJT4WnzKaEcPDn5f16nQ95Ef8D3rtd fBeOling 4BCWxC3ZudbcsmRq5aSWTB8256117JV6YN/gaRIuFDwLcY8p7IuZ33L0+DarEh+St//GLHi70Lda6LihM3zCzxWCTL5ZOEJqcNme3liZhZksOUnPlHpmaF4GeUHRa8vs7RNzlUt9+TlhuK7AwMkWo1ke6FbSxF3QH4VC4WSNSFqpric9/7/5oGKoIpcGbyY2jb59XEm0fP1YVavfnOPeSzm+e16w0Egwb+VEwcjmx613AK1i8x678G5R3LSrJjzK0ZWkcJ5CHi56ou5KIP8WU12o+MXy7v7a906ArMx8FoXQU3r68LFmQX84F4YVemSbM2PHI/yDtsv9ovJt9XXLTPhLeIfMgWsvK6aM+h7nuTHKSYKAoEyZsWWCRTCDssXYOkNkS2Pa7HGN1WwRujxNHmyrS7phF1x1ZSZVamkTyd8tni/A= 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: List-Subscribe: List-Unsubscribe: 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 d052dfcbe8d3..eab87c6beacb 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, From patchwork Sun May 5 16:06:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654466 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 98929C4345F for ; Sun, 5 May 2024 16:07:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 310876B008C; Sun, 5 May 2024 12:07:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C1026B0092; Sun, 5 May 2024 12:07:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 188176B0093; Sun, 5 May 2024 12:07:42 -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 EB63A6B008C for ; Sun, 5 May 2024 12:07:41 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A07AC120141 for ; Sun, 5 May 2024 16:07:41 +0000 (UTC) X-FDA: 82084822722.06.BFD7DF1 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf14.hostedemail.com (Postfix) with ESMTP id 6457D100009 for ; Sun, 5 May 2024 16:07:39 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=mnzdUSuF; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf14.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1714925260; 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=xv1c3NSNlbKJt7QC2dkLsLhlMd2xAG4RTcPEyFkesSs=; b=7cP+UE4ru8ZOp4Lgw8abtA3l8iwc1zc0WynmSLYuYazHXzKZVJyzHCRKYPRnxTnSsO/KCj UufrhO0yOYD+n2Ec+dca1JJAJuSLHqeRfGg/A1ovrOlaS2wLlCftTtLBc100mHRLlz/L0R 8W4nPSPdoQGud3w41r4JLqSCmHZvtP0= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=mnzdUSuF; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf14.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714925260; a=rsa-sha256; cv=none; b=CpNWfNeocbcKIiHlbwH27P1hcqGJZwblEvBnoqBohVoDxEL+oHw6YFI1gxtCOFY8UnjCZN ItZ2vZLQ5tbOCDCnAwYyZthF1OSpDAwoueqboME01k5kS4xg3lFbwln3zK8V4qxTztc1he f2JWNIqTMTfQeebObgHY+CfTcxi8bXw= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 50247CE0AB6; Sun, 5 May 2024 16:07:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 556B2C4DDE6; Sun, 5 May 2024 16:07:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925255; bh=S2WO9rrdnIu5PceUjVXVwYLrUCttkXy1oVefr4+OvH4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mnzdUSuFwZFr/+Ip2l7zLEpPo7HXw0QyaxcHIUqM8tYDbmvTYVi7whZRj6QYhAI5c u+OLcnSpi7V7V0jzzVPB9rWa+rJA3dD3nlH+8wp77vvEuH9IEFWLpzyrsWjJPj/jKs BDJmr/0582lWHgGlperk2Rs+BsENvYpmK5JvRFZoFvCPINOMHITRzkh8LcMznIdb8y hOOVaEDM0UZeQGuU9MlrUVaRg389IJ8S7gihJymsFxUbKAYtkt7Avfm7rb5zhV1CaN R6G5Pk6nhS/74iVs2XgCvdWj3a1mXB9GimpVhAzA7uDys6bqCeiKfazaVLcWk7io+d ZIn5pR9SP9ZcA== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Liviu Dudau , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 RESEND v8 04/16] sparc: simplify module_alloc() Date: Sun, 5 May 2024 19:06:16 +0300 Message-ID: <20240505160628.2323363-5-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6457D100009 X-Stat-Signature: ofsa353u3fzdj8dfzcu9jzp9cuiesywn X-Rspam-User: X-HE-Tag: 1714925259-797693 X-HE-Meta: U2FsdGVkX1/ZuZLa4SBTE73pjOywsgJDnxBwv9ZEazgLe7Ee6SOO9ddotzSbqc2XXH/GQxumDXSPElfsU+UU2GYoTes/0bc2Y2ijMFft3D/rSZlkaSLkaRWE15YwHhAZUdwHp5gOYaYXssXXgUDNMH5nEKLEPuKdZuFbLyt8u6Ml9XH8WeAnpCw0EGulXx8nwVrlpe/12gRLqz/QQkSnMdwsCfmEglsev7pZ7QQk8v2/O8g+B5pfjruq5bf78kpcj14Z2YMEIqdP0Xm1kpFT988z7XQ7f9S+IAZTCkU/oN1nRMT1qPQf05vfC7Zy7+UMqACavgM2ucUsbjdB7wqZ8L784iAZR1ARIfSKqB7iH7vj9eIg4JVLsAABm0mwxFarHVtqP0d9m+YmW9okE+2S8HVl2+f+lmhAmXP6hL7HVSrl5jNfm62/5edzdPbOvMYQ7U8ew54/x4Yqb3sFbs7DUZ13ysa+4cSI2+rm2ab5CoMaiBGqy/FTKUpiYiv3egmPxK4d+YZIrZ7xTqPdN7suhJjoFpAnOryHrxO633hRQjjDWg+JxdDUc0ASvIViKK9CDw9cOcKq35byWs69kUDD9rZWD0hzS8REXTRfbVGz0tOdJYGxvHOhEbO4v9zTDmhx4mYLHagTF+C10shv5ntJ6OZojRjoSSSnrd02wvwfA1ZhGUgSjTcEIpZJI9SMhHWqx9MYr8qNocTaIN1OvEnj9n55UIdWKD3NqYg2qXRC4Ys8fllwUhIS1kbVWi5hFfdgl0dj/YF5lJEIyB/4VuWW2AinDwA5LOSoy21bG1AHuI36fOvWxUSUZS67BATauYjZ8SejOI8sgivGC9Ijs3fOWgCNj191ZIpZQqYcQwUJ3BzaKkLrBVwWaZxa39NQBEr2Ef9J348mNFF0hKElaKRya/FaaTv/+oM5HO+Xc7aFnVVIPXKODLw4K6ESDUL+vd9tH0Nsm9M/afnqNsPxvhj YG2Rs6/e N9GsP4jXGKFbzYZpVzVlfhCfbsyehEVtG9pa4x4TYZT0eET0xat6JOsa0kzKn7z+eJmkho5GnaFaO9a6sDFFJQi60x1P6XZMNheovI3z2Pf97idSF7pEJ2E/okVgdr2nquOgNIDKnuAhBQVYMEYoo5ptyHftlrLD9myDhXZnAY2+MZe++C4pxCXHnoPuNLVXeVinBIe2OgExxxej5BKRp0trXYcTAB9OsdOhqRrDATcr1TE/x4DUbWTcOP+yi8WELoGLfbMcsZDku/OK8ErZUTbYlJW9AfZ2hEsbUJVb6lB7nkbV2LXEq2dAxtkZE77Ze/xf8DGEBvR/1lM4j5QVsGlclZS3AN9IxGG8gp4SogRYjoSGQPAJH9aGKf3TbwrIjlBrn/vXYIk8EvhBjj635J0pUhBzYzXgY9RwMf4TQyJYcN2fDRyWNiyUUfhG/9jtqGsbenGrc9g0/cCztwwqYkWWLbCbPJr+K/8FD0o23PDKw47EZyvjULqoUZrfMlplsGD6/GS8I6hfNUQbDTHAdq3dieQfO3KRZ2I1V81ARmCIhYkBH8o5BxwOtdIN7u4ffpMLxnmR6e+5FSF4VfHbsVoQEEGm/5JlnLFfrjlX9Xv/3RMI= 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" Define MODULES_VADDR and MODULES_END as VMALLOC_START and VMALLOC_END for 32-bit and reduce module_alloc() to __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, ...) as with the new defines the allocations becomes identical for both 32 and 64 bits. While on it, drop unused include of Suggested-by: Sam Ravnborg Signed-off-by: Mike Rapoport (IBM) Reviewed-by: Sam Ravnborg --- arch/sparc/include/asm/pgtable_32.h | 2 ++ arch/sparc/kernel/module.c | 25 +------------------------ 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h index 9e85d57ac3f2..62bcafe38b1f 100644 --- a/arch/sparc/include/asm/pgtable_32.h +++ b/arch/sparc/include/asm/pgtable_32.h @@ -432,6 +432,8 @@ static inline int io_remap_pfn_range(struct vm_area_struct *vma, #define VMALLOC_START _AC(0xfe600000,UL) #define VMALLOC_END _AC(0xffc00000,UL) +#define MODULES_VADDR VMALLOC_START +#define MODULES_END VMALLOC_END /* We provide our own get_unmapped_area to cope with VA holes for userland */ #define HAVE_ARCH_UNMAPPED_AREA diff --git a/arch/sparc/kernel/module.c b/arch/sparc/kernel/module.c index 66c45a2764bc..d37adb2a0b54 100644 --- a/arch/sparc/kernel/module.c +++ b/arch/sparc/kernel/module.c @@ -21,35 +21,12 @@ #include "entry.h" -#ifdef CONFIG_SPARC64 - -#include - -static void *module_map(unsigned long size) +void *module_alloc(unsigned long size) { - if (PAGE_ALIGN(size) > MODULES_LEN) - return NULL; return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE, __builtin_return_address(0)); } -#else -static void *module_map(unsigned long size) -{ - return vmalloc(size); -} -#endif /* CONFIG_SPARC64 */ - -void *module_alloc(unsigned long size) -{ - void *ret; - - ret = module_map(size); - if (ret) - memset(ret, 0, size); - - return ret; -} /* Make generic code ignore STT_REGISTER dummy undefined symbols. */ int module_frob_arch_sections(Elf_Ehdr *hdr, From patchwork Sun May 5 16:06:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654467 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 5E1A5C4345F for ; Sun, 5 May 2024 16:07:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF7E76B0093; Sun, 5 May 2024 12:07:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EA8DF6B0095; Sun, 5 May 2024 12:07:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D21246B0096; Sun, 5 May 2024 12:07:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B42E66B0093 for ; Sun, 5 May 2024 12:07:50 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 43E68120496 for ; Sun, 5 May 2024 16:07:50 +0000 (UTC) X-FDA: 82084823100.28.83D666D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id 8FA6AC0005 for ; Sun, 5 May 2024 16:07:48 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aAa5MSgJ; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf28.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=1714925268; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IIBGIsCSUWlsjH08h6Yqq1vKj8aLzQai1EKlJHl3zyY=; b=Y3zbGa3AqthnPnV53jg1B0GJtS4Ed2dmU1fA8WJ7JBT0IxBI/cF32q0VbgT4Ut1TcilRB/ 8aEKqoi2H0TwYDVg6Y3KoK459z/2GMHNo+v0dUahiJCAHVHmnDDS+2LYNNlilS3XDzXBI5 yFVjjIkx8kk6fgPEPekHOCDT30F16Os= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=aAa5MSgJ; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf28.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=1714925268; a=rsa-sha256; cv=none; b=BujRM9DLQn4Ja5Bp53mugKDHPPuuyWZHnONwm71SY1Tps2B9oeR41y1UCqWYGzC4SAmm1v b+Yrx1vaK0WYJeVWmmPfTndno2qevfF400ilczdX6Bjqy9KH2sSyMZ99cFkW9vbHW+Jefe k2g/s6HEsM56HUc5fSE7l4hhNl/nwOg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B1F8F60CBB; Sun, 5 May 2024 16:07:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21FD0C4DDE7; Sun, 5 May 2024 16:07:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925267; bh=vbQmVIViLlnHnV/HmsoDNHPWB+6N7x9rENWps4lsXos=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aAa5MSgJQJM45G3HokYLiiJiOZDEeE2ajV8iw/yf1DX/fQ3Kmw6A3USHH0Ot5m3Op TVZYg1AWKghmbLAQnkVMS+GBWsm8aShhkYMk2oUWFTCwZ221sTIuktvc3sHgn5Di67 0I35GiFLFgXviW5AdRB+u7RdDHkgSpW6HhkZwMFM/gPwvOTBBTyPfyI73Civ8D9YvS rNWePZxZHMorQMyuKc+VCAWVVq3t2idHccNWlW0YiN3gXtGTvkETcE/v5FdYXJ2KJf LyxaKhxqABmwc9SmSM4tJ4eoIiC7UL7HsecM0w4e+PWxQYptDGBGAdqaW44NkUBYgt DP/ubOUkGv4RQ== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Liviu Dudau , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 RESEND v8 05/16] module: make module_memory_{alloc,free} more self-contained Date: Sun, 5 May 2024 19:06:17 +0300 Message-ID: <20240505160628.2323363-6-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8FA6AC0005 X-Stat-Signature: gm4nj6orp5kt1kqxwk41kjbscyrnd13o X-Rspam-User: X-HE-Tag: 1714925268-62191 X-HE-Meta: U2FsdGVkX19iHl3FxFqJ8qt2VYJRNRt9JyI96qDCc+eycpWPg5MzYdc1nrPUsa7nmYW0pKwJRPrVTz+J2i4OXhYiAxQrfSB5IUM20P/DHCyt0eBTjwx7oyjlSw+uZj1g0TYA3LPuodjTEMO6p/zi2T5jkqIBLlO00BEc/GhpW7wUKIbI7p6YiC16nRDuCJuE2h/MsyBUAM1eEazykuEQl3dsynRtfE3yye9D6u7KeL24EGzjTRo4WyNGMic8Q29K2LoVAoKd9vJdoQDTiAIxyOEbCyef3iQnRHM1GVkzLtN/fdqsv+lejjfGdAUtDAHZYuN+2+TxU7U1zBUqp79ABo7IrzDZ7/Jg02Ux1NjcY68qPO7to7q7QcOWT6JYdTgG5JGLUX9Uvcrf2hnuCs00kHbnXWuZVcxQQhUgTWFG2pkrEHvO4591JyQhpQjfjDUkpT+d23W+nJPiBI75qJAyfnK21+O3RCWlIw1wng3fBnQw69TkDSmIJBVHrSa3GeDDRQuytSMbi484Q4ZwwFJ0mIVYPyiYb5NvjEvOfI4oA33ABi0SWPlMF6ZNqLRnwPFpJdImNgKv6SDUQ3NLbJzQ6/r/sr4aug7JKsD56I51sNyLjxupfmUP1aMuGGfqZw+5nl+vvjGNMYnh/e3UYQ0QknnC/ZdFpSU2RkotOc7tD+/4hkvhaHRExXSfnqPN9x9FPYvRfkrj45B1Eb6liaUnLzWQzXpZYmi/02YdWCDgGNWL37yj5kZi6BXazo1fJwQSwsbDYYD7WyoRw8YndXIs7CzWMzeEwt2QcOqTW2HMNB/7YYAkgYgJYb7/w4t2GJ1XMK/LLcbawCwr20PGeLnisw+p7C5NBDil7kSrTxiTbUQt5Y5zVMNPAcv29F3XP60eP3MtDDo+qmw4VF7PQnB6dR6Bq9xEPdpJiBJmD5UnmrPPGI3ptT0DAq5ZRkdteB6Zd9AXSDYTanAGWC+TDsg nHndWVRw MLwBiQGLH4XL5/LlrLUQaXBamchDeBcbAv6Aa/Q0raNktbOYLKDuLwfhQBp/9VPEFHkr3kaiMRm871Y5lQlho5nPsjyMjZDoj+GEuNquzP8B04crlQPAet8kHfA3DSr09NIyLup74lxy4NzYwF2rWCYsFwpV4sxaRC5xme9pxelZJFyc+1bxc1sfzqbjIGfVgttLFIzLQo3nGPfuxpEwQWb+uy7DzjnVP8pjeXkQGFz6iVC1DVV30wRiZeQmgCz4f16gMFZ5nz3P1RVlpbDj9Xvta6J6sCWUPN87ukW+Xzmw5pFqQ2dwnp/fp+JXrKAMB6xk3jz67JVfRBwzUOxj89BBrBWlSoSgQT+IvrDi6Oo1Q6CpU8RafMJMNg4IMHOVkX6Up8KLAeLCuGFqk9xKLHdVbZhaUmKlafxvtRQd+cnQtgavhzy3vGBcww3lXLgKzzJRms3S7C8rlqyFe5QMDVo0AOfDhPgqrJGjxmTcETpeGuz1t2PpvQ5v9sCBKLyOHcJ4orHUffq3gZChvWByboZHzSg== 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" Move the logic related to the memory allocation and freeing into module_memory_alloc() and module_memory_free(). Signed-off-by: Mike Rapoport (IBM) Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Masami Hiramatsu (Google) --- kernel/module/main.c | 64 +++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/kernel/module/main.c b/kernel/module/main.c index e1e8a7a9d6c1..5b82b069e0d3 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -1203,15 +1203,44 @@ static bool mod_mem_use_vmalloc(enum mod_mem_type type) mod_mem_type_is_core_data(type); } -static void *module_memory_alloc(unsigned int size, enum mod_mem_type type) +static int module_memory_alloc(struct module *mod, enum mod_mem_type type) { + unsigned int size = PAGE_ALIGN(mod->mem[type].size); + void *ptr; + + mod->mem[type].size = size; + if (mod_mem_use_vmalloc(type)) - return vzalloc(size); - return module_alloc(size); + ptr = vmalloc(size); + else + ptr = module_alloc(size); + + if (!ptr) + return -ENOMEM; + + /* + * The pointer to these blocks of memory are stored on the module + * structure and we keep that around so long as the module is + * around. We only free that memory when we unload the module. + * Just mark them as not being a leak then. The .init* ELF + * sections *do* get freed after boot so we *could* treat them + * slightly differently with kmemleak_ignore() and only grey + * them out as they work as typical memory allocations which + * *do* eventually get freed, but let's just keep things simple + * and avoid *any* false positives. + */ + kmemleak_not_leak(ptr); + + memset(ptr, 0, size); + mod->mem[type].base = ptr; + + return 0; } -static void module_memory_free(void *ptr, enum mod_mem_type type) +static void module_memory_free(struct module *mod, enum mod_mem_type type) { + void *ptr = mod->mem[type].base; + if (mod_mem_use_vmalloc(type)) vfree(ptr); else @@ -1229,12 +1258,12 @@ static void free_mod_mem(struct module *mod) /* Free lock-classes; relies on the preceding sync_rcu(). */ lockdep_free_key_range(mod_mem->base, mod_mem->size); if (mod_mem->size) - module_memory_free(mod_mem->base, type); + module_memory_free(mod, type); } /* MOD_DATA hosts mod, so free it at last */ lockdep_free_key_range(mod->mem[MOD_DATA].base, mod->mem[MOD_DATA].size); - module_memory_free(mod->mem[MOD_DATA].base, MOD_DATA); + module_memory_free(mod, MOD_DATA); } /* Free a module, remove from lists, etc. */ @@ -2225,7 +2254,6 @@ static int find_module_sections(struct module *mod, struct load_info *info) static int move_module(struct module *mod, struct load_info *info) { int i; - void *ptr; enum mod_mem_type t = 0; int ret = -ENOMEM; @@ -2234,26 +2262,12 @@ static int move_module(struct module *mod, struct load_info *info) mod->mem[type].base = NULL; continue; } - mod->mem[type].size = PAGE_ALIGN(mod->mem[type].size); - ptr = module_memory_alloc(mod->mem[type].size, type); - /* - * The pointer to these blocks of memory are stored on the module - * structure and we keep that around so long as the module is - * around. We only free that memory when we unload the module. - * Just mark them as not being a leak then. The .init* ELF - * sections *do* get freed after boot so we *could* treat them - * slightly differently with kmemleak_ignore() and only grey - * them out as they work as typical memory allocations which - * *do* eventually get freed, but let's just keep things simple - * and avoid *any* false positives. - */ - kmemleak_not_leak(ptr); - if (!ptr) { + + ret = module_memory_alloc(mod, type); + if (ret) { t = type; goto out_enomem; } - memset(ptr, 0, mod->mem[type].size); - mod->mem[type].base = ptr; } /* Transfer each section which specifies SHF_ALLOC */ @@ -2296,7 +2310,7 @@ static int move_module(struct module *mod, struct load_info *info) return 0; out_enomem: for (t--; t >= 0; t--) - module_memory_free(mod->mem[t].base, t); + module_memory_free(mod, t); return ret; } From patchwork Sun May 5 16:06:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654468 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 A4A7AC04FFE for ; Sun, 5 May 2024 16:08:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D40C6B0096; Sun, 5 May 2024 12:08:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3AB166B0098; Sun, 5 May 2024 12:08:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 24C0A6B0099; Sun, 5 May 2024 12:08:06 -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 02F7F6B0096 for ; Sun, 5 May 2024 12:08:05 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7D6CC40453 for ; Sun, 5 May 2024 16:08:05 +0000 (UTC) X-FDA: 82084823730.24.CA15149 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf11.hostedemail.com (Postfix) with ESMTP id 2C76040003 for ; Sun, 5 May 2024 16:08:02 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="j/RMbwKE"; spf=pass (imf11.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1714925283; 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=i7FZp0zonekZW3EwnTZ4IAjpowIqYEajCRCFum9b+3U=; b=MoblsJ/gXXOCypnwKLGNDOG+i7PWQlkhVm1KNB3cEAcFpreIGHPwkPK5Qe81NcftIzxCYx GEgyRU4Mo3XTnYg54aDJ+7kvgJBOGkYncv3MsYaGlINq3g1I0bmZXFixFISdjEav81aPO2 0/6yUUfCK/S3lVEenmKOei8ijJDLEQc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="j/RMbwKE"; spf=pass (imf11.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1714925283; a=rsa-sha256; cv=none; b=2EyuUULxuVaR63WhwFBoPp/4irvuSsB0JlKoFpnAsj0cfDS5+MBbVlytyLXsxO04MO/vzf naVCAZyp+o1DW8TioXZx1WdTKSPTtu1exDJEPmIsljcOBFzwZsLBZFIPOJOY1HBY0zxK7O eV2zjIYhsDUDXfjRJFT4SklrruJAIqs= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id E4AB7CE0AB6; Sun, 5 May 2024 16:07:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E49CEC113CC; Sun, 5 May 2024 16:07:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925279; bh=O80Ih29W+vz+LMoOHSIificIIW/tpeoH6wwn4K1HsxQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j/RMbwKE6mjFyW0y3wIziuIjzeC+9ZmAt144YV04fnGNWSBiGjLBMZHtE44jgK0W3 dh0wbz6RNWLysGAfKIn7jBeKdkPe6YXSXZZHn95U/tt6k+FCrHbSWOqI9AKirDXzF6 qkSy7bhY/SQn5hIed8cS3y1WKCNVA8iRzLyM1gd0GveDq8EqL+nCo9lV9g4P+5grw4 H//VKlmNGTrC/z40q6br7YMMnYpHbsCMOheUN6HLnhR9Uw8HE3CQE/Db4kWj6gQV48 SAK9eRMuDschdeyT3MhqzcctCW0fEadnMaMouCgVEGMFFhKEaY3HnsmatOyc4K2IXX UU49ZWoeL17gA== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Liviu Dudau , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 RESEND v8 06/16] mm: introduce execmem_alloc() and execmem_free() Date: Sun, 5 May 2024 19:06:18 +0300 Message-ID: <20240505160628.2323363-7-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 2C76040003 X-Rspamd-Server: rspam06 X-Stat-Signature: 49cwca9hdg1t6jhaiaa7kmcpcyppbqut X-HE-Tag: 1714925282-271627 X-HE-Meta: U2FsdGVkX1/BZmx5ZRfMG3ceJZKZi8YIll1Yr7jrd2jsC/td1kD3SaCu3GrLhXU88f2AFkas9V3QtpKJCXRHkhTzAbNEGgtjKWwRAkZUS/ocVQOTomqjrzOhNrFBmsmCQyOkRlFx/Btrw3xhPoTWT8JMWPtb4pXOW5xRGPHey7g/hGJSED8IJxOeKCAhZeoBnArX5yt5qxrPYxw+hLhIPlrYNtZG7olpj3wL5DoIa+pvMRDg+slFD/aLQZFQBcbqW45ayYNnOFWvFIZ6E4mu3VzRMGSuKp9DoLOJnShFAI0EnB8vmVMqV7S8QNiZ6Lr5P+DhIBuwm9dQ94W7znD5ofukhUFxLWWacQl5r1jeD4sBGvnNaojj5iZ6sUiXYaEVsBItXUjlD4fOpL4h593R31Wb/iQFgqLHb3nSovhS+w1937ssFjGzSx6jioZCsrHPwT1sf2/0ffdowCcKxfZBLwfoLBzyJCH3vy6N/34ORFwDl3MbH7CuJkCCIz23qfQZCFC9Pa3cDQTNNjmRZW9M+lTu3939pvD6NrwCWlP25LDd4sfQrUUVoyVuHCP6mLcemqhJOw5D2fjw9+doA6xmsgr9C94Qdeg7Sq0Hss/HBit3mob6oHghC5VG5mPjJ2KneeDsSMPV+CWH0od3tYG66Zkt+wsu0LaAEygE8Jx2V1QhEcYvjs8Bkld5HOmIccTzLz+11wsL6j8xiY9DK8x1lVZz8Wwei6sb48OY3biwZEiyEaYvQWMbAK71UvNxC1F/XvSQqZn9iQbF2bdT3iCM9MIWrFnoMiNRBr9CL/CEhgTqMKNq3Npe7dyQkD3T2vgx1Pz+ZpsgGrpv9ftUMSyqQxDdy1xO/KhSL8Tt7m7WXbvt6FY7jQI0Nee+7ZH531VLOrhC6NVR4UIun3SwpqDVIWAQoqjrZaSBOlSiej8Hsd2422Y0Xj4K9voZ//skB2MKbYiYqXvhsO37an/19WC JLe0R3S4 +6n5sSO3J4BfdwsYVeE+LyB1VmRMW3fPAUUvqXlaj5QU/1M2hX56otgc27QNpZoekHndRpn2KwL03opTehcdeJV5/npLqcjNmdRxnNiNxCcEew928e6UxSWMbzx5TDgqrkmCPoNrVr2i7D+tVPLzEYhRe0bpJjDbh1EH2MTZQImT4wBs3KpKutKbCuIOlKr8hMa2kbyYaEUlCDJfAd7lZR4lshY46lBhB+SUQPMXSLi3vMaJJNM7rD5Usm8scpEftaoCApkGyU8JAy+zpJ4GSe1O2iuoR/yXZ05bfbVXovwUoIXJ0/F+UPNe0cnr7zhLltlGo61QLtHGVqFSjGUVPeP+VydHshozjck4tEH0wy0/bz7IpbQPgAYWPg2127w7jHyEtGYWG1jpu0J2GERoqFPqhka30LRWUnaT5KqK4/UDoKyo4dqkOgEbREEAB5hy915khf3wNBHthb5c= 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" module_alloc() is used everywhere as a mean to allocate memory for code. Beside being semantically wrong, this unnecessarily ties all subsystems that need to allocate code, such as ftrace, kprobes and BPF to modules and puts the burden of code allocation to the modules code. Several architectures override module_alloc() because of various constraints where the executable memory can be located and this causes additional obstacles for improvements of code allocation. Start splitting code allocation from modules by introducing execmem_alloc() and execmem_free() APIs. Initially, execmem_alloc() is a wrapper for module_alloc() and execmem_free() is a replacement of module_memfree() to allow updating all call sites to use the new APIs. Since architectures define different restrictions on placement, permissions, alignment and other parameters for memory that can be used by different subsystems that allocate executable memory, execmem_alloc() takes a type argument, that will be used to identify the calling subsystem and to allow architectures define parameters for ranges suitable for that subsystem. No functional changes. Signed-off-by: Mike Rapoport (IBM) Acked-by: Masami Hiramatsu (Google) Acked-by: Song Liu --- arch/powerpc/kernel/kprobes.c | 6 ++-- arch/s390/kernel/ftrace.c | 4 +-- arch/s390/kernel/kprobes.c | 4 +-- arch/s390/kernel/module.c | 5 +-- arch/sparc/net/bpf_jit_comp_32.c | 8 ++--- arch/x86/kernel/ftrace.c | 6 ++-- arch/x86/kernel/kprobes/core.c | 4 +-- include/linux/execmem.h | 57 ++++++++++++++++++++++++++++++++ include/linux/moduleloader.h | 3 -- kernel/bpf/core.c | 6 ++-- kernel/kprobes.c | 8 ++--- kernel/module/Kconfig | 1 + kernel/module/main.c | 25 +++++--------- mm/Kconfig | 3 ++ mm/Makefile | 1 + mm/execmem.c | 32 ++++++++++++++++++ 16 files changed, 128 insertions(+), 45 deletions(-) create mode 100644 include/linux/execmem.h create mode 100644 mm/execmem.c diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c index bbca90a5e2ec..9fcd01bb2ce6 100644 --- a/arch/powerpc/kernel/kprobes.c +++ b/arch/powerpc/kernel/kprobes.c @@ -19,8 +19,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -130,7 +130,7 @@ void *alloc_insn_page(void) { void *page; - page = module_alloc(PAGE_SIZE); + page = execmem_alloc(EXECMEM_KPROBES, PAGE_SIZE); if (!page) return NULL; @@ -142,7 +142,7 @@ void *alloc_insn_page(void) } return page; error: - module_memfree(page); + execmem_free(page); return NULL; } diff --git a/arch/s390/kernel/ftrace.c b/arch/s390/kernel/ftrace.c index c46381ea04ec..798249ef5646 100644 --- a/arch/s390/kernel/ftrace.c +++ b/arch/s390/kernel/ftrace.c @@ -7,13 +7,13 @@ * Author(s): Martin Schwidefsky */ -#include #include #include #include #include #include #include +#include #include #include #include @@ -220,7 +220,7 @@ static int __init ftrace_plt_init(void) { const char *start, *end; - ftrace_plt = module_alloc(PAGE_SIZE); + ftrace_plt = execmem_alloc(EXECMEM_FTRACE, PAGE_SIZE); if (!ftrace_plt) panic("cannot allocate ftrace plt\n"); diff --git a/arch/s390/kernel/kprobes.c b/arch/s390/kernel/kprobes.c index f0cf20d4b3c5..3c1b1be744de 100644 --- a/arch/s390/kernel/kprobes.c +++ b/arch/s390/kernel/kprobes.c @@ -9,7 +9,6 @@ #define pr_fmt(fmt) "kprobes: " fmt -#include #include #include #include @@ -21,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -38,7 +38,7 @@ void *alloc_insn_page(void) { void *page; - page = module_alloc(PAGE_SIZE); + page = execmem_alloc(EXECMEM_KPROBES, PAGE_SIZE); if (!page) return NULL; set_memory_rox((unsigned long)page, 1); diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c index 42215f9404af..ac97a905e8cd 100644 --- a/arch/s390/kernel/module.c +++ b/arch/s390/kernel/module.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -76,7 +77,7 @@ void *module_alloc(unsigned long size) #ifdef CONFIG_FUNCTION_TRACER void module_arch_cleanup(struct module *mod) { - module_memfree(mod->arch.trampolines_start); + execmem_free(mod->arch.trampolines_start); } #endif @@ -510,7 +511,7 @@ static int module_alloc_ftrace_hotpatch_trampolines(struct module *me, size = FTRACE_HOTPATCH_TRAMPOLINES_SIZE(s->sh_size); numpages = DIV_ROUND_UP(size, PAGE_SIZE); - start = module_alloc(numpages * PAGE_SIZE); + start = execmem_alloc(EXECMEM_FTRACE, numpages * PAGE_SIZE); if (!start) return -ENOMEM; set_memory_rox((unsigned long)start, numpages); diff --git a/arch/sparc/net/bpf_jit_comp_32.c b/arch/sparc/net/bpf_jit_comp_32.c index da2df1e84ed4..bda2dbd3f4c5 100644 --- a/arch/sparc/net/bpf_jit_comp_32.c +++ b/arch/sparc/net/bpf_jit_comp_32.c @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-2.0 -#include #include #include #include #include #include +#include #include #include @@ -713,7 +713,7 @@ cond_branch: f_offset = addrs[i + filter[i].jf]; if (unlikely(proglen + ilen > oldproglen)) { pr_err("bpb_jit_compile fatal error\n"); kfree(addrs); - module_memfree(image); + execmem_free(image); return; } memcpy(image + proglen, temp, ilen); @@ -736,7 +736,7 @@ cond_branch: f_offset = addrs[i + filter[i].jf]; break; } if (proglen == oldproglen) { - image = module_alloc(proglen); + image = execmem_alloc(EXECMEM_BPF, proglen); if (!image) goto out; } @@ -758,7 +758,7 @@ cond_branch: f_offset = addrs[i + filter[i].jf]; void bpf_jit_free(struct bpf_prog *fp) { if (fp->jited) - module_memfree(fp->bpf_func); + execmem_free(fp->bpf_func); bpf_prog_unlock_free(fp); } diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index 70139d9d2e01..c8ddb7abda7c 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -261,15 +262,14 @@ void arch_ftrace_update_code(int command) #ifdef CONFIG_X86_64 #ifdef CONFIG_MODULES -#include /* Module allocation simplifies allocating memory for code */ static inline void *alloc_tramp(unsigned long size) { - return module_alloc(size); + return execmem_alloc(EXECMEM_FTRACE, size); } static inline void tramp_free(void *tramp) { - module_memfree(tramp); + execmem_free(tramp); } #else /* Trampolines can only be created if modules are supported */ diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index d0e49bd7c6f3..72e6a45e7ec2 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -40,12 +40,12 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include @@ -495,7 +495,7 @@ void *alloc_insn_page(void) { void *page; - page = module_alloc(PAGE_SIZE); + page = execmem_alloc(EXECMEM_KPROBES, PAGE_SIZE); if (!page) return NULL; diff --git a/include/linux/execmem.h b/include/linux/execmem.h new file mode 100644 index 000000000000..8eebc8ef66e7 --- /dev/null +++ b/include/linux/execmem.h @@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_EXECMEM_ALLOC_H +#define _LINUX_EXECMEM_ALLOC_H + +#include +#include + +/** + * enum execmem_type - types of executable memory ranges + * + * There are several subsystems that allocate executable memory. + * Architectures define different restrictions on placement, + * permissions, alignment and other parameters for memory that can be used + * by these subsystems. + * Types in this enum identify subsystems that allocate executable memory + * and let architectures define parameters for ranges suitable for + * allocations by each subsystem. + * + * @EXECMEM_DEFAULT: default parameters that would be used for types that + * are not explicitly defined. + * @EXECMEM_MODULE_TEXT: parameters for module text sections + * @EXECMEM_KPROBES: parameters for kprobes + * @EXECMEM_FTRACE: parameters for ftrace + * @EXECMEM_BPF: parameters for BPF + * @EXECMEM_TYPE_MAX: + */ +enum execmem_type { + EXECMEM_DEFAULT, + EXECMEM_MODULE_TEXT = EXECMEM_DEFAULT, + EXECMEM_KPROBES, + EXECMEM_FTRACE, + EXECMEM_BPF, + EXECMEM_TYPE_MAX, +}; + +/** + * execmem_alloc - allocate executable memory + * @type: type of the allocation + * @size: how many bytes of memory are required + * + * Allocates memory that will contain executable code, either generated or + * loaded from kernel modules. + * + * The memory will have protections defined by architecture for executable + * region of the @type. + * + * Return: a pointer to the allocated memory or %NULL + */ +void *execmem_alloc(enum execmem_type type, size_t size); + +/** + * execmem_free - free executable memory + * @ptr: pointer to the memory that should be freed + */ +void execmem_free(void *ptr); + +#endif /* _LINUX_EXECMEM_ALLOC_H */ diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h index 89b1e0ed9811..a3b8caee9405 100644 --- a/include/linux/moduleloader.h +++ b/include/linux/moduleloader.h @@ -29,9 +29,6 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section); sections. Returns NULL on failure. */ void *module_alloc(unsigned long size); -/* Free memory returned from module_alloc. */ -void module_memfree(void *module_region); - /* Determines if the section name is an init section (that is only used during * module loading). */ diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 696bc55de8e8..75a54024e2f4 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -37,6 +36,7 @@ #include #include #include +#include #include #include @@ -1050,12 +1050,12 @@ void bpf_jit_uncharge_modmem(u32 size) void *__weak bpf_jit_alloc_exec(unsigned long size) { - return module_alloc(size); + return execmem_alloc(EXECMEM_BPF, size); } void __weak bpf_jit_free_exec(void *addr) { - module_memfree(addr); + execmem_free(addr); } struct bpf_binary_header * diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 65adc815fc6e..ddd7cdc16edf 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -39,6 +38,7 @@ #include #include #include +#include #include #include @@ -113,17 +113,17 @@ enum kprobe_slot_state { void __weak *alloc_insn_page(void) { /* - * Use module_alloc() so this page is within +/- 2GB of where the + * Use execmem_alloc() so this page is within +/- 2GB of where the * kernel image and loaded module images reside. This is required * for most of the architectures. * (e.g. x86-64 needs this to handle the %rip-relative fixups.) */ - return module_alloc(PAGE_SIZE); + return execmem_alloc(EXECMEM_KPROBES, PAGE_SIZE); } static void free_insn_page(void *page) { - module_memfree(page); + execmem_free(page); } struct kprobe_insn_cache kprobe_insn_slots = { diff --git a/kernel/module/Kconfig b/kernel/module/Kconfig index f3e0329337f6..744383c1eed1 100644 --- a/kernel/module/Kconfig +++ b/kernel/module/Kconfig @@ -2,6 +2,7 @@ menuconfig MODULES bool "Enable loadable module support" modules + select EXECMEM help Kernel modules are small pieces of compiled code which can be inserted in the running kernel, rather than being diff --git a/kernel/module/main.c b/kernel/module/main.c index 5b82b069e0d3..d56b7df0cbb6 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -57,6 +57,7 @@ #include #include #include +#include #include #include "internal.h" @@ -1179,16 +1180,6 @@ resolve_symbol_wait(struct module *mod, return ksym; } -void __weak module_memfree(void *module_region) -{ - /* - * This memory may be RO, and freeing RO memory in an interrupt is not - * supported by vmalloc. - */ - WARN_ON(in_interrupt()); - vfree(module_region); -} - void __weak module_arch_cleanup(struct module *mod) { } @@ -1213,7 +1204,7 @@ static int module_memory_alloc(struct module *mod, enum mod_mem_type type) if (mod_mem_use_vmalloc(type)) ptr = vmalloc(size); else - ptr = module_alloc(size); + ptr = execmem_alloc(EXECMEM_MODULE_TEXT, size); if (!ptr) return -ENOMEM; @@ -1244,7 +1235,7 @@ static void module_memory_free(struct module *mod, enum mod_mem_type type) if (mod_mem_use_vmalloc(type)) vfree(ptr); else - module_memfree(ptr); + execmem_free(ptr); } static void free_mod_mem(struct module *mod) @@ -2496,9 +2487,9 @@ static void do_free_init(struct work_struct *w) llist_for_each_safe(pos, n, list) { initfree = container_of(pos, struct mod_initfree, node); - module_memfree(initfree->init_text); - module_memfree(initfree->init_data); - module_memfree(initfree->init_rodata); + execmem_free(initfree->init_text); + execmem_free(initfree->init_data); + execmem_free(initfree->init_rodata); kfree(initfree); } } @@ -2608,10 +2599,10 @@ static noinline int do_init_module(struct module *mod) * We want to free module_init, but be aware that kallsyms may be * walking this with preempt disabled. In all the failure paths, we * call synchronize_rcu(), but we don't want to slow down the success - * path. module_memfree() cannot be called in an interrupt, so do the + * path. execmem_free() cannot be called in an interrupt, so do the * work and call synchronize_rcu() in a work queue. * - * Note that module_alloc() on most architectures creates W+X page + * Note that execmem_alloc() on most architectures creates W+X page * mappings which won't be cleaned up until do_free_init() runs. Any * code such as mark_rodata_ro() which depends on those mappings to * be cleaned up needs to sync with the queued work by invoking diff --git a/mm/Kconfig b/mm/Kconfig index b1448aa81e15..f08a216d4793 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -1241,6 +1241,9 @@ config LOCK_MM_AND_FIND_VMA config IOMMU_MM_DATA bool +config EXECMEM + bool + source "mm/damon/Kconfig" endmenu diff --git a/mm/Makefile b/mm/Makefile index 4abb40b911ec..001336c91864 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -133,3 +133,4 @@ obj-$(CONFIG_IO_MAPPING) += io-mapping.o obj-$(CONFIG_HAVE_BOOTMEM_INFO_NODE) += bootmem_info.o obj-$(CONFIG_GENERIC_IOREMAP) += ioremap.o obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o +obj-$(CONFIG_EXECMEM) += execmem.o diff --git a/mm/execmem.c b/mm/execmem.c new file mode 100644 index 000000000000..480adc69b20d --- /dev/null +++ b/mm/execmem.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2002 Richard Henderson + * Copyright (C) 2001 Rusty Russell, 2002, 2010 Rusty Russell IBM. + * Copyright (C) 2023 Luis Chamberlain + * Copyright (C) 2024 Mike Rapoport IBM. + */ + +#include +#include +#include +#include + +static void *__execmem_alloc(size_t size) +{ + return module_alloc(size); +} + +void *execmem_alloc(enum execmem_type type, size_t size) +{ + return __execmem_alloc(size); +} + +void execmem_free(void *ptr) +{ + /* + * This memory may be RO, and freeing RO memory in an interrupt is not + * supported by vmalloc. + */ + WARN_ON(in_interrupt()); + vfree(ptr); +} From patchwork Sun May 5 16:06:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654469 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 0BE4CC4345F for ; Sun, 5 May 2024 16:08:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9EE566B0099; Sun, 5 May 2024 12:08:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 99E546B009A; Sun, 5 May 2024 12:08:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 83F9A6B009B; Sun, 5 May 2024 12:08:14 -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 6065C6B0099 for ; Sun, 5 May 2024 12:08:14 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E24F7120395 for ; Sun, 5 May 2024 16:08:13 +0000 (UTC) X-FDA: 82084824066.10.3FB36F5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id 3B15E1C0008 for ; Sun, 5 May 2024 16:08:12 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qy7fbZ3s; spf=pass (imf18.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=1714925292; a=rsa-sha256; cv=none; b=AHoVladd7yfMlinWBKuqAJbn73XgQb14S0VOBho+qJI9I/qW68uQW9ROKyDUgL9XiR50nm gQA59m6MdDDPzrVO+Yg6yNV4wd4oqvruY/kU6+lY1aKaBzKjj8i8ObvYV13p0vYmWBAVbu FoMOQ9E3J5lA8SQAIc443wcngJgUxSc= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qy7fbZ3s; spf=pass (imf18.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=1714925292; 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=P8adOcY5bgQffQMY+FSoXypp+yh7TEtbKuUsGAS8Fco=; b=OhsWHB0gr0Swir1pp0ht34rF4XjZYihS+r4ms597yFeBpbhet/3UGt8PC9R+UMqY+b+U6y jvPur6aw5OU5SHi8yzKOJzL22c4YyL+wlOruGVfgUu+Kr4++uYNBXrZwhqRid2odOlhhWs dlaU2q9pDCoYLGGNR+D32PlTk3HRDZc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 533C260C90; Sun, 5 May 2024 16:08:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6E61C4DDE3; Sun, 5 May 2024 16:07:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925291; bh=H1Yrs9oS3D7w/IH5Du6/u6WvPsm3z4WLJALiS8Y8DQ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qy7fbZ3sR5SpWYo9BfaPnLREtW6tcVlwYjkUThI241bz+XFpPVmWviyMy6XqTm6aQ dORU/UekgwSj27ajsbinG1OwPjL9K+SIsvs4fsUK8b3eFCh2fUpSfqvbtanznko+qy 73Ro0XMWqbMJ9rPGK0W5cArd1g69QQW/8ZPzU5+NVnxrXnjRYbEu6WUmAwrx5eqBvc LJWmIu7MXQJ2RAZ1BmHzdr7cHlO+FJ89P3S6tCmUfcCvgysRPuyItr44uH0fIMQcJK zfjzHgHS0WwDn5Hh0Muj2jWVN1o261zIWg73Iv07eey1MVZIFFfYZnZF8PJhFxxWCc vezWRt98tYJRw== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Liviu Dudau , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 RESEND v8 07/16] mm/execmem, arch: convert simple overrides of module_alloc to execmem Date: Sun, 5 May 2024 19:06:19 +0300 Message-ID: <20240505160628.2323363-8-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Stat-Signature: kib8xqz5r67cj9hxcpmu88krwnfrhfp8 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 3B15E1C0008 X-HE-Tag: 1714925292-79568 X-HE-Meta: U2FsdGVkX1/JoUxZUJF/ymzp3kGUTwHvm1dhQ/AentLSVmbfj4Yx78GR2PiwGik5+VSUbBlbfcrFnsY4rcfgUZxXiWDtciYdD1YQpNGpa4X30y7TGeuHsvYGkZ0qTcGXUl1qwfQXr6DuMPynTaeKzUXS7FHW3VB6Jfg82FyPC/lltraPLZ2CXCsUwTcZ5rWQxK1JYc+7D4+rLkg/mf1WdFcIZb5PWSJhQoZMasgUpH7TIlyYEVxsf/MGSMtz5zSMPjcRH6qdyIMB5zUTN//MGoFULXcHJ4BowSjBa7lgRuR8KpMfz5RFZglsSpxenlgc9jcGk+PJ5CDEV0xYUpBnDfNhPV6BUigXjrxiZV57ZYp6e7w8xMoUDymj2UgwDQKXsMAX0guQSh7Svt0QoPJ/+snZruv0Ko6qdPaqTAYIzplKowXxfhhFjpcIb0k7X0rf+96ycdvZQGMsJDvrj8RO7FeaiqYn48sw5+GJvMZGU3pMgjMpuZ7Vp7gxqp0cycEwWhoWnTKnDEkmFLT024lUkLlWXlxHmFPJzknQbtUcIqY4HVfw5c/jfzf1a03GWlFcbcKo1u8h9oGBiB8lYzs9F4Ibl0xnWrTuxK0FDsbUTo4UKT61pwjx+CErsPqnvsR57nVXmJLb26N9ToDZ14QwywXehmMJkmDqVFlEVOZntdzJzK5AVzWDMm/U4cZMWeGbBrD0wHkZGSaKRRGot5A5Zp/8PKMxoHq0roxbSqAx+FfcexmuJlcSI6ZaHwOjKXVk1th/vuCESOI02xw+JnSc2I37sMjiDX6Vdwy1XZBMBtscVwbDh6J8XJybI7Av5SJp65EkuiEPYrFRjym48h1oRDEAqOo9KMkMICm+y8hNtD0MztaMoehru6dpG1DuJQpNvHBbfWzw4h0wlfCOapVyqOBru2rIzBWVNuEfquGgAMn5wr8i/dF1+8BiyjX3mJqhjUH4HRoPgWJ4gCu57AL oJM89DGh I9b5DPrBsoXfynAnXv+B/wSz8BHvX1V0jtocV1Lcv8lUj+imiu9365HHP0VRni6HODBQQ3r3ZQhgg4z/pjedmBd/L7JjelA8PvfqmYHybKyDj90jbNOkuFp6wVXHO5BjzNdEsYljm0B/DCfA9BklXFcYenfNnFEmmk1fP1libPSnp1jEP4vUruSDN4Vsw6i+yYgnEjOsnxLhLX46xKz3aR0W4JXarOHbuJWzSQcGzshiHsX7K9revgRROBR373OKnyDZvgRLmbmatP8TRXLvOhc0sCUltRMNkaI76KbJayEYZer2PjKsxsFBUryE8YYuFB6W08jtRvnQF94uRM2d3ZwzizHHtzKDMbjVRiXqoUkjL8wo= 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" Several architectures override module_alloc() only to define address range for code allocations different than VMALLOC address space. Provide a generic implementation in execmem that uses the parameters for address space ranges, required alignment and page protections provided by architectures. The architectures must fill execmem_info structure and implement execmem_arch_setup() that returns a pointer to that structure. This way the execmem initialization won't be called from every architecture, but rather from a central place, namely a core_initcall() in execmem. The execmem provides execmem_alloc() API that wraps __vmalloc_node_range() with the parameters defined by the architectures. If an architecture does not implement execmem_arch_setup(), execmem_alloc() will fall back to module_alloc(). Signed-off-by: Mike Rapoport (IBM) Acked-by: Song Liu Reviewed-by: Masami Hiramatsu (Google) --- arch/loongarch/kernel/module.c | 19 ++++++++-- arch/mips/kernel/module.c | 20 ++++++++-- arch/nios2/kernel/module.c | 21 ++++++++--- arch/parisc/kernel/module.c | 24 ++++++++---- arch/riscv/kernel/module.c | 24 ++++++++---- arch/sparc/kernel/module.c | 20 ++++++++-- include/linux/execmem.h | 47 ++++++++++++++++++++++++ mm/execmem.c | 67 ++++++++++++++++++++++++++++++++-- mm/mm_init.c | 2 + 9 files changed, 210 insertions(+), 34 deletions(-) diff --git a/arch/loongarch/kernel/module.c b/arch/loongarch/kernel/module.c index c7d0338d12c1..ca6dd7ea1610 100644 --- a/arch/loongarch/kernel/module.c +++ b/arch/loongarch/kernel/module.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -490,10 +491,22 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, return 0; } -void *module_alloc(unsigned long size) +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) { - return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, - GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE, __builtin_return_address(0)); + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = MODULES_VADDR, + .end = MODULES_END, + .pgprot = PAGE_KERNEL, + .alignment = 1, + }, + }, + }; + + return &execmem_info; } static void module_init_ftrace_plt(const Elf_Ehdr *hdr, diff --git a/arch/mips/kernel/module.c b/arch/mips/kernel/module.c index 9a6c96014904..59225a3cf918 100644 --- a/arch/mips/kernel/module.c +++ b/arch/mips/kernel/module.c @@ -20,6 +20,7 @@ #include #include #include +#include #include struct mips_hi16 { @@ -32,11 +33,22 @@ static LIST_HEAD(dbe_list); static DEFINE_SPINLOCK(dbe_lock); #ifdef MODULES_VADDR -void *module_alloc(unsigned long size) +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) { - return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, - GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE, - __builtin_return_address(0)); + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = MODULES_VADDR, + .end = MODULES_END, + .pgprot = PAGE_KERNEL, + .alignment = 1, + }, + }, + }; + + return &execmem_info; } #endif diff --git a/arch/nios2/kernel/module.c b/arch/nios2/kernel/module.c index 9c97b7513853..0d1ee86631fc 100644 --- a/arch/nios2/kernel/module.c +++ b/arch/nios2/kernel/module.c @@ -18,15 +18,26 @@ #include #include #include +#include #include -void *module_alloc(unsigned long size) +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) { - 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)); + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = MODULES_VADDR, + .end = MODULES_END, + .pgprot = PAGE_KERNEL_EXEC, + .alignment = 1, + }, + }, + }; + + return &execmem_info; } int apply_relocate_add(Elf32_Shdr *sechdrs, const char *strtab, diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c index d214bbe3c2af..bdfa85e10c1b 100644 --- a/arch/parisc/kernel/module.c +++ b/arch/parisc/kernel/module.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -173,15 +174,22 @@ static inline int reassemble_22(int as22) ((as22 & 0x0003ff) << 3)); } -void *module_alloc(unsigned long size) +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) { - /* using RWX means less protection for modules, but it's - * easier than trying to map the text, data, init_text and - * init_data correctly */ - return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END, - GFP_KERNEL, - PAGE_KERNEL_RWX, 0, NUMA_NO_NODE, - __builtin_return_address(0)); + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = VMALLOC_START, + .end = VMALLOC_END, + .pgprot = PAGE_KERNEL_RWX, + .alignment = 1, + }, + }, + }; + + return &execmem_info; } #ifndef CONFIG_64BIT diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index 5e5a82644451..182904127ba0 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -906,13 +907,22 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, } #if defined(CONFIG_MMU) && defined(CONFIG_64BIT) -void *module_alloc(unsigned long size) -{ - return __vmalloc_node_range(size, 1, MODULES_VADDR, - MODULES_END, GFP_KERNEL, - PAGE_KERNEL, VM_FLUSH_RESET_PERMS, - NUMA_NO_NODE, - __builtin_return_address(0)); +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) +{ + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = MODULES_VADDR, + .end = MODULES_END, + .pgprot = PAGE_KERNEL, + .alignment = 1, + }, + }, + }; + + return &execmem_info; } #endif diff --git a/arch/sparc/kernel/module.c b/arch/sparc/kernel/module.c index d37adb2a0b54..8b7ee45defc3 100644 --- a/arch/sparc/kernel/module.c +++ b/arch/sparc/kernel/module.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -21,11 +22,22 @@ #include "entry.h" -void *module_alloc(unsigned long size) +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) { - return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, - GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE, - __builtin_return_address(0)); + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = MODULES_VADDR, + .end = MODULES_END, + .pgprot = PAGE_KERNEL, + .alignment = 1, + }, + }, + }; + + return &execmem_info; } /* Make generic code ignore STT_REGISTER dummy undefined symbols. */ diff --git a/include/linux/execmem.h b/include/linux/execmem.h index 8eebc8ef66e7..96fc59258467 100644 --- a/include/linux/execmem.h +++ b/include/linux/execmem.h @@ -33,6 +33,47 @@ enum execmem_type { EXECMEM_TYPE_MAX, }; +/** + * struct execmem_range - definition of an address space suitable for code and + * related data allocations + * @start: address space start + * @end: address space end (inclusive) + * @pgprot: permissions for memory in this address space + * @alignment: alignment required for text allocations + */ +struct execmem_range { + unsigned long start; + unsigned long end; + pgprot_t pgprot; + unsigned int alignment; +}; + +/** + * struct execmem_info - architecture parameters for code allocations + * @ranges: array of parameter sets defining architecture specific + * parameters for executable memory allocations. The ranges that are not + * explicitly initialized by an architecture use parameters defined for + * @EXECMEM_DEFAULT. + */ +struct execmem_info { + struct execmem_range ranges[EXECMEM_TYPE_MAX]; +}; + +/** + * execmem_arch_setup - define parameters for allocations of executable memory + * + * A hook for architectures to define parameters for allocations of + * executable memory. These parameters should be filled into the + * @execmem_info structure. + * + * For architectures that do not implement this method a default set of + * parameters will be used + * + * Return: a structure defining architecture parameters and restrictions + * for allocations of executable memory + */ +struct execmem_info *execmem_arch_setup(void); + /** * execmem_alloc - allocate executable memory * @type: type of the allocation @@ -54,4 +95,10 @@ void *execmem_alloc(enum execmem_type type, size_t size); */ void execmem_free(void *ptr); +#ifdef CONFIG_EXECMEM +void execmem_init(void); +#else +static inline void execmem_init(void) {} +#endif + #endif /* _LINUX_EXECMEM_ALLOC_H */ diff --git a/mm/execmem.c b/mm/execmem.c index 480adc69b20d..80e61c1e7319 100644 --- a/mm/execmem.c +++ b/mm/execmem.c @@ -11,14 +11,30 @@ #include #include -static void *__execmem_alloc(size_t size) +static struct execmem_info *execmem_info __ro_after_init; + +static void *__execmem_alloc(struct execmem_range *range, size_t size) { - return module_alloc(size); + unsigned long start = range->start; + unsigned long end = range->end; + unsigned int align = range->alignment; + pgprot_t pgprot = range->pgprot; + + return __vmalloc_node_range(size, align, start, end, + GFP_KERNEL, pgprot, VM_FLUSH_RESET_PERMS, + NUMA_NO_NODE, __builtin_return_address(0)); } void *execmem_alloc(enum execmem_type type, size_t size) { - return __execmem_alloc(size); + struct execmem_range *range; + + if (!execmem_info) + return module_alloc(size); + + range = &execmem_info->ranges[type]; + + return __execmem_alloc(range, size); } void execmem_free(void *ptr) @@ -30,3 +46,48 @@ void execmem_free(void *ptr) WARN_ON(in_interrupt()); vfree(ptr); } + +static bool execmem_validate(struct execmem_info *info) +{ + struct execmem_range *r = &info->ranges[EXECMEM_DEFAULT]; + + if (!r->alignment || !r->start || !r->end || !pgprot_val(r->pgprot)) { + pr_crit("Invalid parameters for execmem allocator, module loading will fail"); + return false; + } + + return true; +} + +static void execmem_init_missing(struct execmem_info *info) +{ + struct execmem_range *default_range = &info->ranges[EXECMEM_DEFAULT]; + + for (int i = EXECMEM_DEFAULT + 1; i < EXECMEM_TYPE_MAX; i++) { + struct execmem_range *r = &info->ranges[i]; + + if (!r->start) { + r->pgprot = default_range->pgprot; + r->alignment = default_range->alignment; + r->start = default_range->start; + r->end = default_range->end; + } + } +} + +struct execmem_info * __weak execmem_arch_setup(void) +{ + return NULL; +} + +void __init execmem_init(void) +{ + struct execmem_info *info = execmem_arch_setup(); + + if (!info || !execmem_validate(info)) + return; + + execmem_init_missing(info); + + execmem_info = info; +} diff --git a/mm/mm_init.c b/mm/mm_init.c index 549e76af8f82..b6a1fcf6e13a 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "internal.h" #include "slab.h" #include "shuffle.h" @@ -2793,4 +2794,5 @@ void __init mm_core_init(void) pti_init(); kmsan_init_runtime(); mm_cache_init(); + execmem_init(); } From patchwork Sun May 5 16:06:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654470 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 E9A04C4345F for ; Sun, 5 May 2024 16:08:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F3046B009B; Sun, 5 May 2024 12:08:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A3906B009C; Sun, 5 May 2024 12:08:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61D5C6B009D; Sun, 5 May 2024 12:08:29 -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 36E596B009B for ; Sun, 5 May 2024 12:08:29 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id EA59D4054C for ; Sun, 5 May 2024 16:08:28 +0000 (UTC) X-FDA: 82084824696.17.D186CD5 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf18.hostedemail.com (Postfix) with ESMTP id 942EE1C0003 for ; Sun, 5 May 2024 16:08:26 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="K/7t7ddd"; spf=pass (imf18.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1714925307; 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=dUHb+PJwcHNeJJuSNqKm8o6d4m9NAW1QhHMz4OW5A9Y=; b=WPJxCl2ngDRCJ1EmqVxYh6wWWQp/K5f9OXWFkFUIkDyA3/o6aRMYvjsY8J0h84qj8dmpDt Jy/c0+CVhFNGD3MgYNqTlnnE25TjbW38kIU2Cz5GCInwjPpYQtSShNw03fwhnj5vF32A01 nJOPPJrcNEc9jJtg6dE8i8A/zp4lnpk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714925307; a=rsa-sha256; cv=none; b=qBvKSqRlrzGs3+qe+Dc81wDxVWhtu+oFi/38Vv06AVuiZ4HjHtoMmTC+6vnKKN45fCTDlV TzFLAxIT4oFLRMnbWOe8qLrdF2QsCRwepOyk9739LslN37ZvVyyilLwcGilF6S5LJDhbYB 2HdqLUgqS3V7v7PPdhXGnYAPXka6EWQ= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="K/7t7ddd"; spf=pass (imf18.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id BD396CE0AB2; Sun, 5 May 2024 16:08:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87474C113CC; Sun, 5 May 2024 16:08:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925303; bh=mPkzltgN0mXGnoqVwLMYHmKvyIn9jEJGiEzdN/feIVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K/7t7dddjmQ8iT6NVAHgFxdHh4ql31eROOAKJS8bf4btKLnc30/pW1+kFUZA2f9rO myqSWJojYsdNVCy24kKurXli0fp3907hjPSFu3KRjYjuFvv3M2h5nFga7R95XJ70d/ +2+g7Nt2ULhrLvAqvM7kVgQaq5qEpegYoPs2DPUkJSG2efqs7I+ib9FSzoYe+acV4Q aJeTDfeXlLA3Ox64zNHuGLMQsr3LW7SvoH63itB6NgXI+Vff9b2UhwtswJFGhwxemG ck4XgrWnwHoj8BxB0cAMzTwnx+u5/Qaea/l5HDhbDV9j45whzko5tPvqUyx2eqyxiN sMNrijbbiA8yQ== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Liviu Dudau , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 RESEND v8 08/16] mm/execmem, arch: convert remaining overrides of module_alloc to execmem Date: Sun, 5 May 2024 19:06:20 +0300 Message-ID: <20240505160628.2323363-9-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: th9hnw4dbq1n5qcniksyp4xsin6k1iah X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 942EE1C0003 X-HE-Tag: 1714925306-621011 X-HE-Meta: U2FsdGVkX187+zTwfTFGWn1eHNXIIhu4gbQQWUAd3xEW0SbIhxNyW7XAo84e41rICH9tvquqcNcSGZy9BXfEifi83b0fA/3j4WuARIfWuT2yrUmWAfEqO3PKRYWU5N6kl6hiAVz+Dw0yVKiK1sKKI4ZSrUktpmuN/x84jtzcmjLupx6I6qBN8dDIiOzvFHE8VfNrdiSCvMiupOtJt/Omlfv9qwzCBXGQrNped1UhpCJ9nfT53NXnUu2QHub0TBxfDdD6nCqKWoxVta/id7+H3rI7uRV9LlKf1KkKCZ6UQINILvnQjJskf/cuXZ3lQgnDRs8sxcMDHiSyvv+H48lL3xjQfwJ33DnVOHdrq3kpUopO5yr7Arz3k6x8GRHHFwqNFzzcumwyslMqvMLGY6JZ+lrAPvG6RhK5oJYXBeGb7Xz5rFXEtRgCSSsBgFxEjsMfIBaEG4KwKABJsrNgoo+MhQyCg03KkBlpMfJMozZahyEu6qdH5oucwxFMxmeFcPwOM8TNIWVBHptsbhq86ghBoVNhejV7K6mJzBob0Y5Y4rXumm2zKiC0gpHikdhRmHNSeIca90yiDT+AKZ2/PU6FJxlGfKggOEjFGUuC5lWemDTko0ueyp76tfeJGTSMbgvaxKza3MeI7o8yLoRMN5mUu22t/Nthgsrsj1MGY3fX4kaiWf/0B+tfuTaZtfo93GWY07ozXOaKFkY+dKeb4Zp0jw6iMx2pSxvEv0Co1/O5BNEirtSdciMhFRrEJqCGIETPNa1D7w6qMsXXE0nkfPsvwJfw0dDR70u54be50vmoDGoSaL0MbUMNWHXkmgLkS5A6wKSuILOxbBR/Kc8YE5OAurbzVYQ7WotKGYVGNB8i4NUcAYb0misvW3EQoi4ux5mUGna8HsGwMnifL3ZmNuF43QpfAsOaJxj49/qJNSmg6kmCOubqMx4ypyhlBjwjQLX5/n2qVqL77QawqC7Gqli FRjSYjm3 O5qAc4TY+Z4NbqNwzA1qy4ggtDCZQlZS/Ea8O1jT1T5n6te3NwpLMYwr/ahV1M4TLbO7J/ES5GuTPGjL9FQrmWQVyJhVMYM0224hvn5kktBBiQdo+qtjzNzBXHjXZraajOKkC2VjAEO2uCGuIkfF4hPGrxaJIWRxvwv5OjzVXHuSq5hmrryhmOXKst+TDU/GZmV7ybtvAbMXsv1yL0h2Jby0JYQRnfYi/cJueochex812Sy1SagJ83y1/BIQcIrlNRsx0NvE1SmOuhOoBPeIEFJntbAvNVF3kQS+KGUg8wg6O9S2gJ2W/l6X88t2A4KSRilIZDWzX2MvRVA8jeoco9e4Yw1uWwx/AivPmQwxgXZVcPRG6zPSn4yUDD87byxTC07k+WFGCvJ9EeFXQ3Yro0wTx5IYMMWcwa0wI 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" Extend execmem parameters to accommodate more complex overrides of module_alloc() by architectures. This includes specification of a fallback range required by arm, arm64 and powerpc, EXECMEM_MODULE_DATA type required by powerpc, support for allocation of KASAN shadow required by s390 and x86 and support for late initialization of execmem required by arm64. The core implementation of execmem_alloc() takes care of suppressing warnings when the initial allocation fails but there is a fallback range defined. Signed-off-by: Mike Rapoport (IBM) Acked-by: Will Deacon Acked-by: Song Liu Tested-by: Liviu Dudau --- arch/Kconfig | 8 ++++ arch/arm/kernel/module.c | 41 ++++++++++++-------- arch/arm64/Kconfig | 1 + arch/arm64/kernel/module.c | 55 +++++++++++++++------------ arch/powerpc/kernel/module.c | 60 +++++++++++++++++++---------- arch/s390/kernel/module.c | 54 +++++++++++--------------- arch/x86/kernel/module.c | 70 +++++++++++----------------------- include/linux/execmem.h | 30 ++++++++++++++- include/linux/moduleloader.h | 12 ------ kernel/module/main.c | 26 +++---------- mm/execmem.c | 74 ++++++++++++++++++++++++++++++------ 11 files changed, 246 insertions(+), 185 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 65afb1de48b3..4fd0daa54e6c 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -960,6 +960,14 @@ config ARCH_WANTS_MODULES_DATA_IN_VMALLOC For architectures like powerpc/32 which have constraints on module allocation and need to allocate module data outside of module area. +config ARCH_WANTS_EXECMEM_LATE + bool + help + For architectures that do not allocate executable memory early on + boot, but rather require its initialization late when there is + enough entropy for module space randomization, for instance + arm64. + config HAVE_IRQ_EXIT_ON_IRQ_STACK bool help diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c index e74d84f58b77..a98fdf6ff26c 100644 --- a/arch/arm/kernel/module.c +++ b/arch/arm/kernel/module.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -34,23 +35,31 @@ #endif #ifdef CONFIG_MMU -void *module_alloc(unsigned long size) +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) { - gfp_t gfp_mask = GFP_KERNEL; - void *p; - - /* Silence the initial allocation */ - if (IS_ENABLED(CONFIG_ARM_MODULE_PLTS)) - gfp_mask |= __GFP_NOWARN; - - p = __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, - gfp_mask, PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE, - __builtin_return_address(0)); - if (!IS_ENABLED(CONFIG_ARM_MODULE_PLTS) || p) - return p; - return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END, - GFP_KERNEL, PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE, - __builtin_return_address(0)); + unsigned long fallback_start = 0, fallback_end = 0; + + if (IS_ENABLED(CONFIG_ARM_MODULE_PLTS)) { + fallback_start = VMALLOC_START; + fallback_end = VMALLOC_END; + } + + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = MODULES_VADDR, + .end = MODULES_END, + .pgprot = PAGE_KERNEL_EXEC, + .alignment = 1, + .fallback_start = fallback_start, + .fallback_end = fallback_end, + }, + }, + }; + + return &execmem_info; } #endif diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 7b11c98b3e84..74b34a78b7ac 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -105,6 +105,7 @@ config ARM64 select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_HUGE_PMD_SHARE if ARM64_4K_PAGES || (ARM64_16K_PAGES && !ARM64_VA_BITS_36) select ARCH_WANT_LD_ORPHAN_WARN + select ARCH_WANTS_EXECMEM_LATE if EXECMEM select ARCH_WANTS_NO_INSTR select ARCH_WANTS_THP_SWAP if ARM64_4K_PAGES select ARCH_HAS_UBSAN diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c index e92da4da1b2a..b7a7a23f9f8f 100644 --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -108,41 +109,47 @@ static int __init module_init_limits(void) return 0; } -subsys_initcall(module_init_limits); -void *module_alloc(unsigned long size) +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) { - void *p = NULL; + unsigned long fallback_start = 0, fallback_end = 0; + unsigned long start = 0, end = 0; + + module_init_limits(); /* * Where possible, prefer to allocate within direct branch range of the * kernel such that no PLTs are necessary. */ if (module_direct_base) { - p = __vmalloc_node_range(size, MODULE_ALIGN, - module_direct_base, - module_direct_base + SZ_128M, - GFP_KERNEL | __GFP_NOWARN, - PAGE_KERNEL, 0, NUMA_NO_NODE, - __builtin_return_address(0)); - } + start = module_direct_base; + end = module_direct_base + SZ_128M; - if (!p && module_plt_base) { - p = __vmalloc_node_range(size, MODULE_ALIGN, - module_plt_base, - module_plt_base + SZ_2G, - GFP_KERNEL | __GFP_NOWARN, - PAGE_KERNEL, 0, NUMA_NO_NODE, - __builtin_return_address(0)); - } - - if (!p) { - pr_warn_ratelimited("%s: unable to allocate memory\n", - __func__); + if (module_plt_base) { + fallback_start = module_plt_base; + fallback_end = module_plt_base + SZ_2G; + } + } else if (module_plt_base) { + start = module_plt_base; + end = module_plt_base + SZ_2G; } - /* Memory is intended to be executable, reset the pointer tag. */ - return kasan_reset_tag(p); + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = start, + .end = end, + .pgprot = PAGE_KERNEL, + .alignment = 1, + .fallback_start = fallback_start, + .fallback_end = fallback_end, + }, + }, + }; + + return &execmem_info; } enum aarch64_reloc_op { diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c index f6d6ae0a1692..ac80559015a3 100644 --- a/arch/powerpc/kernel/module.c +++ b/arch/powerpc/kernel/module.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -89,39 +90,56 @@ int module_finalize(const Elf_Ehdr *hdr, return 0; } -static __always_inline void * -__module_alloc(unsigned long size, unsigned long start, unsigned long end, bool nowarn) +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) { pgprot_t prot = strict_module_rwx_enabled() ? PAGE_KERNEL : PAGE_KERNEL_EXEC; - gfp_t gfp = GFP_KERNEL | (nowarn ? __GFP_NOWARN : 0); + unsigned long fallback_start = 0, fallback_end = 0; + unsigned long start, end; /* - * Don't do huge page allocations for modules yet until more testing - * is done. STRICT_MODULE_RWX may require extra work to support this - * too. + * BOOK3S_32 and 8xx define MODULES_VADDR for text allocations and + * allow allocating data in the entire vmalloc space */ - return __vmalloc_node_range(size, 1, start, end, gfp, prot, - VM_FLUSH_RESET_PERMS, - NUMA_NO_NODE, __builtin_return_address(0)); -} - -void *module_alloc(unsigned long size) -{ #ifdef MODULES_VADDR unsigned long limit = (unsigned long)_etext - SZ_32M; - void *ptr = NULL; BUILD_BUG_ON(TASK_SIZE > MODULES_VADDR); /* First try within 32M limit from _etext to avoid branch trampolines */ - if (MODULES_VADDR < PAGE_OFFSET && MODULES_END > limit) - ptr = __module_alloc(size, limit, MODULES_END, true); - - if (!ptr) - ptr = __module_alloc(size, MODULES_VADDR, MODULES_END, false); + if (MODULES_VADDR < PAGE_OFFSET && MODULES_END > limit) { + start = limit; + fallback_start = MODULES_VADDR; + fallback_end = MODULES_END; + } else { + start = MODULES_VADDR; + } - return ptr; + end = MODULES_END; #else - return __module_alloc(size, VMALLOC_START, VMALLOC_END, false); + start = VMALLOC_START; + end = VMALLOC_END; #endif + + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = start, + .end = end, + .pgprot = prot, + .alignment = 1, + .fallback_start = fallback_start, + .fallback_end = fallback_end, + }, + [EXECMEM_MODULE_DATA] = { + .start = VMALLOC_START, + .end = VMALLOC_END, + .pgprot = PAGE_KERNEL, + .alignment = 1, + }, + }, + }; + + return &execmem_info; } diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c index ac97a905e8cd..7fee64fdc1bb 100644 --- a/arch/s390/kernel/module.c +++ b/arch/s390/kernel/module.c @@ -37,41 +37,31 @@ #define PLT_ENTRY_SIZE 22 -static unsigned long get_module_load_offset(void) +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) { - static DEFINE_MUTEX(module_kaslr_mutex); - static unsigned long module_load_offset; - - if (!kaslr_enabled()) - return 0; - /* - * Calculate the module_load_offset the first time this code - * is called. Once calculated it stays the same until reboot. - */ - mutex_lock(&module_kaslr_mutex); - if (!module_load_offset) + unsigned long module_load_offset = 0; + unsigned long start; + + if (kaslr_enabled()) module_load_offset = get_random_u32_inclusive(1, 1024) * PAGE_SIZE; - mutex_unlock(&module_kaslr_mutex); - return module_load_offset; -} -void *module_alloc(unsigned long size) -{ - gfp_t gfp_mask = GFP_KERNEL; - void *p; - - if (PAGE_ALIGN(size) > MODULES_LEN) - return NULL; - p = __vmalloc_node_range(size, MODULE_ALIGN, - MODULES_VADDR + get_module_load_offset(), - MODULES_END, gfp_mask, PAGE_KERNEL, - VM_FLUSH_RESET_PERMS | VM_DEFER_KMEMLEAK, - NUMA_NO_NODE, __builtin_return_address(0)); - if (p && (kasan_alloc_module_shadow(p, size, gfp_mask) < 0)) { - vfree(p); - return NULL; - } - return p; + start = MODULES_VADDR + module_load_offset; + + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .flags = EXECMEM_KASAN_SHADOW, + .start = start, + .end = MODULES_END, + .pgprot = PAGE_KERNEL, + .alignment = MODULE_ALIGN, + }, + }, + }; + + return &execmem_info; } #ifdef CONFIG_FUNCTION_TRACER diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index e18914c0e38a..45b1a7c03379 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -36,55 +37,30 @@ do { \ } while (0) #endif -#ifdef CONFIG_RANDOMIZE_BASE -static unsigned long module_load_offset; +static struct execmem_info execmem_info __ro_after_init; -/* Mutex protects the module_load_offset. */ -static DEFINE_MUTEX(module_kaslr_mutex); - -static unsigned long int get_module_load_offset(void) -{ - if (kaslr_enabled()) { - mutex_lock(&module_kaslr_mutex); - /* - * Calculate the module_load_offset the first time this - * code is called. Once calculated it stays the same until - * reboot. - */ - if (module_load_offset == 0) - module_load_offset = - get_random_u32_inclusive(1, 1024) * PAGE_SIZE; - mutex_unlock(&module_kaslr_mutex); - } - return module_load_offset; -} -#else -static unsigned long int get_module_load_offset(void) +struct execmem_info __init *execmem_arch_setup(void) { - return 0; -} -#endif - -void *module_alloc(unsigned long size) -{ - gfp_t gfp_mask = GFP_KERNEL; - void *p; - - if (PAGE_ALIGN(size) > MODULES_LEN) - return NULL; - - p = __vmalloc_node_range(size, MODULE_ALIGN, - MODULES_VADDR + get_module_load_offset(), - MODULES_END, gfp_mask, PAGE_KERNEL, - VM_FLUSH_RESET_PERMS | VM_DEFER_KMEMLEAK, - NUMA_NO_NODE, __builtin_return_address(0)); - - if (p && (kasan_alloc_module_shadow(p, size, gfp_mask) < 0)) { - vfree(p); - return NULL; - } - - return p; + unsigned long start, offset = 0; + + if (kaslr_enabled()) + offset = get_random_u32_inclusive(1, 1024) * PAGE_SIZE; + + start = MODULES_VADDR + offset; + + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .flags = EXECMEM_KASAN_SHADOW, + .start = start, + .end = MODULES_END, + .pgprot = PAGE_KERNEL, + .alignment = MODULE_ALIGN, + }, + }, + }; + + return &execmem_info; } #ifdef CONFIG_X86_32 diff --git a/include/linux/execmem.h b/include/linux/execmem.h index 96fc59258467..32cef1144117 100644 --- a/include/linux/execmem.h +++ b/include/linux/execmem.h @@ -5,6 +5,14 @@ #include #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 * @@ -22,6 +30,7 @@ * @EXECMEM_KPROBES: parameters for kprobes * @EXECMEM_FTRACE: parameters for ftrace * @EXECMEM_BPF: parameters for BPF + * @EXECMEM_MODULE_DATA: parameters for module data sections * @EXECMEM_TYPE_MAX: */ enum execmem_type { @@ -30,22 +39,38 @@ enum execmem_type { EXECMEM_KPROBES, EXECMEM_FTRACE, EXECMEM_BPF, + EXECMEM_MODULE_DATA, EXECMEM_TYPE_MAX, }; +/** + * enum execmem_range_flags - options for executable memory allocations + * @EXECMEM_KASAN_SHADOW: allocate kasan shadow + */ +enum execmem_range_flags { + EXECMEM_KASAN_SHADOW = (1 << 0), +}; + /** * struct execmem_range - definition of an address space suitable for code and * related data allocations * @start: address space start * @end: address space end (inclusive) + * @fallback_start: start of the secondary address space range for fallback + * allocations on architectures that require it + * @fallback_end: start of the secondary address space (inclusive) * @pgprot: permissions for memory in this address space * @alignment: alignment required for text allocations + * @flags: options for memory allocations for this range */ struct execmem_range { unsigned long start; unsigned long end; + unsigned long fallback_start; + unsigned long fallback_end; pgprot_t pgprot; unsigned int alignment; + enum execmem_range_flags flags; }; /** @@ -82,6 +107,9 @@ struct execmem_info *execmem_arch_setup(void); * Allocates memory that will contain executable code, either generated or * loaded from kernel modules. * + * Allocates memory that will contain data coupled with executable code, + * like data sections in kernel modules. + * * The memory will have protections defined by architecture for executable * region of the @type. * @@ -95,7 +123,7 @@ void *execmem_alloc(enum execmem_type type, size_t size); */ void execmem_free(void *ptr); -#ifdef CONFIG_EXECMEM +#if defined(CONFIG_EXECMEM) && !defined(CONFIG_ARCH_WANTS_EXECMEM_LATE) void execmem_init(void); #else static inline void execmem_init(void) {} diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h index a3b8caee9405..e395461d59e5 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). */ @@ -126,12 +122,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 d56b7df0cbb6..91e185607d4b 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -1188,24 +1188,20 @@ void __weak module_arch_freeing_init(struct module *mod) { } -static bool mod_mem_use_vmalloc(enum mod_mem_type type) -{ - return IS_ENABLED(CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC) && - mod_mem_type_is_core_data(type); -} - static int module_memory_alloc(struct module *mod, enum mod_mem_type type) { unsigned int size = PAGE_ALIGN(mod->mem[type].size); + enum execmem_type execmem_type; void *ptr; mod->mem[type].size = size; - if (mod_mem_use_vmalloc(type)) - ptr = vmalloc(size); + if (mod_mem_type_is_data(type)) + execmem_type = EXECMEM_MODULE_DATA; else - ptr = execmem_alloc(EXECMEM_MODULE_TEXT, size); + execmem_type = EXECMEM_MODULE_TEXT; + ptr = execmem_alloc(execmem_type, size); if (!ptr) return -ENOMEM; @@ -1232,10 +1228,7 @@ static void module_memory_free(struct module *mod, enum mod_mem_type type) { void *ptr = mod->mem[type].base; - if (mod_mem_use_vmalloc(type)) - vfree(ptr); - else - execmem_free(ptr); + execmem_free(ptr); } static void free_mod_mem(struct module *mod) @@ -1630,13 +1623,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 80e61c1e7319..0c4b36bc6d10 100644 --- a/mm/execmem.c +++ b/mm/execmem.c @@ -12,27 +12,49 @@ #include static struct execmem_info *execmem_info __ro_after_init; +static struct execmem_info default_execmem_info __ro_after_init; static void *__execmem_alloc(struct execmem_range *range, size_t size) { + bool kasan = range->flags & EXECMEM_KASAN_SHADOW; + unsigned long vm_flags = VM_FLUSH_RESET_PERMS; + gfp_t gfp_flags = GFP_KERNEL | __GFP_NOWARN; unsigned long start = range->start; unsigned long end = range->end; unsigned int align = range->alignment; pgprot_t pgprot = range->pgprot; + void *p; + + if (kasan) + vm_flags |= VM_DEFER_KMEMLEAK; + + p = __vmalloc_node_range(size, align, start, end, gfp_flags, + pgprot, vm_flags, NUMA_NO_NODE, + __builtin_return_address(0)); + if (!p && range->fallback_start) { + start = range->fallback_start; + end = range->fallback_end; + p = __vmalloc_node_range(size, align, start, end, gfp_flags, + pgprot, vm_flags, NUMA_NO_NODE, + __builtin_return_address(0)); + } + + if (!p) { + pr_warn_ratelimited("execmem: unable to allocate memory\n"); + return NULL; + } + + if (kasan && (kasan_alloc_module_shadow(p, size, GFP_KERNEL) < 0)) { + vfree(p); + return NULL; + } - return __vmalloc_node_range(size, align, start, end, - GFP_KERNEL, pgprot, VM_FLUSH_RESET_PERMS, - NUMA_NO_NODE, __builtin_return_address(0)); + return kasan_reset_tag(p); } void *execmem_alloc(enum execmem_type type, size_t size) { - struct execmem_range *range; - - if (!execmem_info) - return module_alloc(size); - - range = &execmem_info->ranges[type]; + struct execmem_range *range = &execmem_info->ranges[type]; return __execmem_alloc(range, size); } @@ -67,10 +89,16 @@ static void execmem_init_missing(struct execmem_info *info) struct execmem_range *r = &info->ranges[i]; if (!r->start) { - r->pgprot = default_range->pgprot; + if (i == EXECMEM_MODULE_DATA) + r->pgprot = PAGE_KERNEL; + else + r->pgprot = default_range->pgprot; r->alignment = default_range->alignment; r->start = default_range->start; r->end = default_range->end; + r->flags = default_range->flags; + r->fallback_start = default_range->fallback_start; + r->fallback_end = default_range->fallback_end; } } } @@ -80,14 +108,36 @@ struct execmem_info * __weak execmem_arch_setup(void) return NULL; } -void __init execmem_init(void) +static void __init __execmem_init(void) { struct execmem_info *info = execmem_arch_setup(); - if (!info || !execmem_validate(info)) + if (!info) { + info = execmem_info = &default_execmem_info; + info->ranges[EXECMEM_DEFAULT].start = VMALLOC_START; + info->ranges[EXECMEM_DEFAULT].end = VMALLOC_END; + info->ranges[EXECMEM_DEFAULT].pgprot = PAGE_KERNEL_EXEC; + info->ranges[EXECMEM_DEFAULT].alignment = 1; + } + + if (!execmem_validate(info)) return; execmem_init_missing(info); execmem_info = info; } + +#ifdef CONFIG_ARCH_WANTS_EXECMEM_LATE +static int __init execmem_late_init(void) +{ + __execmem_init(); + return 0; +} +core_initcall(execmem_late_init); +#else +void __init execmem_init(void) +{ + __execmem_init(); +} +#endif From patchwork Sun May 5 16:06:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654471 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 821E7C4345F for ; Sun, 5 May 2024 16:08:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D8B56B009D; Sun, 5 May 2024 12:08:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 18A066B009E; Sun, 5 May 2024 12:08:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 029BC6B009F; Sun, 5 May 2024 12:08:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D88D16B009D for ; Sun, 5 May 2024 12:08:37 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 960061C0AD9 for ; Sun, 5 May 2024 16:08:37 +0000 (UTC) X-FDA: 82084825074.12.4D23331 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id E98AA1C0006 for ; Sun, 5 May 2024 16:08:35 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=shLi723c; spf=pass (imf18.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=1714925316; 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=4DBgWrGRLrMji5A4t9bmWQ2nAQ4rfSDlHheE5nQXccM=; b=pRof1tSTgmEXMUdk4kAFoVLet559tdniCWQVUpJ+idFMx1NhwRahD5HQouteeNcZQlV0Cd slV40ycf2vpfYNSqzJOpxgxwHSfrFhdEbecSgMxhUMkE2VMPZopeq1wB50y7r2q5R3JET7 6Arfecya6WjCA56BKAnDds/1/qE+YUI= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=shLi723c; spf=pass (imf18.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=1714925316; a=rsa-sha256; cv=none; b=J/yYDVctnNtwOZEzbcMv0B57TY1oWzXI2zEdoft6IXXNFjROTguDDga7XNeIdI/e/UmBpn QSpmeb6YcBtNErW2ZU/Hhk12Jf2mOp+l2uVlC13kF42QhLQmYyrb2vvIc76+Ue8KSWVgzO m1Lbrhs+zb5I4HNgGDAukuQxdsBE73s= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 27C9460CA0; Sun, 5 May 2024 16:08:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D6A0C4DDE6; Sun, 5 May 2024 16:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925314; bh=Rvc7E+HMMA3ADjVUaU2tKv0yhJenjSe9igrLALIYU0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=shLi723c0/Ur3b0A8AHsKhvLohUMcp+fFUUMZ6JoWOuO5vEUs39+L/bLU4HZMazLh Oe6j35z9wVArorVs5UWBuTif/KnGVNE2nfSyvJKdHwrGSco94b1q6uzOJ2LqA78xCn r0X3Zn9A9c05w7DN1MgC7iLBw5Ui0bVVQ40QO9g5xM2P2hs4Y6ocEzmpBsDnuRAR4P G3oB630XCTubm/c95bjffP8cHPmyJKAYpKOuSeWQhA9ZJFkEyZKwxIOrliQxhSZR7j LUCtg/FcS7hI0tGhTTnDjYlsQ2LUMngmkGzHm7RFwEmCYtpOND4xtNEjQmNcnbgywN nVHYzWj/AfQUg== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Liviu Dudau , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 RESEND v8 09/16] riscv: extend execmem_params for generated code allocations Date: Sun, 5 May 2024 19:06:21 +0300 Message-ID: <20240505160628.2323363-10-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: E98AA1C0006 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 4femefiu3yy7ian9ytj3bgojbawjcn6r X-HE-Tag: 1714925315-243030 X-HE-Meta: U2FsdGVkX185IfW4SN+ITBrMsyDVKbkiCI3hv1v/n3V71vqH+KtXR7DkaKFOguH3RctPKcehQXBg0RwWOclBioYXrUQLAonsgOJ1VUtcK8YbtO4Uh6WvrDNpPJ0mxJg/Vl6iHIZc1Jzsh/uzJ/ulDvUGJUKsgUQRhmo2km4+kKJhSClnXByjPaZrHi4g2sB6kbhYhGDunTtzv1L+OcBjswMA9ioK17SKHYy5CKai0jTw9hc2ND7my9AROHPKYgP9y6G/PeonVRslD6nKSIkGcgjasqU7V4X0wZ8f679vnaxtjlVwlJSx3ab8Q9MggmQrgQaeDGWM+Qx5Cav8KJm62ueXcUNFHqBhbHYbT4p8Gp9MbVOCzrd/HaAzzGCopnWlhUDrIdln6tt+ezhqAKWIxmXDpe+biafqfryRqodxeHBbr07Gn19MCESUi7f0djQoba3qPEOKKoznoeATUqnQdH6fGBzuFXY7ahZEIyzDyLe5wA07h33QawBYNtmJWE5BQGyOR3AetZryDdFPLoGEZ7O27wpsGtrHxWby8VhLCeuglGgbHPeW0dNxnT/ObF0n/lMm8UUOFuHIJon5pNxWdXZd6Tig3L71jLDYhfY9178CM/MZO3+tYbPsoQdILmD8dC7AnygVWDX0tFkZ4Ds8axpoo05lTiGaby9c5FeV3nvuZbaD5YyLQ/W86DI3hZUhlRQwy7zkCsXZ0bdTrljgz3G7SlgX5Q4oiVdnDpvEnJDEyTTG3GKOnFj5BK3Ln5ayGDjm6uqNxJnBS3OvnO+T5HQUIkxvp+7TMbaeMVajT/RdER0wSFV0i9KOanzhzacQzkP3CdBZwI6k/7rAbGKf5tPlDAW4XsQOtauATf5r+FLcfHJ342SW0zx2oRzmQOMIBjM02OInKG73ygH+Ivz8bH86ODnBk7o2yfs/e/U8cnHGqc5JdpxaT2C50Zp/MXL4NJJZdLg1lzJnRIHY/wG AcIR8mhy 7u3yXLK1c9bfWKndkdWYZOunMqu3dvbHX5PI9wRxsdNAdb/jJWc2iCh3w0PWYZKFIaB5+xywJJBLw3+eo/ze3e28UZaKl5gEhpxHj9uNQoG9eltN2V0alqJCRXxweIITLcsOs9SmezpRV4krJuXA+ahQ2wSJRHnIp2QB+jyacbom8C1YyUJyuzC7WrdGM+aTw9Xsg+gfkiZekzt7k1MQWF4Uz5H+PvVsMoNIMHq+Mzq/oHwF7RVa1Z0z9P4dH6ufk7PSJjYlzMCpHG7o8xge8C9ZE1T4PaXOVjMlh+MKiJlBKRnALZYZE/rKH+NTwPkJhWzVcGdByRRrlO6FRTIFa2cZDz4PYOceX0JVoiksU2L6dsDGqVL2iAg/q3iuLEnshgdk3kdT+mkd86TA795oTyQpjDlZdHN9m4TOKsjyYGCvJB6c= 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" The memory allocations for kprobes and BPF on RISC-V are not placed in the modules area and these custom allocations are implemented with overrides of alloc_insn_page() and bpf_jit_alloc_exec(). Define MODULES_VADDR and MODULES_END as VMALLOC_START and VMALLOC_END for 32 bit and slightly reorder execmem_params initialization to support both 32 and 64 bit variants, define EXECMEM_KPROBES and EXECMEM_BPF ranges in riscv::execmem_params and drop overrides of alloc_insn_page() and bpf_jit_alloc_exec(). Signed-off-by: Mike Rapoport (IBM) Reviewed-by: Alexandre Ghiti --- arch/riscv/include/asm/pgtable.h | 3 +++ arch/riscv/kernel/module.c | 14 +++++++++++++- arch/riscv/kernel/probes/kprobes.c | 10 ---------- arch/riscv/net/bpf_jit_core.c | 13 ------------- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 9f8ea0e33eb1..5f21814e438e 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -55,6 +55,9 @@ #define MODULES_LOWEST_VADDR (KERNEL_LINK_ADDR - SZ_2G) #define MODULES_VADDR (PFN_ALIGN((unsigned long)&_end) - SZ_2G) #define MODULES_END (PFN_ALIGN((unsigned long)&_start)) +#else +#define MODULES_VADDR VMALLOC_START +#define MODULES_END VMALLOC_END #endif /* diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index 182904127ba0..0e6415f00fca 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -906,7 +906,7 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, return 0; } -#if defined(CONFIG_MMU) && defined(CONFIG_64BIT) +#ifdef CONFIG_MMU static struct execmem_info execmem_info __ro_after_init; struct execmem_info __init *execmem_arch_setup(void) @@ -919,6 +919,18 @@ struct execmem_info __init *execmem_arch_setup(void) .pgprot = PAGE_KERNEL, .alignment = 1, }, + [EXECMEM_KPROBES] = { + .start = VMALLOC_START, + .end = VMALLOC_END, + .pgprot = PAGE_KERNEL_READ_EXEC, + .alignment = 1, + }, + [EXECMEM_BPF] = { + .start = BPF_JIT_REGION_START, + .end = BPF_JIT_REGION_END, + .pgprot = PAGE_KERNEL, + .alignment = PAGE_SIZE, + }, }, }; diff --git a/arch/riscv/kernel/probes/kprobes.c b/arch/riscv/kernel/probes/kprobes.c index 2f08c14a933d..e64f2f3064eb 100644 --- a/arch/riscv/kernel/probes/kprobes.c +++ b/arch/riscv/kernel/probes/kprobes.c @@ -104,16 +104,6 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p) return 0; } -#ifdef CONFIG_MMU -void *alloc_insn_page(void) -{ - return __vmalloc_node_range(PAGE_SIZE, 1, VMALLOC_START, VMALLOC_END, - GFP_KERNEL, PAGE_KERNEL_READ_EXEC, - VM_FLUSH_RESET_PERMS, NUMA_NO_NODE, - __builtin_return_address(0)); -} -#endif - /* install breakpoint in text */ void __kprobes arch_arm_kprobe(struct kprobe *p) { diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c index 6b3acac30c06..e238fdbd5dbc 100644 --- a/arch/riscv/net/bpf_jit_core.c +++ b/arch/riscv/net/bpf_jit_core.c @@ -219,19 +219,6 @@ u64 bpf_jit_alloc_exec_limit(void) return BPF_JIT_REGION_SIZE; } -void *bpf_jit_alloc_exec(unsigned long size) -{ - return __vmalloc_node_range(size, PAGE_SIZE, BPF_JIT_REGION_START, - BPF_JIT_REGION_END, GFP_KERNEL, - PAGE_KERNEL, 0, NUMA_NO_NODE, - __builtin_return_address(0)); -} - -void bpf_jit_free_exec(void *addr) -{ - return vfree(addr); -} - void *bpf_arch_text_copy(void *dst, void *src, size_t len) { int ret; From patchwork Sun May 5 16:06:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654472 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 53C4CC04FFE for ; Sun, 5 May 2024 16:08:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DBFE76B0085; Sun, 5 May 2024 12:08:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D70A56B009F; Sun, 5 May 2024 12:08:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C10DF6B00A0; Sun, 5 May 2024 12:08:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A0A156B0085 for ; Sun, 5 May 2024 12:08:49 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 605481A04B5 for ; Sun, 5 May 2024 16:08:49 +0000 (UTC) X-FDA: 82084825578.06.324FD82 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id BF018100002 for ; Sun, 5 May 2024 16:08:47 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=o8jiLvcf; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.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=1714925327; 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=VpbkUxuadtAaKX6Fnq0w2CEcga3ignfuLmYWKso72/Y=; b=63MyeCe5WWYF+fCbgXkmpB/FpAPoiWTepDiwIPLSU8PNff4/aYUHLrdkDzkc9AaIyHvP9e jBMdaTW/akqLwlQPOXIWumdjKe98a6TLJkJeFWKBmJtMqS0jZe5QrwYlf5YHy3zufRlzo/ IXI0v/yW1uZpnRX2TGL5AhY9BFjIk8g= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=o8jiLvcf; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.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=1714925327; a=rsa-sha256; cv=none; b=yeIJDrp+WMjak+hLeP2+JSPoz7MnTp2ZOYGqNm15LU5e1DHFciZKmMvvfpiTesi2MTetAM INYWy8iYyYuF8f52T5Jv03dxp3h0TU8TZg4p+FDnErpLcyM66fQU5aIAUeVBbrzDthKdRq jZnQIBYZEi0MPzYYVDEcyxHQ1u7bxtU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E9BF360CBB; Sun, 5 May 2024 16:08:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C2B7C4AF66; Sun, 5 May 2024 16:08:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925326; bh=baelIo5gqQ6dNoONu464d37hHX6/MoaALRFlqjsyJfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o8jiLvcfyNXB2iKxVuJHVMVEodBkbD1zblOEpItf8uhQXKQxqKdCGY7s0UctSKPri k3As8VAahDJ4NZSDJZmP61b1qd29PgNi4/WY8gt8pcKwe+U4mL0gWKr6G0c0l3jpEh lALY/R8NgYRkr74Dq4kIvOKK9Z8fxbuOpiw8GpmS2/XpjxcCx/Vu0WjnQ947IN3TrW v+f+OWtztPnMo6X5MTTu0wTYyR/w4hxiWyvDCgQheibsLdCYKyF8k/C/97DxOoCjPL DXuwU6qdfZL8+QFtJj1eo0qsbPEa5DTL9c098i09INCdxXLQTtnFDA8FsMheRTKOOZ 98lqdYyVWEYLg== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Liviu Dudau , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 RESEND v8 10/16] arm64: extend execmem_info for generated code allocations Date: Sun, 5 May 2024 19:06:22 +0300 Message-ID: <20240505160628.2323363-11-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Stat-Signature: g8jrnosx8nwguweii9e19jwb6tzuk3cy X-Rspam-User: X-Rspamd-Queue-Id: BF018100002 X-HE-Tag: 1714925327-434999 X-HE-Meta: U2FsdGVkX1/kpTqZzk3kJrqLgJtogi9RtDUJXbrhZh67roh6vqqPpURgJ0pF8nQlL+RswFpHI1voRLhQXJlU78BuaKEWQMLIyC9XL4wafmvQnHhbpokQkSyXjilzm+I5NIV/YE8SgIgy0JGYtjeHEzKf2JOGc0LxR+gbwqkaw8xSJPf6yf6Xl1r/HIfYd8XbP+HoHlh2oOoIovKbUkqTQgmenHs7EgxYOekNoEKquUI9eRnwxEr9O5+o48Tbc0JlwZtPSrrXUpv9f5bmHgDboLeNJMAlwgaYcpfxNgfLOvGWpp/pYysB+F0GTs6Ukt9huKSbcrB0U5DI4P80lu2Nsjdl2g2/xOVQUUaPVnivlMdsXF7kW0zYd524/ssx9yhqg9USSM3wTF2pdhTtscoM8KYGGb5E7mwS/YXhruvNFU322zjQPHMKJhzDAMstAPZzli9flPvC5AiIfiBboCh4a/OXIXua++KrjC62ioNWhn15bOuJDdGhboIRzCy7vT7iAdvnnjbBAQ4z35muR398gd+ILEZSNYJzpsS3aonPxJRSVlrZJXqpup9NnvIbuzItByKT1O97rtVkIqeahVdRYAdzqgIqwOTwHk2kBqhGM4cmgSud/z7YrlEmE/B6fHbk5RCqWaAlxEFy10uyPCVZzliIajhltcQQn58Yo3N6xZlrKflRUneQBJjifM6iSj37IkJYaSoF2MwgSQxGcdDnHOfGLz5wZYLoRtEcKgfcf3qqU6Vzslc4DOWUZ3jEIa0BxnHAX+wx6jP/4zQMuK3fgaJRYICsXHoj3QHcitCtUP+HYZ+/PVcDtkEEqDXUhVrguo1VoXTq0mo49s/YJmgFiV5tfZNXJTgG9hefMLAias5gR6H6glTHI4J+0zkkbii0GCYSKkIm3OeouL3wnSgWBQYkEmcWN0Xgj5jjecjU0/FOKVGKPSVQ3LtK7Q0vxUk5TFuibkkForWLtHd6lPu FAF5PPsh kZpJ0idAL6n3JPcNOG9JgG8JJVwImBimCuJXVLpv0SSNa+4GkBZA9U7jZa6LDica4rLV9CpxHPFoKnh7oxOR74Zvot48mvhNLdnXj0r/AJ2KrNyr8fA2eVA86ynvMFDENiH7eZNXxPsk2V57cc1fCOvJplNZaqbE68PKRc6Z1qUJnvdd9NBNgMQ4okK1RPcWFZiMmNwkxlCnGpLCPReO9T29XIAEnLs8rDZ6r8s6sZA0Qq7+etvniv6AsG9yatuBSBwXynXz2xIQMHAL3t3YLm+c4yms3RQzCwwVT+/LijBVa85AUtlnb8BoFRNym4I9b4OIUCBdCtlpmHCkkkFxSBhboQorcYwlpJRiH5vrESA317BefBHni69CPh990z3hVKj02J48IddE3rItdg3P9BYZF1j2M7OH6c5y+EOCW68zZwrLsqX9ztTsf9Q== 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" The memory allocations for kprobes and BPF on arm64 can be placed anywhere in vmalloc address space and currently this is implemented with overrides of alloc_insn_page() and bpf_jit_alloc_exec() in arm64. Define EXECMEM_KPROBES and EXECMEM_BPF ranges in arm64::execmem_info and drop overrides of alloc_insn_page() and bpf_jit_alloc_exec(). Signed-off-by: Mike Rapoport (IBM) Acked-by: Will Deacon --- arch/arm64/kernel/module.c | 12 ++++++++++++ arch/arm64/kernel/probes/kprobes.c | 7 ------- arch/arm64/net/bpf_jit_comp.c | 11 ----------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c index b7a7a23f9f8f..a52240ea084b 100644 --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c @@ -146,6 +146,18 @@ struct execmem_info __init *execmem_arch_setup(void) .fallback_start = fallback_start, .fallback_end = fallback_end, }, + [EXECMEM_KPROBES] = { + .start = VMALLOC_START, + .end = VMALLOC_END, + .pgprot = PAGE_KERNEL_ROX, + .alignment = 1, + }, + [EXECMEM_BPF] = { + .start = VMALLOC_START, + .end = VMALLOC_END, + .pgprot = PAGE_KERNEL, + .alignment = 1, + }, }, }; diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c index 327855a11df2..4268678d0e86 100644 --- a/arch/arm64/kernel/probes/kprobes.c +++ b/arch/arm64/kernel/probes/kprobes.c @@ -129,13 +129,6 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p) return 0; } -void *alloc_insn_page(void) -{ - return __vmalloc_node_range(PAGE_SIZE, 1, VMALLOC_START, VMALLOC_END, - GFP_KERNEL, PAGE_KERNEL_ROX, VM_FLUSH_RESET_PERMS, - NUMA_NO_NODE, __builtin_return_address(0)); -} - /* arm kprobe: install breakpoint in text */ void __kprobes arch_arm_kprobe(struct kprobe *p) { diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 122021f9bdfc..456f5af239fc 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -1793,17 +1793,6 @@ u64 bpf_jit_alloc_exec_limit(void) return VMALLOC_END - VMALLOC_START; } -void *bpf_jit_alloc_exec(unsigned long size) -{ - /* Memory is intended to be executable, reset the pointer tag. */ - return kasan_reset_tag(vmalloc(size)); -} - -void bpf_jit_free_exec(void *addr) -{ - return vfree(addr); -} - /* Indicate the JIT backend supports mixing bpf2bpf and tailcalls. */ bool bpf_jit_supports_subprog_tailcalls(void) { From patchwork Sun May 5 16:06:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654473 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 65316C04FFE for ; Sun, 5 May 2024 16:09:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0526C6B00A1; Sun, 5 May 2024 12:09:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 003616B00A2; Sun, 5 May 2024 12:09:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE6FD6B00A3; Sun, 5 May 2024 12:09:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id BF2E26B00A1 for ; Sun, 5 May 2024 12:09:04 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7FFC64050A for ; Sun, 5 May 2024 16:09:04 +0000 (UTC) X-FDA: 82084826208.22.32F3D0F Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf16.hostedemail.com (Postfix) with ESMTP id 473F6180011 for ; Sun, 5 May 2024 16:09:01 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=V9ugyDvV; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1714925343; 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=zrqzgDNRKNGQexwDTOARBJiJTaC27zRhVtBugvEVZcA=; b=bJfv/r25YA3xCz10DuiezBlOz16mED+YumBAQBQryMZfXmuoeS8/cNSMc2m2f5kFV2Ckvg sh/OoG9ZKuu/dWKMr6M1Bj4bMBvbP4o58/r9GufATIar3jdVXCglznEuE51qFEMTLrIuze 48euC0T0QCYY6JEVrlEI2mKpaFuxp2I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714925343; a=rsa-sha256; cv=none; b=HkIhmT7alNhx0gPpSm0begVvWRsEDVX+AlahcE1DWddMuhwGNmadSCCfrK07loP2APlH8u 9gDWwo9NDE2IhyLZHdl3l7+tr0MM1C/LuvZ6k/WeL3WeuJqemoBZVbhIbHV1mSFA9mgERk z3+LSrXY3K/PaHgWGD2jdOUr/HTpQPg= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=V9ugyDvV; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 2CECBCE0ABA; Sun, 5 May 2024 16:08:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BD9DC4AF67; Sun, 5 May 2024 16:08:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925338; bh=QWGTfmxM6u4L/G8sJRSYS9LtFcq3UHArwE9pGA7ZHH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V9ugyDvVuvSs/IjM/QctAFO62DH9XQommkAxsxi4rdAIIff0oz6X9Qud+GkrDWACM RYQi+mih740PBAh9yI8vFEoeet38MCrU8nEZEy07fSxynn/GgVcd072Ihsx2EaHbY4 Z27gTNeymS2cYPNHB2tcTnBIsC4q2mJ6iW7K1ExKD7uVI3lUYcdOAwJFh/DfD+OqrW 7/wkJExymiv498tChhAzeu53jc+ORXNU0laY/Aj4OLEg+tUJsKk0iVBj9EfjrO1Ij0 XBfIVdsalrZBo/iYhsLX7slbIb8fHOpQyFnOlaCclEnik8YVloSy1kYXig+pYSJtTX 9TAT/kTQtt5fw== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Liviu Dudau , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 RESEND v8 11/16] powerpc: extend execmem_params for kprobes allocations Date: Sun, 5 May 2024 19:06:23 +0300 Message-ID: <20240505160628.2323363-12-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 473F6180011 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: cdu7qapqkthefjyt4c1t4b1ci6k4bwxy X-HE-Tag: 1714925341-917650 X-HE-Meta: U2FsdGVkX1/cFJJFaXCSi6IhM9GgC5o6/8uwH+0w0l0maA9tOrWpgTw+42tZy69joAe8o1/wLmnJSc1bmFBlqphxkL0vMdoks69fdbEYaNh3+My8mHhpEeFx993/MLtR3KXmBQ3G8+ZsBUgEdYSHpTX/AQQDHTCroIYOmwlOVeHHWyTix8fyiRibAwDAdIhKZpAnW6mfUDNMps+mhYLIkunpkxZEiOQvPrIDHWxKbkV2TH8dGqZUjAJXkB6EEI2ywIGtiLV3dG0WWKHSSrvm4kKg3bYJR3tXztOHbt9oE+QljNayaz2sqWPKdrHrOfnft1Jizk6J+DLtZnXEyJA2jNyLq/90APvJaBYLEKYS4SfhXJ6GYhbcvY9l1E7xkp+UWsBUmBhIhSrDI958U/t/QGFv6WiLJmrgPNKq86nVNjU7pf1tNTylrXJgFpBp0LjgSIXEc++vb52rj1mPcpsdTWbRFpBHc2eRJPDCFpDhYKawqFKsWYiV3XI91pTpWvq3vshH59Adw1XHXMSIh6ip8UBECfswBbh6U2dfunqLKjfiIwKT+cE3TsWYGfc6UjwdLc8RLzdmgi8yyCwrwofTLlUnM0pzpKl1MhDgrJ9E8/ivJcEAT8UogkHz8AZOltqYO4Ph4g896dSZFFAANTK5OehYVXGtkWlCR7+dZ7yVuKRpGve8PP7UP9+0bVhDHV1pUM1nsWP6NlIoMFaaSxJ2gGBdY7Zj36J/Z7gZ5uLUVklLxet57dUSH0cgBnZtybTXWuXYEDv7hUU6ulsP5I4Z6M0zwDs8RExcvHnUMoVIgYNEfk72yEonFg2k0nlE9cNEBz9Sv+YzsfxCEqjKw8suiAfi8gBusTNch2kAwuagdItDnLA9QR+sTUxMdMlr2EmplElmHNLquP7JpMV2TehNvGrO2hnlN+Xc0mz4/0nbKjPoQaclWd4ju74BQ/TY1X2RtXZ71JjFbHidI4rNH+6 gxmPJn9E KPul2fb7L9NHxnc5AZ/bZjyWgL2dPccTWRmMvlHqKMSzqgBkgKngIE1yklVqhLSrjiSCiN7iSHbsrit/6xJJ6y8wRBLn1Tyw5k825yaYFK+24olaj36AHbo+Yys2rVAg+77nE/8Cp6qLUGadVXuQMR8tm+DXLmBu6AfFGjgrDb3ZAIGGdlemT9GIFEMKgwIgeisROX61dhyf9oZn9TqaL690B3fuTXGFCO0jyXCUi13TuEiHdNTh5lzx6hDnpYop7lihwLzSP5XmyVBJ6NHF0MNcAIuFZxqNCQKFcjGT/8Aev61o3oUdclKzcxHljqh/3F6mHtyhmAN0iATfCnHbY4lQpLSgrAcv5nnWLpwoNOqN0ByENymVcbcanJy/drVh2mQmiIOfCUQN8Jwp5lPnRqE0O58lVk93kmjhqweK6rj6vI3sTk7RBNX530w== 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" powerpc overrides kprobes::alloc_insn_page() to remove writable permissions when STRICT_MODULE_RWX is on. Add definition of EXECMEM_KRPOBES to execmem_params to allow using the generic kprobes::alloc_insn_page() with the desired permissions. As powerpc uses breakpoint instructions to inject kprobes, it does not need to constrain kprobe allocations to the modules area and can use the entire vmalloc address space. Signed-off-by: Mike Rapoport (IBM) --- arch/powerpc/kernel/kprobes.c | 20 -------------------- arch/powerpc/kernel/module.c | 7 +++++++ 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c index 9fcd01bb2ce6..14c5ddec3056 100644 --- a/arch/powerpc/kernel/kprobes.c +++ b/arch/powerpc/kernel/kprobes.c @@ -126,26 +126,6 @@ kprobe_opcode_t *arch_adjust_kprobe_addr(unsigned long addr, unsigned long offse return (kprobe_opcode_t *)(addr + offset); } -void *alloc_insn_page(void) -{ - void *page; - - page = execmem_alloc(EXECMEM_KPROBES, PAGE_SIZE); - if (!page) - return NULL; - - if (strict_module_rwx_enabled()) { - int err = set_memory_rox((unsigned long)page, 1); - - if (err) - goto error; - } - return page; -error: - execmem_free(page); - return NULL; -} - int arch_prepare_kprobe(struct kprobe *p) { int ret = 0; diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c index ac80559015a3..2a23cf7e141b 100644 --- a/arch/powerpc/kernel/module.c +++ b/arch/powerpc/kernel/module.c @@ -94,6 +94,7 @@ static struct execmem_info execmem_info __ro_after_init; struct execmem_info __init *execmem_arch_setup(void) { + pgprot_t kprobes_prot = strict_module_rwx_enabled() ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC; pgprot_t prot = strict_module_rwx_enabled() ? PAGE_KERNEL : PAGE_KERNEL_EXEC; unsigned long fallback_start = 0, fallback_end = 0; unsigned long start, end; @@ -132,6 +133,12 @@ struct execmem_info __init *execmem_arch_setup(void) .fallback_start = fallback_start, .fallback_end = fallback_end, }, + [EXECMEM_KPROBES] = { + .start = VMALLOC_START, + .end = VMALLOC_END, + .pgprot = kprobes_prot, + .alignment = 1, + }, [EXECMEM_MODULE_DATA] = { .start = VMALLOC_START, .end = VMALLOC_END, From patchwork Sun May 5 16:06:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654474 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 D3F96C4345F for ; Sun, 5 May 2024 16:09:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 694466B008A; Sun, 5 May 2024 12:09:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6444E6B00A3; Sun, 5 May 2024 12:09:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4708F6B00A5; Sun, 5 May 2024 12:09:17 -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 254006B008A for ; Sun, 5 May 2024 12:09:17 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C51E8C0509 for ; Sun, 5 May 2024 16:09:16 +0000 (UTC) X-FDA: 82084826712.08.9839320 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf13.hostedemail.com (Postfix) with ESMTP id 61F7620011 for ; Sun, 5 May 2024 16:09:13 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HUOjkTY0; spf=pass (imf13.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1714925355; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=T7xAcO5/CoULMfPQgJR7+ovdKspvbrejEkNN0k7yqQ4=; b=tVhTYlMYWG/6l9J9YpKG6szz5qwuab8TQknGePCZkTj/FN08UBzEkSSUigyPtGBNsraZbE enJ02mO7/5cgkyu2Nq3H9CXEvUGPJVcb/B1ea1cfmEV/MDhQT6kqYJnFefoyttatQnpkQl 0+Lbe5kgXpTEIVACVaC/v9zmin4qJj8= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HUOjkTY0; spf=pass (imf13.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1714925355; a=rsa-sha256; cv=none; b=GDIR0YKQoMldHAEtL76r5voxlUtdhiuicpT5L4Bry0lOAp8tSvJ6hYLA9iecMl5/7iMR9k XavT4CEijwIX/VwxCoUPS99iRiOtqhn4OY0vcRN4x/2HmkzKPpugjkcIBlrPrgJA6n03YB sN47XyKn8kQ1yJXP+/X2mebYBQplVqM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id EB8C9CE0AB2; Sun, 5 May 2024 16:09:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED18EC4DDE2; Sun, 5 May 2024 16:08:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925350; bh=5OMBgTFrr36VXyNsljkCHRabEmmDGidsMIUvtOQa2/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HUOjkTY0MY4Avcwze7CfRrRzvZ8uJCMrkjJMVefuOUwtMJ5EdhxU7JNfJcc54972f 3oOhpCvwmoQ9Q1GPkwpinF5evj2fIyiPqFqm2A6rXSrs6J+b5saRST0hEptRzBNchm Auf1aZnNL10BrlRGGKBPvzfY9zUsb8WDijER56YCQ/T3mYlDNtjhQrdcTBiDC4+1sT 39YY7luhKaiRxcdo24wF1OZY2OK73xFTQ7yliDwpr/XtTQ0GXkhPn658Wk2etTrXSA AvAmAW4UhT0vEPNgqOYrKQUZ1Ak+cHmYwEhJlWambSDSLpHUwgD8LRPOLI6LdEFSyk +vzxUot7u+I/w== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Liviu Dudau , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 RESEND v8 12/16] arch: make execmem setup available regardless of CONFIG_MODULES Date: Sun, 5 May 2024 19:06:24 +0300 Message-ID: <20240505160628.2323363-13-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 61F7620011 X-Rspamd-Server: rspam06 X-Stat-Signature: ihyeh19rn9zi73r4aazaxbht99yqqdqb X-HE-Tag: 1714925353-948506 X-HE-Meta: U2FsdGVkX18L7Nga9BD3+sdP+Bel3xP7+kOJ1qm+EUHimkLomhl4epR4guG36btx+KvIrILu26rHF6iZmYmfNtCiiiCsceYdF80BsL83JOlyvaeDNftuGu56WFUOVLvQnxngHRBny3yLebcQpv/iBTzgkmUtJa+CiTI64GbhAhL8SMGnBconpYLi0v4NFgWZpiaxcdLdF3Mw6sFWJm8e3eI0H2fWYyEztDPYW3Ce2PMvSIf9KBmFr66dWkZwDpL/WwdDYdtYZkiCAWq1DfEayW2WEXDRh7pGRTBGi6B9mGzKt3pAkwQ+KOma9tKsVkDC7I5LRSyMTFixMKfNgu85/uD5mEBYIeFyNBmAIAZdUSDj08DY1w0xcqxCJbN9SbLoORFLlZY1Lz4/9k/md4c1Urr+jJKrEFTze0NYSZk9om1XBeA1IyN0vIQfRmqNQGFQ/pWcMDqLRGrqKuwAT7puI4TaDnMtkHPqjz5mktA1VFX0nNGSaEQNngR+SjHuVGRVdxNxsMFH903rODcxRx94yGplmzLyrYzY34s0+74mTQ+Y44CEC4Y3zBvOyFyRt9ltS/T1cWjuq7XGkw06ybZbpEUrU3VntvexUQ6H8Q11UNfiiZrbOpDVcra11ksnVd7RKX0xSvqVGHNDQ28SsjNdBCHNXUZH3zCabPqSSLTzuMsnHsjV78uTtzDvM3+HfDKhvImR4M7DZ3Ov/5p1HWZcCjjTco7jiW7sVurkXVzXo58tSlm8FDAfos6X3SMAYAQ0qG1wp8ICdUZbeCvU5yFEbYpS/5XCIvPwU+z1HsUy67xVNdi85kPd5ItRztlj0wydYw1R/6gJw/gcosCN85/Bvpj8++4ojs/AHnd8H1p2CvQ4C1qfZ6WWzOXok8Bx4lk8iU8ZDTz8OJ0puDhqkrX5F7nrdh2bccDcAd4Sh+n6tMochumHJwwcprxGkUTw8M2EF4GJiUFIg2c3ejh8hN3 zEhGNE7P co8yOUDTOxXieM2G4UebaKMwJBZNbOKzcW24/xWm4SDcSMFnyWVBUVgXuYCB8pY+qihh1+nHOPavwxQyGZW//MvAnmJkjm5CEa+wvV5e4PYffIXGJOnA8yKpZHwx2KnM1EvRDN/uErsH6mDZ1sldj41TDog5RFTa41FUm+7OjVBnMUtTxAARoLcj/8sEWdgij5uq+uqy4UybFGoQBHopO1jACH8/IYNv9QDqFtqSvgjBsevYDMfKHDDfjE/C9attZ6CIhDxnNKpa6nvG+iSuerFDe8x8hq4fEuyRBfYgBZhpWhDNSEmtBG1ZCBpo+WFCnbm2zBtWwI09QTAccEDTPdi1CJ2xtTDEUSXHajHNoARaE/iA4YCYUKLsyU+a3W0Xi20QcBMWZ29joIwbaG1Cb2gb6WCfKFjaGS+BfFQ16WdIEDXMAHBm0N4BpGQO3nYv5wQNqGMmLMS2Jx5zjT86S0GNxLmXkRwWyhlZt6XSHMQzA9OSaEYnNglKnkD3cqjF9XRJES8ZWRkGjrxnq6ea9usaPGw== 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" execmem does not depend on modules, on the contrary modules use execmem. To make execmem available when CONFIG_MODULES=n, for instance for kprobes, split execmem_params initialization out from arch/*/kernel/module.c and compile it when CONFIG_EXECMEM=y Signed-off-by: Mike Rapoport (IBM) Reviewed-by: Philippe Mathieu-Daudé --- arch/arm/kernel/module.c | 43 ---------- arch/arm/mm/init.c | 45 +++++++++++ arch/arm64/kernel/module.c | 140 --------------------------------- arch/arm64/mm/init.c | 140 +++++++++++++++++++++++++++++++++ arch/loongarch/kernel/module.c | 19 ----- arch/loongarch/mm/init.c | 21 +++++ arch/mips/kernel/module.c | 22 ------ arch/mips/mm/init.c | 23 ++++++ arch/nios2/kernel/module.c | 20 ----- arch/nios2/mm/init.c | 21 +++++ arch/parisc/kernel/module.c | 20 ----- arch/parisc/mm/init.c | 23 +++++- arch/powerpc/kernel/module.c | 63 --------------- arch/powerpc/mm/mem.c | 64 +++++++++++++++ arch/riscv/kernel/module.c | 34 -------- arch/riscv/mm/init.c | 35 +++++++++ arch/s390/kernel/module.c | 27 ------- arch/s390/mm/init.c | 30 +++++++ arch/sparc/kernel/module.c | 19 ----- arch/sparc/mm/Makefile | 2 + arch/sparc/mm/execmem.c | 21 +++++ arch/x86/kernel/module.c | 27 ------- arch/x86/mm/init.c | 29 +++++++ 23 files changed, 453 insertions(+), 435 deletions(-) create mode 100644 arch/sparc/mm/execmem.c diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c index a98fdf6ff26c..677f218f7e84 100644 --- a/arch/arm/kernel/module.c +++ b/arch/arm/kernel/module.c @@ -12,57 +12,14 @@ #include #include #include -#include #include #include -#include -#include #include #include #include #include -#ifdef CONFIG_XIP_KERNEL -/* - * The XIP kernel text is mapped in the module area for modules and - * some other stuff to work without any indirect relocations. - * MODULES_VADDR is redefined here and not in asm/memory.h to avoid - * recompiling the whole kernel when CONFIG_XIP_KERNEL is turned on/off. - */ -#undef MODULES_VADDR -#define MODULES_VADDR (((unsigned long)_exiprom + ~PMD_MASK) & PMD_MASK) -#endif - -#ifdef CONFIG_MMU -static struct execmem_info execmem_info __ro_after_init; - -struct execmem_info __init *execmem_arch_setup(void) -{ - unsigned long fallback_start = 0, fallback_end = 0; - - if (IS_ENABLED(CONFIG_ARM_MODULE_PLTS)) { - fallback_start = VMALLOC_START; - fallback_end = VMALLOC_END; - } - - execmem_info = (struct execmem_info){ - .ranges = { - [EXECMEM_DEFAULT] = { - .start = MODULES_VADDR, - .end = MODULES_END, - .pgprot = PAGE_KERNEL_EXEC, - .alignment = 1, - .fallback_start = fallback_start, - .fallback_end = fallback_end, - }, - }, - }; - - return &execmem_info; -} -#endif - bool module_init_section(const char *name) { return strstarts(name, ".init") || diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index e8c6f4be0ce1..5345d218899a 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -486,3 +487,47 @@ void free_initrd_mem(unsigned long start, unsigned long end) free_reserved_area((void *)start, (void *)end, -1, "initrd"); } #endif + +#ifdef CONFIG_EXECMEM + +#ifdef CONFIG_XIP_KERNEL +/* + * The XIP kernel text is mapped in the module area for modules and + * some other stuff to work without any indirect relocations. + * MODULES_VADDR is redefined here and not in asm/memory.h to avoid + * recompiling the whole kernel when CONFIG_XIP_KERNEL is turned on/off. + */ +#undef MODULES_VADDR +#define MODULES_VADDR (((unsigned long)_exiprom + ~PMD_MASK) & PMD_MASK) +#endif + +#ifdef CONFIG_MMU +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) +{ + unsigned long fallback_start = 0, fallback_end = 0; + + if (IS_ENABLED(CONFIG_ARM_MODULE_PLTS)) { + fallback_start = VMALLOC_START; + fallback_end = VMALLOC_END; + } + + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = MODULES_VADDR, + .end = MODULES_END, + .pgprot = PAGE_KERNEL_EXEC, + .alignment = 1, + .fallback_start = fallback_start, + .fallback_end = fallback_end, + }, + }, + }; + + return &execmem_info; +} +#endif /* CONFIG_MMU */ + +#endif /* CONFIG_EXECMEM */ diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c index a52240ea084b..36b25af56324 100644 --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c @@ -12,158 +12,18 @@ #include #include #include -#include #include #include #include #include #include #include -#include -#include #include #include #include #include -static u64 module_direct_base __ro_after_init = 0; -static u64 module_plt_base __ro_after_init = 0; - -/* - * Choose a random page-aligned base address for a window of 'size' bytes which - * entirely contains the interval [start, end - 1]. - */ -static u64 __init random_bounding_box(u64 size, u64 start, u64 end) -{ - u64 max_pgoff, pgoff; - - if ((end - start) >= size) - return 0; - - max_pgoff = (size - (end - start)) / PAGE_SIZE; - pgoff = get_random_u32_inclusive(0, max_pgoff); - - return start - pgoff * PAGE_SIZE; -} - -/* - * Modules may directly reference data and text anywhere within the kernel - * image and other modules. References using PREL32 relocations have a +/-2G - * range, and so we need to ensure that the entire kernel image and all modules - * fall within a 2G window such that these are always within range. - * - * Modules may directly branch to functions and code within the kernel text, - * and to functions and code within other modules. These branches will use - * CALL26/JUMP26 relocations with a +/-128M range. Without PLTs, we must ensure - * that the entire kernel text and all module text falls within a 128M window - * such that these are always within range. With PLTs, we can expand this to a - * 2G window. - * - * We chose the 128M region to surround the entire kernel image (rather than - * just the text) as using the same bounds for the 128M and 2G regions ensures - * by construction that we never select a 128M region that is not a subset of - * the 2G region. For very large and unusual kernel configurations this means - * we may fall back to PLTs where they could have been avoided, but this keeps - * the logic significantly simpler. - */ -static int __init module_init_limits(void) -{ - u64 kernel_end = (u64)_end; - u64 kernel_start = (u64)_text; - u64 kernel_size = kernel_end - kernel_start; - - /* - * The default modules region is placed immediately below the kernel - * image, and is large enough to use the full 2G relocation range. - */ - BUILD_BUG_ON(KIMAGE_VADDR != MODULES_END); - BUILD_BUG_ON(MODULES_VSIZE < SZ_2G); - - if (!kaslr_enabled()) { - if (kernel_size < SZ_128M) - module_direct_base = kernel_end - SZ_128M; - if (kernel_size < SZ_2G) - module_plt_base = kernel_end - SZ_2G; - } else { - u64 min = kernel_start; - u64 max = kernel_end; - - if (IS_ENABLED(CONFIG_RANDOMIZE_MODULE_REGION_FULL)) { - pr_info("2G module region forced by RANDOMIZE_MODULE_REGION_FULL\n"); - } else { - module_direct_base = random_bounding_box(SZ_128M, min, max); - if (module_direct_base) { - min = module_direct_base; - max = module_direct_base + SZ_128M; - } - } - - module_plt_base = random_bounding_box(SZ_2G, min, max); - } - - pr_info("%llu pages in range for non-PLT usage", - module_direct_base ? (SZ_128M - kernel_size) / PAGE_SIZE : 0); - pr_info("%llu pages in range for PLT usage", - module_plt_base ? (SZ_2G - kernel_size) / PAGE_SIZE : 0); - - return 0; -} - -static struct execmem_info execmem_info __ro_after_init; - -struct execmem_info __init *execmem_arch_setup(void) -{ - unsigned long fallback_start = 0, fallback_end = 0; - unsigned long start = 0, end = 0; - - module_init_limits(); - - /* - * Where possible, prefer to allocate within direct branch range of the - * kernel such that no PLTs are necessary. - */ - if (module_direct_base) { - start = module_direct_base; - end = module_direct_base + SZ_128M; - - if (module_plt_base) { - fallback_start = module_plt_base; - fallback_end = module_plt_base + SZ_2G; - } - } else if (module_plt_base) { - start = module_plt_base; - end = module_plt_base + SZ_2G; - } - - execmem_info = (struct execmem_info){ - .ranges = { - [EXECMEM_DEFAULT] = { - .start = start, - .end = end, - .pgprot = PAGE_KERNEL, - .alignment = 1, - .fallback_start = fallback_start, - .fallback_end = fallback_end, - }, - [EXECMEM_KPROBES] = { - .start = VMALLOC_START, - .end = VMALLOC_END, - .pgprot = PAGE_KERNEL_ROX, - .alignment = 1, - }, - [EXECMEM_BPF] = { - .start = VMALLOC_START, - .end = VMALLOC_END, - .pgprot = PAGE_KERNEL, - .alignment = 1, - }, - }, - }; - - return &execmem_info; -} - enum aarch64_reloc_op { RELOC_OP_NONE, RELOC_OP_ABS, diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 03efd86dce0a..9b5ab6818f7f 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -432,3 +433,142 @@ void dump_mem_limit(void) pr_emerg("Memory Limit: none\n"); } } + +#ifdef CONFIG_EXECMEM +static u64 module_direct_base __ro_after_init = 0; +static u64 module_plt_base __ro_after_init = 0; + +/* + * Choose a random page-aligned base address for a window of 'size' bytes which + * entirely contains the interval [start, end - 1]. + */ +static u64 __init random_bounding_box(u64 size, u64 start, u64 end) +{ + u64 max_pgoff, pgoff; + + if ((end - start) >= size) + return 0; + + max_pgoff = (size - (end - start)) / PAGE_SIZE; + pgoff = get_random_u32_inclusive(0, max_pgoff); + + return start - pgoff * PAGE_SIZE; +} + +/* + * Modules may directly reference data and text anywhere within the kernel + * image and other modules. References using PREL32 relocations have a +/-2G + * range, and so we need to ensure that the entire kernel image and all modules + * fall within a 2G window such that these are always within range. + * + * Modules may directly branch to functions and code within the kernel text, + * and to functions and code within other modules. These branches will use + * CALL26/JUMP26 relocations with a +/-128M range. Without PLTs, we must ensure + * that the entire kernel text and all module text falls within a 128M window + * such that these are always within range. With PLTs, we can expand this to a + * 2G window. + * + * We chose the 128M region to surround the entire kernel image (rather than + * just the text) as using the same bounds for the 128M and 2G regions ensures + * by construction that we never select a 128M region that is not a subset of + * the 2G region. For very large and unusual kernel configurations this means + * we may fall back to PLTs where they could have been avoided, but this keeps + * the logic significantly simpler. + */ +static int __init module_init_limits(void) +{ + u64 kernel_end = (u64)_end; + u64 kernel_start = (u64)_text; + u64 kernel_size = kernel_end - kernel_start; + + /* + * The default modules region is placed immediately below the kernel + * image, and is large enough to use the full 2G relocation range. + */ + BUILD_BUG_ON(KIMAGE_VADDR != MODULES_END); + BUILD_BUG_ON(MODULES_VSIZE < SZ_2G); + + if (!kaslr_enabled()) { + if (kernel_size < SZ_128M) + module_direct_base = kernel_end - SZ_128M; + if (kernel_size < SZ_2G) + module_plt_base = kernel_end - SZ_2G; + } else { + u64 min = kernel_start; + u64 max = kernel_end; + + if (IS_ENABLED(CONFIG_RANDOMIZE_MODULE_REGION_FULL)) { + pr_info("2G module region forced by RANDOMIZE_MODULE_REGION_FULL\n"); + } else { + module_direct_base = random_bounding_box(SZ_128M, min, max); + if (module_direct_base) { + min = module_direct_base; + max = module_direct_base + SZ_128M; + } + } + + module_plt_base = random_bounding_box(SZ_2G, min, max); + } + + pr_info("%llu pages in range for non-PLT usage", + module_direct_base ? (SZ_128M - kernel_size) / PAGE_SIZE : 0); + pr_info("%llu pages in range for PLT usage", + module_plt_base ? (SZ_2G - kernel_size) / PAGE_SIZE : 0); + + return 0; +} + +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) +{ + unsigned long fallback_start = 0, fallback_end = 0; + unsigned long start = 0, end = 0; + + module_init_limits(); + + /* + * Where possible, prefer to allocate within direct branch range of the + * kernel such that no PLTs are necessary. + */ + if (module_direct_base) { + start = module_direct_base; + end = module_direct_base + SZ_128M; + + if (module_plt_base) { + fallback_start = module_plt_base; + fallback_end = module_plt_base + SZ_2G; + } + } else if (module_plt_base) { + start = module_plt_base; + end = module_plt_base + SZ_2G; + } + + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = start, + .end = end, + .pgprot = PAGE_KERNEL, + .alignment = 1, + .fallback_start = fallback_start, + .fallback_end = fallback_end, + }, + [EXECMEM_KPROBES] = { + .start = VMALLOC_START, + .end = VMALLOC_END, + .pgprot = PAGE_KERNEL_ROX, + .alignment = 1, + }, + [EXECMEM_BPF] = { + .start = VMALLOC_START, + .end = VMALLOC_END, + .pgprot = PAGE_KERNEL, + .alignment = 1, + }, + }, + }; + + return &execmem_info; +} +#endif /* CONFIG_EXECMEM */ diff --git a/arch/loongarch/kernel/module.c b/arch/loongarch/kernel/module.c index ca6dd7ea1610..36d6d9eeb7c7 100644 --- a/arch/loongarch/kernel/module.c +++ b/arch/loongarch/kernel/module.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -491,24 +490,6 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, return 0; } -static struct execmem_info execmem_info __ro_after_init; - -struct execmem_info __init *execmem_arch_setup(void) -{ - execmem_info = (struct execmem_info){ - .ranges = { - [EXECMEM_DEFAULT] = { - .start = MODULES_VADDR, - .end = MODULES_END, - .pgprot = PAGE_KERNEL, - .alignment = 1, - }, - }, - }; - - return &execmem_info; -} - static void module_init_ftrace_plt(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, struct module *mod) { diff --git a/arch/loongarch/mm/init.c b/arch/loongarch/mm/init.c index 4dd53427f657..bf789d114c2d 100644 --- a/arch/loongarch/mm/init.c +++ b/arch/loongarch/mm/init.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -248,3 +249,23 @@ EXPORT_SYMBOL(invalid_pmd_table); #endif pte_t invalid_pte_table[PTRS_PER_PTE] __page_aligned_bss; EXPORT_SYMBOL(invalid_pte_table); + +#ifdef CONFIG_EXECMEM +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) +{ + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = MODULES_VADDR, + .end = MODULES_END, + .pgprot = PAGE_KERNEL, + .alignment = 1, + }, + }, + }; + + return &execmem_info; +} +#endif /* CONFIG_EXECMEM */ diff --git a/arch/mips/kernel/module.c b/arch/mips/kernel/module.c index 59225a3cf918..ba0f62d8eff5 100644 --- a/arch/mips/kernel/module.c +++ b/arch/mips/kernel/module.c @@ -13,14 +13,12 @@ #include #include #include -#include #include #include #include #include #include #include -#include #include struct mips_hi16 { @@ -32,26 +30,6 @@ struct mips_hi16 { static LIST_HEAD(dbe_list); static DEFINE_SPINLOCK(dbe_lock); -#ifdef MODULES_VADDR -static struct execmem_info execmem_info __ro_after_init; - -struct execmem_info __init *execmem_arch_setup(void) -{ - execmem_info = (struct execmem_info){ - .ranges = { - [EXECMEM_DEFAULT] = { - .start = MODULES_VADDR, - .end = MODULES_END, - .pgprot = PAGE_KERNEL, - .alignment = 1, - }, - }, - }; - - return &execmem_info; -} -#endif - static void apply_r_mips_32(u32 *location, u32 base, Elf_Addr v) { *location = base + v; diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c index 39f129205b0c..4583d1a2a73e 100644 --- a/arch/mips/mm/init.c +++ b/arch/mips/mm/init.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -576,3 +577,25 @@ EXPORT_SYMBOL_GPL(invalid_pmd_table); #endif pte_t invalid_pte_table[PTRS_PER_PTE] __page_aligned_bss; EXPORT_SYMBOL(invalid_pte_table); + +#ifdef CONFIG_EXECMEM +#ifdef MODULES_VADDR +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) +{ + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = MODULES_VADDR, + .end = MODULES_END, + .pgprot = PAGE_KERNEL, + .alignment = 1, + }, + }, + }; + + return &execmem_info; +} +#endif +#endif /* CONFIG_EXECMEM */ diff --git a/arch/nios2/kernel/module.c b/arch/nios2/kernel/module.c index 0d1ee86631fc..f4483243578d 100644 --- a/arch/nios2/kernel/module.c +++ b/arch/nios2/kernel/module.c @@ -13,33 +13,13 @@ #include #include #include -#include #include #include #include #include -#include #include -static struct execmem_info execmem_info __ro_after_init; - -struct execmem_info __init *execmem_arch_setup(void) -{ - execmem_info = (struct execmem_info){ - .ranges = { - [EXECMEM_DEFAULT] = { - .start = MODULES_VADDR, - .end = MODULES_END, - .pgprot = PAGE_KERNEL_EXEC, - .alignment = 1, - }, - }, - }; - - return &execmem_info; -} - int apply_relocate_add(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, unsigned int relsec, struct module *mod) diff --git a/arch/nios2/mm/init.c b/arch/nios2/mm/init.c index 7bc82ee889c9..3459df28afee 100644 --- a/arch/nios2/mm/init.c +++ b/arch/nios2/mm/init.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -143,3 +144,23 @@ static const pgprot_t protection_map[16] = { [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] = MKP(1, 1, 1) }; DECLARE_VM_GET_PAGE_PROT + +#ifdef CONFIG_EXECMEM +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) +{ + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = MODULES_VADDR, + .end = MODULES_END, + .pgprot = PAGE_KERNEL_EXEC, + .alignment = 1, + }, + }, + }; + + return &execmem_info; +} +#endif /* CONFIG_EXECMEM */ diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c index bdfa85e10c1b..4e5d991b2b65 100644 --- a/arch/parisc/kernel/module.c +++ b/arch/parisc/kernel/module.c @@ -41,7 +41,6 @@ #include #include -#include #include #include #include @@ -49,7 +48,6 @@ #include #include #include -#include #include #include @@ -174,24 +172,6 @@ static inline int reassemble_22(int as22) ((as22 & 0x0003ff) << 3)); } -static struct execmem_info execmem_info __ro_after_init; - -struct execmem_info __init *execmem_arch_setup(void) -{ - execmem_info = (struct execmem_info){ - .ranges = { - [EXECMEM_DEFAULT] = { - .start = VMALLOC_START, - .end = VMALLOC_END, - .pgprot = PAGE_KERNEL_RWX, - .alignment = 1, - }, - }, - }; - - return &execmem_info; -} - #ifndef CONFIG_64BIT static inline unsigned long count_gots(const Elf_Rela *rela, unsigned long n) { diff --git a/arch/parisc/mm/init.c b/arch/parisc/mm/init.c index f876af56e13f..34d91cb8b259 100644 --- a/arch/parisc/mm/init.c +++ b/arch/parisc/mm/init.c @@ -24,6 +24,7 @@ #include /* for node_online_map */ #include /* for release_pages */ #include +#include #include #include @@ -481,7 +482,7 @@ void free_initmem(void) /* finally dump all the instructions which were cached, since the * pages are no-longer executable */ flush_icache_range(init_begin, init_end); - + free_initmem_default(POISON_FREE_INITMEM); /* set up a new led state on systems shipped LED State panel */ @@ -992,3 +993,23 @@ static const pgprot_t protection_map[16] = { [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] = PAGE_RWX }; DECLARE_VM_GET_PAGE_PROT + +#ifdef CONFIG_EXECMEM +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) +{ + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = VMALLOC_START, + .end = VMALLOC_END, + .pgprot = PAGE_KERNEL_RWX, + .alignment = 1, + }, + }, + }; + + return &execmem_info; +} +#endif /* CONFIG_EXECMEM */ diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c index 2a23cf7e141b..77ea82e9dc5f 100644 --- a/arch/powerpc/kernel/module.c +++ b/arch/powerpc/kernel/module.c @@ -7,10 +7,8 @@ #include #include #include -#include #include #include -#include #include #include #include @@ -89,64 +87,3 @@ int module_finalize(const Elf_Ehdr *hdr, return 0; } - -static struct execmem_info execmem_info __ro_after_init; - -struct execmem_info __init *execmem_arch_setup(void) -{ - pgprot_t kprobes_prot = strict_module_rwx_enabled() ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC; - pgprot_t prot = strict_module_rwx_enabled() ? PAGE_KERNEL : PAGE_KERNEL_EXEC; - unsigned long fallback_start = 0, fallback_end = 0; - unsigned long start, end; - - /* - * BOOK3S_32 and 8xx define MODULES_VADDR for text allocations and - * allow allocating data in the entire vmalloc space - */ -#ifdef MODULES_VADDR - unsigned long limit = (unsigned long)_etext - SZ_32M; - - BUILD_BUG_ON(TASK_SIZE > MODULES_VADDR); - - /* First try within 32M limit from _etext to avoid branch trampolines */ - if (MODULES_VADDR < PAGE_OFFSET && MODULES_END > limit) { - start = limit; - fallback_start = MODULES_VADDR; - fallback_end = MODULES_END; - } else { - start = MODULES_VADDR; - } - - end = MODULES_END; -#else - start = VMALLOC_START; - end = VMALLOC_END; -#endif - - execmem_info = (struct execmem_info){ - .ranges = { - [EXECMEM_DEFAULT] = { - .start = start, - .end = end, - .pgprot = prot, - .alignment = 1, - .fallback_start = fallback_start, - .fallback_end = fallback_end, - }, - [EXECMEM_KPROBES] = { - .start = VMALLOC_START, - .end = VMALLOC_END, - .pgprot = kprobes_prot, - .alignment = 1, - }, - [EXECMEM_MODULE_DATA] = { - .start = VMALLOC_START, - .end = VMALLOC_END, - .pgprot = PAGE_KERNEL, - .alignment = 1, - }, - }, - }; - - return &execmem_info; -} diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c index 3a440004b97d..5de62a3c1d4b 100644 --- a/arch/powerpc/mm/mem.c +++ b/arch/powerpc/mm/mem.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -406,3 +407,66 @@ int devmem_is_allowed(unsigned long pfn) * the EHEA driver. Drop this when drivers/net/ethernet/ibm/ehea is removed. */ EXPORT_SYMBOL_GPL(walk_system_ram_range); + +#ifdef CONFIG_EXECMEM +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) +{ + pgprot_t kprobes_prot = strict_module_rwx_enabled() ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC; + pgprot_t prot = strict_module_rwx_enabled() ? PAGE_KERNEL : PAGE_KERNEL_EXEC; + unsigned long fallback_start = 0, fallback_end = 0; + unsigned long start, end; + + /* + * BOOK3S_32 and 8xx define MODULES_VADDR for text allocations and + * allow allocating data in the entire vmalloc space + */ +#ifdef MODULES_VADDR + unsigned long limit = (unsigned long)_etext - SZ_32M; + + BUILD_BUG_ON(TASK_SIZE > MODULES_VADDR); + + /* First try within 32M limit from _etext to avoid branch trampolines */ + if (MODULES_VADDR < PAGE_OFFSET && MODULES_END > limit) { + start = limit; + fallback_start = MODULES_VADDR; + fallback_end = MODULES_END; + } else { + start = MODULES_VADDR; + } + + end = MODULES_END; +#else + start = VMALLOC_START; + end = VMALLOC_END; +#endif + + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = start, + .end = end, + .pgprot = prot, + .alignment = 1, + .fallback_start = fallback_start, + .fallback_end = fallback_end, + }, + [EXECMEM_KPROBES] = { + .start = VMALLOC_START, + .end = VMALLOC_END, + .pgprot = kprobes_prot, + .alignment = 1, + }, + [EXECMEM_MODULE_DATA] = { + .start = VMALLOC_START, + .end = VMALLOC_END, + .pgprot = PAGE_KERNEL, + .alignment = 1, + }, + }, + }; + + return &execmem_info; +} +#endif /* CONFIG_EXECMEM */ diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index 0e6415f00fca..906f9a3a5d65 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -11,10 +11,8 @@ #include #include #include -#include #include #include -#include #include #include @@ -906,38 +904,6 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, return 0; } -#ifdef CONFIG_MMU -static struct execmem_info execmem_info __ro_after_init; - -struct execmem_info __init *execmem_arch_setup(void) -{ - execmem_info = (struct execmem_info){ - .ranges = { - [EXECMEM_DEFAULT] = { - .start = MODULES_VADDR, - .end = MODULES_END, - .pgprot = PAGE_KERNEL, - .alignment = 1, - }, - [EXECMEM_KPROBES] = { - .start = VMALLOC_START, - .end = VMALLOC_END, - .pgprot = PAGE_KERNEL_READ_EXEC, - .alignment = 1, - }, - [EXECMEM_BPF] = { - .start = BPF_JIT_REGION_START, - .end = BPF_JIT_REGION_END, - .pgprot = PAGE_KERNEL, - .alignment = PAGE_SIZE, - }, - }, - }; - - return &execmem_info; -} -#endif - int module_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, struct module *me) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index fe8e159394d8..a8290609554f 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -24,6 +24,7 @@ #include #endif #include +#include #include #include @@ -1481,3 +1482,37 @@ void __init pgtable_cache_init(void) preallocate_pgd_pages_range(MODULES_VADDR, MODULES_END, "bpf/modules"); } #endif + +#ifdef CONFIG_EXECMEM +#ifdef CONFIG_MMU +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) +{ + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = MODULES_VADDR, + .end = MODULES_END, + .pgprot = PAGE_KERNEL, + .alignment = 1, + }, + [EXECMEM_KPROBES] = { + .start = VMALLOC_START, + .end = VMALLOC_END, + .pgprot = PAGE_KERNEL_READ_EXEC, + .alignment = 1, + }, + [EXECMEM_BPF] = { + .start = BPF_JIT_REGION_START, + .end = BPF_JIT_REGION_END, + .pgprot = PAGE_KERNEL, + .alignment = PAGE_SIZE, + }, + }, + }; + + return &execmem_info; +} +#endif /* CONFIG_MMU */ +#endif /* CONFIG_EXECMEM */ diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c index 7fee64fdc1bb..91e207b50394 100644 --- a/arch/s390/kernel/module.c +++ b/arch/s390/kernel/module.c @@ -37,33 +37,6 @@ #define PLT_ENTRY_SIZE 22 -static struct execmem_info execmem_info __ro_after_init; - -struct execmem_info __init *execmem_arch_setup(void) -{ - unsigned long module_load_offset = 0; - unsigned long start; - - if (kaslr_enabled()) - module_load_offset = get_random_u32_inclusive(1, 1024) * PAGE_SIZE; - - start = MODULES_VADDR + module_load_offset; - - execmem_info = (struct execmem_info){ - .ranges = { - [EXECMEM_DEFAULT] = { - .flags = EXECMEM_KASAN_SHADOW, - .start = start, - .end = MODULES_END, - .pgprot = PAGE_KERNEL, - .alignment = MODULE_ALIGN, - }, - }, - }; - - return &execmem_info; -} - #ifdef CONFIG_FUNCTION_TRACER void module_arch_cleanup(struct module *mod) { diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c index f6391442c0c2..e769d2726f4e 100644 --- a/arch/s390/mm/init.c +++ b/arch/s390/mm/init.c @@ -49,6 +49,7 @@ #include #include #include +#include pgd_t swapper_pg_dir[PTRS_PER_PGD] __section(".bss..swapper_pg_dir"); pgd_t invalid_pg_dir[PTRS_PER_PGD] __section(".bss..invalid_pg_dir"); @@ -302,3 +303,32 @@ void arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap) vmem_remove_mapping(start, size); } #endif /* CONFIG_MEMORY_HOTPLUG */ + +#ifdef CONFIG_EXECMEM +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) +{ + unsigned long module_load_offset = 0; + unsigned long start; + + if (kaslr_enabled()) + module_load_offset = get_random_u32_inclusive(1, 1024) * PAGE_SIZE; + + start = MODULES_VADDR + module_load_offset; + + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .flags = EXECMEM_KASAN_SHADOW, + .start = start, + .end = MODULES_END, + .pgprot = PAGE_KERNEL, + .alignment = MODULE_ALIGN, + }, + }, + }; + + return &execmem_info; +} +#endif /* CONFIG_EXECMEM */ diff --git a/arch/sparc/kernel/module.c b/arch/sparc/kernel/module.c index 8b7ee45defc3..b8c51cc23d96 100644 --- a/arch/sparc/kernel/module.c +++ b/arch/sparc/kernel/module.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include @@ -22,24 +21,6 @@ #include "entry.h" -static struct execmem_info execmem_info __ro_after_init; - -struct execmem_info __init *execmem_arch_setup(void) -{ - execmem_info = (struct execmem_info){ - .ranges = { - [EXECMEM_DEFAULT] = { - .start = MODULES_VADDR, - .end = MODULES_END, - .pgprot = PAGE_KERNEL, - .alignment = 1, - }, - }, - }; - - return &execmem_info; -} - /* Make generic code ignore STT_REGISTER dummy undefined symbols. */ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs, diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile index 809d993f6d88..2d1752108d77 100644 --- a/arch/sparc/mm/Makefile +++ b/arch/sparc/mm/Makefile @@ -14,3 +14,5 @@ obj-$(CONFIG_SPARC32) += leon_mm.o # Only used by sparc64 obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o + +obj-$(CONFIG_EXECMEM) += execmem.o diff --git a/arch/sparc/mm/execmem.c b/arch/sparc/mm/execmem.c new file mode 100644 index 000000000000..0fac97dd5728 --- /dev/null +++ b/arch/sparc/mm/execmem.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include + +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) +{ + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = MODULES_VADDR, + .end = MODULES_END, + .pgprot = PAGE_KERNEL, + .alignment = 1, + }, + }, + }; + + return &execmem_info; +} diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index 45b1a7c03379..837450b6e882 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include @@ -37,32 +36,6 @@ do { \ } while (0) #endif -static struct execmem_info execmem_info __ro_after_init; - -struct execmem_info __init *execmem_arch_setup(void) -{ - unsigned long start, offset = 0; - - if (kaslr_enabled()) - offset = get_random_u32_inclusive(1, 1024) * PAGE_SIZE; - - start = MODULES_VADDR + offset; - - execmem_info = (struct execmem_info){ - .ranges = { - [EXECMEM_DEFAULT] = { - .flags = EXECMEM_KASAN_SHADOW, - .start = start, - .end = MODULES_END, - .pgprot = PAGE_KERNEL, - .alignment = MODULE_ALIGN, - }, - }, - }; - - return &execmem_info; -} - #ifdef CONFIG_X86_32 int apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index 679893ea5e68..be4fee17b717 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -1099,3 +1100,31 @@ unsigned long arch_max_swapfile_size(void) return pages; } #endif + +#ifdef CONFIG_EXECMEM +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) +{ + unsigned long start, offset = 0; + + if (kaslr_enabled()) + offset = get_random_u32_inclusive(1, 1024) * PAGE_SIZE; + + start = MODULES_VADDR + offset; + + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .flags = EXECMEM_KASAN_SHADOW, + .start = start, + .end = MODULES_END, + .pgprot = PAGE_KERNEL, + .alignment = MODULE_ALIGN, + }, + }, + }; + + return &execmem_info; +} +#endif /* CONFIG_EXECMEM */ From patchwork Sun May 5 16:06:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654475 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 D846EC4345F for ; Sun, 5 May 2024 16:09:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6944B6B0092; Sun, 5 May 2024 12:09:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 644EE6B00A6; Sun, 5 May 2024 12:09:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E5716B00A7; Sun, 5 May 2024 12:09:25 -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 30A2C6B0092 for ; Sun, 5 May 2024 12:09:25 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E0934C0313 for ; Sun, 5 May 2024 16:09:24 +0000 (UTC) X-FDA: 82084827048.06.BF40251 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf16.hostedemail.com (Postfix) with ESMTP id 3B34718000F for ; Sun, 5 May 2024 16:09:23 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=T7Y2tIoI; spf=pass (imf16.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=1714925363; 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=bP6HuoUMXi9ivDdJhuywQ3Y30eb1dSG7Z8hyYP5sWNc=; b=BahXYWLskul0BYODfxozKoAHG+VjNURddCetUsFj2diQY3H6AttBG7OnAONCk2HFEKQHia c8LUuy1JGJzpf496rnjY6aFdagimXbZaRKDZ7KwTFiPHbQLBAMXbl5Z/4PN8iP8S9yDTv3 CMwFoUCPHRTQdNqtCRub2v24VTeGg24= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=T7Y2tIoI; spf=pass (imf16.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=1714925363; a=rsa-sha256; cv=none; b=zEJJfYmAlvaB+bLWaPxoVomdYE92RvvEsKvX3+j3fsCkv9PiSKczjht16VYagWyppM/8s6 8P4UfZaG+yDIdCKDY+ME6ZuiL+7Q6U4DhRoLYftaZTuNJRd4SoBB8AftXbxO/deY0JzTni b6XeEXAG4GAbtRewrd1XkbRySQgyowU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 5F1AC60CEE; Sun, 5 May 2024 16:09:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC4ABC113CC; Sun, 5 May 2024 16:09:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925362; bh=IjQRyjekukMjpd5h0+fXfebHcomYxPC0ei8vi/yCB1s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T7Y2tIoI+ouDiNcQpQ86aQxIzvrgfLXieAAtowk4KtTkMUCc8jxPAWO18JJ7SD9Xt UGr6EXLLow4ZiiZ9f1+fF0t/CKI95SkQ5wNiCan6darR1D58vauIEK88aQiX0uY+yK fFic9b/6Dr9IMMoO9aumzLI/hH0HrlsLDUsj4bpN4eBOrAuFq5d4d7SBei5FXxjNvb Qcolv2fZ6kgJVW4Pl5ylISFS6jnJLMVovlleGEduKhjiJeQ2hBhy43GrygVJ8E5Xuh cAZFS/Jh3HvrD6rXC8n01vsku8OgU0v1fZ9t/8pvT0jjsUQjs6FrZnrM7QlqVnOESq LuLV4gmANK50Q== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Liviu Dudau , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 RESEND v8 13/16] x86/ftrace: enable dynamic ftrace without CONFIG_MODULES Date: Sun, 5 May 2024 19:06:25 +0300 Message-ID: <20240505160628.2323363-14-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Stat-Signature: whep7s6infyz1o4zdpo3ta8676g6hk86 X-Rspam-User: X-Rspamd-Queue-Id: 3B34718000F X-Rspamd-Server: rspam05 X-HE-Tag: 1714925363-277540 X-HE-Meta: U2FsdGVkX19J0yce4UjIfRMmWwRutAE0hFjJgkNzi7Vwn7OZx/a3/PzXsHiQvTrg9bYHfunLPFHgajjCBKgIlRSUZZoE9JFAO77PIaGIT2UE8W95mIencLhsTZDnGfi5GtGQjxTXVw6B2m0UssdGJRIevHgx9fQ1RbnihPBieOs+48OvdIz0Vq47iF6wANWfnjb4sh158q6e39z748MMvLrOZpsnw2HqnLx1y/acynerplcs0S6yySOD+DhVj+hULk3BvzeGlD+JNnZWO4cLqumHbnLR4ZLzi5u41WLmyn4CNXZ54E1c0QB0HDD6hYzrVycrCoIm4Rik+xYZl9OU+ywDin4gJmcrg1DUqby07s2aeij7BB5x8Nz09yH2MLwxYL3tPGWrFgtDlSC58QZaN++SGXzFwqReqUU67NsxzYIi8B94CEPHhSLgaB61Gsh7iaTsD7VWoyzdT2lOe5AC2BV0t9U5qdbHEVNekSSiDYYLJe0crwg835Cgo7SV+v1UM+U+3pLthGNfeFQP6jo6SALquWo9x6KKua0OUievvLqSYgJWdLX7qeNjkPvBGZOioLHpu3nSq3/O/bdg0JGK4su6nKuNSj62BXYqPfZEHMdHE1bRWmMYCSSmUSenxb3R8UK5IeNKKf2yAGR7FnNTd6oAJECeiA0yKUFYMtAKH2ohVKstX63jgrN8ZpsIz4WkPslHJR1A+mwnkcVZov6M4b65j0qD8qr5HiRiqb+NRWR+1QnoZdeiWdLQkiA0GWkvyM+EIU3lOaCGJ5ZYlyBYk01E4Z0OlzJkdw3ctM4wUt2LdRm7J7ZSlABPxWh1V2+eeBGZIKtV77Pgb+mCADDtqVVSVDYEliRhPPbFFT86SsmtIFFKtqJBw5kBRN23YlvhPDaGwvDb8gK2i0fNEz6nwQmaikjrHHNK5LnPojnaQaFuGB1f+MHkq0+lMc+GlBMa/t6cgULwYnDdcRR34qf QFsg6C/V aN9K0R9GzDFWJakgYQjCYWKvD/mbS0vXfujBJE1KsYxHl18BRDUM7lABKNC+S6CcSZJG3MMpHlGP8dVP5N7p/DsD7tDYDwOzfOrCIhmgVBTfhK8CXVU/586mfCsowdwm5hqQDtnbsUW/YhntzXmTnMdHR+ywU6330Qb3oXVrTkM5+tQcpRDeorUyyyjb2ZvrO29AI2tftrgDRVGwK4wcIsMkSuLJbbhEZFJwqhnuHyGPU1ONM/j6wMEJDD/E7sQj94zA+Rd/KjWRQfJr/GmfD4u4wXnrDiyiXAvdfsJtxWMC0uAmfj0apkpYOX6Fapf7j3oNoxtlRBws4HDuMlFHa9i3BngOsoJrid9QzFm/g2DYW8j1RAFVz3KHZooQ3/ChDqUpS9QR4aFE65BHZ+zu2e8xj2+05ymWGniXRfn4qi009+J7GwTeY7gu1+g== 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" Dynamic ftrace must allocate memory for code and this was impossible without CONFIG_MODULES. With execmem separated from the modules code, execmem_text_alloc() is available regardless of CONFIG_MODULES. Remove dependency of dynamic ftrace on CONFIG_MODULES and make CONFIG_DYNAMIC_FTRACE select CONFIG_EXECMEM in Kconfig. Signed-off-by: Mike Rapoport (IBM) --- arch/x86/Kconfig | 1 + arch/x86/kernel/ftrace.c | 10 ---------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 4474bf32d0a4..f2917ccf4fb4 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -34,6 +34,7 @@ config X86_64 select SWIOTLB select ARCH_HAS_ELFCORE_COMPAT select ZONE_DMA32 + select EXECMEM if DYNAMIC_FTRACE config FORCE_DYNAMIC_FTRACE def_bool y diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index c8ddb7abda7c..8da0e66ca22d 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -261,8 +261,6 @@ void arch_ftrace_update_code(int command) /* Currently only x86_64 supports dynamic trampolines */ #ifdef CONFIG_X86_64 -#ifdef CONFIG_MODULES -/* Module allocation simplifies allocating memory for code */ static inline void *alloc_tramp(unsigned long size) { return execmem_alloc(EXECMEM_FTRACE, size); @@ -271,14 +269,6 @@ static inline void tramp_free(void *tramp) { execmem_free(tramp); } -#else -/* Trampolines can only be created if modules are supported */ -static inline void *alloc_tramp(unsigned long size) -{ - return NULL; -} -static inline void tramp_free(void *tramp) { } -#endif /* Defined as markers to the end of the ftrace default trampolines */ extern void ftrace_regs_caller_end(void); From patchwork Sun May 5 16:06:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654476 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 95EA6C4345F for ; Sun, 5 May 2024 16:09:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35FF26B00A8; Sun, 5 May 2024 12:09:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 310596B00A9; Sun, 5 May 2024 12:09:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D85C6B00AA; Sun, 5 May 2024 12:09:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F2D326B00A8 for ; Sun, 5 May 2024 12:09:39 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B314F8054D for ; Sun, 5 May 2024 16:09:39 +0000 (UTC) X-FDA: 82084827678.03.525422B Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf17.hostedemail.com (Postfix) with ESMTP id 7991740011 for ; Sun, 5 May 2024 16:09:37 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=iGgFisiA; spf=pass (imf17.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1714925378; 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=L2IvRt6u6jqo/e5amHBUqWQrOE6g/Jgm0JvMVudiXTE=; b=OYZzBR6Ouwn5yfS8GRcJntShLgEa1vIjcgPVFhFYW03SngNjrTnMrP2F016NIjRyLy4otY aotEOZsyfrmwpc0K2zp1mLnKA5AsU7ysS2Gohyiuu+elZf13w6WbOLa4slyQ+t6/OK1u0v DPQyZyh4iOh/bsYHL91WIdu8JPGBLe4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=iGgFisiA; spf=pass (imf17.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1714925378; a=rsa-sha256; cv=none; b=aCu8T0TW7hp2WXtvOaZJ2L/5DMipNK1XSy/ZiraqrOYljwKOwpi6scss5BROnFIolUtstL G1u9avzUqhgYv92pXKLNsOQHYXaBjkB37QiM785pZ9B7kHuxnfkLtUbpH18KXu9YCl0qse 4v5UiDaYhRB2jwk27ay1blC691WBlYg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 8EEB5CE0AB3; Sun, 5 May 2024 16:09:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A6A0C4DDE1; Sun, 5 May 2024 16:09:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925373; bh=dj8Jeem56mTOW4r4fQ6hbW3YTYti2N5hSv58QgNFPjs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iGgFisiAEFSOr/0NCt1B6/ofJq6Y8eCTFiY7pWI9j4hTDzXZ6ABNwSpG76WCIUhcT th66rOSuWjs7gukW+VtRqy7le5COM2JbDmDXcMGGGmHwf7ZvSC66EEsfujIm7AOXyg k38kTuIo+MCs9Grb4mPndP5TB041EVmntdGbWC2MuJwyToWGtfpujdCPayDRUPDIJN HdVZ99JXyxdKwXN46hvq/r3eCJ7bQf/vEAL0OSAzMW+PjCBy8Dj/4Cb/+uB5v1F+1G KX2YObmfWD4r1+JmPC5Sblz7icAwe6/z7uxqhxFVXupHuqAjz2nIKTh3WUW+H0pvnN trj9hNJzYmw5A== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Liviu Dudau , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 RESEND v8 14/16] powerpc: use CONFIG_EXECMEM instead of CONFIG_MODULES where appropriate Date: Sun, 5 May 2024 19:06:26 +0300 Message-ID: <20240505160628.2323363-15-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7991740011 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: zg5r9nwmskuyuhe8y6q8qjcps4zixbnm X-HE-Tag: 1714925377-406693 X-HE-Meta: U2FsdGVkX1/DBnnBwXSrhRWU3ST7NLzuiacf7eqH+KCPB8oiMaL9XB+nZKdQAcYSMWy0uNzOBZ0HKNAlL5iG81j64xrppD5J+C6pFBVlD9HOyhB4Efqq6Z8Bc/oPyOunFoIc+/5PrEoE4Bb2r+mKyaPHm+QZ/joX7Hwb7s+e2Usc7DwCwi/kmLinFlfGOaEePPXuynCA9Lj78coA7l+M5uYrN8fOIzKLzUKXynXWzDB+RKXFAIhp/dhk6Ko0zaf7XDnLV/7NvXBfa2zp+9oZOPzo/+Mjzcsj2lwLfEeMv9Scv3HzXBfAYCkZRk42gwCMcX9usr1qkOumKIco+QuTxAnOvuqeNJgetjRczG4bA2AKLUXhoYSbnFNRemK8Qe3JI1hkg5o3MXkHLTLo5/Ny5Rf/geZGK435M7tQNZLjg2gztbFvC2EgwJf9tbkcX0Kh5LKm6JjnG5vnwZ1djdInDFCFjYJKFGMalkgX61v4Wb6MUlU4/hdXEdreTfsoYdQtz5UmX0td2s5/siHVaaRpFkrEYLeKA2t9ZxiJHPQJRfsd7fze6r7RxIAZskB3uX7mQFcY0YCG7zKpI1YZ7X06MH4tAYzQ+32YclbLl/ayKJGAxy/cU53o2+QxDkomzDOd2CviXLIhkJ/uF/pWckp9kqLGhMQt9Bu1k/U7lxR/a1xWRXfcLbzZy7FDa/K37ikesqB5/eiXDnVuk+sPnk/aMW6rGeJ31hkhB3uItEb3ZWUAA0MYa/OFVTTxl7t4ak4jHLAOYkCUktTBYxYw6hS/ZQL3dIICaj0oG/XQRnOpfEWAIBkKbuUVOs2snd3ZhF4a4cKSwWkQ+Fv1SEZKGtanPnGe1NKS3AFeSoYxfotncBL5KctrLwVWdvIKxSGluOzXvfXNZ9YbOoPcVI6iUkfJ6OTDl82ZwQaF+iI+VqzFZf0tEKdo42AGRhSBdWeeL3j+YwODwZ2caBUcKK3xPGA mfYJXCTv +bHL5RchIVphuLTMZLpx1egwxiSqW0xU1qujkzcVmGl7DNdGxOxP3QET7dtnda2D9vV1aLG8y/Y+s+rsdq7pfIOEbcGMkftROKXW2vv3HK86ebzfi52pJgLSlnWVBPH9Jjn534bnJ4hP2nMduw0P2zLcmraFhKOkNEUVT3Vi/+te6ZYwwrQ1PG1qT07N0HpdPw0w/4GiyWSo1/hqHkwf5ubTyttWMFPmrjCtOc087HWwys7/UIfCIzRFI6i0rZHgyzLbWGXkC/5f00l3wFP53OsADaRZN9n7+Ti6FyubeiSxdqWIKvCFzPd44JgJ6rKAYqppPhokR1poBxj8uYEhmfVaQePuL0S1Ed9lNHmjlb+8BZw6krwwvG94pNHgoSGkREHBuTCSxiuQUtotbceWlCejKZAe3NK3jK3EH67k1426KlyTM8z79TOSC7A== 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" There are places where CONFIG_MODULES guards the code that depends on memory allocation being done with module_alloc(). Replace CONFIG_MODULES with CONFIG_EXECMEM in such places. Signed-off-by: Mike Rapoport (IBM) --- arch/powerpc/Kconfig | 2 +- arch/powerpc/include/asm/kasan.h | 2 +- arch/powerpc/kernel/head_8xx.S | 4 ++-- arch/powerpc/kernel/head_book3s_32.S | 6 +++--- arch/powerpc/lib/code-patching.c | 2 +- arch/powerpc/mm/book3s32/mmu.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 1c4be3373686..2e586733a464 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -285,7 +285,7 @@ config PPC select IOMMU_HELPER if PPC64 select IRQ_DOMAIN select IRQ_FORCED_THREADING - select KASAN_VMALLOC if KASAN && MODULES + select KASAN_VMALLOC if KASAN && EXECMEM select LOCK_MM_AND_FIND_VMA select MMU_GATHER_PAGE_SIZE select MMU_GATHER_RCU_TABLE_FREE diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h index 365d2720097c..b5bbb94c51f6 100644 --- a/arch/powerpc/include/asm/kasan.h +++ b/arch/powerpc/include/asm/kasan.h @@ -19,7 +19,7 @@ #define KASAN_SHADOW_SCALE_SHIFT 3 -#if defined(CONFIG_MODULES) && defined(CONFIG_PPC32) +#if defined(CONFIG_EXECMEM) && defined(CONFIG_PPC32) #define KASAN_KERN_START ALIGN_DOWN(PAGE_OFFSET - SZ_256M, SZ_256M) #else #define KASAN_KERN_START PAGE_OFFSET diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S index 647b0b445e89..edc479a7c2bc 100644 --- a/arch/powerpc/kernel/head_8xx.S +++ b/arch/powerpc/kernel/head_8xx.S @@ -199,12 +199,12 @@ instruction_counter: mfspr r10, SPRN_SRR0 /* Get effective address of fault */ INVALIDATE_ADJACENT_PAGES_CPU15(r10, r11) mtspr SPRN_MD_EPN, r10 -#ifdef CONFIG_MODULES +#ifdef CONFIG_EXECMEM mfcr r11 compare_to_kernel_boundary r10, r10 #endif mfspr r10, SPRN_M_TWB /* Get level 1 table */ -#ifdef CONFIG_MODULES +#ifdef CONFIG_EXECMEM blt+ 3f rlwinm r10, r10, 0, 20, 31 oris r10, r10, (swapper_pg_dir - PAGE_OFFSET)@ha diff --git a/arch/powerpc/kernel/head_book3s_32.S b/arch/powerpc/kernel/head_book3s_32.S index c1d89764dd22..57196883a00e 100644 --- a/arch/powerpc/kernel/head_book3s_32.S +++ b/arch/powerpc/kernel/head_book3s_32.S @@ -419,14 +419,14 @@ InstructionTLBMiss: */ /* Get PTE (linux-style) and check access */ mfspr r3,SPRN_IMISS -#ifdef CONFIG_MODULES +#ifdef CONFIG_EXECMEM lis r1, TASK_SIZE@h /* check if kernel address */ cmplw 0,r1,r3 #endif mfspr r2, SPRN_SDR1 li r1,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC rlwinm r2, r2, 28, 0xfffff000 -#ifdef CONFIG_MODULES +#ifdef CONFIG_EXECMEM li r0, 3 bgt- 112f lis r2, (swapper_pg_dir - PAGE_OFFSET)@ha /* if kernel address, use */ @@ -442,7 +442,7 @@ InstructionTLBMiss: andc. r1,r1,r2 /* check access & ~permission */ bne- InstructionAddressInvalid /* return if access not permitted */ /* Convert linux-style PTE to low word of PPC-style PTE */ -#ifdef CONFIG_MODULES +#ifdef CONFIG_EXECMEM rlwimi r2, r0, 0, 31, 31 /* userspace ? -> PP lsb */ #endif ori r1, r1, 0xe06 /* clear out reserved bits */ diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c index c6ab46156cda..7af791446ddf 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -225,7 +225,7 @@ void __init poking_init(void) static unsigned long get_patch_pfn(void *addr) { - if (IS_ENABLED(CONFIG_MODULES) && is_vmalloc_or_module_addr(addr)) + if (IS_ENABLED(CONFIG_EXECMEM) && is_vmalloc_or_module_addr(addr)) return vmalloc_to_pfn(addr); else return __pa_symbol(addr) >> PAGE_SHIFT; diff --git a/arch/powerpc/mm/book3s32/mmu.c b/arch/powerpc/mm/book3s32/mmu.c index 100f999871bc..625fe7d08e06 100644 --- a/arch/powerpc/mm/book3s32/mmu.c +++ b/arch/powerpc/mm/book3s32/mmu.c @@ -184,7 +184,7 @@ unsigned long __init mmu_mapin_ram(unsigned long base, unsigned long top) static bool is_module_segment(unsigned long addr) { - if (!IS_ENABLED(CONFIG_MODULES)) + if (!IS_ENABLED(CONFIG_EXECMEM)) return false; if (addr < ALIGN_DOWN(MODULES_VADDR, SZ_256M)) return false; From patchwork Sun May 5 16:06:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654477 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 9E66EC25B10 for ; Sun, 5 May 2024 16:09:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 361166B00AA; Sun, 5 May 2024 12:09:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 311186B00AB; Sun, 5 May 2024 12:09:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B17A6B00AC; Sun, 5 May 2024 12:09:52 -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 F151C6B00AA for ; Sun, 5 May 2024 12:09:51 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AFDC016012B for ; Sun, 5 May 2024 16:09:51 +0000 (UTC) X-FDA: 82084828182.16.E5AA2FC Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf20.hostedemail.com (Postfix) with ESMTP id 68C9B1C0008 for ; Sun, 5 May 2024 16:09:49 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=QCCxshqu; spf=pass (imf20.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1714925390; 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=G1rQtiWFoR5W1h5nPiRt+y1DO9ebTEsc0kroLYKNNR8=; b=xEBu+5+JeumoRKuX4VKn7xzG5AS76nWMH6rFLP1RMdzZWNbW/1N8u5FGlyEEmYTGwjkvhQ ndTQZ/dg6qqfMRpp7HW+U4kk8h7cZ3ceUJmnIJ677ES/IL6SvtkCtczBlKYH4EsmKu1iov S95SUcfr3Ww0AP2hEaqFfb56iQAvIww= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714925390; a=rsa-sha256; cv=none; b=jl4S8Fll8Qa3SEa3TXNhV5SlxJ5osTpofyVDzwqpT/WQkWbgDVgJEuiinzGVPi5dRjhQZ4 ygEmlZ9c24HMTQfCt8Uf091Tx3lTdIS5VPrxo0pDN6aSuXxMZV8TmCHDhqCZNB7nluXDvK caoqcpn/ES6/ZWRy7bApWw/WKLpOyUE= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=QCCxshqu; spf=pass (imf20.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 5E337CE0AB6; Sun, 5 May 2024 16:09:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EA5FC113CC; Sun, 5 May 2024 16:09:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925385; bh=n6mgI0H/39mvE4gYkoCj3q2CT30/D9BQcnyPUkYmzdE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QCCxshquMQZIYmLR9BC2goOIG2WvDcQZSg4DMYmv4seH5u50FAyr5sSSu2cZTrq1k 1aq+DM7MtvC7uYy0L8lK7PUeKUGNcYzI26AhgX3k+r02BvoRIp85vYxuQwIqVSaqj2 hLeSFjrZkntdHxjj1YiwU+8/c+M2CdO9FTQ83Tem8TFxYi+7kYUCfmvU8yl0uDpd2x m78cxpLmGVeNZ571v7raPKrnKA0wMo/A7REebj23qa4T/Fhgzr+SGtEZsj8TQEZkpT W1OzDnAhQ8QtznLGNpOdi4R9Un20Sv+DQV1jy2eugEuIIQ+7oEtAwZhBh0k+TDvo2C r8YK/n2WwOQHw== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Liviu Dudau , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 RESEND v8 15/16] kprobes: remove dependency on CONFIG_MODULES Date: Sun, 5 May 2024 19:06:27 +0300 Message-ID: <20240505160628.2323363-16-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: s4ak4oeofiorntdczo73thgr8au855ma X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 68C9B1C0008 X-HE-Tag: 1714925389-790853 X-HE-Meta: U2FsdGVkX18IVHGmsIr2O5WSZCUxKouN2Nymp4RdMreVTK18fLB4UPvMa7KZXnyfGcFyyeQYjsm5YjRnBrtKmZnAbSbvpbH6mxHredl5VRxmFX+vOZDR5czsmNiTO7wyziGBrRxZkGTyplYjYD+yXiBoNVE5VPQr63SPY6FFcwHGOGs8gtZxtdJZvDoapL9r5j0ZhdYuaPQ/vfh7DVZoFZXz6wruRas7GyYhAm4+eojNnieg5ey4NsMv+FGFRo610C2Ua6ZCy7eVpzzRnI7DuqJphPWBh2/ybaum2LFIy+p0HwpqTgeRPDIDhCf+9p1V0Tj4HfdT68wY5oNavdn9UnpHSO/8KuqwUCJlniWVp9nDsVJwz5hKTzgvjP48OlYbSgA3YLIF75VoPzEhKJomlE7BKav1QA3wf7xDfYNl9tj2LPQ3x1iLVU5bgeS/8lkCisCbCav0wmMHVvIQ4hCCR+jh1E+/memH2jfmzTTVWMOFyBUz6VDEjdkQj5/SFV/1N7DIqHaylU+wtb8jayrvWM31pq+st/Pb4FAjG3G5zj9UbgwUR6W/zX6dFaHqODKjI+snoIhAYpnYIfbunefK5iBxNI0nu8BtoQ6p2MC1vb56vnWcFnlMImMa4zqm/lT4daxZW5ZxJvdBtsByjYSzTIESL2/vKSHsOoA7aVYNWxGpsLO0cJ7ffE7edDkch1jJq7MV/cwMkszZ8/p48FgTy6tr9pDSG9P8QX0cvz1AZLOouUantyq0SzB6l95BWyhDX5Ih1Z1IHM4l+YkkSJOiFxbDvsU65M8qFY6WNOnY+sovVqajVYyg0pJcYeBqn/A0xsYKKBgMQcuAJ8Apr3Awge0ll3p+BHKqTuFVTNn2xGlVM2z3Ytd2a66av9Z3tZWzZGPmjgPcZ3HHZNVmprvQx3CIBLzfBpRVfq/9ohzLyxQLI8WiHCtcZH5myyW25osAehUkAR+nAN/Q2GaJKvP 6JjFn6qp Lyw6Y+zs0K+WzRNjP8Llcc2oOi6/6kPWZJv88yqUTGgnpWP6UQ7ASB+YHWbeOqhmELudyWrCPb7wdTLkL1vhNF09mpL0eCvkMZgSwbwv2gBCFemGWRVEiu76XlFMxUc498sZFZXlA87H3PNHzZnqfjqcxuwjR7pHWOT45bF/NJYlnzTU3NZrmc57YabcjDB1i69hoQkRg6JyPgFe2vgA7yc3Sl77401B0uZeuRhb30tKDn9mtWbXbFLfr8/C+4j8aC4+CfeSK/NLom6wXXwGq7T6iPKx4dQw4mXCC/jvhMj798R+AcHAD5+9yqKXRb1k4Is/hYWhpKVchSPCXP6Il+uzcjIvRR0M53xEcVwD9CkzvuhDtDCfZb8vVK2n0XPKY2vHCI1WqjOLazCxnTUImyETvAtFZz9wgmn+wIpSs1xDSoumAd8pMlvVi28zkAVhVGzOVYDVtHmD1yWB9CyEDsTEU4g== 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" kprobes depended on CONFIG_MODULES because it has to allocate memory for code. Since code allocations are now implemented with execmem, kprobes can be enabled in non-modular kernels. Add #ifdef CONFIG_MODULE guards for the code dealing with kprobes inside modules, make CONFIG_KPROBES select CONFIG_EXECMEM and drop the dependency of CONFIG_KPROBES on CONFIG_MODULES. Signed-off-by: Mike Rapoport (IBM) Acked-by: Masami Hiramatsu (Google) --- arch/Kconfig | 2 +- include/linux/module.h | 9 ++++++ kernel/kprobes.c | 55 +++++++++++++++++++++++-------------- kernel/trace/trace_kprobe.c | 20 +++++++++++++- 4 files changed, 63 insertions(+), 23 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 4fd0daa54e6c..caa459964f09 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -52,9 +52,9 @@ config GENERIC_ENTRY config KPROBES bool "Kprobes" - depends on MODULES depends on HAVE_KPROBES select KALLSYMS + select EXECMEM select TASKS_RCU if PREEMPTION help Kprobes allows you to trap at almost any kernel address and diff --git a/include/linux/module.h b/include/linux/module.h index 1153b0d99a80..ffa1c603163c 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -605,6 +605,11 @@ static inline bool module_is_live(struct module *mod) return mod->state != MODULE_STATE_GOING; } +static inline bool module_is_coming(struct module *mod) +{ + return mod->state == MODULE_STATE_COMING; +} + struct module *__module_text_address(unsigned long addr); struct module *__module_address(unsigned long addr); bool is_module_address(unsigned long addr); @@ -857,6 +862,10 @@ void *dereference_module_function_descriptor(struct module *mod, void *ptr) return ptr; } +static inline bool module_is_coming(struct module *mod) +{ + return false; +} #endif /* CONFIG_MODULES */ #ifdef CONFIG_SYSFS diff --git a/kernel/kprobes.c b/kernel/kprobes.c index ddd7cdc16edf..ca2c6cbd42d2 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1588,7 +1588,7 @@ static int check_kprobe_address_safe(struct kprobe *p, } /* Get module refcount and reject __init functions for loaded modules. */ - if (*probed_mod) { + if (IS_ENABLED(CONFIG_MODULES) && *probed_mod) { /* * We must hold a refcount of the probed module while updating * its code to prohibit unexpected unloading. @@ -1603,12 +1603,13 @@ static int check_kprobe_address_safe(struct kprobe *p, * kprobes in there. */ if (within_module_init((unsigned long)p->addr, *probed_mod) && - (*probed_mod)->state != MODULE_STATE_COMING) { + !module_is_coming(*probed_mod)) { module_put(*probed_mod); *probed_mod = NULL; ret = -ENOENT; } } + out: preempt_enable(); jump_label_unlock(); @@ -2488,24 +2489,6 @@ int kprobe_add_area_blacklist(unsigned long start, unsigned long end) return 0; } -/* Remove all symbols in given area from kprobe blacklist */ -static void kprobe_remove_area_blacklist(unsigned long start, unsigned long end) -{ - struct kprobe_blacklist_entry *ent, *n; - - list_for_each_entry_safe(ent, n, &kprobe_blacklist, list) { - if (ent->start_addr < start || ent->start_addr >= end) - continue; - list_del(&ent->list); - kfree(ent); - } -} - -static void kprobe_remove_ksym_blacklist(unsigned long entry) -{ - kprobe_remove_area_blacklist(entry, entry + 1); -} - int __weak arch_kprobe_get_kallsym(unsigned int *symnum, unsigned long *value, char *type, char *sym) { @@ -2570,6 +2553,25 @@ static int __init populate_kprobe_blacklist(unsigned long *start, return ret ? : arch_populate_kprobe_blacklist(); } +#ifdef CONFIG_MODULES +/* Remove all symbols in given area from kprobe blacklist */ +static void kprobe_remove_area_blacklist(unsigned long start, unsigned long end) +{ + struct kprobe_blacklist_entry *ent, *n; + + list_for_each_entry_safe(ent, n, &kprobe_blacklist, list) { + if (ent->start_addr < start || ent->start_addr >= end) + continue; + list_del(&ent->list); + kfree(ent); + } +} + +static void kprobe_remove_ksym_blacklist(unsigned long entry) +{ + kprobe_remove_area_blacklist(entry, entry + 1); +} + static void add_module_kprobe_blacklist(struct module *mod) { unsigned long start, end; @@ -2672,6 +2674,17 @@ static struct notifier_block kprobe_module_nb = { .priority = 0 }; +static int kprobe_register_module_notifier(void) +{ + return register_module_notifier(&kprobe_module_nb); +} +#else +static int kprobe_register_module_notifier(void) +{ + return 0; +} +#endif /* CONFIG_MODULES */ + void kprobe_free_init_mem(void) { void *start = (void *)(&__init_begin); @@ -2731,7 +2744,7 @@ static int __init init_kprobes(void) if (!err) err = register_die_notifier(&kprobe_exceptions_nb); if (!err) - err = register_module_notifier(&kprobe_module_nb); + err = kprobe_register_module_notifier(); kprobes_initialized = (err == 0); kprobe_sysctls_init(); diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 14099cc17fc9..2cb2a3951b4f 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -111,6 +111,7 @@ static nokprobe_inline bool trace_kprobe_within_module(struct trace_kprobe *tk, return strncmp(module_name(mod), name, len) == 0 && name[len] == ':'; } +#ifdef CONFIG_MODULES static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk) { char *p; @@ -129,6 +130,12 @@ static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk) return ret; } +#else +static inline bool trace_kprobe_module_exist(struct trace_kprobe *tk) +{ + return false; +} +#endif static bool trace_kprobe_is_busy(struct dyn_event *ev) { @@ -670,6 +677,7 @@ static int register_trace_kprobe(struct trace_kprobe *tk) return ret; } +#ifdef CONFIG_MODULES /* Module notifier call back, checking event on the module */ static int trace_kprobe_module_callback(struct notifier_block *nb, unsigned long val, void *data) @@ -704,6 +712,16 @@ static struct notifier_block trace_kprobe_module_nb = { .notifier_call = trace_kprobe_module_callback, .priority = 1 /* Invoked after kprobe module callback */ }; +static int trace_kprobe_register_module_notifier(void) +{ + return register_module_notifier(&trace_kprobe_module_nb); +} +#else +static int trace_kprobe_register_module_notifier(void) +{ + return 0; +} +#endif /* CONFIG_MODULES */ static int count_symbols(void *data, unsigned long unused) { @@ -1933,7 +1951,7 @@ static __init int init_kprobe_trace_early(void) if (ret) return ret; - if (register_module_notifier(&trace_kprobe_module_nb)) + if (trace_kprobe_register_module_notifier()) return -EINVAL; return 0; From patchwork Sun May 5 16:06:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13654478 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 E2E39C04FFE for ; Sun, 5 May 2024 16:10:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CDF96B00AC; Sun, 5 May 2024 12:10:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 77DF26B00AD; Sun, 5 May 2024 12:10:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 646006B00AE; Sun, 5 May 2024 12:10:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 44DB06B00AC for ; Sun, 5 May 2024 12:10:05 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EE92C1A053A for ; Sun, 5 May 2024 16:10:04 +0000 (UTC) X-FDA: 82084828728.03.F7EA504 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf18.hostedemail.com (Postfix) with ESMTP id C884F1C0032 for ; Sun, 5 May 2024 16:10:00 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="nCjy//GN"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf18.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1714925401; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lhsv45r1t4Tm+Nf53YDSZFCWV2ksRDlGBGes39kXPmM=; b=mD9XYaAvROCJMRX/KQcwi7gpdjMaut8mxvtvLIMbqtRdfYoXQ3aZRveSxHvrUZzj6WzaNo AQQsnzSVUYAE5hMJBq2RytreTWu6TaA+0yDccYFK/QT3lNqciuplTkA0lIBTRmQacSnZ1t E9f8+I6l5qcLBhjKjUHw0WpCo6jXddQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714925401; a=rsa-sha256; cv=none; b=xJCeSZAwUvgarwwj9BQtLV90pgYM6MNTM6OFUZP9TedGAgXnLyPj30doEITnkR+UtMoxqT KnrJwKFGklT6SObicfLX3Jxa1TkULCNAQZygz5utt2FpxsiiB1X1JL5UT4B7L7bTxQdkyA wd1cB4TYvWsIN1e6mTwNPy2MtCvGV5E= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="nCjy//GN"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf18.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 2A432CE0AB4; Sun, 5 May 2024 16:09:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DF8BC4AF68; Sun, 5 May 2024 16:09:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714925397; bh=+AOj3OMDSB3feHYUPdQfVhUVtDWDdcImqVlO1v4xpng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nCjy//GNLhmqA5rs+dZZl1QCmyYSxaQlXDUwvYrm33awCSrxBgoNQtgTEd+Og5reU 1zfpiAJVvYvH9wItGrJ4dlyOo1VBxfVQT+0TPSwS6pBwlj4x0T0vXWLHRxsW+NBcov 1GBUBgTju3SAFfkJpbUB5d/D4ixYKRZbSC2UwjlZqcgVu4MQggxhkG6KAr21NEWq3L 0KkdIVsYS7NgzJvC2au3jbEGcFX64kCrdx6ChAeAXd70cAqr/40KbW438zRh/iz+Bp AYkRBsIesQ4rIkXq2RH197dPeLajwJNlegZb6k18Wf6vs/nf1+m+19Rl2bg2C/92qW uPmG0zhErxdXQ== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Alexandre Ghiti , Andrew Morton , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Liviu Dudau , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rick Edgecombe , Russell King , Sam Ravnborg , Song Liu , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@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 RESEND v8 16/16] bpf: remove CONFIG_BPF_JIT dependency on CONFIG_MODULES of Date: Sun, 5 May 2024 19:06:28 +0300 Message-ID: <20240505160628.2323363-17-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240505160628.2323363-1-rppt@kernel.org> References: <20240505160628.2323363-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: C884F1C0032 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: eypmnrkrg7fwaswear6u5if4dw1g51kf X-HE-Tag: 1714925400-468120 X-HE-Meta: U2FsdGVkX1/DI1K1xrGegqE4FRB3Z2cxer5D48+eMtjlAg7BEDDuzKzHyPXt5pY2nuQjmIJZO8cYkOhBf0p7vCURHBY550vR3LB3mE1tb20MqoeS+oNV4nL+yelUhSeA2U6J8mLPZNRCaiF0Y8h0JAGrZg01B0LjOMGaGJBEKbgdQyDY4s3H58i4jAOLPcjU7Sw1mVNiX74VgQqqoRz3hSVmV8K9xDxcxS2/0RG4FFMD+Z9qEDpi5AILyYFT3D37b6Yei6UheYfpE7zpPA2ZKIeNwD/yTfnOcMlY/tsxtU/+NSk0lNaZYnmEGkRCxDsYxi2LDlgAtduO5MaTKW2lFh5WLQrdXelREvs3Cv9kfg88sHrYQviYwxTcJjL4YZArzUlHw2YT4I+CuOYd+keq6i1zRyRDQcmSOiainWClRiB+4BzkPdVrdmODUGhGXuX0HzSEvunQ8nfFOr5lCR39nhFfUe0vJC7ZPzv6M2zaPQmH6d4kVPVzcevA2qL39aa2Omk5AHmwCt3sK8FxlSQu7CLLR62d3RNXa+lTtV0gqQmvn+iUceyma2d5/I0ZjC5GV84a9n+H9qxTrJdgZ13EE731o/mOQrT16tbxPsv8UUNAI3l3GVZpb5fzkLBdmmVa+aN7gtjglVc1FSJSSrLI+8OQBoRh+imWgcI7uJob2aW31kBNvwPLAcBhiZ34cbL1hh8Ejt6LFyszlH72H5o+Xpq42ioCubBDS6zjk+P1Dol2f4KDEKOzKtaZ/sKXddywZb/CdmQ/nyMXmfoCklucWIdwrHj70kyUpJ1cUEIDRznqjChAd3QBHwO4XqZxWtksl8gM2e9B50ZQIW8qRx0wGT5uLH/4GzS6MJTcLndKHfJ3ASRGbn/yR3ZCPO5G8RtNNP82Lf45CTXSlIjmiW2glF6qYY799MXfZSqpqo5vu2HTU9zSOukFoKpnnATkpEoIrBOiKRCwfDydS/6BYmV LAL07R15 LgjTpVzJ0HPur1NbM+8zY90SccdFS+KMs+aYLYw+yJc7JALfJru/bLbnUgaoiYKLER8Ls5p51MaL3lXgWnT9NtCo54Tw4OBAoF7se8U7sh9b7IxA9pQyNi4FAdPj6PCGGRO8pPxVoI/diV0snQB8O6CPFzXvGjUd0C2HWi7lCKEtvituPXRtR2bn1YwDvc0ekjvndZMHp+fwFDdlxlEFkOqudrfSw/JNoIXhuElQ0mv/rQVdO0COseRTw3JTdyis0+qdbTK4tsfY8Z/me2C2/xr/K1zjyuvm5pTuY8CiNVUvUCp4rpx4BvCFqPhHpn3XgZ7TIBwJMejAY8vKv9X9CkfY3fhnl8dNTdJfsuEo8RGQ4V6NA4aIzQlt85VHPQ5TuzyOMVoQQSe+m1AL+oxQB0fkXQJ9hNCgHL+pAjwRwxIEoMFLOqhMIXM2FQkEs4ooawHrYpk3oEsNbsthkxzsQq9rViw== 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: List-Subscribe: List-Unsubscribe: From: "Mike Rapoport (IBM)" BPF just-in-time compiler depended on CONFIG_MODULES because it used module_alloc() to allocate memory for the generated code. Since code allocations are now implemented with execmem, drop dependency of CONFIG_BPF_JIT on CONFIG_MODULES and make it select CONFIG_EXECMEM. Suggested-by: Björn Töpel Signed-off-by: Mike Rapoport (IBM) Tested-by: Klara Modin --- kernel/bpf/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bpf/Kconfig b/kernel/bpf/Kconfig index bc25f5098a25..f999e4e0b344 100644 --- a/kernel/bpf/Kconfig +++ b/kernel/bpf/Kconfig @@ -43,7 +43,7 @@ config BPF_JIT bool "Enable BPF Just In Time compiler" depends on BPF depends on HAVE_CBPF_JIT || HAVE_EBPF_JIT - depends on MODULES + select EXECMEM help BPF programs are normally handled by a BPF interpreter. This option allows the kernel to generate native code when a program is loaded