summaryrefslogtreecommitdiff
path: root/mm/execmem.c
diff options
context:
space:
mode:
authorMike Rapoport (Microsoft) <rppt@kernel.org>2025-04-23 17:48:07 +0300
committerAndrew Morton <akpm@linux-foundation.org>2025-05-12 23:50:33 -0700
commit6bbf0e728528addd5f9dd140b03b06438f032166 (patch)
tree6c72586e1d27775295a8fd955c049922271c86c2 /mm/execmem.c
parentb25f97d0f8043903a64e3a203b79219cc69f2f77 (diff)
execmem: enforce allocation size aligment to PAGE_SIZE
Before introduction of ROX cache execmem allocation size was always implicitly aligned to PAGE_SIZE inside vmalloc. However, when allocation happens from the ROX cache, this is not enforced. Make sure that the allocation size is always consistently aligned to PAGE_SIZE. Mike said: : Right now it'll make the maple trees in execmem_cache more compact. : And it's a precaution for the case when execmem callers would want to : change permissions on unaligned range because that would WARN_ON() : loudly. Peter said : It should not have a runtime effect -- currently all this code is used : with PAGE_SIZE multiples and everything just works. But whilst I was : perusing this code, I noticed that nothing actually enforced this. If : someone were to break this assumption things will go sideways. Link: https://lkml.kernel.org/r/20250423144808.1619863-1-rppt@kernel.org Fixes: 2e45474ab14f ("execmem: add support for cache of large ROX pages") Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Suggested-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm/execmem.c')
-rw-r--r--mm/execmem.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/mm/execmem.c b/mm/execmem.c
index e6c4f5076ca8..2b683e7d864d 100644
--- a/mm/execmem.c
+++ b/mm/execmem.c
@@ -377,6 +377,8 @@ void *execmem_alloc(enum execmem_type type, size_t size)
pgprot_t pgprot = range->pgprot;
void *p;
+ size = PAGE_ALIGN(size);
+
if (use_cache)
p = execmem_cache_alloc(range, size);
else