From patchwork Wed Oct 16 12:24:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13838296 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 C9B28D1AD50 for ; Wed, 16 Oct 2024 12:27:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47B386B009D; Wed, 16 Oct 2024 08:27:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 42BAD6B009E; Wed, 16 Oct 2024 08:27:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F3976B009F; Wed, 16 Oct 2024 08:27:08 -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 118366B009D for ; Wed, 16 Oct 2024 08:27:08 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B8C841C4D5F for ; Wed, 16 Oct 2024 12:26:56 +0000 (UTC) X-FDA: 82679389758.08.1CAE7F7 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf29.hostedemail.com (Postfix) with ESMTP id A6327120004 for ; Wed, 16 Oct 2024 12:26:54 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ewgSS7JQ; 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=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729081481; 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=yHnNtzpe4A7HBhM1JHCXKLDO71zzjAKRfmgOfZQgIGY=; b=hSiO5IAPrSHgiMlTJoceFIxerQPoNC7mgDFnwXWXDs5JX8mU6HpMBsHQ1//NKosw0lCyHJ myxHh/T5wwMRRoteUEmef8ebWCObBxAIOvPkhhZ/ZID2Vmql7t0RXWXXT+zZi1hzBxr1BB y1m9brP/TLyEDw1SZGIPnkM7Zf5wlrY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729081481; a=rsa-sha256; cv=none; b=bHig8Kiz/frqYhXdC1KZIAD2+pDm0QBU+y1cf5qpsJoC8Fu3DGkGmbce2P0qIeyPqLqHvU uD6sFW5OOjxGapwsw0xGFOCTpB8Nvx1at4BsaT/Jko0HjLZBuU29lUneFJVAcyengMSDiZ CJ/LxT5I5EiNThXdH9hEaef2F/9sCeQ= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ewgSS7JQ; 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=quarantine) 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 B8A1F5C4ADF; Wed, 16 Oct 2024 12:27:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4677BC4CECF; Wed, 16 Oct 2024 12:26:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729081624; bh=eY6kLN8OlN+AhPSjfqE9l5XEI+8YBmb961qfGDylvwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ewgSS7JQnctq7Hgrv3uuVnVef5NJ6/W1nB36pkS9n4SMtyIyVrElKtKyFF1q0jkpP EsFcTPX0SKB8iugJZ8fG/3GbaKQ9JTTxiSf0x8Je0VGHSki/f8KCPFSVhlw3IAbCgq dHZxxLb3XDQt5YWY63oWKwfSJfIRrZ4ETnxR7W4suuZEwzrS9kg5Y5qEjXIsmjEAIc d+qNLfS/dkDTekE3774d/xn4huY0MjrfXRLRM5fT0pICnGA4BMmSBqBpOwDvhxDH7h lEAtUAvDJvuqN4dGETbbq15U4XHTm20JcFbizm6eRWYoC4wDxNk9mafVHZRkNrpKww GhffryNbJ3RBQ== From: Mike Rapoport To: Andrew Morton , Luis Chamberlain 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" , 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 , Suren Baghdasaryan , 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 v6 8/8] x86/module: enable ROX caches for module text on 64 bit Date: Wed, 16 Oct 2024 15:24:24 +0300 Message-ID: <20241016122424.1655560-9-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241016122424.1655560-1-rppt@kernel.org> References: <20241016122424.1655560-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A6327120004 X-Stat-Signature: y8q11ktfjhhpfbb1x6tquhbkx7dco1am X-HE-Tag: 1729081614-326690 X-HE-Meta: U2FsdGVkX19aYy/JEs1//xHm8EXOmurrIUuSdUQ6r4LmC9+zsdGCiwzHXioyvFDIXfu4cU9vtlZTpulTaV87UfilOsWZ2h53tONj6I+5B3m+XIG/Qn1bWN4PGxc9HnqjDMCMtDa3bThOibtX7yeqrwx74lEJTA5RBczHhnf8NAQWAbELf29z0t8brBZeAt2K4pj3pqDAFKEWGQuUNfjgKF+VtyzEd/tetBvJdlBLCF6BbfVymZRx3lsM+Rixr4f3K+w8uEE0iZ/toFuAjpVRjPeW9DuiySM3EUEkN8llJAvX/25MaGUO74Rd3EZKbRocYIYYxVOk9PSDcBLgVqCB03uW6XAOfsSO42Qzy6fWzLBhFcQSTxHXNMyYmJQ8G8Ozxh7v/f2vD8/eqIirZvCiZf+6mSghUT72KcltCQHf10wnv670zOXTWFoAm9w5bxyjI4+F2eqYrpDoKI3kjBJWy+rTbzcYFD6jkjPCiplE6I9nNGtjfK8L+yG+uxfF+6n3o5cVbxLqrZOeMRwX0WN7kZS4Ta1Cj+Vd7k0Si5LHLkyLobC/If2I3ub73j5ws3dTCG6sDvAcwCaTW7Wa7uLQqviQ90QYt+tlnvDDkVGMTzu5T450mVAoVlWC0hPBVs48u1C4EB3/VICJqYAiwv1xucIB77eVkb35ogCjeiv83IWPkgX5hRe0QU/Fswt9gu975u+ZLi61rRhSWooNtrIQHTONMxSOT2B0YZVUVnsRo6KS8KLCVZ2ztdQuQmTNGEMcCSp/d91i28sJCUm6kdPpqTiEMxHNWIOEnj69ATI0UZstteM6U45Gge4/E4OqwHeQ2snr2zKFttqj89kQA3kTXHlU8jmRW41hTVQj8uDb0Ah1KhOp5tL547bMnLEd2UqLNJYbvZxsGbv9XalC6ExZcsmKDGlj2Sfhn597GIeZaUoap6GMMjsMG4z27yM5YO5qd+qlnpLsXrVkXAAUi61 cx3+L0XL PDuuaogLotYTzpv4T4U/UCJMzEUS3La9ZtnHdd8BwQZbE2HDfM5fyE0EDx6+cjzfP/1DWoVGl8lqXBftGVAE/OuHsJ6ewymVOAxkao8OzkCHND7dn1tVztXXI1PizfTyuiMJFcB+6XpSYdtAIsZ8P2BQaJuw0cNwGcHLE/q0rZSM97FNuWwxbF/9jRDgCzVIXfigP34J7wm6k1UnK3h5db4Z0Vc5jJy1h2yb7MQgPwBaSbwk= 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 on 64 bit. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Luis Chamberlain --- arch/x86/Kconfig | 1 + arch/x86/mm/init.c | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 2852fcd82cbd..ff71d18253ba 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -83,6 +83,7 @@ config X86 select ARCH_HAS_DMA_OPS if GART_IOMMU || XEN select ARCH_HAS_EARLY_DEBUG if KGDB select ARCH_HAS_ELF_RANDOMIZE + select ARCH_HAS_EXECMEM_ROX if X86_64 select ARCH_HAS_FAST_MULTIPLIER select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index eb503f53c319..c2e4f389f47f 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -1053,18 +1053,53 @@ unsigned long arch_max_swapfile_size(void) #ifdef CONFIG_EXECMEM static struct execmem_info execmem_info __ro_after_init; +#ifdef CONFIG_ARCH_HAS_EXECMEM_ROX +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); +} +#endif + struct execmem_info __init *execmem_arch_setup(void) { unsigned long start, offset = 0; + enum execmem_range_flags flags; + pgprot_t pgprot; if (kaslr_enabled()) offset = get_random_u32_inclusive(1, 1024) * PAGE_SIZE; start = MODULES_VADDR + offset; + if (IS_ENABLED(CONFIG_ARCH_HAS_EXECMEM_ROX)) { + pgprot = PAGE_KERNEL_ROX; + flags = EXECMEM_KASAN_SHADOW | EXECMEM_ROX_CACHE; + } else { + pgprot = PAGE_KERNEL; + flags = EXECMEM_KASAN_SHADOW; + } + execmem_info = (struct execmem_info){ .ranges = { - [EXECMEM_DEFAULT] = { + [EXECMEM_MODULE_TEXT] = { + .flags = flags, + .start = start, + .end = MODULES_END, + .pgprot = pgprot, + .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,