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: 13829042 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07A771E1A37; Wed, 9 Oct 2024 18:11:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728497472; cv=none; b=mBt2r0aus31TzKthBrCX0QeEdmwZMi9QOeBMQ8aSFAiLvrt5iK8scfePpah0TUZcIk0YdHUgPhZJpoav9v++SgDVirvtGUKI8YYoSRNq4O9A79TqjAHiwcLHfpoKvqj5fJ4U0JDGcDdMf8TMNRZbpT7hyRIJI+ZhxQ8znLoOw/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728497472; c=relaxed/simple; bh=l7egSUNcilONf7gTBq0Hjl37ut+S55vwboWjXSdFWe0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UB2hUC0dYboLxiD0em0YvgiK39jkV2WwzDzBziXlZndr2id2phrIlS4huk1EIX+N+zWvuH/F6GwdETg/dw6k1xlKwzXwKEb8lil+QSiLF29B4p9IQgQGI6VvhcUFYCdpX8VH45UYsR0dAOxIEVXXXC7XIE7QO8ooATbaIbRpuU4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FXfE/sHa; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FXfE/sHa" 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> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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,