From patchwork Tue Jan 21 09:57:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13946009 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 E455AC02182 for ; Tue, 21 Jan 2025 09:58:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 70F346B007B; Tue, 21 Jan 2025 04:58:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BEBE6B0082; Tue, 21 Jan 2025 04:58:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 561206B0083; Tue, 21 Jan 2025 04:58:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 39A8F6B007B for ; Tue, 21 Jan 2025 04:58:02 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B1B631208BC for ; Tue, 21 Jan 2025 09:58:01 +0000 (UTC) X-FDA: 83031007962.14.31AD4C9 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf14.hostedemail.com (Postfix) with ESMTP id 26C11100012 for ; Tue, 21 Jan 2025 09:57:59 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="rh/Hlilr"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf14.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737453480; a=rsa-sha256; cv=none; b=XEyC3+HhN1b/p9PG0y2TBz1JBqWceZ9dA/IW9OroRkRnt3/VAYA566ooduJGz43Ev5Q8hl 7L7hmOixJF8CDm9riseT2uuxmd9qpDEFI/OrcQe9WB0n5a5RmafxWw9jPgon8EBtygJiQ4 SkXJvfkU7ldQyyYagS3bnLikhsx4/d8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="rh/Hlilr"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf14.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 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=1737453480; 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:references:dkim-signature; bh=d2vU3yVbWk+iyIT5+OGlsu0VZIqzMABeI9eBwwMut2I=; b=tc84C5RMtul06u5KaaqciQ1CEet3Lpc2ULkROysv6rse2Qtd62zyIsBHcqIjDIqhpR4z7+ audRYrsSn+WdQHpqzXdLsgjhWaXxbbcZVvMtmdGtm7TxKDzae7+xCkiNghPG9LOJwi7wH9 UBCgK7BxJfv+Jhjc463r3QO4yXGf8Jk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id C10AAA41431; Tue, 21 Jan 2025 09:56:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85B91C4CEDF; Tue, 21 Jan 2025 09:57:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737453479; bh=Wme3RadWyvhvMdPRne38RcnHRR4tq7D20M16ECVXgvE=; h=From:To:Cc:Subject:Date:From; b=rh/HlilriYiUfxxSoSn1Dvm4ive39BJjvEcaYkJPYDB4Bq159WaYziRMj9GttPwV4 oNJSZE/CM2l9cUTU/sgeYj916s4tKhaxqflrklPGwUoUglcrt8k38IZ3mnKVmfe85Y w1gmDK9AOGg0wGUcs/4/ufhN7/imdYoNgMCLLC4f6HA8JR1YIM/ho6/94/W16wKcUh HqZ3wE417GufCR++pfx67iGYJhxnZ1tnwT6vt2+4pq4r8W3tAcMQ3/lc3PDxJbju9x 5DU87NBLb7gkP2FrZ5zr5ekyyUTyizVQkPCFzaKNT9bc5g12mboVzYrIz0bs5KMlAE 6HjYs6N1b8mgw== From: Mike Rapoport To: x86@kernel.org Cc: Andrew Morton , Andy Lutomirski , Anton Ivanov , Borislav Petkov , Brendan Higgins , Daniel Gomez , Daniel Thompson , Dave Hansen , David Gow , Douglas Anderson , Ingo Molnar , Jason Wessel , Jiri Kosina , Joe Lawrence , Johannes Berg , Josh Poimboeuf , "Kirill A. Shutemov" , Lorenzo Stoakes , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Mike Rapoport , Miroslav Benes , "H. Peter Anvin" , Peter Zijlstra , Petr Mladek , Petr Pavlu , Rae Moar , Richard Weinberger , Sami Tolvanen , Shuah Khan , Song Liu , Steven Rostedt , Thomas Gleixner , kgdb-bugreport@lists.sourceforge.net, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-um@lists.infradead.org, live-patching@vger.kernel.org Subject: [PATCH v2 00/10] x86/module: rework ROX cache to avoid writable copy Date: Tue, 21 Jan 2025 11:57:29 +0200 Message-ID: <20250121095739.986006-1-rppt@kernel.org> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 26C11100012 X-Stat-Signature: 35ebtomkeu4rfmfts7896uqtkm51wzr9 X-Rspam-User: X-HE-Tag: 1737453479-574399 X-HE-Meta: U2FsdGVkX1+ZBCrw34p11WljK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F9gXpLQ8j8/U4V9OZS/zw5r1DIRTO8FoQcT1F5/WNI2hL9PhNPck2G946jLpwHQ+PT29hlRwTQ9gBGCuV/XGZm1zCQmDNb+glcYna3kJllyv/gX5ApDPfi3lz2qLSSmb0jqN9wDiIj+gtlbcRX2MtafRJB9eAIvGicmwQ06nv/ 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)" Hi, Following Peter's comments [1] these patches rework handling of ROX caches for module text allocations. Instead of using a writable copy that really complicates alternatives patching, temporarily remap parts of a large ROX page as RW for the time of module formation and then restore it's ROX protections when the module is ready. To keep the ROX memory mapped with large pages, make set_memory_rox() capable of restoring large pages (more details are in patch 3). Since this is really about x86, I believe this should go in via tip tree. The patches also available in git https://git.kernel.org/rppt/h/execmem/x86-rox/v9 v2 changes: * only collapse large mappings in set_memory_rox() * simplify RW <-> ROX remapping * don't remove ROX cache pages from the direct map (patch 4) v1: https://lore.kernel.org/all/20241227072825.1288491-1-rppt@kernel.org [1] https://lore.kernel.org/all/20241209083818.GK8562@noisy.programming.kicks-ass.net Kirill A. Shutemov (1): x86/mm/pat: restore large ROX pages after fragmentation Mike Rapoport (Microsoft) (9): x86/mm/pat: cpa-test: fix length for CPA_ARRAY test x86/mm/pat: drop duplicate variable in cpa_flush() execmem: don't remove ROX cache from the direct map execmem: add API for temporal remapping as RW and restoring ROX afterwards module: introduce MODULE_STATE_GONE module: switch to execmem API for remapping as RW and restoring ROX Revert "x86/module: prepare module loading for ROX allocations of text" module: drop unused module_writable_address() x86: re-enable EXECMEM_ROX support arch/um/kernel/um_arch.c | 11 +- arch/x86/Kconfig | 1 + arch/x86/entry/vdso/vma.c | 3 +- arch/x86/include/asm/alternative.h | 14 +- arch/x86/include/asm/pgtable_types.h | 2 + arch/x86/kernel/alternative.c | 181 ++++++-------- arch/x86/kernel/ftrace.c | 30 ++- arch/x86/kernel/module.c | 45 ++-- arch/x86/mm/pat/cpa-test.c | 2 +- arch/x86/mm/pat/set_memory.c | 220 +++++++++++++++++- include/linux/execmem.h | 31 +++ include/linux/module.h | 22 +- include/linux/moduleloader.h | 4 - include/linux/vm_event_item.h | 2 + kernel/module/kallsyms.c | 8 +- kernel/module/kdb.c | 2 +- kernel/module/main.c | 86 ++----- kernel/module/procfs.c | 2 +- kernel/module/strict_rwx.c | 9 +- kernel/tracepoint.c | 2 + lib/kunit/test.c | 2 + mm/execmem.c | 39 ++-- mm/vmstat.c | 2 + samples/livepatch/livepatch-callbacks-demo.c | 1 + .../test_modules/test_klp_callbacks_demo.c | 1 + .../test_modules/test_klp_callbacks_demo2.c | 1 + .../livepatch/test_modules/test_klp_state.c | 1 + .../livepatch/test_modules/test_klp_state2.c | 1 + 28 files changed, 442 insertions(+), 283 deletions(-) base-commit: ffd294d346d185b70e28b1a28abe367bbfe53c04