[PATCH 0/5] mm/execmem: fixes and cleanups for the ROX cache

From: Mike Rapoport (Microsoft)

Date: Thu Sep 03 2026 - 12:37:22 EST


Sashiko review of the ROX cache refill path asked what happens when the
PMD_SIZE allocation fails there. Pulling that thread uncovered a bit
more than the fallback.

Patch 1 fixes a real bug, although rare bug: execmem_cache_clean() can
free a chunk that is still partially in use, because a PMD sized and PMD
aligned free range in the middle of a larger chunk looks exactly like a
chunk that nobody uses.

Patch 2 handles maple tree allocation failures in the cache. They are
unlikely, but silently dropping an area from the tree is not a great way
to deal with them.

Patch 3 deals with the fallback that started all this. The cache exists to
keep the direct map free of unnecessary splits, and the fallback happily
filled it with base page mapped areas that could never be freed from the
cache again. Ask vmalloc for a huge mapping or nothing, and serve whatever
does not fit outside the cache.

Patches 4 and 5 convert the ROX cache to scope based cleanup.

The series was tested on x86 with module load/unload cycles, with PTDUMP
confirming that the cache is using 2M mappings, and with nohugevmalloc
to exercise the uncached fallback.

Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
---
Mike Rapoport (Microsoft) (5):
mm/execmem: free ROX cache chunks only when they span an entire vm area
mm/execmem: handle potential allocation errors in the maple tree
mm/execmem: make sure ROX cache always contains multiples of PMD_SIZE
mm/vmalloc: add DEFINE_FREE() for vfree()
mm/execmem: use cleanup infrastructure in ROX cache functions

drivers/hid/hid-core.c | 4 +-
include/linux/vmalloc.h | 4 ++
mm/execmem.c | 124 ++++++++++++++++++++++++++++--------------------
mm/vmalloc.c | 15 +++++-
4 files changed, 92 insertions(+), 55 deletions(-)
---
base-commit: 8499b4645c7f199707510461779f82d85732e742
change-id: 20260903-execmem-rox-cache-pmd-v1-ab97da2c4364
prerequisite-change-id: 20260816-execmem-set-vm-perms-v0-2-bae847a4f64f:v3
prerequisite-patch-id: 4d8c7989581fd5f4aaa2e315bfc903a9f0aadedc
prerequisite-patch-id: 211c002f2501d5aad7dea733fc6273c76bed910f
prerequisite-patch-id: a328539ba621866e4a63b39ab72a54dbfb3ed0a1
prerequisite-patch-id: 991f843051a913188e0cb671f3e8768682f895e5
prerequisite-patch-id: c05688baf37b3e80a57fe85d351f997f017acea2
prerequisite-patch-id: 36038f3f55748416fe56dc990d3836f70e851f59

--
Sincerely yours,
Mike.