Subject: Re: [PATCH 2/3] mm: update core kernel code to use vm_flags_t consistently

From: Harry Yoo <[email-masked]>
Date: Tue, 29 Jul 2025 09:15:51 +0900

On Wed, Jun 18, 2025 at 08:42:53PM +0100, Lorenzo Stoakes wrote:
> The core kernel code is currently very inconsistent in its use of
> vm_flags_t vs. unsigned long. This prevents us from changing the type of
> vm_flags_t in the future and is simply not correct, so correct this.
> 
> While this results in rather a lot of churn, it is a critical pre-requisite
> for a future planned change to VMA flag type.
> 
> Additionally, update VMA userland tests to account for the changes.
> 
> To make review easier and to break things into smaller parts, driver and
> architecture-specific changes is left for a subsequent commit.
> 
> The code has been adjusted to cascade the changes across all calling code
> as far as is needed.
> 
> We will adjust architecture-specific and driver code in a subsequent patch.
> 
> Overall, this patch does not introduce any functional change.
> 
> Signed-off-by: Lorenzo Stoakes <[email-masked]>
> ---

[Adding Uladzislau to Cc]

Hi Lorenzo, just wanted to clarify one thing.

You know, many people acked and reviewed it, which makes me wonder if
I'm misunderstanding something... but it wouldn't hurt to check, right? 

> diff --git a/mm/execmem.c b/mm/execmem.c
> index 9720ac2dfa41..bd95ff6a1d03 100644
> --- a/mm/execmem.c
> +++ b/mm/execmem.c
> @@ -26,7 +26,7 @@ static struct execmem_info default_execmem_info __ro_after_init;
>  
>  #ifdef CONFIG_MMU
>  static void *execmem_vmalloc(struct execmem_range *range, size_t size,
> -			     pgprot_t pgprot, unsigned long vm_flags)
> +			     pgprot_t pgprot, vm_flags_t vm_flags)
>  {
>  	bool kasan = range->flags & EXECMEM_KASAN_SHADOW;
>  	gfp_t gfp_flags = GFP_KERNEL | __GFP_NOWARN;

Is it intentional to use vm_flags_t for vm_struct flags, not vma flags?

You didn't update the type of struct vm_struct.flags field and vm_flags
parameter in __vmalloc_node_range_noprof() (of MMU version in mm/vmalloc.c)
...which makes me suspect it's not intentional?

> @@ -82,7 +82,7 @@ struct vm_struct *execmem_vmap(size_t size)
>  }
>  #else
>  static void *execmem_vmalloc(struct execmem_range *range, size_t size,
> -			     pgprot_t pgprot, unsigned long vm_flags)
> +			     pgprot_t pgprot, vm_flags_t vm_flags)
>  {
>  	return vmalloc(size);
>  }

ditto.

> @@ -284,7 +284,7 @@ void execmem_cache_make_ro(void)
>  
>  static int execmem_cache_populate(struct execmem_range *range, size_t size)
>  {
> -	unsigned long vm_flags = VM_ALLOW_HUGE_VMAP;
> +	vm_flags_t vm_flags = VM_ALLOW_HUGE_VMAP;
>  	struct vm_struct *vm;
>  	size_t alloc_size;
>  	int err = -ENOMEM;

ditto.

> @@ -407,7 +407,7 @@ void *execmem_alloc(enum execmem_type type, size_t size)
>  {
>  	struct execmem_range *range = &execmem_info->ranges[type];
>  	bool use_cache = range->flags & EXECMEM_ROX_CACHE;
> -	unsigned long vm_flags = VM_FLUSH_RESET_PERMS;
> +	vm_flags_t vm_flags = VM_FLUSH_RESET_PERMS;
>  	pgprot_t pgprot = range->pgprot;
>  	void *p;

ditto.
  
> diff --git a/mm/internal.h b/mm/internal.h
> index feda91c9b3f4..506c6fc8b6dc 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -1360,7 +1360,7 @@ int migrate_device_coherent_folio(struct folio *folio);
>  
>  struct vm_struct *__get_vm_area_node(unsigned long size,
>  				     unsigned long align, unsigned long shift,
> -				     unsigned long flags, unsigned long start,
> +				     vm_flags_t vm_flags, unsigned long start,
>  				     unsigned long end, int node, gfp_t gfp_mask,
>  				     const void *caller);

ditto.

> diff --git a/mm/nommu.c b/mm/nommu.c
> index b624acec6d2e..87e1acab0d64 100644
> --- a/mm/nommu.c
> +++ b/mm/nommu.c
> @@ -126,7 +126,7 @@ void *vrealloc_noprof(const void *p, size_t size, gfp_t flags)
>  
>  void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
>  		unsigned long start, unsigned long end, gfp_t gfp_mask,
> -		pgprot_t prot, unsigned long vm_flags, int node,
> +		pgprot_t prot, vm_flags_t vm_flags, int node,
>  		const void *caller)
>  {

ditto.

>  	return __vmalloc_noprof(size, gfp_mask);

-- 
Cheers,
Harry / Hyeonggon