From patchwork Mon Oct 7 06:28:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13824145 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 2845ECFB442 for ; Mon, 7 Oct 2024 06:31:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B9B736B00AA; Mon, 7 Oct 2024 02:31:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B24376B00D5; Mon, 7 Oct 2024 02:31:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99D846B00D8; Mon, 7 Oct 2024 02:31:32 -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 6C8426B00AA for ; Mon, 7 Oct 2024 02:31:32 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 19A2840E47 for ; Mon, 7 Oct 2024 06:31:32 +0000 (UTC) X-FDA: 82645834824.14.676D633 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id 6757F40011 for ; Mon, 7 Oct 2024 06:31:30 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=d5WdCg6Q; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf11.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=1728282543; 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=GDjJU5nmBT8etXIXn7RGxVpMWMQoSKtr2yUTnYJTfLGR25bG0/ddDTfkdKlLuEdxl9LMsq TgKGsHQv/F0Vay3YQgr2flpzBKTH34o2Ji8CBGtS4Z5cACob2QrHMdqOnPTEgEHL4fpxh7 RD9Eq420M1eabx0R0fJe8yMWnAY2Gb0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728282543; a=rsa-sha256; cv=none; b=5z7DodtdEsc5ZbHHJJL9SEJkGNh8eNzf2RAouddlr83jbmlXbcqJnUZGJYUq9b4Epml7Bd gOZXvUlcjiZdPtzhyzbHe1X6EwN1Qn0hKzIHUnQvOI5Kt8EEIGumP1YyiMij0dksuc9sD+ KznkpMpT6c33y2hEBYxB+LrculHLIVg= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=d5WdCg6Q; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf11.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 794CD5C5849; Mon, 7 Oct 2024 06:31:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01844C4CECF; Mon, 7 Oct 2024 06:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728282689; bh=l7egSUNcilONf7gTBq0Hjl37ut+S55vwboWjXSdFWe0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d5WdCg6QSd7SstfrUQDCwWsvOnXL2HjQin7m1gEvD09o/DpyujqnKes3WgYGTvKOT 8fJupYh4P7AD8z21iOCA24rSlPpZgrC0ler/FB88Rk83zueQWu5DliMx8e2O8aTZy1 2WuyKBqO7T0WcSvhAXTmxQ8uEF0O7cPfGLlPULXqmDuI73io26/AinRB6Mxie4EdiX eqqjSoB2Hzf0RdcuIX8LTr/1ZAWIhDwvRQaFN3mQv0heCDOMIj3IHzRdHmbpyUkqBx A7M0PE4IScMmPLSDTSkp1aHDV0LltxKlDIJG2E+qlhVUGri7q26OTN/ytz1rzd+xsQ LLK619DlFqppA== 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 v4 8/8] x86/module: enable ROX caches for module text Date: Mon, 7 Oct 2024 09:28:58 +0300 Message-ID: <20241007062858.44248-9-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241007062858.44248-1-rppt@kernel.org> References: <20241007062858.44248-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6757F40011 X-Stat-Signature: tcreww5utma4nsq7i963fmdouxf31oiz X-Rspam-User: X-HE-Tag: 1728282690-974950 X-HE-Meta: U2FsdGVkX1/i3JtY5GzR2U+lrbKeIZV0YDdCR6bzzx6G6sb0h7Kbozz6VN1fXOaqEH7PV9KDmrL5ZrDAwjSwin05l8F8rslnlcGUU05fqjjNTntALTCpJhPlFSe1B1XIqqXxxrFdFkYNOJbkMi2Rh+7IukF5tXU/XaqO993JAlZCfvDvC32J5lZ1Wyg0v+spEBTlbNB40kcgD+K8KC1SezrXRaEWOjT7ZFHd5eRhXU5QUCpMUMT0cGZSRrAXkzvP7xxva+ICG0qWd7p5mTPmq27cSqyUEO5UYPLLPJoDqnAO3bBpJSUlZpwsiqQNc2mfhkR7PZYLI6GG+wT823qikt02S6dU53GnswEAXGhheJJZxF1019LxY8XIaklHatBoFNKtqJwaqTxMaSQAWCPiQkqU7GNez8wcAOlqqcl9AqAS9EULrv1MMzLcqWgxLthbyeKFxAJLFOIaBN3qmaCCLfEm+eBrP6/3zebyOaFXzzovJDhDvr6CRTG+Yauvmj/U1Iz1z7BTU1n1nB64UV0158b7DGfbY+8/izu7wJJDZkbaDLDMTTHu3Oc7PV7zOxuewQ4E398iDJ9buEDQ5EvCJIaf1AHQ9VW/rSeMDXw3Cb8KmyK9XltMNeza4hQBSXgHDVeHJWPB8TxxFujXcr+WHV15qWLgw1Rs4T/d3IYOOp5hXBnJ7hy069iHUvfMDFps32Zlzu9jZ24faw6WEbXwnSAggHrkHxId+vLxuvBz4oMQ/UFEGfH3V53lIHDHaE1yJiSh2l0McZYHAZyvNtQuP8eSEDQvJfWLNLlbxZdQyxjWMJQQsuJdc/owsXf3DQFY6cFS6cypCOoD/Jx0vJJVRoSIOlRRiu8U1+Qy0Blw13aEpry27aBC7SF2SJGacnsP5OWQO4c4KitaPx0l0yL1fxJoJbK8gwQ9PI01CxW1VAVnYMP/xjn91BYX5AGsv2bUX5z7RP0Uqy/HSyXVZVf mKah0XIh kUcCcxuZuw1ROWREHIhMu9bZX45Ot8LIm8kCg194JWnMezuH470DGCZWQ6wpmBqAAERc+L5gfvR0xCctbs0qRknqZ93RXbLG34e+jHW/yarYWNj6itQGWPU4nfcCY00fUUZBx5INKn6xKOi1rSAph8BDHRcPUR9Ib22uHsFZ2Xs+zei0PK2ttxaQso5XX0AHF2FN/ABbNnC8k3WN30pGLzq8UL7n71HuX9uljdpKEWVEMZ10= 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,