[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240326163624.3253157-2-mark.rutland@arm.com>
Date: Tue, 26 Mar 2024 16:36:21 +0000
From: Mark Rutland <mark.rutland@....com>
To: linux-kernel@...r.kernel.org
Cc: agordeev@...ux.ibm.com,
anil.s.keshavamurthy@...el.com,
aou@...s.berkeley.edu,
bp@...en8.de,
catalin.marinas@....com,
dave.hansen@...ux.intel.com,
davem@...emloft.net,
gor@...ux.ibm.com,
hca@...ux.ibm.com,
jarkko@...nel.org,
jcalvinowens@...il.com,
linux-arm-kernel@...ts.infradead.org,
mark.rutland@....com,
mhiramat@...nel.org,
mingo@...hat.com,
mpe@...erman.id.au,
naveen.n.rao@...ux.ibm.com,
palmer@...belt.com,
paul.walmsley@...ive.com,
tglx@...utronix.de,
will@...nel.org
Subject: [PATCH 1/4] arm64: patching: always use fixmap
For historical reasons, patch_map() won't bother to fixmap non-image
addresses when CONFIG_STRICT_MODULE_RWX=n, matching the behaviour prior
to the introduction of CONFIG_STRICT_MODULE_RWX. However, as arm64
doesn't select CONFIG_ARCH_OPTIONAL_KERNEL_RWX, CONFIG_MODULES implies
CONFIG_STRICT_MODULE_RWX, so any kernel built with module support will
use the fixmap for any non-image address.
Historically we only used patch_map() for the kernel image and modules,
but these days its also used by BPF and KPROBES to write to read-only
pages of executable text. Currently these both depend on CONFIG_MODULES,
but we'd like to change that in subsequent patches, which will require
using the fixmap regardless of CONFIG_STRICT_MODULE_RWX.
This patch changes patch_map() to always use the fixmap, and simplifies
the logic.
* Use is_image_text() directly in the if-else, rather than using a
temporary boolean variable.
* Use offset_in_page() to get the offset within the mapping.
* Remove uintaddr and cast the address directly when using
is_image_text().
For kernels built with CONFIG_MODULES=y, there should be no functional
change as a result of this patch. For kernels built with
CONFIG_MODULES=n, patch_map() will use the fixmap for non-image
addresses, but there are no extant users with non-image addresses when
CONFIG_MODULES=n.
Signed-off-by: Mark Rutland <mark.rutland@....com>
Cc: Catalin Marinas <catalin.marinas@....com>
Cc: Will Deacon <will@...nel.org>
---
arch/arm64/kernel/patching.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/arch/arm64/kernel/patching.c b/arch/arm64/kernel/patching.c
index 2555349303684..f0f3a2a82ca5a 100644
--- a/arch/arm64/kernel/patching.c
+++ b/arch/arm64/kernel/patching.c
@@ -30,20 +30,16 @@ static bool is_image_text(unsigned long addr)
static void __kprobes *patch_map(void *addr, int fixmap)
{
- unsigned long uintaddr = (uintptr_t) addr;
- bool image = is_image_text(uintaddr);
struct page *page;
- if (image)
+ if (is_image_text((unsigned long)addr))
page = phys_to_page(__pa_symbol(addr));
- else if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX))
- page = vmalloc_to_page(addr);
else
- return addr;
+ page = vmalloc_to_page(addr);
BUG_ON(!page);
return (void *)set_fixmap_offset(fixmap, page_to_phys(page) +
- (uintaddr & ~PAGE_MASK));
+ offset_in_page(addr));
}
static void __kprobes patch_unmap(int fixmap)
--
2.30.2
Powered by blists - more mailing lists