Re: [PATCH v3 5/6] mm/execmem: use VM_FLUSH_RESET_PERMS for ROX cache allocations
From: Kevin Brodsky
Date: Thu Sep 17 2026 - 17:08:07 EST
On 03/09/2026 11:28, Mike Rapoport (Microsoft) wrote:
> Initially execmem completely removed direct map alias for the memory
> allocated for the ROX cache in PMD_SIZE chunks. When that memory was
> freed, its direct map was restored also in PMD_SIZE chunks to avoid
> fragmentation of the direct map caused by vmalloc::vm_reset_perms().
>
> This required execmem to implement the wrappers for set_direct_map APIs for
> proper sequencing of removal and restoration of the direct map aliases.
>
> Since then x86's CPA gained support for collapsing the direct map page
> tables for ROX pages and execmem switched from removing ROX caches from the
> direct map to making them ROX there, so execmem only needs to update direct
> map alias permissions when freeing the ROX cache memory.
>
> vmalloc already handles those updates for areas with VM_FLUSH_RESET_PERMS
> set and vmalloc::vm_reset_perms() does not force split of the direct map
> for PMD_SIZE chunks.
>
> Set the area permissions with set_vm_flush_reset_perms() when populating
> the execmem cache just before flipping the area to ROX.
>
> This way freeing an allocated area on an error path won't incur two
> updates of the direct map alias of that area and TLB flushing in
> vm_reset_perms().
>
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
Reviewed-by: Kevin Brodsky <kevin.brodsky@xxxxxxx>