From patchwork Mon Aug 26 06:55:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13777180 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 B19B8C5321D for ; Mon, 26 Aug 2024 06:57:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B0538D0041; Mon, 26 Aug 2024 02:57:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 460628D0029; Mon, 26 Aug 2024 02:57:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34F3D8D0041; Mon, 26 Aug 2024 02:57:59 -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 1726E8D0029 for ; Mon, 26 Aug 2024 02:57:59 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 883B41A0C5B for ; Mon, 26 Aug 2024 06:57:58 +0000 (UTC) X-FDA: 82493491836.19.AF524C3 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf18.hostedemail.com (Postfix) with ESMTP id F14E21C000F for ; Mon, 26 Aug 2024 06:57:56 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=u9brm9ff; spf=pass (imf18.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=1724655391; 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=ArYD9klKJpLbPkeCWvbD0jTNuBjTRJif8n/bkwNLIj6cKpusukQ2jJy8CwC4IJEdONNqWI pOEZWIbdmBMPRQ+yty0kkIuYWKtUNvwwRSE7qzX85Db4GrPmsyDIt6XacqwrWo7k//q9VK wq5QwPAb5TM07Cijyhn5sTWHxpBp81s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724655391; a=rsa-sha256; cv=none; b=slKFm5Mq0SVjiN2fTubdiU5fG5Eo79Mo1Wkv4dLDV5bo3pPENTV+fzQlCjuMsQkmETEYkk 4NYXF9/dtOfN+zZqaBZLEjUOSiM1BdAebtDB9AwmFHr+jSDcjpZiF1r25sU+Qx18uFtZvF YfMbHy53xMR8jA0L1lguXgUjvcG7klg= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=u9brm9ff; spf=pass (imf18.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 40DF9A41190; Mon, 26 Aug 2024 06:57:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F0D5C567EB; Mon, 26 Aug 2024 06:57:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724655475; bh=l7egSUNcilONf7gTBq0Hjl37ut+S55vwboWjXSdFWe0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u9brm9ffBKJJy0lQBqVUmOtRsmRW1o2mBFKA4EhD7/nH8h2gv+M7lKVr7gSQptliB hbOarsMop4k9H3WwY7Yn4SDp1vUrBJIaGRD3L7h2LyBRLq6p3w2M+aMtu5fF8yUiOT JzgM/Mh7LerNq33JfGbB0R6dXwMiZvlBUPNF03eoh1GhN4IuDSdJxnUg45kUvxXE/S I1P3qHXaDeHHHmN8Cm9t03nsqNN6vCskEjl1NxrPzvke5fbuCG5/WnwkhujA6NhoOt p9raTRTUjWPVS0MKDT5Lhfx819pdvVyaXynnIIS3xdhWfXB7iG8JbUVNzrCj5nDxC0 KwcaUZEBkiEAw== From: Mike Rapoport To: Andrew Morton Cc: Andreas Larsson , Andy Lutomirski , 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 v2 8/8] x86/module: enable ROX caches for module text Date: Mon, 26 Aug 2024 09:55:32 +0300 Message-ID: <20240826065532.2618273-9-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240826065532.2618273-1-rppt@kernel.org> References: <20240826065532.2618273-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: F14E21C000F X-Stat-Signature: 5ui5ruigbcwrqcqb859cpsis7ck5kdzz X-HE-Tag: 1724655476-635541 X-HE-Meta: U2FsdGVkX19/7bKrpEq9/d2VV4glDH9LuLJ+JYPOu2YzSgdU5/Y5F3xIvzCMpDhFd6620MlzZdCz/QfkvBrHNziili28+yJ3bE/STKgQF7LbgYyroAMzkZ737mBFElKebNlKSfPfOH07g36tjI+EKo/kA9fb7e6A/kTTyYuZ3GRzjRnFWv452WGgmHS5enw1Jhyx1fdUkPckqtFfQGOtB/kl8bOzLNyWsMl6jqLVm/hO3JKVvrDMjkySx8+M6mf8owc26JCzeVYusuLrtOvSa7cdR5VmN4frKyrLgTcj63U26isril5/K09lCa6TBjs8ukBilgguMLzdejlETPtU2fkuaunTq6EUIWA/NMQxRQ8XyAVU8Vhs3m6F7hjM2CGZtPhRI9U4xF4alYubORVWk1SlZGBRVaS6hBRPEIvfBjd7f6mlcmNfr372ORcHU49WOSoByJvY23AEubIDBUaQRVjhMX3LEltXcbVuT+lgYSMRZC2LVVCrwiNMrgnS+b+mxoyGrvUr2UhtF8n2gKRztk4odx3Jc8GFp6gDnNkaFePxuZvxsrrBWc5PloSywSC8BtmVltNDpbN8CpHjU5Sl8sfr2TstOMPpgPMv6jrNKKGkOuKqnJnUXnec03yHSEIF0F40hft0hUZvWscw2Ph2LGPh7ijOtYtTVL1rid3lpEQZFs99jMNl3ZYiO+321O4AUHRRM+bddyptdNKxcE6PtLwuxPF6k3GDMb6PP2RfPxUU1TB9q6vkvzMWTnPbPtrq04vn92fMiXJB0Hz2Yc14P/UgpvR2OjtNjAwk7hXUYtfiGdiRSw4tpZ2TbMRQ5LwD2AcwBAqnG1mChPPNj6FuRShkQ4Y2WzslaoUxYF/PUhVb2fQ4dVaKde99cmXgvyM+AjhJtokodlwdI3lQt60+K2D0c3ovbYdKahPuF18A4MaMDnrtRSt/5hU4qqYADT+UEvG1AXt5Qk0+XApJPUe 91m54dLC RGNmnG/W9aM0Y0Tmr2HLLd/KxeR47Up50BOpjaU7xtei1sgpeJK2p5EFKryKWrIwEARVDOQPYBtTGoM2tQ1GCJoPc7/BYeEi9F6c9o7rTjVsgUh5iZCCtMJVq3wcnp+xrzhvVgSWKFLN+NoKlyPPU5FzXnk3Rup/Mp7Do251at5ylgRID32ANjwz4Ajwah0F1QKi9oro41xUjfdNxVdvZFYgbQhlgOYCGNPT8Q/q/HfiilhWYZRfrKVcCkg== 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,