Re: [PATCH v2 7/8] execmem: add support for cache of large ROX pages

Christophe Leroy
2024-09-06T09:44:53Z

Le 26/08/2024 à 08:55, Mike Rapoport a écrit :
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
>
> Using large pages to map text areas reduces iTLB pressure and improves
> performance.
>
> Extend execmem_alloc() with an ability to use PMD_SIZE'ed pages with ROX
> permissions as a cache for smaller allocations.

Why only PMD_SIZE ?

On power 8xx, PMD_SIZE is 4M and the 8xx doesn't have such a page size.
When you call vmalloc() with VM_ALLOW_HUGE_VMAP you get 16k pages or
512k pages depending on the size you ask for, see function
arch_vmap_pte_supported_shift()

>
> 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.
>
> 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.
>
> The cache is enabled when an architecture sets EXECMEM_ROX_CACHE flag in
> definition of an execmem_range.
>

Christophe