From patchwork Mon Sep 9 06:47:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13795965 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 8864BECE57C for ; Mon, 9 Sep 2024 06:50:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21F806B0124; Mon, 9 Sep 2024 02:50:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A7DA6B0126; Mon, 9 Sep 2024 02:50:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3C1B6B0127; Mon, 9 Sep 2024 02:50:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D5C5E6B0124 for ; Mon, 9 Sep 2024 02:50:00 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 872F51C6B63 for ; Mon, 9 Sep 2024 06:50:00 +0000 (UTC) X-FDA: 82544274960.01.60373ED Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf11.hostedemail.com (Postfix) with ESMTP id EDA824001B for ; Mon, 9 Sep 2024 06:49:57 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BkZCp3fS; spf=pass (imf11.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=1725864571; 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=jBmUR/ZiNzj9wRjo1Sj/i+gt+7eGSBFRYnfKY7iBmOk0lhwU+2jXOhdLXnzhcLnzUAOdbr 5kh+mVUCmdOdPJv7XQAV7ekZmqliIY6EwK+KdasebRTwQaXlU14c58TzhaSD8uHAZOq+Ok 04xhDPTaEG7/0kwOlS2Fw0TgePRAT8k= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BkZCp3fS; spf=pass (imf11.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725864571; a=rsa-sha256; cv=none; b=DIHcLxwN46sX3VSE6BQPvV62cxSpYE++/oVDwQYWWd2tPCcTBhs+EzA/ine1EavTTbBlpA TH88jv3g49MG0At4+Q8WtabV2qfvFVbNcPyzW2ZlxOurVCVWdfOTiNpcly98SMklNnYUGU 6wG4zDwt7bicM82KYn8uWXfRU0yTIOg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id E74E4A42713; Mon, 9 Sep 2024 06:49:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62106C4CECB; Mon, 9 Sep 2024 06:49:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725864597; bh=l7egSUNcilONf7gTBq0Hjl37ut+S55vwboWjXSdFWe0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BkZCp3fShQXfTG1Nn+VMmuW0LYueTyrn7acbRvvboJKcY6YjPoDDx968iFpKR1CWC aF/p0o4PzZ/eloW/K8mvH2s9aJhYiRq+CLA/Z6C5cf0zaOL7QYXEhZf0/TByS50AhI bJWZ0vLimK/FFtaJwXD9Yjc4jTIfHrr3Tv5YRIoRd3fkkJvNyNI486dzezhXOWgnQJ HbPC0BW8QqdHVqqtZvDGdZd2DLKkW13q6h3MOVdLTl2ijRdrSJoovSlNGk+YE1vLSL MY6Kf9lXc+klIMZqkADFnytoN8MKNCrTtrBVamTW4DGupk55fMoWoan0CIHDPihKAp 1QrOM6cpJNDWA== 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 v3 8/8] x86/module: enable ROX caches for module text Date: Mon, 9 Sep 2024 09:47:30 +0300 Message-ID: <20240909064730.3290724-9-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240909064730.3290724-1-rppt@kernel.org> References: <20240909064730.3290724-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 4hdd17tz7zqtrbnsbkfufmbjry1yquz1 X-Rspamd-Queue-Id: EDA824001B X-Rspamd-Server: rspam11 X-HE-Tag: 1725864597-662935 X-HE-Meta: U2FsdGVkX18bL2wTDo/TVH+Okf8/8y7KMoeLPgMQdRioYqjOeOGkE1/FtVpJfcvXTYoJNJ3uJMzbKRi2qh2w/Sqp8MvFACyzd1iMrhRcpNAzKMUQ3OIJ8tDBNPOOiKYHYEQASBPiRFVR0Wm5etP4Eh9mlbBV+jtuA7X4SQDKOX/eFTfq2EaxzVQXqmJwfS7o9rbeUvBVLdbfs6HEr8Thj4RUFS3yAdT7PgVLpQbZvOTfkL++ObVlHEMUUnghlfuzkgnIhmcyI5O55Qp0vSQ9Sdw+tVuC8ZCbTicWj+RI6o6ff1mi+g1div9lyHrnuaa85MqonEPOCBJIv2irPDV/kUo/BWSa2Hgo+WivlD/2S/r8fqxVcQ1H7ZFuk0EvOV46zz9ntMaaTSj63BMHFRSyc0xtBkTv1Hct6JMn1oLtKNAzS/DmjfYS46HDlYAjTAzbxFbhkZzH4Z21I5Gc37zkrfesEJ7+U3J9md9iub3iJD2H/OS3HZq1M7WSc88hPL8vJkW54wHAZmH40jUHUEC3KsAOTiooU8USB9ElMVvDWUkAyUPU6rj3ofMBFllTgaKjZCrcXZpRQuIjr/TLb1SmUxzPM8dmdIGFsdHSvM74sc5ff1XWq0FmHckrpYGVQZuk4VVVBo1RU2dhbmqCdGDu2yASOWZk9/sFLrM9hygeKcsUXI64X46k1GG2h/X16nVX4DnlPu8vKHYfdDli+nXsbBnUwRscLpLzPoHEBfrwXAm+pCULvbgiAwCZA9W2R/c0PyBu9W4bjn6r1lyl4bI2OifBh9s4VJ5g/9AVw70l0THTjVB/d0lHtN7fWBIXuyIT8OHNwLG5PlFCcTvRLHlNVssHERs4psr5YJREJRZfnoaVUtX4O1GtqdyhZQiwmzSvP7xdRBAe7BjTSX1NCSENClqRKWYrXlZJGUc7sPf7OZuU38B3qsPmq99FNIwl8bGQ+Nna0fkoJd+cKzEvDs9 IKGzMi84 ImpUudI9GtoGwTI9iL1CKAMN0QZkWqBuAnvZztGSa7NyoX30XV+N/s5rOXCV0Fl2X6wZoKWxMKYQw5cU2RNOmcknmvki7atvuh27vj5MT6WosSXTT+qLBi3XU8ZdqcYC/H1Vwtawrib+zmwF/75XsYmJTHhwjCx9MScZNeLpnFQfurBpPwPaXgFdcSPB6jr/XKpO9pRU0lQUvFk7irQKQXXYEsLSdpqR0SNWVDWH4bZsF8Gc= 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,