linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] execmem: enforce allocation size aligment to PAGE_SIZE
@ 2025-04-23 14:48 Mike Rapoport
  2025-04-23 14:56 ` Peter Zijlstra
  2025-04-23 21:36 ` Andrew Morton
  0 siblings, 2 replies; 5+ messages in thread
From: Mike Rapoport @ 2025-04-23 14:48 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Mike Rapoport, Peter Zijlstra, linux-mm, linux-kernel

From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>

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.

Fixes: 2e45474ab14f ("execmem: add support for cache of large ROX pages")
Suggested-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
 mm/execmem.c | 2 ++
 1 file changed, 2 insertions(+)

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
-- 
2.47.2



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] execmem: enforce allocation size aligment to PAGE_SIZE
  2025-04-23 14:48 [PATCH] execmem: enforce allocation size aligment to PAGE_SIZE Mike Rapoport
@ 2025-04-23 14:56 ` Peter Zijlstra
  2025-04-23 21:36 ` Andrew Morton
  1 sibling, 0 replies; 5+ messages in thread
From: Peter Zijlstra @ 2025-04-23 14:56 UTC (permalink / raw)
  To: Mike Rapoport; +Cc: Andrew Morton, linux-mm, linux-kernel

On Wed, Apr 23, 2025 at 05:48:07PM +0300, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> 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.
> 
> Fixes: 2e45474ab14f ("execmem: add support for cache of large ROX pages")
> Suggested-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

Thanks!

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

> ---
>  mm/execmem.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> 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
> -- 
> 2.47.2
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] execmem: enforce allocation size aligment to PAGE_SIZE
  2025-04-23 14:48 [PATCH] execmem: enforce allocation size aligment to PAGE_SIZE Mike Rapoport
  2025-04-23 14:56 ` Peter Zijlstra
@ 2025-04-23 21:36 ` Andrew Morton
  2025-04-24  5:50   ` Mike Rapoport
  2025-04-24  8:53   ` Peter Zijlstra
  1 sibling, 2 replies; 5+ messages in thread
From: Andrew Morton @ 2025-04-23 21:36 UTC (permalink / raw)
  To: Mike Rapoport; +Cc: Peter Zijlstra, linux-mm, linux-kernel

On Wed, 23 Apr 2025 17:48:07 +0300 Mike Rapoport <rppt@kernel.org> wrote:

> 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.

Does this have any known runtime effect?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] execmem: enforce allocation size aligment to PAGE_SIZE
  2025-04-23 21:36 ` Andrew Morton
@ 2025-04-24  5:50   ` Mike Rapoport
  2025-04-24  8:53   ` Peter Zijlstra
  1 sibling, 0 replies; 5+ messages in thread
From: Mike Rapoport @ 2025-04-24  5:50 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Peter Zijlstra, linux-mm, linux-kernel

On Wed, Apr 23, 2025 at 02:36:50PM -0700, Andrew Morton wrote:
> On Wed, 23 Apr 2025 17:48:07 +0300 Mike Rapoport <rppt@kernel.org> wrote:
> 
> > 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.
> 
> Does this have any known runtime effect?

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.

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] execmem: enforce allocation size aligment to PAGE_SIZE
  2025-04-23 21:36 ` Andrew Morton
  2025-04-24  5:50   ` Mike Rapoport
@ 2025-04-24  8:53   ` Peter Zijlstra
  1 sibling, 0 replies; 5+ messages in thread
From: Peter Zijlstra @ 2025-04-24  8:53 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Mike Rapoport, linux-mm, linux-kernel

On Wed, Apr 23, 2025 at 02:36:50PM -0700, Andrew Morton wrote:
> On Wed, 23 Apr 2025 17:48:07 +0300 Mike Rapoport <rppt@kernel.org> wrote:
> 
> > 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.
> 
> Does this have any known runtime effect?

It should not -- 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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-04-24  8:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-23 14:48 [PATCH] execmem: enforce allocation size aligment to PAGE_SIZE Mike Rapoport
2025-04-23 14:56 ` Peter Zijlstra
2025-04-23 21:36 ` Andrew Morton
2025-04-24  5:50   ` Mike Rapoport
2025-04-24  8:53   ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox