Skip to content

Commit 1bdf654

Browse files
committed
execmem: add support for cache of large ROX pages
jira LE-4694 Rebuild_History Non-Buildable kernel-6.12.0-55.43.1.el10_0 commit-author Mike Rapoport (Microsoft) <[email protected]> commit 2e45474 Using large pages to map text areas reduces iTLB pressure and improves performance. Extend execmem_alloc() with an ability to use huge pages with ROX permissions as a cache for smaller allocations. To populate the cache, a writable large page is allocated from vmalloc with VM_ALLOW_HUGE_VMAP, filled with invalid instructions and then remapped as ROX. The direct map alias of that large page is exculded from the direct map. Portions of that large page are handed out to execmem_alloc() callers without any changes to the permissions. When the memory is freed with execmem_free() it is invalidated again so that it won't contain stale instructions. An architecture has to implement execmem_fill_trapping_insns() callback and select ARCH_HAS_EXECMEM_ROX configuration option to be able to use the ROX cache. The cache is enabled on per-range basis when an architecture sets EXECMEM_ROX_CACHE flag in definition of an execmem_range. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Mike Rapoport (Microsoft) <[email protected]> Reviewed-by: Luis Chamberlain <[email protected]> Tested-by: kdevops <[email protected]> Cc: Andreas Larsson <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Borislav Petkov (AMD) <[email protected]> Cc: Brian Cain <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Dinh Nguyen <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Guo Ren <[email protected]> Cc: Helge Deller <[email protected]> Cc: Huacai Chen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Johannes Berg <[email protected]> Cc: John Paul Adrian Glaubitz <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: Liam R. Howlett <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Masami Hiramatsu (Google) <[email protected]> Cc: Matt Turner <[email protected]> Cc: Max Filippov <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Michal Simek <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Richard Weinberger <[email protected]> Cc: Russell King <[email protected]> Cc: Song Liu <[email protected]> Cc: Stafford Horne <[email protected]> Cc: Steven Rostedt (Google) <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: Thomas Bogendoerfer <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Uladzislau Rezki (Sony) <[email protected]> Cc: Vineet Gupta <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]> (cherry picked from commit 2e45474) Signed-off-by: Jonathan Maple <[email protected]>
1 parent 74226bd commit 1bdf654

File tree

5 files changed

+345
-8
lines changed

5 files changed

+345
-8
lines changed

arch/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,14 @@ config ARCH_WANTS_EXECMEM_LATE
10241024
enough entropy for module space randomization, for instance
10251025
arm64.
10261026

1027+
config ARCH_HAS_EXECMEM_ROX
1028+
bool
1029+
depends on MMU && !HIGHMEM
1030+
help
1031+
For architectures that support allocations of executable memory
1032+
with read-only execute permissions. Architecture must implement
1033+
execmem_fill_trapping_insns() callback to enable this.
1034+
10271035
config HAVE_IRQ_EXIT_ON_IRQ_STACK
10281036
bool
10291037
help

include/linux/execmem.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ enum execmem_range_flags {
5353
EXECMEM_ROX_CACHE = (1 << 1),
5454
};
5555

56+
#ifdef CONFIG_ARCH_HAS_EXECMEM_ROX
57+
/**
58+
* execmem_fill_trapping_insns - set memory to contain instructions that
59+
* will trap
60+
* @ptr: pointer to memory to fill
61+
* @size: size of the range to fill
62+
* @writable: is the memory poited by @ptr is writable or ROX
63+
*
64+
* A hook for architecures to fill execmem ranges with invalid instructions.
65+
* Architectures that use EXECMEM_ROX_CACHE must implement this.
66+
*/
67+
void execmem_fill_trapping_insns(void *ptr, size_t size, bool writable);
68+
#endif
69+
5670
/**
5771
* struct execmem_range - definition of an address space suitable for code and
5872
* related data allocations

0 commit comments

Comments
 (0)