From patchwork Wed Oct 9 18:08:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13829026 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 A19DFCEE339 for ; Wed, 9 Oct 2024 18:11:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F9656B00CF; Wed, 9 Oct 2024 14:11:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A7A06B00DC; Wed, 9 Oct 2024 14:11:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1220B6B00DD; Wed, 9 Oct 2024 14:11:15 -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 E5FDE6B00CF for ; Wed, 9 Oct 2024 14:11:14 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 54FAD14190D for ; Wed, 9 Oct 2024 18:11:12 +0000 (UTC) X-FDA: 82654855668.15.D1A4021 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf16.hostedemail.com (Postfix) with ESMTP id 05462180006 for ; Wed, 9 Oct 2024 18:11:12 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="FXfE/sHa"; spf=pass (imf16.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728497336; 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=pivIpmPrEiNkGS0zm1hicx+P3hpfRXHzQg0zuVaSO98=; b=KkUsZGkazrsMpkUvh112EaEpg7U4H6wbVQMMNlON3IlQMweo0/9CB6926b23s3e23r/Eu8 VqwzbpYSvAF2Lw9HS2vE7cBDvFOj5PEsMNmoEq7NPKM2jHKPZERMN9+xXkksgWs950Q+D9 0m+c9AjqrZPGeK7ctuu4zAibnxjptTE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728497336; a=rsa-sha256; cv=none; b=jSLNeA+G7i08NeLCzTde/k7Kx9ZEXdBNr6fz5oJzeQwiGUWQsXflR8B9+l1g7oXp37+duy vdAzuC6LThcnTgtF8XK/h1TI+hBGWZDz70zl/vYCQZDnfUSETiAkQkvAb89WzEziWH4Xfi f+2VrOUdj4A1PyKhHfZNAfY7XWY2zXM= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="FXfE/sHa"; spf=pass (imf16.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 9107FA443E5; Wed, 9 Oct 2024 18:11:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 215B8C4CEDA; Wed, 9 Oct 2024 18:10:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728497471; bh=l7egSUNcilONf7gTBq0Hjl37ut+S55vwboWjXSdFWe0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FXfE/sHay4UZzDr2fpnc2NuqlQrUe5ZOPEV5kEcagzZ0+u19ui7qjj9bE1VRxKdth HK0scPDe/IbicUr5P2sGxdhPwk1RBpTZ7icvH77x5GnWU6n2AisPsAppJtYaR6HA/B yrnCX892KuWofTmdMZr6iBJfSTtBiwbSCAxY8SdlcP/cDPEDF7eiF/JmfWrX9bU8lW uz1YgvDXn1ZSA+CKqUDRLlC1GmUJ6GAdx984jhOmJa8UXqqtCdb2/vX9bKBQO8vUoY OjXKfML4r0Z+EYFSa65S7pOq3b9au06CuhQHuRmk3ThCkxIILj5O5faywuz3zNJF9A Ns2wf4ETdE7+A== From: Mike Rapoport To: Andrew Morton Cc: Andreas Larsson , Andy Lutomirski , Ard Biesheuvel , Arnd Bergmann , Borislav Petkov , Brian Cain , Catalin Marinas , Christoph Hellwig , Christophe Leroy , Dave Hansen , Dinh Nguyen , Geert Uytterhoeven , Guo Ren , Helge Deller , Huacai Chen , Ingo Molnar , Johannes Berg , John Paul Adrian Glaubitz , Kent Overstreet , "Liam R. Howlett" , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Matt Turner , Max Filippov , Michael Ellerman , Michal Simek , Mike Rapoport , Oleg Nesterov , Palmer Dabbelt , Peter Zijlstra , Richard Weinberger , Russell King , Song Liu , Stafford Horne , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Uladzislau Rezki , Vineet Gupta , Will Deacon , bpf@vger.kernel.org, linux-alpha@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-kernel@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, linux-openrisc@vger.kernel.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-sh@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-trace-kernel@vger.kernel.org, linux-um@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev, sparclinux@vger.kernel.org, x86@kernel.org Subject: [PATCH v5 8/8] x86/module: enable ROX caches for module text Date: Wed, 9 Oct 2024 21:08:16 +0300 Message-ID: <20241009180816.83591-9-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241009180816.83591-1-rppt@kernel.org> References: <20241009180816.83591-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 05462180006 X-Stat-Signature: knup4byyzex8z51z6pbsibxk3ct61rdq X-HE-Tag: 1728497472-167566 X-HE-Meta: U2FsdGVkX1/8TGaRWo8Urh+cVCqXNVBb3kmf51syrK6jNx2SU/lUejKRZmWr7lJ4Ku0mrkF+VLLqOXXxCUWUwf72hiSb+A+Odp4jNwF420lMJu9nw9TB5FkV4/fAfwJYMaK6pI8/+Nd+HDCYAitJnDwp7AbCfGg6K52rID5j0Jk9bJtsKx6k7S2dspgGKIvcK2HtcaciUDwUApIZp1zyrUN+OpATeFulBbD6zDLm/Vydr+ILrbtF7Z3Pr/PBw+BZ/kGTpY4OOaaW6n30NQ2wDCiGWYg7DQnDoDKk9iTBPFoqrb3zMKo+snh1xOodsbLjRGksN54eV0NqIK2wRIeCuWVWFdgVsH8UF+HJn8L8O1qUy7DJu9O9LBbxTJHkEXWwcoBU6P4fgZIkQJdd3GIqW86/UitoYzCYVRCDgkjDTu2g5wyEJy06c0Uer1Fvzs7yffuylzjpQqfC0a8DXKCdiqnHOj1szQ689xyO8mLRIKDlRK+UYFduEFdeplGcNqrtF+WGF3fqkrR5dxSLZzlO2spDFcFByxV4dyK9iLzgcf6ETa3NnFilaZxUU005853F9cK9jHUIN007EbKRgkRO/XwQeVe5FEXgOMrGZtVQl5Ie+i5l83W6cyAA7wWGb8PDyEBxKqefqsfQmQtrOs9sU2qjRbjPzSy68vCvDRl3NmfaGoebz8sxBPIdG0aZYkLz9zyUDCAdoBt+LMF4oM0VWOjc0vcjTT7n/hOONEz0JBMuV59GUkuLVy6ohovUk4lPGtcSCkGM7eq+u6InlRqpMGUx5Y6IcVXtXKOG32t1z4IMiR4yClql73Fp2pbu53dqqOFNXaUYhb45MroucAcnCtboeYWmbFELdDGpfbKB8WBfaHnN1EP3MQJnIsfWs+7lT/M32I2wI1dQ6ENkNGgvbZfzLatZisgsJ9M5214FoVfQ5uUQO75jiq+c/NRyt2nNaHa/ugudQWj5s415riR TYbWYMFD E2RlpcJozRQQQC6zZfrgcg150TBlrkHrPRU8dZiEz74EcYA4fxcI+XaCAs2DuZ7yFViPa6bbAZVvE5iy0zeeA9X7PD99YqM7GRpuC/ubbTzdTxWdZxY1hKJYG6bf+HdN6a9ZJbJt6WisKQhox3/jf1O6HfpXtlijDwY+LM0Nzv0kSJQ9KR15q1qYCUYe8dAyimNWyzjPvTp6wvZspceRyHQODfZx7NgcZR4H/qzTVSETtazW/78cRNao2fn+M+We6PtpnqGsTTnbLHGda6a3DRb7vtYkU2h5biXmXlJnH5YGwMuyuutiGVjWI1SvcHYFVCe0Ic04qHZB1HX+ljNNQPf0aXdS6Cumy1l+p 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 (Microsoft)" Enable execmem's cache of PMD_SIZE'ed pages mapped as ROX for module text allocations. Signed-off-by: Mike Rapoport (Microsoft) --- arch/x86/mm/init.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index eb503f53c319..a0ec99fb9385 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -1053,6 +1053,15 @@ unsigned long arch_max_swapfile_size(void) #ifdef CONFIG_EXECMEM static struct execmem_info execmem_info __ro_after_init; +static void execmem_fill_trapping_insns(void *ptr, size_t size, bool writeable) +{ + /* fill memory with INT3 instructions */ + if (writeable) + memset(ptr, INT3_INSN_OPCODE, size); + else + text_poke_set(ptr, INT3_INSN_OPCODE, size); +} + struct execmem_info __init *execmem_arch_setup(void) { unsigned long start, offset = 0; @@ -1063,8 +1072,23 @@ struct execmem_info __init *execmem_arch_setup(void) start = MODULES_VADDR + offset; execmem_info = (struct execmem_info){ + .fill_trapping_insns = execmem_fill_trapping_insns, .ranges = { - [EXECMEM_DEFAULT] = { + [EXECMEM_MODULE_TEXT] = { + .flags = EXECMEM_KASAN_SHADOW | EXECMEM_ROX_CACHE, + .start = start, + .end = MODULES_END, + .pgprot = PAGE_KERNEL_ROX, + .alignment = MODULE_ALIGN, + }, + [EXECMEM_KPROBES ... EXECMEM_BPF] = { + .flags = EXECMEM_KASAN_SHADOW, + .start = start, + .end = MODULES_END, + .pgprot = PAGE_KERNEL, + .alignment = MODULE_ALIGN, + }, + [EXECMEM_MODULE_DATA] = { .flags = EXECMEM_KASAN_SHADOW, .start = start, .end = MODULES_END,