Re: [PATCH v3 0/6] arch, mm/execmem: resolve confusion about set_direct_map_valid_noflush()
From: Andrew Morton
Date: Sat Sep 05 2026 - 22:01:00 EST
On Thu, 03 Sep 2026 12:28:26 +0300 "Mike Rapoport (Microsoft)" <rppt@xxxxxxxxxx> wrote:
> Recent discussion about implementation of execmem's ROX caches on arm64
> revealed a confusion about how set_direct_map_valid_noflush()
> implemented on different architectures.
>
> ...
>
> Implement these adjustments, make execmem always use VM_FLUSH_RESET_PERMS
> and revert set_direct_map_valid_noflush() changes.
>
Thanks, I updated mm-unstable to this version.
>
> v3 changes:
> * set VM_FLUSH_RESET_PERMS to allocated area just before flipping the
> permissions rather than at allocation time
>
Here's how v3 altered mm.git:
mm/execmem.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
--- a/mm/execmem.c~b
+++ a/mm/execmem.c
@@ -36,7 +36,6 @@ static void *execmem_vmalloc(struct exec
unsigned long end = range->end;
void *p;
- vm_flags |= VM_FLUSH_RESET_PERMS;
if (kasan)
vm_flags |= VM_DEFER_KMEMLEAK;
@@ -277,6 +276,8 @@ static void *execmem_cache_populate_allo
/* fill memory with instructions that will trap */
execmem_fill_trapping_insns(p, alloc_size);
+ set_vm_flush_reset_perms(p);
+
err = set_memory_rox((unsigned long)p, vm->nr_pages);
if (err)
goto err_free_mem;
@@ -439,6 +440,7 @@ void *execmem_alloc(enum execmem_type ty
{
struct execmem_range *range = &execmem_info->ranges[type];
bool use_cache = range->flags & EXECMEM_ROX_CACHE;
+ unsigned long vm_flags = VM_FLUSH_RESET_PERMS;
pgprot_t pgprot = range->pgprot;
void *p = NULL;
@@ -447,7 +449,7 @@ void *execmem_alloc(enum execmem_type ty
if (use_cache)
p = execmem_cache_alloc(range, size);
else
- p = execmem_vmalloc(range, size, pgprot, 0);
+ p = execmem_vmalloc(range, size, pgprot, vm_flags);
return kasan_reset_tag(p);
}
_