mm-execmem-make-sure-rox-cache-always-contains-multiples-of-pmd_size.patch removed from -mm tree
The quilt patch titled
Subject: mm/execmem: make sure ROX cache always contains multiples of PMD_SIZE
has been removed from the -mm tree. Its filename was
mm-execmem-make-sure-rox-cache-always-contains-multiples-of-pmd_size.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: "Mike Rapoport (Microsoft)" <[email protected]>
Subject: mm/execmem: make sure ROX cache always contains multiples of PMD_SIZE
Date: Thu, 03 Sep 2026 18:50:00 +0300
The ROX cache relies on its chunks being PMD mapped. For a PMD mapped chunk, set_memory_rox() updates the direct map alias one PMD at a time and the large mappings there survive.
When execmem refills the cache, it rounds up the requested allocation size to PMD_SIZE and tries to allocate that with vmalloc(VM_ALLOW_HUGE_VMAP). If that allocation fails, execmem falls back to vmalloc() of the original size.
There are two issues with this approach:
* If huge pages are not available, __vmalloc_node_range() silently falls back to base pages. The area execmem gets is virtually contiguous, but it is backed by 512 scattered base pages.
Permission updates on such areas split large mappings in the direct map that contain those base pages, up to 512 PMD splits in the worst case.
* execmem's own fallback adds a small base page mapped area to the cache. This adds the overhead of cache management to these allocations with no benefit of reducing fragmentation either in the vmalloc/modules address space or in the direct map.
Worse, these areas are never freed from the cache, because execmem_cache_clean() releases only chunks that are a multiple of PMD_SIZE and aligned to PMD_SIZE, exactly to minimize the number of base page mappings.
Add VM_REQUIRE_HUGE_VMAP option to vmalloc that fails if the allocation of huge pages fails or if such an allocation is not possible because huge page allocations in vmalloc were disabled or the architecture does not support them.
Use this option when populating the ROX cache. If vmalloc(VM_REQUIRE_HUGE_VMAP) fails or vmalloc of huge pages is unavailable, handle the memory allocation outside the ROX cache with plain vmalloc().
Since the fallback allocation has to return ROX memory, add an execmem_alloc_rox() helper and use it for both populating the ROX cache and dealing with a fallback allocation in a ROX execmem_range.
With that, the cache only ever contains PMD aligned chunks sized as a multiple of PMD_SIZE, and the PMD checks in execmem_cache_clean() become a VM_WARN_ON_ONCE() to ensure that the PMD mapping invariant does not change.
---
include/linux/vmalloc.h | 1 mm/execmem.c | 76 +++++++++++++++++++++++--------------- mm/vmalloc.c | 15 +++++++ 3 files changed, 62 insertions(+), 30 deletions(-)
include/linux/vmalloc.h renamed from include/linux/vmalloc.h~mm-execmem-make-sure-rox-cache-always-contains-multiples-of-pmd_size +1 -0
@@ -38,6 +38,7 @@ struct iov_iter; /* in uio.h */#define VM_DEFER_KMEMLEAK 0#endif #define VM_SPARSE 0x00001000/* sparse vm_area. not all pages are present. */ +#define VM_REQUIRE_HUGE_VMAP 0x00002000/* huge page mapping or nothing */ /* bits [20..32] reserved for arch specific ioremap internals */
mm/execmem.c renamed from mm/execmem.c~mm-execmem-make-sure-rox-cache-always-contains-multiples-of-pmd_size +47 -29
130 lines not on this page · raw message
mm/vmalloc.c renamed from mm/vmalloc.c~mm-execmem-make-sure-rox-cache-always-contains-multiples-of-pmd_size +14 -1
@@ -4021,6 +4021,12 @@ static gfp_t vmalloc_fix_flags(gfp_t fla* %__GFP_SKIP_KASAN can be used to skip unpoisoning of mapped pages * (when prot=%PAGE_KERNEL). * +* %VM_ALLOW_HUGE_VMAP allocates huge pages when possible and falls back to +* base pages if huge page allocation fails. +* +* %VM_REQUIRE_HUGE_VMAP implies %VM_ALLOW_HUGE_VMAP and fails instead of +* silently falling back to base pages. +* * Can not be called from interrupt nor NMI contexts. * Return: the address of the area or %NULL on failure */
@@ -4046,6 +4052,10 @@ void *__vmalloc_node_range_noprof(unsignreturn NULL ; } +/* VM_REQUIRE_HUGE_VMAP implies VM_ALLOW_HUGE_VMAP */ +if (vm_flags &VM_REQUIRE_HUGE_VMAP ) + vm_flags |=VM_ALLOW_HUGE_VMAP ; +if (vmap_allow_huge && (vm_flags &VM_ALLOW_HUGE_VMAP )) {/* * Try huge pages. Only try for PAGE_KERNEL allocations,
@@ -4062,6 +4072,9 @@ void *__vmalloc_node_range_noprof(unsign align =max (original_align,1UL << shift); } +if ((vm_flags &VM_REQUIRE_HUGE_VMAP ) && shift ==PAGE_SHIFT ) +return NULL ; + again: area = __get_vm_area_node(size, align, shift, VM_ALLOC | VM_UNINITIALIZED | vm_flags, start, end, node,
@@ -4136,7 +4149,7 @@ again:return area->addr; fail: -if (shift >PAGE_SHIFT ) { +if (shift >PAGE_SHIFT && !(vm_flags &VM_REQUIRE_HUGE_VMAP )) { shift =PAGE_SHIFT ; align = original_align; goto again;
_
Patches currently in -mm which might be from [email protected] are
docs-mm-describe-set_memory-and-set_direct_map-apis.patch docs-mm-describe-set_memory-and-set_direct_map-apis-fix.patch arch-mm-promote-debug_wx-to-check_wx.patch sh-remove-config_numa-and-realted-configuration-options.patch sh-mm-remove-numac.patch sh-mm-drop-allocate_pgdat.patch sh-remove-setup_bootmem_node-and-plat_mem_setup.patch sh-drop-dead-code-guarded-by-ifdef-config_numa.patch sh-drop-include-asm-mmzoneh.patch init-kconfig-drop-arch_want_numa_variable_locality.patch sh-init-remove-call-the-memblock_set_node.patch sh-remove-sparsemem-related-entries-from-kconfig.patch sh-drop-include-asm-sparsememh.patch