From patchwork Fri Apr 26 08:28:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13644223 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 D8363C04FFE for ; Fri, 26 Apr 2024 08:29:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CB0A6B0098; Fri, 26 Apr 2024 04:29:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 653246B0099; Fri, 26 Apr 2024 04:29:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4CD886B009A; Fri, 26 Apr 2024 04:29:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2AF566B0098 for ; Fri, 26 Apr 2024 04:29:29 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8A7271607B5 for ; Fri, 26 Apr 2024 08:29:28 +0000 (UTC) X-FDA: 82051008816.27.9709713 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf24.hostedemail.com (Postfix) with ESMTP id B1149180003 for ; Fri, 26 Apr 2024 08:29:26 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=c24bKCQ5; spf=pass (imf24.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=1714120166; a=rsa-sha256; cv=none; b=Bh31vBS8rXsTfTsINWAo0NZ+YQbUU18TsjOHBnvmLz1JMwA5R2/aYDFDfhuCFiyebA4dvh dl8Ld3wdBGt4x2NBNJiDhZP5GNujXcLEStaoQSaViEi33e+VEHq3C8YHEDqSE6Fuupbj6V R3dKm2zW25Sjg21rD/5L0wKgY4aTmWY= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=c24bKCQ5; spf=pass (imf24.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=1714120166; 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=CPWDNXmwhi9o8vV2rl90jQHaYBRDvgWtHtg81IxnCKmYG9rjKffkQEzJmdARYiiNMIk0Gx TPJphAWn+fq95F1FPAEDs6pK9irRlXrb0J77uMD1gCR0KR/p+5DhZZ6H3NYahybI9em8Wv cDnBafIg0AQcPopGGDeKYOcpZozYkcc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id EA10F61DC2; Fri, 26 Apr 2024 08:29:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10782C2BD10; Fri, 26 Apr 2024 08:29:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120165; bh=M6QQiy27Yx7cZTOC0617KB9Ln6pKKwikPWIcgenY/bM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c24bKCQ5nLfUTxCLWqOfgQrHZ66rXyNyy3K6/+7sZXY22/FWn10Lrl4zlYIe0pOUL lMnQgr2DBeTE7Bdkj6zwaYAFThxItyYHuSMxTkR0gqtLqINDT0PqizlT6gcZfC4sUN cieclkW2Qd72tX8Cj3W9rhCEbYpq2tQ2fcTxNT68cuSCVGGQF9jBPxBPfgkA9Q/udF LO2K80uaKqbrLmZ/ItY6/g8LKcrRxJOXkN4u2sbfQDiJFWKzUulbs75isiDuLjTGaY uzUNXOQZI0lkj3aD0OIRott2pxFL3MoWNBgluhl33vYY3U3o4rppM5pe3CB1zIuwEx 1m5Xuoq/+vTHA== 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 , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , 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 v6 01/16] arm64: module: remove unneeded call to kasan_alloc_module_shadow() Date: Fri, 26 Apr 2024 11:28:39 +0300 Message-ID: <20240426082854.7355-2-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: B1149180003 X-Stat-Signature: gikarzwbtrgpmareauxjwjoi76epu4bh X-Rspam-User: X-HE-Tag: 1714120166-645100 X-HE-Meta: U2FsdGVkX19taU3FQkpzNycEO4d0Mto37MsyQQPUsd3eNFl2e11AnzCk/szKMNjxkBtvtlutx+CjO25kLleXSpMHW6Ehv9QQ9UWQwbHntiW/zwSWk8n5ZBXJPHIsyyALAtN3UZUFmLSoql5fTb80PBjvQ47AuVf/mo8VgPIUlfg5PKLRcr96+pMcvDep9Jx8WYRJX7sRl75Z+hNbJOlEKq+06E8Ja50DWDM6VVK8TQMYloobG5MxMqxoI6tIACntbfPJ7uDdBX+ZE7Wj9gbfNCCbx5tloj8w3SV8LCCScN0FQkXRQ6g+vSvmUtSfHIT4Jls5t2PjaCuyorW2dX8ug+dmgyZe+hHkEpzfe2mrvdo+a6f7XK9NWq2Q4PDmNqFSMx56uSAQ8UehTdEnP126CzPfsgE6k6e7Vx1ctPnWPy7itWfBlLlOn/57selNZLbKayRgCEyb2Skn5nD4+jR/Ct7Qb9Dn/u1b3bMReUDxVKgZnryMqUpMAgk37uawJID9o04mF8OOlkvqvayBWGyfmyTaoev+ALz80TEmSlrC+sZvlCi8eso22TCpQe2BdqSBTyaHi9K/nEpAnpgT8953OlydNRahE8tuZTRiVMtZmWYlksYLXWG/wOD4sjadE+a5gkTqZuPZdvQwS/m2hXNMtqOw6uWXj09GdfY9P/cUAwjuwFSTt8FvdlkvEwUkaVHE+VjRPaLgDSRJkW84EhKQNtii+D19MLaKzlSEzbfyz1ZknD549uKGmIGNHmz8lscCR+q5qAFfXNqJAb1e6mG2cwArs4UAzqR7nbG1tUrqxCjmC7j1UvAatvaaYTSU3TfR9aCQKO0u/qj0BtLx6C4PO96cDcmMEy5mLMLo+6jN7rDAitpY78a+8YzCtNTAskKW6YTgaaj3JqirbPrKVbU13mRvnKfUrC+ub3gNO39gS6Y6vuj85gCP3ZMY2lW8cWnNjkSpmk4OMj+MSGD/hAo WI4atCoj rEhkh2FinFP/v/LlztE/wB+9Te0Gax29RNo3dh3OhcKR6qg4bmpZ9IdMSqOhoAuocWKWssDXvy4NzIoLzOf7/Ws2vjekOJGPYJ29XwjfwETaFlbEw4uPh8bQ4QSziZdk5lOEy9eItFDdMLE5jfkVBMOvE9SJ5Lm5aJ1HQQ5N1rD8yIsvF+do3nTjGcpHkf9tRv4PKi5YZVzY73vXtAJ2uEVvNJCs6MvvFTSHSAVVeu2pj8QiA5DozA+6cuIbBxaZdZTjQ72ei+UDhCd6uOsKEQgxrK/RljcNwUeaJyfZtLM4HkRGsGJYFx+cgF0lLq73AxJzjsQTkL0hDmxqiwOtCQIaJo8xImne1w+7uy+52jkIuZavdqnFQ3ZcqE0flbJruHAJlQ/WBZayPt+Jhjjk27+5xkAik3HzyrW3agESPsbvtFZL8sPW5KhLdLw== 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 Fri Apr 26 08:28:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13644224 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 30FB7C04FFE for ; Fri, 26 Apr 2024 08:29:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B864D6B009A; Fri, 26 Apr 2024 04:29:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B0E0E6B009B; Fri, 26 Apr 2024 04:29:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 961776B009C; Fri, 26 Apr 2024 04:29:44 -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 765EE6B009A for ; Fri, 26 Apr 2024 04:29:44 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 23F14A216C for ; Fri, 26 Apr 2024 08:29:44 +0000 (UTC) X-FDA: 82051009488.23.6CFF419 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf11.hostedemail.com (Postfix) with ESMTP id C9EEB4000E for ; Fri, 26 Apr 2024 08:29:41 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=mJ85BCEt; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.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=1714120182; 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=0iUpsgAYDlmupm7Q+PIVrmFR5Ze3/f/h3DDb4lFkXSjbZUjd1n5X8uvoSi825s0rT8+lmS ACWTHgXM0mVOyicK7MnjSdf3bePMYh5SG4crEG4T4oAO/gizWEstcYAI6yDTusgA9bkexo wa6HT0Ql6aBzORWIDaj/SeF95CYXHjY= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=mJ85BCEt; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.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=1714120182; a=rsa-sha256; cv=none; b=fmrGvr0IG0xKn7hj6PqCrleHPG8KH1MiGJfmAfA6IczAO8+cCqYflu7WNSDRGq1oAOshKc OMejZ3yO9OrT018GENHCXouR9j3fzppJDCpVMnnqkn8igTJn/rn0bni+VQKWlJbODG+n4h L75RNBOLqqYdLH921ygkjfUZwSxACKU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 84B0ECE1800; Fri, 26 Apr 2024 08:29:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2679DC113CD; Fri, 26 Apr 2024 08:29:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120176; bh=DCxnhfiOCuZ1vbHkz6N1kzg5vD2Mqvj8bCN8VHj/6O4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mJ85BCEtXn9eC/rmnQOAFLqtOnqZnrIZhj7bfmRPi7oxShQXrtP4Uo5HR8nSbD8vo gPsy+y4atIh2HMiSUwxm9ruLsRzgF8GKd0SQITa9LSTNZ3s1l6VFdUmjWVa18XNtDm wmndfdYM2HWsi1NxgEkL3Yi/2Wd3TbOQELwu5rL+6f7WiXzzXzTM2B5ch4q1YZRsjH iSzijG4ahNzTFxxFNb1voatba0/dKnlSX0rJtmZQwKsejOJeAysUtuMBrUvR1kI8G2 77cQ1XEqmgjSmkLajSNAy9YWclmvvuVxCBhH0De74z5sFFxkmJLPXuTC6q2ljZFp/S FiiZiNa8VahbQ== 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 , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , 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 v6 02/16] mips: module: rename MODULE_START to MODULES_VADDR Date: Fri, 26 Apr 2024 11:28:40 +0300 Message-ID: <20240426082854.7355-3-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: C9EEB4000E X-Rspam-User: X-Stat-Signature: epcyyqy76hisqqz976aib16gsj9w86wb X-HE-Tag: 1714120181-456259 X-HE-Meta: U2FsdGVkX1+hqVKn9rN6ZokI9puJRKIH3EiWRK3xramWuCpkrprakcEAKjhlGjRQzLSCvL+4HNRYdZRh3getAn9yTBuKu4BIinFC9JliFG5gDvOW9u8pYIZDeOVNKQkyqbmgaZK00/RFXvcIhYduQA8ZR3RGI6E/yWZsUlghLAoYZWkfwhpiaCdWED11xSFm5+774iz9leqfL8aWu1xH99js5w+k6IAnXFn0a9Kka/Nl+PR42xmfheLTg7fmR2tEiKLEc6WZb01v905XhaVtOrIc+f/S6ztT+riMVWbXLW5YoHtIDGQkFIIS+mOjBQrYD0XRe/mBhkER0zgeRQRMBkLx6JUfCyQ+f9q5IZsWk0iMgoJImakxhyqmdgWn/Pq8XhBhm1pHBItcS3URat4VMKj3WHYawLmSW3z0FISnudsmOXKiKzJSSIdV1TQhW8R7X/eTeKfTAGgz9Kbn3LG8dJ6laeI8nSKIokBOz9hhYWbVhBjCjSUh4Qx/HqihJ9jbnQA04UM4i9/Nkc+y86vCerDX/7CXHQ1fzb+QVnoyvuA8h2rSTCUViByxHzWxaEdIHxedeIZCqMNME/pOPLuEpJJWRqSLEnQagXrtsRDawQRT4W/GUA5bUvr/3Fm+Lv2OQatmuRcuIxkDSv1vfKTn5n0NOwOw50QRvBWK0cTUat/BiLXeHO/n66EaFGPTyggoOxvf9ms45E1drwfAAKexjl97dzG3wyoUR4OFZh3lTvIKoCXMCVt7wEEqjMpdq/7zRj/SFK8CrF3T4oBvG0v14f4TKXyObAZHKsGWx8hDYe3eE+gBk8Q412HkPRBhj9R4UD1znbRp/cMwFGO/WWtXHP/X6Qx+CJruXh+2Wyh2Bk6vSoFR9q8wr7uKTlcv8GMLpemnHBqofA/E5QcOsxTTfZhMmHjc5NQ7xmubrdhpkiTlJ13/yR1z4KNAQ2RZ1zgyyEtZiK+tc1OuwCNdujl nwxUiHot PbMA3Nx6AdxEDqC3J2/zaehOfRwV//7U9Ckd4/NtDK3QMdpB646Y6tRVRC9yjCQMLr+y8lI+Aip6JuIu9FP2gK501MJq4iNL7r68anvSzGpjzlahewrVn2Mxf2S6U5KkQOBiTnTzigY1Xw8nHLOEKOehIUMpyX+BypJ5fm2gVCo4xz9SczDK1t5mbyv0lN3EfR0/9S3IkAw5+TaiVmTY0chpTfrq+x/+jJ+YbGGtqd16MWVMief/NTGULC9K9oulZVCbbTBZrz9pShWygMYzkSccXZBWx6izxZRLyGOKwMpWrxps4CZsm3ojDgmt4Lu8AFUrqRVK9ikgl9scv0UitgrRE4wFfbOVUYZBRI2vo5GpPeM8MvMXf/ZPjxtNFCp5nt+5E1cJEm04N+z4/WwCYwDMSPVoX7FdRyWpXCbSgFrSfvT0QMSA94JzhgA== 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 Fri Apr 26 08:28:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13644225 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 D60C0C4345F for ; Fri, 26 Apr 2024 08:29:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 718C46B009C; Fri, 26 Apr 2024 04:29:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A23F6B009D; Fri, 26 Apr 2024 04:29:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 542B26B009E; Fri, 26 Apr 2024 04:29:54 -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 35D5A6B009C for ; Fri, 26 Apr 2024 04:29:54 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B42E5A081D for ; Fri, 26 Apr 2024 08:29:53 +0000 (UTC) X-FDA: 82051009866.20.8F48DD4 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf26.hostedemail.com (Postfix) with ESMTP id 9FA1B140007 for ; Fri, 26 Apr 2024 08:29:51 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NPrdkx38; spf=pass (imf26.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=1714120192; 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=DH/+DyvVm0SjhKTlQmNYjVkCebCwemBbL+T9l/mdoRF3uCXuZ4IbqaJ57TucQE5tIXGbUp uQiF5ISC72i1n1EbHTOYH0rP/K3iAQPW1RuKK2aT58VZHv8t3ZQR/Jw9X7KCtAx+NvBDr+ vHJIESXwN72ifdlLwWVgyo9Nr/X/fIE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714120192; a=rsa-sha256; cv=none; b=rTGjezy+7URDZdh/iqliB7Ez6Lo1E/MpbL8TMPIFtgAa/hgXQ5zPv+wLuD3UgOYcfsuN+s K3oq1epWq5h1iFcvsiyd41vwtWuSdT8bJecqkps2yJs0Zs140LfSv95GnEz/aKLdCXLRbB 4fHe5rHJv9c8I7/CGiPgrF4LMmXML14= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NPrdkx38; spf=pass (imf26.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 9D0B8CE1BDF; Fri, 26 Apr 2024 08:29:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CD2DC32782; Fri, 26 Apr 2024 08:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120187; bh=Q5aCDGAMhe9LWjmBOe0KfqvsLthVcLCeaQ3ItO7ykso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NPrdkx38WFrLGifzoA5K0QA3eIW1eoED+MgwpJcnRO4aMuvJHTNJozBx1ouUGQqXB QKvWVzKbowOfw+ctzP8PL3hhetlcUkPSieNI36n1bfkk2lbmKbEV9MYfG8JIcDuPnn TWYAoPdM4iZrJPVhOdhDM+lXTJS3T0ugeMkrbKCNz7h+NtHwV7Kh+zUE2iNpjbhggg 35NSzKOCyRnoVxeLV85ojoWTJUpr+ggXbNk7gyIkr2wcPQtTKAn9CirBNIwHHW+Bgf GhpUHCmP7WnGQfeuvGP091Q8GXQYHZ+nkAZ8Mvws8O83TgAv5lx2QCZBZWN12E7gGD 853B08FIaHrXQ== 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 , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , 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 v6 03/16] nios2: define virtual address space for modules Date: Fri, 26 Apr 2024 11:28:41 +0300 Message-ID: <20240426082854.7355-4-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9FA1B140007 X-Rspam-User: X-Stat-Signature: 9ob4yttyxd681damtyaqzu1mcx7e34mi X-HE-Tag: 1714120191-628241 X-HE-Meta: U2FsdGVkX1+o9Dag4/tXW0RZf/shFi7hJYGSv8zEVk8GMIEnUgwRMJ/OmyI5Vs0PORsPYZHM6UVBI9dv4bj2f/RX/s47NmhYEWRXw/5B+hkO/LzRAfCgEj0WhL8h0gtOW80kYfX9ktqYybPVz8mTh0p7NcCgz6WLIKO8pZDwnuGswKhN80VbmhzqyOSXwx+V+V5esEqzesS7BhLMH+c6Iwc/XP26MfsixkRh7Zj2FZqL0XfjBJP7U+kSrsCAm/uWMJ3ULIZuNrLrxb5CglLTtm3HPO8Pm50xKQGph3CTu81jl1+VFydm1TrMhX5807ehXj9iz7RhbFjolJ0r4jv+Jtdr1+I+k+PtBl7UoU0YBGYzgSZ1LmudhjpfNJENc29xZwrmCEB66Ewa6bmFCOW1EcnhH1TMeruZPJnP52D2+QnbYMixpgAxfeiMaBkvHBi8VSuB7zJulhWU7lp9ItVTNI6YlqRVkfofEi4yV6JMYApgHDjXsrOvIy5ZKpmgjvDMK493jiutfe2JOvskOQhTXzODwG7vi+q/vEqFlqEO1Ci2CNY3bFBCpt/3wgv9VTES1SOw7X+r3Urw8kWWaHzv0xJ5YlOgSFkR5VUyYH97v4Onyc8+lH7PcXBt9do5MS0+Yvr/9nWiYEMyxEjyK4erRj09hpOGQMPuwNyvCcD+9SqnLEVCfQ6lYkUNuuc+bIT9Se3aoTUkgBTXbiu7LNpwMbvQYcdykEcs4T+A+FyrXG5dybrX+GYbfgBghgJmRuBcWAmCH1l2EPYyLKtz6FOZTWmuAJSeiLiYDBUYERS6s7xisMMVfB76PZADBrfgWl4r83jaa1GWH79BDvq44DcW+2aZYF/++H8O5emmZT50hWb7FvhQMUQLDmCKTEkBiPOBGXm++KXAVJPIAwEdb0nHqLNv7EJPjRkKeTzmv+o9sJ1AokjEDwgmmIIfX6OZbglIMtX2ZqrWyi0l9FB1Kpy Px339oBH 1oJ6AwANUbbV4+vv+0yABLWBynwadLl/Krq9M8AHVmG4AfQWaS+ElHFC3Apgcbvyvfme481VrtcH7/4GpSiVUgbPtsdByKA0KjK/SVZKjXJRfI9M= 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 Fri Apr 26 08:28:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13644226 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 B56D9C4345F for ; Fri, 26 Apr 2024 08:30:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F5C76B009E; Fri, 26 Apr 2024 04:30:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 47F006B009F; Fri, 26 Apr 2024 04:30:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F8896B00A0; Fri, 26 Apr 2024 04:30:02 -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 0B99D6B009E for ; Fri, 26 Apr 2024 04:30:02 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B191E40F34 for ; Fri, 26 Apr 2024 08:30:01 +0000 (UTC) X-FDA: 82051010202.26.BCC90D3 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id 10C4418001D for ; Fri, 26 Apr 2024 08:29:59 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=FxtLE7FD; spf=pass (imf06.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=1714120200; 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=v9h5Ceo2H7n+7/flj6+VCTiMD2pRka7m4z/lLKCOaas=; b=xXRe+00EoYDyfwzwRlbD8XSMd9O2NMmorYeIo+bazG7eGh9neqe/QYkve21oJrelZRX2U8 ISc8EReKnE7ETFZ1OKT4aQt7dTFkZE46vFCEpPFUeBEswPXzzIIqFZgUjQuRewTZP1DuSr FWVfXK/HAcIU6O5oJFA+7Kl6+0QXdKE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=FxtLE7FD; spf=pass (imf06.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=1714120200; a=rsa-sha256; cv=none; b=r79ndjetrJLGk1FYBZzXtIjnEnIH0MkL+Y0804Qyo13Fcxb82b0YfdVtRUr7pPbQCSlqXx DUJvgWKHfGb+1+/jrZYEA8yLZTBBqn9KtO9dMZYCWwOrm3Tz5K9GBbgIa5f6PHrgsdj39u TsqpRUkhQBb3EPlyOepk8TSI5IKGclo= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 3D14762002; Fri, 26 Apr 2024 08:29:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 542DDC4AF07; Fri, 26 Apr 2024 08:29:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120198; bh=3M2ZG/VEWUi/tLsKuWV23dNNSZ6f7DkD53R0UR9I374=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FxtLE7FDecUHDXtLc4lOQtpBLWDxwjYFEEqYIkPR0QwLBDoD0zZ8t9vMwtiNZytp+ ABQ7RDoHM2Wc8RbUl8TpphzmEPE3zGDm9H3NJtnVJldRKMdfi/pFNBIoxoDEyAWloM qKk5ZdZFe/QBUMzCeM17G3JEc1Q4ge5Z39+eSmY1YmeSj+KnOWOdkwt7Vg0syHyV2v MWiu4EM+A60684+xjiReNXSAogLjTsxd0SEDmFZ/ASqSKiS3Ag5ts/MGVnz++OOj4B XyuNjsYN43GEx4Pus1MPQkKPSwr0XVDkAZGhn7sXt+cl6vvS3YrJ7KQi2FaOLbqO+3 OD3ZnzghTMFZg== 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 , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , 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 v6 04/16] sparc: simplify module_alloc() Date: Fri, 26 Apr 2024 11:28:42 +0300 Message-ID: <20240426082854.7355-5-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> MIME-Version: 1.0 X-Stat-Signature: jdqemawouf38szkmnys9w4x4z1h6psmh X-Rspamd-Queue-Id: 10C4418001D X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1714120199-867177 X-HE-Meta: U2FsdGVkX1/p/6XY4mMrcW84ipn1hl7BrlCyuhm1rG9EoGIwhlm1vmD8c3v4OSH20AdmnhNZAVjmQVl/qQRankjF4ALWHa51LsH2uHeWIdSSgYVgDg7NnpfvRLFFhj8k4Zk2LLyrBwfjXj+hWUVzqfPtSDBWpHCGGpnJPOU35qF5BYpMfvZQAd4eM23o06k26b0Dw5VdCipY+5MlsQLYo3AaY3PBafGhtHN+dBQEoRg+x25+lo50N4A15AZnd4xuyGNtsJWbQU2ksuvt4zGDYH5mMguzqD32SkT2UqlXkTfXXDpEabtXgG8y6ORDdPQpBz1oEzzFJiK/h/X82JjqD9ooHvCCG9IjlGjvJ8G3eurQM5N4uNeRkB8eURJB/UHnVDN45Mu0UQw1BQES35rXD3YVJBhDcH6FFXBMB1P+fgrJwmXbbNB498G1+mq8VlEIk4X2DrtAGatWsl9e2YIJC0JtuerFGt1sqlCAL9FbZqdZuD+8WpIH4JTpTo1Y51LpzDepE1v41EAYyYEhamwv3yJYaJOcr31HbHAknTS80iN1pLJSbYSAjKVltrSmCmEY2192RlWySXmhy19NmI/UiIEDXm2Tm7Kf8gYv8P6lIMi59S1AXXrT3ljWcZU787sTVh15SKJMdw8z8fpXM1X5qIfbEFhO1VF5MSVdf/OagP00x+wDb4rqTd/WeHfJXiZqXsid/T+j0KNng/YdfoB6ADiGAiN/Y6UiM2ccIthcW1y+vti1pn1rrwllXrfeufvZyBa9oWazfTahmwDHPee9wxZUdtnP3XZyPhT4pgpXLQP42XzQgPGV+yrirbml3LViAEs9/u6LQV3eWiptTeQtbFXfKRRW5WVghkCgGNjRJBqMm3qwhdNU/+P5F1U7TkUw5/UAtQKZ8CirS60IqRS2K+nDiPLbyQDQe8ZJGgImnax2Yt1zDv/UqWuflF0CdT3zfpm6dUafxPszOiCFC9H ohIEnwVK Y9+7wCQqVmEzYtvVrN6o2DuwtqiWXPOoyGiKFhqbeccRE37liJP20Lp1r4s0gvquUxeyYbo/2crgmYQeJfl4p+/LAzjCqlhTrfmZH4ksRR1XRopmImvAZQeVokKS5Y1JS87VBax1k8h1gHyCgv0JygvXeHRKm04sfXa2eX+tifqNtgVEwvpFvjIL7r1NEdfKIqBEybItPYLd7ETR6vXddEMpoU9K76Y1HhH7tAw681ghLRZuhFIXXUFjQ3tHIutGTHmoKfd6xUsHca01uA5CG7nBKc0Yg6NIfNeCaRLj+J2YD6Qpb9j1V/azVkM70GsoesxKyJKcYrszz9SiDaDxSTcx2EF+iBC06XkcjovHByImt9mSufkdxoyd6n/jFZHNLDFs6liKR1LGsyd0Rwb7743JeUCDceznhIoA4qtQrYFt89tE58y3wfZk+nNBOwM5b4eDa4gLU7XrT2HZh5BsGsgOzDlE25egwsGqCLSvsKVrg+kE1Eny4WIgAs0PXhJ9dBKTJ 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) --- 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 Fri Apr 26 08:28:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13644227 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 AE8ECC4345F for ; Fri, 26 Apr 2024 08:30:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 432CE6B00A0; Fri, 26 Apr 2024 04:30:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BBE66B00A1; Fri, 26 Apr 2024 04:30:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25F766B00A2; Fri, 26 Apr 2024 04:30:13 -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 081696B00A0 for ; Fri, 26 Apr 2024 04:30:13 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B14BFC079E for ; Fri, 26 Apr 2024 08:30:12 +0000 (UTC) X-FDA: 82051010664.19.693B843 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf22.hostedemail.com (Postfix) with ESMTP id 0EF5AC0014 for ; Fri, 26 Apr 2024 08:30:10 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LwMZeOSx; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf22.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=1714120211; 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=y49Hw3YbQx9uAvZVira3B8a8v6zI7tnQdDmrRCpQIPU=; b=BLWRcyRiRI90idy+95fKmQWR+HYXRFb0Eo78Y3HYMLYN2PtG/rMaOdUVYXLM5bcPHW8uPu oWwrmYBtYWJxSSyCBrcV580D+F25RLoimPKuSeK0kksrc+MX5fqz27FR2DYUbQ3s5u5WaI JzbIM6Y2cmITSDkcPVYERX1KYoec6J4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LwMZeOSx; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf22.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=1714120211; a=rsa-sha256; cv=none; b=Lc9wKPEyVTgPC/4yju3QH5K+RJfm/YSYjMwA1PzTQBYCEZSwHjLWz+rEyflYw3m6s33r6b MB9Q+Pcy839dpHLMbIMRFHySHLxq+CyIkYSAwN46NWsm08wKxOAr/SyUU4zpDRAyugTg7S FWcNDAdO8bMtJU70EwPdiK3LAxfEVLU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 54B826200F; Fri, 26 Apr 2024 08:30:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BCE9C2BD10; Fri, 26 Apr 2024 08:29:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120210; bh=et4MgsnYGm8cVKv9jXBAzJOVzMpXCbC7LVUAQwPu1L8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LwMZeOSxTcaopA8l7aFjn836oXymor4oh/sP036EJ9NTUjJddS/giJA53rY22kGtM KczrvrgOvL4jlS5ocJMnqvIGuQSp0OvGJ0hX9z+Tp5xcpLS9VtMNZQ3XfsGQqGJzqh 6vldDmI/hSudf9GnoBcMLm1mGO6GHJdcybJzDMOYPZI3pmfQ75uHgx+OE2DCnV+U12 lVKgZat3LQ8YKcRYxjpCf6QjFQlnNLKrfALh6wX0HX0FaFFgF+GXlRYsZACOcR95ZI GWE8siM8d7u7xPg2qxDsktAAwONYtV/flV0qRa5qeob8ziShnD/IXh7jk+Tlb9Ub81 a7RL/aC3317VA== 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 , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , 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 v6 05/16] module: make module_memory_{alloc,free} more self-contained Date: Fri, 26 Apr 2024 11:28:43 +0300 Message-ID: <20240426082854.7355-6-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 0EF5AC0014 X-Stat-Signature: 3bkwcw4yoariw88ksyj4tos4hdrx65pt X-HE-Tag: 1714120210-27447 X-HE-Meta: U2FsdGVkX1+07XrjoIMzcN3Aimxw4KCdxJ1EmX2NdjMN94q6N2dL556DPb39CHX41JfWgAVWO5SipjihWVjjU0jO/yp0j6NSEdZrMyJiZjf4PYwrKhkf8MYpODu33n7//a9aUaBmA2uLyFAor7oTovPIy0wlC9yWF76xACIu6k7vaHFFkHSvgs/8px42ss+ZZvX0FuGZnjB6RgiFeSBGwRbaMDl0gZKxthNbHfGHXH98Bq5ZeGRceIiESCIdg5EHmZIvSfYSClk+tvDPzITloUHCwm0XZkLp0IyaYFhRdRHVsxsn4bRaEcp79YhKrANl/xCtvifSVGr17WHbdKQqT8I+sHyoqW9KIw2xHZ904tmnK0+1lsTg4GEMCtgRFC89yP32PJdbaOiIh9WLt4fSirItTmGwH1utrBgHLzFy2yFsVoAehOVxYk2QQaWLxD5EIKt5tnPeYjzni58jUuvhMz9YIDk9n3NKKOXc8J1UTD/aS8eAd72ukUGMZJAl824mj/VKpS9heJ1w6f2Y9bmjCXeBYsz9l1R1nWzmmjJMJdbBmvXRfv8o3yGVDQES/IfeRHXZsK6riIqxOjlSJJ8+5F5ol8TfM+9j5pfqJiPTjyT27PcyQ61K7+tOzHSd8KcK+hZkO1VMl9q/biAqNVnmmxdUnN6zxDuHbQkxNg8PKJnxk27uqhjuaIn1n+r+pLSYYZB3jM0DaunEy0AQhCkN+7zGrspGKUnLaQOrZCjkuQ+0ys46+gvv0hv70W+VrCwCUkQT9wi5aYMaU2TZOas3oZVSquP0b+mYfakGMYXuz0yErFxJtUaPsDud3bgnkGSMlswJA6tK8LMnizaIhcQPXqbih7h7LrgH5a556ijeUCdWX/5sow4AtaDio/nTSSoaSqDHepR0XFfFzgODW3OiutNXPsXfBSVb+kYVzyoLaPzqIXdM71MV9WDKiMTSf2DunJb/oJJaD6EW0nM8nB/ UygK9+OJ slD2Bubsftpj9vXIQ/FjnpwP4xLiu48vtDwZ7B9KxPLcn7AaEk06C2fb5YMarRF1f/6enQffQENNJz6vLHUoig9pDPeoif533Nzg05edfT7eeDczITcp8iNQ0vcmslboLUtlkuCNzqsw+T2NhgPNXtMNqf32UxGk+8Aj4gMI6fgkEzQD6VQgxPu8MdfBJzlZx/E2y4KPF9RNdE4xzL8x2HtV0jUXxR6nswb4RtZEL5A3JStvs4LyR6ODYEa2/UEYqYkTkmvAeIKphQblBNF5XkNPUOTHak6fLoCRo1Tp7FwARr2dACFn/h2xr2onf5NdoELpCdWtsbxQ3nylRwz7VyMDp71LfMqMM1NsQs1ZAjtHOPkE/uPFjGQjvf2J/jnV6nRWZ2YK4+YKth3ebXgC5Znejdn1CT1b/sd3f7Nt1cx8btSMnU/hjK7Ma3g== 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) Acked-by: Song Liu --- 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 Fri Apr 26 08:28:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13644228 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 4E974C4345F for ; Fri, 26 Apr 2024 08:30:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF7A26B00A4; Fri, 26 Apr 2024 04:30:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D80236B00A3; Fri, 26 Apr 2024 04:30:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BAB916B00A4; Fri, 26 Apr 2024 04:30:24 -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 93E686B00A2 for ; Fri, 26 Apr 2024 04:30:24 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 13D60A0645 for ; Fri, 26 Apr 2024 08:30:24 +0000 (UTC) X-FDA: 82051011168.25.4164C1E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf01.hostedemail.com (Postfix) with ESMTP id 613E440009 for ; Fri, 26 Apr 2024 08:30:22 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NLQ7It6R; spf=pass (imf01.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=1714120222; 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=qvKKMfKkeEOWPJoUCrny8YwyyY/XnzD/eN+nQYFPRDE=; b=rHJJKOdN6pFT8F26CJ7xsQlPU+5QIz+I92tZZ0ZkHIptN78/retQUkzGD7OxFR/m9vK5Ml pOQDaIIzWN1CgPZ2CZ4ct2W5fl9+VapKqmDTV7uikWCIRSKuEaO6kgnIflt9g6/AYJkPnR 736GDgsPKFz7Wx88smeQSfse8hnQohQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714120222; a=rsa-sha256; cv=none; b=3DsaEihii6PRVXTXSbJ+3bn3EYRwtgW0BBQU1PrAfT836tElIahvxgvZOc7QoSYKlhv3fW LRRnHT6id4KTDEvMGXufXcbSv29J572KTyzyRpnL23kskOSrIRJL3gh+GpvbYRKMPMKtDO frf6Uehxz4P5EQqDei1YVmod1KeBgqk= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NLQ7It6R; spf=pass (imf01.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 6FCFB62008; Fri, 26 Apr 2024 08:30:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 852D7C113CD; Fri, 26 Apr 2024 08:30:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120221; bh=UDu8CBJv+f1oOAfrGuXWbJZJWY0pPgPtLyP6xHc9H28=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NLQ7It6REzVb21gXg5nhWQIMChAitjxOTI65nDOGs2UxDnt4yl6KqxqE6jEu57iCr zMw4MWSph4062TdLD5kdX6lkhcSd9CNiDZEpYe4l6RQnRtvPaPiY19e6ifYbfW8mpD uZ6sgQnov2OjehPzst13pku4eMHaOi3SibGOCY49s+8/QQTihZMLZ92o0hoZwADWec weZ1DW158LklrA8ac5XQUXdAcvwL7TAbdFPGjQxxcl2SR3irfJU4dOT91gyxXez/L2 CiGET/awIgUsqRyrMf2a/x2qO5+NaEKicUg2whe0AJuCRGEmOu28GjjkfMj0JWlnTZ xuzhONeasimMg== 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 , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , 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 v6 06/16] mm: introduce execmem_alloc() and execmem_free() Date: Fri, 26 Apr 2024 11:28:44 +0300 Message-ID: <20240426082854.7355-7-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 613E440009 X-Rspam-User: X-Stat-Signature: a54ampwhx3huqi8nocoabtrn1qmcxz66 X-HE-Tag: 1714120222-715367 X-HE-Meta: U2FsdGVkX1/FAHwjspubKPLKuRCq3iQ0VzL3nH/a6GIXb5a12qJa5GblRxTKtUJu6OLNFBVSNqf6CsAtaWwzObKeyACuI83j6M5vN6J0WQJGFPZcOYeYSkCh8CNQD20rTromf650oddapO8308VmK6fBVsDWa+AEDONQyv+0er4KqAH+67Mh2s143J4MAQjR/X0qo4rhwbjysMYgFOhcNKCRAxhs1Mj9SAGxO/fwFhIYdZlRhmQwbLSQJ6pezJZnOz+JveLZyEv4eb9JLX5kfQPcYjsu1xtfof+gAdNC11QLSO75+Mtu59EvZwp4/rHIO4+fdkASrnmVqMtByxf5WNtaqqPVXak06OqmgRmtNHYTl0NNbV4etaXttTpWkXu+HlWdSEMlP71HJE9/8pZVa9m0ycHrO+ErTcE3YqbQDlqtRSqH9gsR2ky26zXYEMsJ9qCbLgmaDMKnHpuwMzqjyjCQpyEH5vTXzNH6FRoe6mPUlRMBZAKvE0Vluf4oEOz8vofeXu/wqaRTJAlFMnt3wNUMFRodOUZILjQvjyY/4boolNOPOVc0eJTd2mYtvm4Nh8dyiosQRRFr4WkBWM/xuJER1oc8lvQC6ZM8hwL4s6Fm0WtZUFuda+KWl3LCollWo/bTq+YWy6eBg0L9bRq98ENOVAqSEfQlgObTiAaIlqsGTprMA2LglaV9S2caMg0XgvjJad4gd3qzkqd7PBbhgkR5TP3IKomXo5Df0R3ZdzVR1dnRDZlXNxxbGtpRoKVH8x9r4PzjMjDK+VvEWiXUVGZPLqo0KD/jPpFtfs1OMMMVJuN84BTEtFGM+GsPy4GvN7GetCB+17FLLUdO3PtFivO8jyjiRChQSeInOyXKXfR17XAo/pHtMO7S+EiCf+dnARlePAm7buQ2nMTaP+9lldpK62m68oienoiKKJNPiXthHAmYYfAbZbHuSGX19URnhUZEiLbudOJUlOJMuQt CF6Dh9yU tec3rdraDsI70aEcq0x0D11OiVwe2Z4mz7TdOGzfh+Ez8a2uU6KoSmmj2C5jOgrRCJh9dSseptKJvDFwAbvFPHdQlejFiYhCaHFxEAktieHWrX4TKqE+MuprccOnFx+A9hl7qcFR4ShHji3H6mJVgqFrj8Pz9qVfdKCoopuIP0tVUzayJDzAXbUFbYMWsk32ZH/8MTUUE2z+xnAH5RfnNUybgMu8BjdQjPTonzL11cDs8hf3S50hbdNi5Koykt0Tvk/7LjFCBhs1Dkqj7FXUK315sHYSJuNaxtYMbHSvU4DCi8mJNCE146x4CNd4mvtUR7oQTa7DVsuwIMdyQ1xs7bjCK8xhM32PoQ9i7MgH+ou8DRDWl1JYnGiH1UQe/bHEahR86t1FbInhLFVXpscICZm6ycn2jF/BcPqKCUgQqhTh/lzSwhCboyyV+QhaxHRzseVTxEJB2+5No9eO8pRNipOQTVg== 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 Fri Apr 26 08:28:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13644229 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 6CA3EC4345F for ; Fri, 26 Apr 2024 08:30:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD0A66B00A3; Fri, 26 Apr 2024 04:30:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D803B6B00A5; Fri, 26 Apr 2024 04:30:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD2C56B00A6; Fri, 26 Apr 2024 04:30:35 -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 97C5D6B00A3 for ; Fri, 26 Apr 2024 04:30:35 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 503CB81334 for ; Fri, 26 Apr 2024 08:30:35 +0000 (UTC) X-FDA: 82051011630.11.7719525 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf03.hostedemail.com (Postfix) with ESMTP id 9266620021 for ; Fri, 26 Apr 2024 08:30:33 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=e+SdxsBb; spf=pass (imf03.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=1714120233; 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=HhZK+/ekybxg35QWR28CrVnmieB4bYA3VTEGGLVd2GQ=; b=1SQKqIV9QbPSZTopcl75CNKYHmWALRIdrQl2trktWxqPGp7myfR9nUbuqX5uQFfUDFE9fa EBmIvf5Ul9lRdYYnTXkfOvArrzONoajLBj20aqGpcA3GCutmZqQ57F7BlmWKMS1TcD3wJJ lD+omizx62HrMKkjmKYIEb5lyzL80lA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714120233; a=rsa-sha256; cv=none; b=IobTEBFmmWxrjErdVx4OrNmGBOWKyS/ICJsVFDIXO5+c+49VR5H8VRS2kjm1HiKIwRZHcI 0DJPSPKlPd2x0tpaeqUasPWGdyDi0u5uQQfjhGcfYRCRl0am8Wixp8P5IQwv4yCgUUkC0D dBQggE2ev7svt6gP/1hwqhlTOmd6nKI= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=e+SdxsBb; spf=pass (imf03.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 84CD661E83; Fri, 26 Apr 2024 08:30:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E685C4AF0D; Fri, 26 Apr 2024 08:30:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120232; bh=9vTOQy7Y1G36FAG4wOqEVF4S12BUBGgNzRpGhr66FtU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e+SdxsBbtOUdu/kvEcbLF+rBcuO+zU+90hxjouz+iw8dZD6B1gSag4wDecoaRmbwG T1+7kXwIzcwrt9Y9XXqv2RG0O+XKsAwOOkuXy1jPn7WPl69UujHFe41I33euqr9ag9 7qkwyqPWWQSAYmqDQvDRPDOsYIJixgvLt9LpVcOWX5zBmyyl4jorPMpIU8m2ixeTCs ZAkE1d7h3Ht9ykwLjb2hB0liWaH7Pc9ZMDY79aWcdmlILb+6GsbL5WXdWT381vBzmy A3v67nvZWbFmCwQqJJIZMNzqaXodAzeEhfq/TKCeFvo2w4Co8ZQCWz9rQmEDv/G/A6 gHu/37wPxOFKA== 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 , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , 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 v6 07/16] mm/execmem, arch: convert simple overrides of module_alloc to execmem Date: Fri, 26 Apr 2024 11:28:45 +0300 Message-ID: <20240426082854.7355-8-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 9266620021 X-Stat-Signature: 38wezufueo11g6c3563dmki3d1bs3yxa X-Rspam-User: X-HE-Tag: 1714120233-400619 X-HE-Meta: U2FsdGVkX1/Zmsb3l9Z1iMog5BguQRaxgPqzL4JkfrnOAIuE+70VyiJez+uBmpvgtesGgUHiqYGA7KvcrA6r/eYmM6xCrsiN+9Wi3ZopMCQ5WFjGF/JfISJHqUZorf/SyoBp+z9U+Z+7tqG+sSWfh0qJKsWeCaAQbNoDkF+db6g4D2i0c4S5VBZfC+reWmUhXUz+Jj7+7HElphlI70HWtLmsVTx3mpXTLWAFs510JyD5sBpFOVLdfN4RtkIqlCLfHFezIVarcdolcLiP81FAmoF2zGRHX+bVErZJmngleZAhjxPlgeOI5tuhs07Gc1fOvLqNhaa31NcsgZjLl0O7De4zppx0SMa3pPyJm7yAubjed6+dA4PoDxqCjGZ6KStNUaZ2kxy8QBiXQUZlzHP67Oz9xFAXXK3RKAfwY/Iqkn90qVKRB2TJMDp9JwnOCmSFqphmmcjbB6r/DteBi0JJfvAwmO+bHe0ruSIOpfLf0FauHhO7+O8qMPzQgTDopSVI7Kcba5X92npn4y/aEX1RcbNgRvOuTWHNLztBKsj6C5nMHdDC+V2Onq0Jmdx7vGhjM4IoKw06aY3nW7ppIQ8lkjqVVQmv48w9yOxtipyftB6u+oRWDr7Z8uvyy3I7uQAdPQXePBDnet1Nufl0O/950Snx3x8Oqev3iOT6rJs/SRPTTuUPAoONYbZZS7yaso1dsz1A6B/IPa4yAohcfd4CTC3Tkz5j79uEbUWLfDZqpagHwseKPl+nB+617l9LKUJaV7pqfWdjpWfPAMRcciXzG8FLlBIaFdlX3Ke7E7afUeA982q/SOSp2KPXHQ9UNEyUSbXQbAJmxLMDhrrECiH3lC8juQSiTJt3SvoJRacKgj/RhlDQDfOcYN1vp37iddtq/OBjNthMyEHxoDfS+yznywbNoEQtU4d/sAPkZShVTt6KJ4bYcLgBuC0ySq7LhxfljNI88kA8nlLO399BjLN NGHCmsPS gEQEl29wJz5QT1YCiGfupdcwF3Q5GA0UHZeGWhM7VF64P6yuVeEdStQdNzXb9qYCNMQy1K9xMrvOGMWbrcM/8DVHHi9w2nJiqGymEd+Rt97vBVfx+JXIPLnTSBKzI6foo29H6TWWrebNW3NXJNxSt5zjjEbCFX3pKeCnMTL0/Y+aV1Eq8Cfrf0Y4iOKCPm7a1DTVRKeNuFxxPhipQUObc0vH+KQS7wrttLRIVPu3g2L7uc0+MPii7r5ctyRQxi17V3bLE+8y+j3joUuLaUp2ec9xaYP62k5dmj5apa39Jq3Hoz8SZzUe6/nfFdIE1WIeXF70X6p2EO+Xfs0AuPO8uVkoYOKp/INOVAPXAboUKO75i/aw= 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 --- 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 Fri Apr 26 08:28:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13644230 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 D6FBAC4345F for ; Fri, 26 Apr 2024 08:30:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CAA26B00A6; Fri, 26 Apr 2024 04:30:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 655EB6B00A7; Fri, 26 Apr 2024 04:30:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 47FB16B00A8; Fri, 26 Apr 2024 04:30:50 -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 20C1D6B00A6 for ; Fri, 26 Apr 2024 04:30:50 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D35A7161399 for ; Fri, 26 Apr 2024 08:30:49 +0000 (UTC) X-FDA: 82051012218.22.5BE8E19 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf07.hostedemail.com (Postfix) with ESMTP id B6F404000E for ; Fri, 26 Apr 2024 08:30:47 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HvqX1Txt; spf=pass (imf07.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=1714120248; 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=s4SZkJHVTIubJ3xJENK/4JDetrIyChoBQl/6M6iJPUk=; b=mCwTdVrkv/MlsQtqNvqNDPfMWitpbQaecffCpsjTS9+uDYzfvnMhr53Ng6cHn142rGzqhl aPifWhh5qOQm+ul0DmXFXBYVg/ccZDH+qNVjzvIiBMxjT7PZEBm825rsYhIvYo6IG6kqbY BpNf3vuLZoKo9isssdLDbkmXcVGe2kw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714120248; a=rsa-sha256; cv=none; b=Lrkq8YSLmq0RcuCAQBfAjLCtK8Jie8lMQ9Vc4wFMMnx8Zk/GJaOaK9+ead2WusdLh51ybe vlrnhmu5UvwogyvpnnEAGAcmQoGv6zdWKZ/wDyc8IMDispkzkR90agjFGsm7s+CrhScxkf JxJReSeQrQAPUgsU+UYVqrKspWBRqfo= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HvqX1Txt; spf=pass (imf07.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 68CE0CE134C; Fri, 26 Apr 2024 08:30:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5F25C4AF11; Fri, 26 Apr 2024 08:30:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120243; bh=OQ1S8Wnzhy960hPxyFekgjlBfwWsC+NZvejRVeb3Jlo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HvqX1Txt/E3nv38gmt4CitTWXbrhRSIFeoICPVnoRNkXimygg2qetXtxKD44gJR2l E4kpGnYwouP4pyhpdKlOuo5xag7W7GNScxVRlRWBzIjjZTMLmHMXf+NGyxM0cfO4io DZmr82EBOeDDnI+cBk7QQNlRqZTEnf6UwBynsWuhOxfJ9dpMh84pQuzNLSb+h1kcnh gXbEsVhAxE30WWuj8kMivpvoKjUebVfxsiUzgh2W5TrAfzkk+u8lSK7JYi11QuETL/ 4fnTYJa7Ioydw/qwURNgfkKCSN6W4YrNvW5KiYPsWOu5B5rnvKL1ea+pLMN1qC9RWv s/IIjTgPYrYSA== 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 , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , 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 v6 08/16] mm/execmem, arch: convert remaining overrides of module_alloc to execmem Date: Fri, 26 Apr 2024 11:28:46 +0300 Message-ID: <20240426082854.7355-9-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> MIME-Version: 1.0 X-Stat-Signature: xxukdcb1kjcd6re785cwq1to9wre8erq X-Rspamd-Queue-Id: B6F404000E X-Rspamd-Server: rspam06 X-Rspam-User: X-HE-Tag: 1714120247-627617 X-HE-Meta: U2FsdGVkX1+Mcbv3FpSk1ZqTI5Nee53HckBKf8MEK28QWf0vSxP4ZuVu744/NEuDP9h4NqYADbxleMBMoIgcYJVL17salrvpGvAzdc6wFNp4Jc6w0gZ/jqAFRKnIBJKUqtab2gLuuZi/deyZAulD3JrkGITROa4+eD6GDzn3UfFzE3ugJhP8H5lnMwayNLHhCJTsIHSOhCD7Tl+vPIR83BoFCTyLqRu/xdovqqOUHLlmXyouCszMMICLz4HwhwBZMXTXGxwoYJLKGDFhIPbWTWBSxf/J3VroX49kO7p+EVoVT+X2B28WcKIlwFgz0Z3rUhOEojR4Y0J5y9UdS97lMOdYW7sfx16RP7rGR8NFjsivSPMZCKl0cC1Gp7wBUPNlHqV7Nd1NjQbFMbK+aU1PtcbZX48hd5XD1lfMWSN1rbqEvUcPXVu4XTMgv+wsOQQwyl7ul/YhRWRCUJlpXdUpVKMOis/4p261yrQyCEvLbr7Kb/ayttfEHBwrWIDxzC+Ca13JK2EI0VwfjRlu/JSSvRGHu88LsJWqU2A7Ak9SFjcfnKbGw21ulDD57eRy9tdJgC/wTQMUsDUp/EFQ+6g9hJujoXo2/MM+kQaltV0pd3orGeAVN6wKd7rCv+u3QuOxiN453sXCvURMqDv0Mlo1u2QodQQzy0Q87gtDkQqqJ5v5a1ecSaztSz1vWAupjHL5qYRs4raw5U2aQz82yziRM3zrWxHoTTmWVziuTxSLpxLmg8CyvV+yMV9gLKgJDqSHNlRlf/DyJQpKynGZQhNuxJ8f5kNPLdX0b8Mqdd/YsWh0GJ1sjZUwFzPDzUbQ6Idcw01ztfpSivfUtA8JpTLearhZzUARQW2GfQDamrx2eBDjg7afv01zyfVZp8w4k+x5C5+5tbAvr/5I1e59Cx1fQaqhYOhd5YmSyaFArYLbjDnERZqCe2b05VfLrNO1u1/3w4N4hwUc1aVQu/pgGKD k8n0iwOZ ytm0NXqOljw5wlMBcEQqY7svrupFdaa9Q1d8YZ2KgzEp0xWyMVMiXmhbXtvAd+6J8xABfxh6sAw43jqk= 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 --- 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 | 75 ++++++++++++++++++++++++++++++------ 11 files changed, 247 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..f6dc3fabc1ca 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,37 @@ 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; + return; + } + + 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 Fri Apr 26 08:28:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13644231 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 7F882C04FFE for ; Fri, 26 Apr 2024 08:30:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D8A46B00A8; Fri, 26 Apr 2024 04:30:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 060CC6B00A9; Fri, 26 Apr 2024 04:30:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF57A6B00AA; Fri, 26 Apr 2024 04:30:57 -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 C0B756B00A8 for ; Fri, 26 Apr 2024 04:30:57 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 786E5140529 for ; Fri, 26 Apr 2024 08:30:57 +0000 (UTC) X-FDA: 82051012554.21.EC001A4 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf16.hostedemail.com (Postfix) with ESMTP id CDD68180006 for ; Fri, 26 Apr 2024 08:30:55 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=TeunQcB9; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf16.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=1714120255; 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=ov+Zy6p+o+MKzsKOdrDu2h5RMDTUryzC1DCfp/0ZOLE=; b=RvOiXO2Dt+CiF/5ZF3IEZaxe1O78a94gY1UUed6LArpn8wf8CbhtSisWPKXisffuaX1LnL w8ZLQYkYhiYyla6/ux+bAReNcGcy+3exHRSlT5pEu8DJ+h8h9f1cXHx13NcZZn+/6A4ue5 kwUvkBc00gSobvHK0MZwbwCFuTTE3Dk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=TeunQcB9; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf16.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=1714120255; a=rsa-sha256; cv=none; b=Qhr/4wklKvKFXBavjFDUzE+etuPbuZVmnz8qeexMN0nwxObfx0wv3DS9C7u0PDewI9SkU2 +HEKZb+BPn9CEtgtAthKTlb7eFcPWmLaTuTtT9HONwpY6kIsyO6YKnSJjhmPrWz6djRiAC Hl5iBPqPhNqpuakRFcmqa78HKAA4I14= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id ED92562002; Fri, 26 Apr 2024 08:30:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F4F7C113CD; Fri, 26 Apr 2024 08:30:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120254; bh=rAIWAHsYUw427kTFrCCQC+4mkWqWWUZB9Zh1fdelySY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TeunQcB9PoWap6KReLYBjiDgwQ8R6NLCJAuYMonr4uIqQ+FDsUYfn+3QUwjES0THO 1olpZ/7FEsdEfyqW/qHnL8WrRHW7bhKWVRyd1ldZENl0wFTnC2tjVvMcsRqdWxQ0NG fOgKCeODWoEr15HF0gdHFTqF7s0R11U9gt/BL+AKAUE6DNfjLjlYSoOzlK5/SA6Ir3 aeEy+WpXsNjpRuCI4xRDKAQ1U1cl9VeCvbKO1szZlW8y1ZaBEW0T55yafFLe0HfOu8 RbNw8r8Ae2+ZkPMkhxCgXpo49Tk8Ol2963PvtEdvl1QII5UPXpu+UcDH08b+AIH1Si RHTXLgzCjPOuA== 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 , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , 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 v6 09/16] riscv: extend execmem_params for generated code allocations Date: Fri, 26 Apr 2024 11:28:47 +0300 Message-ID: <20240426082854.7355-10-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: CDD68180006 X-Stat-Signature: mdaprta7eeut48k9f88qut6ife1qbhji X-HE-Tag: 1714120255-431737 X-HE-Meta: U2FsdGVkX198NhpgknmA6nML+9+BhnfsL+n068lPH1nBczJB8rP2Q40wkP+Y6HplOIqATYtoayIZ/OEB3pvcFYTRFhdKHh4HNSl2B4bX0M4FSkPDC8O6xS5PApSqvogiw00MsBC5GOhcRbb3kuUAjbVRuK2hVx9kD+lWzz8DugnKZWQG3FW65pzTarUcM4fNSc95nknfQrnoiPGt8fBZqaxvXsojdkfbkNDl6MxGObYauzhGesZqWfZKuCE3xu/6JkHXZIJhqaeWac9FdMXBunOdiCIuWy8uBbf8AuShOKcvwHjIC5pAe+sSavBwSKvVPv85vNrVd4FnFnaHWAhnVmvheLwAyZnBquaQ0ReeWkOeo9QEn788IqB06MkEuCLbMZwMNoj2EExvNM85MVMJRlbwLE6qtKNXsTMiq1QfoTE6JHETlNWMIb+rRa/8GaP6wuYfd8I3AB1OUtMlC2SChEtgpK+PRphaj4tJK6tNTtLRQF6MNcp224vKxxoaWNKjyTlF+CNPc+K59JkIdxUF6lku+ICxVumywaXyUsrvUjPilYqfs+7jGy87rXcreqKXtm8jZXStoSqHUAQ2AO8CmpY6hJPoo4iZOXVun+AC+I2Fg33RvxT9q11QzM7We/giCl1icL0rdu/AntPlLZE5SRc4cP+/aPYLEehYH6s730ooXzZ9yk9xDgyXd4D2C+p5rXA8TXxKH9Lqw+CxkTa6WlrTLeYq5MQwcaGmoQWJq4sZNmt95L91Hi9OKa6jvxG1/ZOL3EWwZWFFhwV1kYwM50bxq1go7BCSxRE4ylzfHGJPt7DJN4A7vROb6eUhYdGKgCF34wYWaDJnr4T6rNd0vbOoqKItYnEfg5L/V9VcbsA9uLcgouej+5+3oQ40xmR5ibyFBO8q5fS/+dBdgtYsV7kolq9D+xehHDneWcSFxxwQhcyB5cNByb9y74KlYDbeTepvcVFU63ADpUDWE00 +OwWe4B+ 8UT8pj+WSY+4xEkRC7xQFbMduorqFh72S6hf5yZv2kRHwHRl+I08tyRIQ8Q55x58QDz6rZiECXsteZWLJTnpRvd6fWvhSBHUKCjwZoLjwRPkoOJ7f+NxbP4mk/vW4ByILLwYVwpgLmep4yrQsA3Po32AqSr61I3Ua4tPNVZHLPpcYHK8m7LzP2l64/DUdZzCZDuDfhDGkWeQQdz5m7jImicG+JLz05qxGoJo/9F4EnuPgODWIpr1g41mfusz9sykKfk5mF/QNnXJbkNZNWVThTgOxrocQPjAmUnO5LMG53wILrnRGCDwy3+Q1vwKnXm7lzvCP9zSaSuith7jIGZRnOm9vA+1rP3m5vr2VEzzlyN8OtKIXjI70aeuc44aJ67DCsxkPgfdyQherHgaJr06WkLobyPC1ouRid9b2sM9XCQx5x3U3ETb2EZHY8DKPJ3Xhoz2wZ0ugLQPUTk1RV5Zf5NitBpXOLMJFnS5t4apvqsrzwr6eqZqNiFcrXw== 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(). 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/kernel/module.c | 28 +++++++++++++++++++++++++--- arch/riscv/kernel/probes/kprobes.c | 10 ---------- arch/riscv/net/bpf_jit_core.c | 13 ------------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index 182904127ba0..2ecbacbc9993 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -906,19 +906,41 @@ 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) { + unsigned long start, end; + + if (IS_ENABLED(CONFIG_64BIT)) { + start = MODULES_VADDR; + end = MODULES_END; + } else { + start = VMALLOC_START; + end = VMALLOC_END; + } + execmem_info = (struct execmem_info){ .ranges = { [EXECMEM_DEFAULT] = { - .start = MODULES_VADDR, - .end = MODULES_END, + .start = start, + .end = 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, + }, }, }; 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 Fri Apr 26 08:28:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13644232 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 7CC0BC4345F for ; Fri, 26 Apr 2024 08:31:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 175406B00AA; Fri, 26 Apr 2024 04:31:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 126626B00AB; Fri, 26 Apr 2024 04:31:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EDFDF6B00AC; Fri, 26 Apr 2024 04:31:08 -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 D00866B00AA for ; Fri, 26 Apr 2024 04:31:08 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 86860C07C4 for ; Fri, 26 Apr 2024 08:31:08 +0000 (UTC) X-FDA: 82051013016.06.7B2D1FC Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf29.hostedemail.com (Postfix) with ESMTP id E9235120003 for ; Fri, 26 Apr 2024 08:31:06 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=PKONgJ1Q; spf=pass (imf29.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=1714120267; 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=24FPA+RX7C/pb0x8VP4Q1A0oO/yWzbUUPrYE7HJMjA46XikLLRAqRUIb3051ijcfFffFUA Vz5s4ujh/BatC/xKy1xYNQ7X6gtxKjXidqXfJp/123SH3b1mMBXkpqF5kRbTqWEEYLexjs ZA/ET36w8AOBvXPA53RBi6t3UiuIFUs= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=PKONgJ1Q; spf=pass (imf29.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=1714120267; a=rsa-sha256; cv=none; b=7cqmKzfulXksYmLVi+peXc4eXFj1Doxg2++ddny03KPgmN0n5zHWT2l4EIG5K5FVyt4ij/ IN6MkxpV0l+Qawb+vPP5YRKiDVJFOp8gDm3c0CcxpKvr9n5eq40HuW9/O+S4qC+ghpOFf9 nm2mXuI2nwJtT57Ee6W6TDZYqPNi6zs= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0E5E862009; Fri, 26 Apr 2024 08:31:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27323C113CE; Fri, 26 Apr 2024 08:30:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120265; bh=baelIo5gqQ6dNoONu464d37hHX6/MoaALRFlqjsyJfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PKONgJ1Qdz8UWrqYN1ZX4SC/mWC6ejttaPgK34VndT+EqYH8tNZm9N5sHEIPTWNOL PeS7hUpNc3Hcxg4NFbS7e4iqg4SMFyWYqPXU297rBbMaGlPxOzaXn7G14FAQ8O1WlM FN4VoFISbQVjVGaP9hjcr2wIWVh0zoP+TSjwYlSYlvNBYFFj7HtF94z6YyELAoklq/ w/p6xes60DM4Iwm2cN4rVzoZveadaxZkTJouD0y4ZNlZXalnXiHtgBflYuf2e3NHKt ppr0urZYCzFq9rcQuln0hib9PLAzoiNM/04RP0lCGJQm0TeX1iTFt1PW6mRy4eG71Q IlXwRUKHBRVmw== 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 , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , 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 v6 10/16] arm64: extend execmem_info for generated code allocations Date: Fri, 26 Apr 2024 11:28:48 +0300 Message-ID: <20240426082854.7355-11-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: E9235120003 X-Stat-Signature: 416s9sq67x1zod1h9krxtw3mzaqen4nc X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1714120266-374570 X-HE-Meta: U2FsdGVkX1++6hI8Ncw/pOcEF9zhyH3TfOf58pLKOVAtX/12v69KgO4Y1IK8NtfL2M+KGeZbdRF9ojETFPTKK58QcfBj2Kzfbzgou01K5xz/cT9cLrbBwToGBNrqYNwViB+0T8i4Fz/pletg/Bs9X7LROwb9F4Q8vPPvpa38Dy/Cd5KFDtcKKbbrVQ2njQAbwUu/nmKGwSc/ef1rYWHViT5EQ9EJaj+hNh7vz6QRh9PXEgG/WKv7iAhn1HxW4M2/6qu8C9LCtN9H2qPtCjuXnUW6CJerkqEc3zsW+++Tc8znxp8v3ULFZ+jkiHYZodm/GgZYU2eDQYO5djCCVM5Qy4vlzdKJh9X5Hb2fs0Ucbj3H39PhuI1y0aBo9skloQaNZd7MoUP4leAzRplfx7gM1+sVW/E3TD7QMul4jG4WuDfAdQ0dmgc1xopSvPfzIsicedO0/Bt31VlhGS9b8VD9gqVKB14svFTB3a5kARmuWU2va4CiitQTvt2xxhwDQjRGnUAAZjnRoqSgaMcupfkEZbQP3J8HKlHXZUUfS+CwMeWsdnDQWOBQ5nq3yxEGYV240Z9Ivb3Woez0tfbKtDNSKHUHm+7IwNGRMYZSf2gJUygzJSL9COIVbT2NcZlT5EfX6vNRMnDYBgAe6YkGVzMwZpxTr78Zwq9xorwMJmBLQ32AAb385BnGnnG4gZkWJLWFvXPed8LBKO3jdiGTEWziF70uHLgmwrFkMFvCIupszaesIiPshi+k4lqnuOLFaVVRrPXerI65KHVDHuUPiR0H4htl3h5nYIwB8DhuFD26JxwQjWLNIRoBzt5vP52eyCwThuWgCrNwqswsm6qL4xajEALcsaWWtUEGQCvl3S+eLOHqqZEmy83I5jAW0UKMFaTfFZBsHM9ON+hCb7E/VGcVAGe4AnkohxXnisyRuweGcDMRUkFOtp6R9dJcGJP7jNAxKJ0OW/5RQV7D16kS2Dj Bslrn65Q SV8fRvMVpLYYev5KD/O24vT18Lps54k75/NMRVHXpvelwLLjalzcqGGpY0IgSUo44r+lLIpSlMxddvxXaqlli4V3yDjroX1NkekxmXZOCCqC1ZLCj5FD6IxBTE5aIct4qUB/7T0oZcvbgDr3VRs3JHmAGYXx9Q1acH/IGI7SNhmCWxqsSi/LC7TRZ22aPvgZbr/y/jBLTfOmhpWUWRWF05kmoc6lfLS7qTgOs1zObYZ/YswCR8l01m3M0WcDl1BNAqwAdLwUQmnLzrNmT942/j2Dfnm0HIT+OU9h4m9JDWxMyRSHyOPTVU+kMsMVK9Rjf/PdjOiWGcC6rWSVQ/fS8RbwP/0pxbWLVyZ3vSQCpmb9QTDs= 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 Fri Apr 26 08:28:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13644308 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 39A15C04FFE for ; Fri, 26 Apr 2024 08:31:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C4B536B00AC; Fri, 26 Apr 2024 04:31:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD2996B00AD; Fri, 26 Apr 2024 04:31:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A731B6B00AE; Fri, 26 Apr 2024 04:31:23 -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 89EDC6B00AC for ; Fri, 26 Apr 2024 04:31:23 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 56E4B161392 for ; Fri, 26 Apr 2024 08:31:23 +0000 (UTC) X-FDA: 82051013646.04.EB46343 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf16.hostedemail.com (Postfix) with ESMTP id 247B118000A for ; Fri, 26 Apr 2024 08:31:20 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SmvyMUme; spf=pass (imf16.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=1714120281; 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=OLL3WoJOm/QjNy4KsWRIRFpwRdAiWRi2iz+1pMPrnF5NivKaKd4tgFaJJvOaT5c444BrNO u49qcqIDoPLZ6+a55d0rOgjl5ccYLUSaS5pr9VPdaOvEg2+lEf5PM/RSqVRMYexc7V53w2 i1330th7zEQUYJpUW1hEMHqq8rdp+/8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714120281; a=rsa-sha256; cv=none; b=FlsmlNMlRv7pXtb1yV7C1JH4yyJ3y6aPi35WKMYjcMU9kETGO+doCJXE0BkqgdAOlAU0OF IcDXURUhCgAiDqeVNUX+gk6YH3Hvc0QVYH6AimMkBRTwNa5nQvqxBqmJGToDFnTNGVq6x0 2n59JmhTnJwMedUG0hhJN51tTfzdz8Q= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SmvyMUme; spf=pass (imf16.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 2B96FCE1BD8; Fri, 26 Apr 2024 08:31:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D06EC32782; Fri, 26 Apr 2024 08:31:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120276; bh=QWGTfmxM6u4L/G8sJRSYS9LtFcq3UHArwE9pGA7ZHH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SmvyMUmeeEFrWhUbUHKYn4DMMnLUUa1g4+adu28RzctMKycdCQJleanPBw3qpvC6e AXnB3fL3Y+frY4KjxDxYGEctRsFjDHtgJpKUgakhljuTLQyByVrPoqm8yiw/ese+Sw 3AINiEao90grvB42lX+M49xK2vOiscW+CXPmMzHjO1X9apGHPz/G5s/ugtCXfPjwN9 214UPXOSJDw2q4YRsmzMcVl4U8SiTEGKs66FQ/JJXbBMCpYr8IcUINJH7HXTRFtQYE XiSs76Z4km7d/H9zgVIB5QWLIoEWTs/cZi94+ScfkrPABGeDB46pF5CGfvdU8JqSEh +esHXQ/w0RQ+A== 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 , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , 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 v6 11/16] powerpc: extend execmem_params for kprobes allocations Date: Fri, 26 Apr 2024 11:28:49 +0300 Message-ID: <20240426082854.7355-12-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> MIME-Version: 1.0 X-Stat-Signature: zpfq97xf333zssph1mjrfr3ate441u1u X-Rspamd-Queue-Id: 247B118000A X-Rspamd-Server: rspam06 X-Rspam-User: X-HE-Tag: 1714120280-526060 X-HE-Meta: U2FsdGVkX19E6vYUvHGHQWF1GFz1wShe+jCaZPhUdXUi+05AFk5SSlpPSpFIXTrNim1aeSksnBbpfUpFqvi3Cd7GIykMJ1GJwPFw/XfL3NxIObG23U1NbX0KOpXbiTae4at0v3Jeqf3OvwQk9rxXAR7UeaaYuxflhBJH/SzOftq0v1Qt+hFgb03qoNAfolvENhQuSL/2fbaFS8jFhF+9e45TVk6grExoOR6ATECjnnQInXMlwpdTmVBOFHy/Ilwy+1Ez7Yws5tGdHqFm62Rd5g1i1dTnwzj4IxFnisepnTQk0zQbX3LAD0jtl0LDn4QWC1fJ+BpN7HEB8DaW/ZrxeZcFRi+j9wz5uo2HP8/VTq6XBwAjbewwblndsnVwpeOvLxzRMQyTbbtELChVQcWEzJ2u5651EAMXk/d54r70C45tG0nCukTJzgGw/tWwk4HdZfg1NVd6KjKP7ek9KxvlheXAicsjToL+ujNCOdjmT+msB/LhaNZ4HU+LEoS3f7+ie2zuhZagKE4xv/DDnIuSb3NCyl1AqeuR9pe4TaW1rfDFWRJLkceFB7l4I47ozeGu3Rwhnz0DvarH+k1Db9nFTewpDRA11FwWynzJMUn/OOqWa5ecbg+Fni4J2i9q+aeU40tJltaKJAKAuXdeSYuyXqsVo8wFqeCjcPXAFYifejv0iTgPGktKlV/CA04r3ScVw+eVYNOlHRaRviB5sQLK4yRgnUIz0COqSKgRYemAg4n1VIutCYzYWNzvGLW06lNShkeHxoGffPXwrdlNzD08QYqHbOOO0I1h8SVe9IQPqH5sVz/AdMoaTOAMqfKTMVUJp2yp/yIDpzL9j1StslDGtBw4MicIGFREFuDlxvVgG210Z3KvQeFtM4uxv8P2gR/mBtBkggtYYFChXlgMnspZcY7WTU7wVKeBxRn/rEfsXYT0E2hLK6r2AbNCKBU1US46S7fzyOsAAKorOYPVOjE pNb3GHBm wxJOCQGNJicn1wQxpA4vOxasTNQ67LXwjamcfXvjrAbHxG+lTaUtGshnbFBpTV6gvbbrr8zJpHHMBcWw3RIXsz2uqlk3lqRdZfUuf7PfW4dL6aBsooxp7Mt6wdL87iyOw7UQO7F4BUHrDQToQ5+TdbiX1anGP7wLG1VWTw3/plrW44hedc1kfmEct60smRSPBeYDcF1uRg4i5c6QJ1XbgQX95Jh0GncrOzxn904ZUAGE7U2e3qNIZhaOPx2Qa6ei5pfFXVsxhVd3bLRoMzMlflYClNsZQobzLuxKKCSBJoImrocaNB/u9X36tr+OtHM6JFd4rVVJeJXbsWn1kbCq7ZV84I0Z0OTB58Zw6suqsTTMsBJxDaA952rBqRjAKoGW2zxkqtniTIjSjgBFJ5Zmgmy+gSnu5BPhuZSmbD15Rp9EhQQ3YgDpqllUKuQ== 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 Fri Apr 26 08:28:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13644309 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 D957DC19F4E for ; Fri, 26 Apr 2024 08:31:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CD9B6B00AE; Fri, 26 Apr 2024 04:31:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 654546B00AF; Fri, 26 Apr 2024 04:31:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 431C46B00B0; Fri, 26 Apr 2024 04:31:35 -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 1DDB16B00AE for ; Fri, 26 Apr 2024 04:31:35 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 683BD1413AE for ; Fri, 26 Apr 2024 08:31:34 +0000 (UTC) X-FDA: 82051014108.29.911292E Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf18.hostedemail.com (Postfix) with ESMTP id 159861C0013 for ; Fri, 26 Apr 2024 08:31:31 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AQFZDVYj; 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=1714120292; 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=hv/GB1lHdfpza6tCVzKGz7oNQioKKFd5B4vlbAthZ3M=; b=gRZMUhaeui5S5ggGLYpoOmKYli7vfINT4lPCEt+gsKS8riyCVpQlVdru4dXOUGzF/VSJlT zHf78sb7P69ntiQ+n2ps7RCmkRyejXOkmoO3c9ayT+wsqJLa8Ufim6awDeqkEmf2aakR1X U39RqQLfBGutkGkjf7Xa/NZ0qF2TE6s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714120292; a=rsa-sha256; cv=none; b=3qQdpphUWzVo7CMgvNQIOMI3lBiCaomYo+h999+hLYzLLrFjpCU2bBzMDRf6zIuM8P4FRV QLrGqeJ1MFG4RCMQ0F3HNCs3670iyE7xwx9rFVm1v/QRGr2eBPsfajP/VqP4/4PuuXuXcs bTmawB79r2b7uAwW7fvureqmOk2R7XM= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AQFZDVYj; 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 B7A93CE1BDF; Fri, 26 Apr 2024 08:31:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5471FC113CD; Fri, 26 Apr 2024 08:31:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120287; bh=FCjslKhHpXCbAGWdIK9tbDmLN8WoJ9Lj5CTF3IMagAE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AQFZDVYjXN0PkZshNaHfvbm2Xs6pOhw9H/CFtQIrtjqHpr+q0rptxR9bvCYQPk6Tp NSX5AZmxz404jxkCbnjS7BEjZDT1h+Avg2Ql93Ge8QV4gl993Ke02YOxN3GPN9KK13 kZNND/Wofh8Mia2yWTfraaMFnVK+LycZxRwbGDK2ymwb1HQgxOC42Wog8N9pBTI8X5 F/lGCQrpLCectXKSMClfZrK3mOBXgWSX1FPheT1m65h4cskOCU0jHn17pEqAtNniHF xb1m2TS8WR5qT+oi0VWfJzTZDBBSiBBsdfYO8QIYtEF62nFRnJd6SpyW6hJaZLpXmF /Tuen/oPZr8Nw== 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 , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , 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 v6 12/16] arch: make execmem setup available regardless of CONFIG_MODULES Date: Fri, 26 Apr 2024 11:28:50 +0300 Message-ID: <20240426082854.7355-13-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> MIME-Version: 1.0 X-Stat-Signature: ikss6h58961357njhgu7cpa1kbc99ngq X-Rspamd-Queue-Id: 159861C0013 X-Rspamd-Server: rspam06 X-Rspam-User: X-HE-Tag: 1714120291-610048 X-HE-Meta: U2FsdGVkX18G4MSdprC4Y1sjwoTxNAV+1wz6ThTpwgusmKUv5MCUwWqh9sOC6lUIUnYRLQ48zWwOf1gFiQTUZ0eQjIUDc/8tq4aYeizwcd9uTt0FHdRUHbF3NR/63zVN99gxbkcL3jSaetIVn768e9FIR1Y9I1+bUuSv6cAvL6lmPobEZxn8vtJuwyyqDz/I8lNPZqOg7iomKVYy0uF4aFxSnsNE/xT2+PMUfY96KKo+hP8pU0NwJL64g0ITmovfNfqRYAGBbCvkvo53HKu1hXfnDfZ6sEEyRMfRQ0746RpWmBtR1vblzlFKGKqe9JwqHdZjFU5JMlAffBGljhSLOvMMj9KaKbRxWgU+22cRzHOuPjkMFzqVHX0OkVwmsdoDdAgk7X1MVR3zc7R/iZtJBmfeUorfjl3VJaeno6csy1hStjZrxwon3/9Vx+6P/n3u1SROKRvYxTzCiCPm6AClwN/uv3KIWHJKBNVrz35dJ8WpDCRibtRS9tiHWrK+0SldHoSpVxWEGMeDUbGhg7+cUPrR0ouQz/OjZPbyvo0YZCokzlYNW02dnPXgJJq+n4Kik1rlnahsfZnQPpWtc5zHpzU8cgpsHwSiWvwbuo+Z88wWGFg0epCK8HO88bErHRusH1j0i3/m8MAP4ZaIL1polPgl597b/Y9I+v0IC+twfTZlxlmFdep97DuJXMHqe3GXLnJoiAkRtYAb0tkas7YGdIcm0ZJosSOjh44IfcDLEsA9keJU39NEXOV0CXbdiVa+GkR7yQXDPMsmp0bWkZbe40CstDyiV5f7N6Xige5x6ghYkUpaOsnVhAyCgNblu76OR80P269VU2WNXh5itelaoXnRsxpAjikBIi80odoUukVjSY0CWffFjRTOUzyAzj3a2cr+2iDmM9wqOslvFYo6b0NUVybjYzmd1WuSBa51r+O2YAmdoqS1VAyeCsTF/iy+fTSK6kEdK0PRq3eFBLQ owisyQ17 9pLpmGPYakXVJo/uAj6t4ju5TjPMqkgdK+v/FlC4BU7UvtYXjce78Tt2eFrE8ZAYmxEHghhSHDNkenkmNTyfboRmayUbAF6NRI0IqJMEDCArC9cPZxABQbRhZmjIBwGUcHBq9WGiEbhDNDoSrLXlnw+WSXlGg7cS0e3AdIchVeH0gwCBfrkiF83TP8cSpO7Z+biZg2QsK9BLAlalPOMjI9jqas+4xVaOypF1zWM9c4eJ7yy3ORaS8KGuIRl58d2UrMxObAaYGTE8kJVFth82hdFSmzmtPC4uIITB2ljkysOqLDvAvsj7uRGUf4//LkKACzksulcNC0aYBCU78JpxHHWCqEKlEwgDegNfZsiXc83Zddpf5YG4eUyjpWekPjTD3T1d/M0skkK0oK8NqjMwc8BGV4MjKWCZkx0N5D7D4uGuFA7hcpb8ET5qLKR4spj5CME0o 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) --- 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 | 44 ----------- arch/riscv/mm/init.c | 45 +++++++++++ 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, 463 insertions(+), 445 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 2ecbacbc9993..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,48 +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) -{ - unsigned long start, end; - - if (IS_ENABLED(CONFIG_64BIT)) { - start = MODULES_VADDR; - end = MODULES_END; - } else { - start = VMALLOC_START; - end = VMALLOC_END; - } - - execmem_info = (struct execmem_info){ - .ranges = { - [EXECMEM_DEFAULT] = { - .start = start, - .end = 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..902a4827a0a8 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,47 @@ 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) +{ + unsigned long start, end; + + if (IS_ENABLED(CONFIG_64BIT)) { + start = MODULES_VADDR; + end = MODULES_END; + } else { + start = VMALLOC_START; + end = VMALLOC_END; + } + + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = start, + .end = 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 Fri Apr 26 08:28:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13644310 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 9B911C4345F for ; Fri, 26 Apr 2024 08:31:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3245A6B00B0; Fri, 26 Apr 2024 04:31:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D1D16B00B1; Fri, 26 Apr 2024 04:31:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14BCD6B00B2; Fri, 26 Apr 2024 04:31:42 -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 E69816B00B0 for ; Fri, 26 Apr 2024 04:31:41 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A31A3160735 for ; Fri, 26 Apr 2024 08:31:41 +0000 (UTC) X-FDA: 82051014402.15.CDEEBE5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id 2DD9216000A for ; Fri, 26 Apr 2024 08:31:40 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LA0moLCc; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.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=1714120300; 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=psLFo6TbUqfvrSKPfWSlG05Is5yttHhilYZp+m5QpUEQpQLYhd/wIaDRjJXCn9p2h8EBAG voiP/gFa/X2PrkOLCqo//hvvMAEEulUk+69NuuPOSQb58bdV7N/htLFNnJ5VujNwgZ5j6G NVK/6I9XzQIq1nL/H5JDMZQC/d2FxZo= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LA0moLCc; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.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=1714120300; a=rsa-sha256; cv=none; b=LSTFrQ5Yl8H2vHz+EkVb3xJ/nTruUQNTc7H1YgHe8264jZZ5MXQersBXSGfKwGtNRIAfjY QRV7pON/cQ2GA4qAvYGPC3x0bRu2BFcyPw2bpMF0urVXRYjT050iPiJf0qeKFfhLWw2ICt BaHkfz6deZAjXk5hiHKTi1/wpFvQw2M= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 5A6E762012; Fri, 26 Apr 2024 08:31:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DA85C113CE; Fri, 26 Apr 2024 08:31:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120299; bh=IjQRyjekukMjpd5h0+fXfebHcomYxPC0ei8vi/yCB1s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LA0moLCc1XyAaxAPTvc2WyIttGhEB1PUkRgD8LjafqmW1PC2dnh9KEdiQSzuSb0T4 YpX/elYXFX8hxPbLkyV1qqjNauUZIgcZg3kzBpvpU6/SKuLo4yitJSpCtiFIFbCwVb ORmYodfdLWjNxtFIjvgEYglV8iMV/tWBwtMAZsyEEgjuUyNZeEVpzh+A6GJki4rfG/ DhmPLsgQ0pxg/0E49LfmzQ/p9zYIhFidW2Xoh1epuanPXsEfkllchRca++MFsCY3GX XMZ71Es0P9TwVba3X9SadBYfOb5dasZkd5McPlM57jv3qH/9znon6bHqyIjzUQqGd4 sYSWwWhOXkvXQ== 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 , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , 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 v6 13/16] x86/ftrace: enable dynamic ftrace without CONFIG_MODULES Date: Fri, 26 Apr 2024 11:28:51 +0300 Message-ID: <20240426082854.7355-14-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2DD9216000A X-Rspam-User: X-Stat-Signature: o9dxwknadi4pxmhui9ozgg9co9sre71i X-HE-Tag: 1714120300-670319 X-HE-Meta: U2FsdGVkX1+By5duOWFhGjLTJNl8XVs7s9Oat74gEmAxWsMkhha46nzZRnAsIowwgPz3HgGgkrR1Nsto4h6ihuADHbwvs5eulpSiINYm9JjUVWkG/BsS6dOtCeQiCZMPvlsDRdQ1aznsOUYgqtf0bTx0fcM+qlaRAUkNbguZzpcnOpgXQJkLN5CgkIgmJB5IMojly+q3e2vtWGpNQBUCJHf1O1nndb5ixGZl1EdW5R5534rqQk2u+ZE/xBHz3g+vKYL8Qw4+tce1lAMxErhTmbP03AeHDWjefLnrFRB6GrA8o1kl2FY45U6WSBuXFzLf1+63UX63/KLfK2V1Hw4eptm1JYOrrze+3gePHkugBr2qdMX7QRH6X/+5e2Qv+xuwet+m7j4yhY0/XX0q8MnwJDZANUPCR/yHY88Fu3sfj2I9Hq4zSucn5aMGO++mTsxqzpIgVtxE+o0OOTaPP/7bkwcm29Iz6l37GCGZXpvDKQvLXIn1pdZBG3mHQ/5Tu6mrDbqWVHiQmnkGJnr68SCwU2QxG5s5iTRodzddf3VQAq8VqM/Co8wlLrsbj9LxGMKvZrtBCZU6TbpLoAwIIDPRZlbDANkXdnLYFd24wMfydzG+JgQNjsmyFdWgjTSVykcySXAK2ffUX0zXNQxYtqyP1FOHig7pfEfc+bh/NyY2y4UFr5f6HKnZtCJKU8gWxC2ctfz5vqwyrSFe/Eg2brxYIsC6yzFl0oiAuZFEhlfk/7+Gm1NbFGBDQmjTXMRsbR6ldTZ2J0cHxzRq4YSceGgrmkfCRSZ0Yt6fQwmkU/rJ85AAOAwntwhGW4lPQAgqFhrJWNpLP3LXV8cYr+7aEbqa09iipovoePuora8qtlXpuUmFd7pKlAi3NLKYNJvDIaCXB09Nabde/Ry5emK97snNlBpJrGmZTZM3H5mTx/hTldRciWLBlin6Y4kzLNv1Z+qaToTxkJJPw0m0Qi9T4FC PEdqfRSP QbpbnDSTX5jbL65ISdJrKlYF9ZkLiwtOt0C+E2BEaU89odgdbnDz1PLuUI9HzJV+FN4BCALGd0ZnmmJ0l6bdh0gVTYkpTJ3AMaKDwkPPjMP/BYrK/1LPxqtUKRIVe36xbRwr5mRA74INvDaY2af3XTjSnqQ== 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 Fri Apr 26 08:28:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13644311 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 ACDDFC4345F for ; Fri, 26 Apr 2024 08:31:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E6086B00B2; Fri, 26 Apr 2024 04:31:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3715B6B00B3; Fri, 26 Apr 2024 04:31:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C22F6B00B4; Fri, 26 Apr 2024 04:31:57 -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 ECF886B00B2 for ; Fri, 26 Apr 2024 04:31:56 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 94D861A0793 for ; Fri, 26 Apr 2024 08:31:56 +0000 (UTC) X-FDA: 82051015032.21.B95CEF2 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf10.hostedemail.com (Postfix) with ESMTP id 4680EC000B for ; Fri, 26 Apr 2024 08:31:53 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=T2zDQNxT; spf=pass (imf10.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=1714120315; 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=ZoaTKIDL4qmEUZLhoxs40DTczOotHWC6D42wMaHf4/ImvxyBvPVU9GZdAdHYgz0dyOLaIb gudjUB/780BQWVnyDfJl77oweQBLeUUv8OliTrOKb4ABKyGM7s3S0ZyQp6b6MWFe2oXu1u YkWgOFBn8+iiXnrhHCP2MG+NTYlYJEo= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=T2zDQNxT; spf=pass (imf10.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=1714120315; a=rsa-sha256; cv=none; b=mVxGoFsGDyH4kXeCAI3vBHr9zPQER+AXvcUa6DYlpRcC8YMP7ztPr8eMQAP+Lhju+yhLQ8 7qb+htVslNkmc5PpKW8uVxJPRAx9JT5t/syuhhKjMLPCLHa/IUb/5aoV0u5PjOsqDEWCjs g57vjWHehekKVzqk8YCS7aCxmPQTweA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id E5F5FCE1BDD; Fri, 26 Apr 2024 08:31:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83575C4AF0E; Fri, 26 Apr 2024 08:31:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120310; bh=dj8Jeem56mTOW4r4fQ6hbW3YTYti2N5hSv58QgNFPjs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T2zDQNxTHEoxJ4aCR22G281nOiollvnCxQOab3enluXTsoB12YVvViBnoB7fetYqJ Qz4E+LTwmZak2qqvfhx89kkdiLHJLSAEA7mzcmpZ3CQivx/dOvo6Kp/Fs+m/P+7Sky 5HWHTSNpba7DicZuIx2fsYuSovhdErrakpV+E62oVc4AFfW+9oMqab0M2onJnInPx+ Sw3HlM3ogzwYsgrEIdl/DFTp059qi6Vt3C936iyKg8laxRC779XoBEssstc19IZg0T ODuYJ73SzaIa0u58HNGjY75N3s/l9v1NtiKzHTlR62sTKxj+VCH8EjvV1fCdIwChug QjvpJ146GlAAQ== 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 , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , 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 v6 14/16] powerpc: use CONFIG_EXECMEM instead of CONFIG_MODULES where appropriate Date: Fri, 26 Apr 2024 11:28:52 +0300 Message-ID: <20240426082854.7355-15-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> MIME-Version: 1.0 X-Stat-Signature: pjypryuh8jrnkpobgu33wz4mbo89k75f X-Rspamd-Queue-Id: 4680EC000B X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1714120313-747926 X-HE-Meta: U2FsdGVkX1/MSzsL/SMeUSHFx5YVtO1hnNm93Gvixv9BRV1kUvMZjdcYTZmaodiFwKRctjUSYUbnGq+VTKV6bvzYVq1MixVLgDYMdxUmlo7PdDZNB7uniUxIqmuv+Kw0EmzTrnJZFUdjbhsjHA4A4bl3lLu9Q8d1CpJ2gzWVgDIlaq6YTaMRQYi6t9RZHjMK3cmKzcOv9+fu/PxC1SddL0FYUjB3L2kbKe21ir5hSgIup/0Sa1Pb0Yzt9T1O2yUMoAiHTBt2Lu5eq6t8jbVNDoKx+c0B31Yj5vD09GqGzP7gp0kW9FWUKCivo/i+VQbrxHp1Vw//ydm5pDpe/TTvjzvzWpbawHS7FzqYGMU9PExKz8Wwmd+dd8yR25Esi+6CDv2BaclVJta86H1wPXP7iQJiGpBlnyA/84QsGVUiwF08vDyZF4JKYxy01g2aXipflPTQ25rQnh0Vh5TPoC0M39jfY+FC3UKmtY/uWHSEu2NN1EOInUGkLHrQZ/6Ax+cNuRDtKD1Hp+rKTk8oLiNyPNNxukO/2WS6hrmUvB3qI6MWFjTNVTLTEixH0Lm4P+kzKFnLQA3p/9HC5FjtO7AU15nYdQTClLWaK4rxxtkiQTqSsyshk9BV8OooFCzPHGNho5Gh5YnNwQ31S+xBWYR1eR4X+uluAY38kAmKud2o18d3f2EEHEJFM7qgt8WM8stoR6FS5uKHWTRZmiYXmVDGseoF1zTKB/j/Vllz6Yp5NboO8A+SgejUCS1VZvOfTovJMl1PbMmg+FxNBW8GsDPaa71Gg3m9wz6+s/+gAwqgIkjQcgTNw218eLT+B8whSP5yFHLYcXzPVYQFdeVn51myUGqAG3vqz0hP12kyFBY8yrw+0AyiKJhcBifhW8GPHMFk9WfT95soD+Rvub01Z7cnf0oElPFfc/fKLpyfwsGgeHaub9s6L5WdJIFgQb5xyltW3KPxS4fqTWHoHFXkMy7 jC4EZmvc xUHgaObb1MOUxcgTFLAul/GtXYcpj6OUI07G3x2dVJvXMyqRNhnstTCUdrpi2sNcHsgcqS4nCqdyODdQ6oEItkR5ID3PN9OPj3ZH3h1nTxuKIQtYI34xR+mz7AqSzKMeHxaIxcPDpxa3A4YcbTldzeywd2a7izK7QP14Yi1KHxaiQ26//LCjYoflz1u3UdZKoz/ttweABOkSGABQhIzhQZJke3n0YWiWSstytiZ/gU7Wbt9WCUQ3EKZp8j8MeDNSM4nRY51+zk7HAYFWRd3F6lUzQEtDBH8nu1r3vtqsJl2RzCz9rg9n2oGpdXtM/BS2J31Fb+BWHydGHyT4m/k+MP2xn0708n+INCtWK43IvB4hZ4Ki4Wb1XAaJVp6501laVh1wp4M5lan/HFIIvb9MS9T5kFVMUR/OZJGQnpGWbvQjItzXbUKfdtzho7Q== 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 Fri Apr 26 08:28:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13644312 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 BA567C04FFE for ; Fri, 26 Apr 2024 08:32:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51F596B00B4; Fri, 26 Apr 2024 04:32:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A71E6B00B5; Fri, 26 Apr 2024 04:32:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F99C6B00B6; Fri, 26 Apr 2024 04:32:08 -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 1145F6B00B4 for ; Fri, 26 Apr 2024 04:32:08 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B76F28132C for ; Fri, 26 Apr 2024 08:32:07 +0000 (UTC) X-FDA: 82051015494.04.63C0FA1 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf08.hostedemail.com (Postfix) with ESMTP id 60E75160019 for ; Fri, 26 Apr 2024 08:32:05 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NtDywaXn; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.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=1714120326; 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=5HFrSsIOQFdwLjQpJN7cSLrlQvcoSs9IGJRBPlLLNY0=; b=jHyvHIB5+AEfFh1EzNPP2bwncUIyeTj+ZEDa2kr00dNBMNuBM2wpRlA92oPFiiFjJhSaff i2Piewc5C0kN1ylCE9KNIxNMs7IK6to2y6bZr4gNzZNUL2IC7YbdJmIprxO/TZ2lwT3wkH gA2zDeO5Ru57KvlDpF8fRYSS4iN2jh4= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NtDywaXn; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.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=1714120326; a=rsa-sha256; cv=none; b=2b3G7s7EPuNH8JDECFr3XsTqwW+gxuWBufFU+JAYdwvfhuycpj+9zfRsAQlN6Q69IkxNYK ExRri9B4TtXiXuFJ1rUh2SK9IeJZLQW+uxT0s0uH9H7uwLf6spbEhxQTV6m5yhz7L+q4VL Y14AI1QhAkYHFnl0/33VoBG7Vw5UPww= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 09AABCE1BE6; Fri, 26 Apr 2024 08:32:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AC87C113CD; Fri, 26 Apr 2024 08:31:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120321; bh=D/LgKkA0Gob427zNusjsii4Fgukj7DrmwMiYlEjdnlY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NtDywaXnqnWhuljILjD8vmTh9geXka1YAKmrSFvlc56Zd5ODWg+iM6Unoh+n3wcxI L4E0HsSEB5v/LHXXRsLUtO0SO7LTmy+BAA3wAxIIVnvtSteMFuA2N3i/4UpIdklune EzfCeM98t8Hc1qm9JZ+1FkFhN1OPt8udZCnF0Wvh3xAotBdjwQf97lT3sW1NeMNYoP 81DpiOWgN5sVjGNNODQSpRT/Lhjj+goH6mo+AYRgO1Kg7HDrhMX16dopMv0So1vXA8 dkFDq+I+68+VjdW3ccTkzktM4kS9aT3Iz/97vDr7gBlrvzvihqzr3gKlC/HdPVeUlA USa/X+rEkZMSg== 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 , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , 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 v6 15/16] kprobes: remove dependency on CONFIG_MODULES Date: Fri, 26 Apr 2024 11:28:53 +0300 Message-ID: <20240426082854.7355-16-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 60E75160019 X-Stat-Signature: 9kcayqupazy8kjr6bqrwpt7pib61mmi3 X-HE-Tag: 1714120325-394015 X-HE-Meta: U2FsdGVkX19ddUuCEUt+zOa2yXXoUwWFqNmIJz+ezeygDutjL0nR221IXNjTxCSiQm1A8e8VkObbhrM1DZjnOfmRJGwC1q1+J0lTkDV0vReO9xT4kNVKQ36nCgRN6HKH3Ewur9feCrmH89vSLlwLRXhfy8GGOuvxLcuOd90cKUR0g6zM48DhTXqo/jAmA/LYk2br0BI5pfzJBP5aMENNEKvQho+6ZVGseTB1UtkJDZ2NswTkXa+gP5vetwjXZpmyTHD1+9Wnue46LaqkHKTjGdq3UddbKDT6I8OrUBXy7FuRUE6BPSgYR/FfO8vRazzRUYcJx2ZfE8GQmfmZ3qDDnspqYlGfE9kvtOY5PfNtK7BW3qwqUcneVQRpKXVwl1MOhRIBvLly02atiwRcueDo4L2GgSi4q8jRU6HYmoM8Yk2syz5pKXHWzToACUplXDyFwGA/NSQIxeNEvu1lz8YZob684BgxxNFJFguc8J9HGoZ7zWkGorJpXdivglGq+vkuMKy62NGLL2SzFp4hNWhcYe1XXdm9K56GHxP6cCMNsZwxn09osvuizxVMjg8S6KH5t4Xq1Tuffb2R+nkDSCwvEd4+nKV56wK7dtJ+HDAuXId0dHvhoyFLQ3E74jrdsFT4fGu3D8vjKC0EhA02ozKs6nFoR8WdvvWpSX3EbIpUxTabIPOHsC4/PcI/f5pGkIgqGyvohp2lPwwxTT0VkwgGpzghi+w/kVkSDBdjubygLJNtspKlcovzYVcJtIrdNTGar3o+zpeBw2RS20/XNMrjE7AvEdeqpzaj2dYtl8LEM/qBy+lG9zb+57lSW0K7VXfgFeOTlyu1teaYmYO6UYUBGDAOl/msMzFgiOBdwaoQSt5B8jhOBUzLElOZkd4ErhhCYqG5U4He3vnyfns5czAliOs34WFGMCyJRNl9wYpLWXXBodagSuqATB5ar5NXEolBW5PddLdE+jnHKNcd62x F80VNDFS DAL0Qj+SAA2Or83IsHfnmS07wj/RUgHl0xocAR8hi2kwf3FNvr1KfcVvb/+aSKZL+Zoic5CKdLqp49MYSOz8GdTsquz65WzLIAZJh499eHoIgjvmzwjbOTmR0IsElhcWYjMhQkbeHtPIM9FPWbLrzGeyrpwKxYEh2JxSO5mVLqrY12g0WfzZR2eUYfFVjA7hP8oALWI++TN7Q+27gk+eYbmjF1WZP9uQgNX/ebo0MM789WNnwsh+y20/ygl0Zz0AgBeAiJlFkjQCwfgpWJBd5jYAdnlWao/8aJh3TbvIBy7XvbdT5PtlgoVHlZ32rmxSqyDeZxLj0iHOBnOsYWYtyRaZgR2WGOZVqhqrKB50D8BhfDNbcnvUBFGTL5RATdR6vvZdICNbO88bmTsINrxcFK0vztHrqAHQ+vifpowzNhOww16KrGP0A1YR5Dw== 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) --- 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 Fri Apr 26 08:28:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13644313 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 02EB3C4345F for ; Fri, 26 Apr 2024 08:32:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F0086B00B6; Fri, 26 Apr 2024 04:32:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 89FC36B00B7; Fri, 26 Apr 2024 04:32:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7190C6B00B8; Fri, 26 Apr 2024 04:32:15 -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 51F8B6B00B6 for ; Fri, 26 Apr 2024 04:32:15 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0BB321C1164 for ; Fri, 26 Apr 2024 08:32:15 +0000 (UTC) X-FDA: 82051015830.30.2ECCCEC Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf02.hostedemail.com (Postfix) with ESMTP id 5B8AA80003 for ; Fri, 26 Apr 2024 08:32:13 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=vQ8mtMLc; spf=pass (imf02.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=1714120333; a=rsa-sha256; cv=none; b=pgWjvDAjmPYZJ8c9fjiz92DSlASYeSd2C7LHAekuHQOLmKbrbioJ5zdcz1E+C4i2jK+VPT xcVppYcIX5We3kuJ1HIZNXXlBw4oc14OR/3KLyLq+92kFcVPXaGhHJhyNpNGaKYZyLajB/ 0iWN3THBQAuB5Uu7EtG47ASPEOK1Moo= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=vQ8mtMLc; spf=pass (imf02.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=1714120333; 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=LsylsHv50oscKvV8ghHGXJmQpdtZImFBuJ35hadA4d3uHV+Hurdk6IEAfkEhlilSdxRE/A ail8QY8tEMGvIU5ITmZrjdBJxaT08JKo2goaxlJxHE7Zv1sNt/ftT+enStOKpoltFKFudo DwHxw0KCAAFMd5tCnXagONpXvXJcIj8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 99E676200D; Fri, 26 Apr 2024 08:32:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5724C2BD10; Fri, 26 Apr 2024 08:32:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714120332; bh=+AOj3OMDSB3feHYUPdQfVhUVtDWDdcImqVlO1v4xpng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vQ8mtMLcrimNPX91Y2YQmvdQw4cikExY2pLxFz+/UT+e9TLir0xOZ3FBo5RrzGpzb JWR44T3XJshDZMYXiba7l/A544v2LOC9MQLrngwOyrxDozIHscwKHoIb5QIGzqfNXg hlLFV/4Q2E5d2sHTZ7tlXh/zsv1dp1lvJElyqwmb0wchrenBmob4Dc1MtkVQ+MEtdh 7oC9vfii7ckW0bsH176/J480uOF/fn8rgcExibP+RvW506G6An6Z0c8ibMrhm9JIVO 4Z8XvkBOO1+QWHViSo081jrAt8THz37irqAEYTIKSADYbtZr55Yu4BB7vII7ZC4wKk Q8kmGiXMxjpQQ== 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 , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Michael Ellerman , Mike Rapoport , Nadav Amit , Palmer Dabbelt , Peter Zijlstra , 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 v6 16/16] bpf: remove CONFIG_BPF_JIT dependency on CONFIG_MODULES of Date: Fri, 26 Apr 2024 11:28:54 +0300 Message-ID: <20240426082854.7355-17-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426082854.7355-1-rppt@kernel.org> References: <20240426082854.7355-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 5B8AA80003 X-Stat-Signature: wmimwtyr7iq514rjt5ftzksg8f6ztcs7 X-Rspam-User: X-HE-Tag: 1714120333-342904 X-HE-Meta: U2FsdGVkX1/SqCDEk2wJYBfJpbcdA/Efc4Ov/HO6KI27mNP2tOqFtVpbffXLat4QwgviCfUzma9vpN0ENhRElCo7ha82NXtnDJ9wQcwY/Y++OKjRImgmjd8v431ZakQxZnTG5Ja7/UWLWbrgPYhYUKceMwyVcM9jTHa+iuWP6GHm8bH3WcFOcmBvQSB80xhWN1q69qZ5A+GLsd1RkAegkUc16NXaQ0v1BpQn3uFiWEhxhx1irDLxkNQZoeIlFRxPojUPm66YZv1O1tCnL0lLcGH1j4Gr1LcmaNn+EMflftfg+nnOybOnm0xKU62/AhtbVLfdWtoH5C5UmYabLsFoUVT1KrUMUiGmDAHtJI8Ny8X3gYKrLdHFjRSabBdHplunl+dfI9wVHTb1eNzbhv+yEVguG/7xTIAGYly/+m2vfvcP77edEEEiVMS6yR+XWV7W/csbkFtqYZwR/1mQTqCyQ0PY7ihF3iTNIwUskpaVsG06GsZLutnzNOitfjHJBwLKlZ82oQWySioO5KOZqEibqjorONeLmwA6n1o8RbXiUx2+TlPmsjmofcVNicxl/k5wwyZk24r7jZqKgjtevV9Nte4VubXpEYp8aggMudhhfV5GsPz6001/8TZJl7j7onpcI26D4d9aBjm1YxhjATfvbfodVhG/9Lc1TPHpDAjmB1Ln4XL16jpQVinBgo0pU1EQcYjfkcLNt0WLZJuXDGOCpI+3dEIEC1PHjTkVQT9wcChJcj04W4m0TXMGaDypOjI/p80zf6OuX8Ph+xVX6N4WWaesKVJpfz816Ei31wtUHstCTI/z0rQu7qBtKhOm/gYMtfGbIGT7UDKr9REtzUb0JlyH7EXZHvE0Y8zu5JtQgEGYTnrHe3fPVONbs5bsNfkotR+x5jDcLuwVkTlkRs79IeoQIX/OUVtj8wrzkn3rtHSF0fhRE8J8WpIpc/mMG53oYUwpGd2GjxDHIQaNl81 +GbENYZK Syl+VDu0s7ChsUnXrIKtIoa1ZwHrq2Zbe/RyoseEllGhP8mj/BLXNvz0TYRgbILCmKPckzpxXHwcjc6R7HrMTg1A2n7jYQKbSZ4+8TzvcGjc2FlJUxiYULvTVn9jyS6ZQbNiUFTi3tWFioehOPnvmzyZHY5ZdgPf3Fho7jcN4CVMY79lzwvTg4yeSg5YDTwCLUR6yQW81hp/gPFBmARDrEY8FPa/ajhWBT2icinrqeEbgz4Omw9K++iV/gWnXoQuhHK9IdfFnRO40O/HDqGm6S/Oud8v5L+XBzKDmmbEzT60DTqptuQiuFimtUtwr9ZilP4LJkp5LCUJmjCofh9PU6XmFiNWe+Mlx9HI3JMPKixVErvY98KWE2mUECCPhAM2f6qYM1e8bPwngxgHxOnQ9SBaoJmELpp9ziMjPoL9SOFyuBPat0mz+D8fFgD/4lExvTfLHch1d9ThFNf/BItRrq2DJX6+W3pqy9p6T 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) --- 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