From patchwork Thu Apr 11 16:05:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13626351 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6D579C04FF0 for ; Thu, 11 Apr 2024 16:08:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Yn51UwJKwafWXcmw8lfGttq6YO9+0bM54N67GdfkuL4=; b=tF2E8NAJRTM9Td XA/DsGC/5TVhYIQOaONfQEcIadTqSxnEsLtJUaIS1nGw5ZO32PlfozUs8odmvCWpc8tlM+t22pfAZ +lUH05qDPLK4xqjGt+MQpeYw6Wn1ZCKHefaSbcqfVT236zrxYqbHEFzT9JXxbMW4PQc7C5meX2u9p Sk4pPfQ4oyvRIToLzvayaVRiYh+1uqRWm5+LI47A36ZQTuE2zLN0VRzjBJEvaxZRysNgwJr750tjX wdDPMpZPNLLECTblZSwhVlHH7B3Bf4/UH3wg45Wt5fLqqc2n6cuuk1/VMNOg+uePRVRcUa8OAC/ij uuDSZkI0GI1uoTNSVoZw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruwyd-0000000Cxtm-48mf; Thu, 11 Apr 2024 16:08:40 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruwwl-0000000CwfH-0mKb; Thu, 11 Apr 2024 16:06:48 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 7DC02620F0; Thu, 11 Apr 2024 16:06:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A810C4AF09; Thu, 11 Apr 2024 16:06:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712851602; bh=GpS8ytfjSzE76nC42qU8VRxGL9fjdKFDqm8vIE1x4YY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eRW/q4WS++c0r4pBuIO3O4Xg4RhucjdHqnNZoi79AHoLhQPJWC7o5buwGGFBPvniC VKRspPAvG+oxGO/Mu52T5QZWLHipAdpse5TDkTXl4UCRQQbTzoV2tVhPjQUCAlmNo0 NG232/NssiPa7JNKn0tv4mghHev6HdVbKr+LbbRCokaCTTwVdChPLdcxxCtgfIMnpO Z1hyZ7UoVGi2N4el/7GuNUEzPhXZ5vzgMOKVlVVadMtRh3z+39u712GiPM9IWHw2qe adjgDWeIItjJVb1bdKVNluXidKTvt1LLI9M1CnLR4urws3bFChygnRYjAkvNDCL/IG 2uw/kGGX3wdrg== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Andy Lutomirski , Arnd Bergmann , Catalin Marinas , Christoph Hellwig , Helge Deller , Lorenzo Stoakes , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Mathieu Desnoyers , Michael Ellerman , Mike Rapoport , Palmer Dabbelt , Peter Zijlstra , Russell King , Song Liu , Steven Rostedt , Thomas Gleixner , Uladzislau Rezki , Will Deacon , bpf@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-trace-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: [RFC PATCH 7/7] x86/module: enable ROX caches for module text Date: Thu, 11 Apr 2024 19:05:26 +0300 Message-ID: <20240411160526.2093408-8-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240411160526.2093408-1-rppt@kernel.org> References: <20240411160526.2093408-1-rppt@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240411_090643_700481_E1AACA2C X-CRM114-Status: GOOD ( 14.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "Mike Rapoport (IBM)" Enable execmem's cache of PMD_SIZE'ed pages mapped as ROX for module text allocations. Signed-off-by: Mike Rapoport (IBM) --- arch/x86/mm/init.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index 8e8cd0de3af6..049a8b4c64e2 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -1102,9 +1102,23 @@ unsigned long arch_max_swapfile_size(void) #endif #ifdef CONFIG_EXECMEM +static void execmem_invalidate(void *ptr, size_t size, bool writeable) +{ + /* fill memory with INT3 instructions */ + if (writeable) + memset(ptr, 0xcc, size); + else + text_poke_set(ptr, 0xcc, size); +} + static struct execmem_info execmem_info __ro_after_init = { + .invalidate = execmem_invalidate, .ranges = { - [EXECMEM_DEFAULT] = { + [EXECMEM_MODULE_TEXT] = { + .flags = EXECMEM_KASAN_SHADOW | EXECMEM_ROX_CACHE, + .alignment = MODULE_ALIGN, + }, + [EXECMEM_KPROBES...EXECMEM_MODULE_DATA] = { .flags = EXECMEM_KASAN_SHADOW, .alignment = MODULE_ALIGN, }, @@ -1119,9 +1133,16 @@ struct execmem_info __init *execmem_arch_setup(void) offset = get_random_u32_inclusive(1, 1024) * PAGE_SIZE; start = MODULES_VADDR + offset; - execmem_info.ranges[EXECMEM_DEFAULT].start = start; - execmem_info.ranges[EXECMEM_DEFAULT].end = MODULES_END; - execmem_info.ranges[EXECMEM_DEFAULT].pgprot = PAGE_KERNEL; + + for (int i = EXECMEM_MODULE_TEXT; i < EXECMEM_TYPE_MAX; i++) { + struct execmem_range *r = &execmem_info.ranges[i]; + + r->start = start; + r->end = MODULES_END; + r->pgprot = PAGE_KERNEL; + } + + execmem_info.ranges[EXECMEM_MODULE_TEXT].pgprot = PAGE_KERNEL_ROX; return &execmem_info; }