Re: [PATCH 25/28] mm: remove vmalloc_user_node_flags

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed,  8 Apr 2020 13:59:23 +0200 Christoph Hellwig wrote:
> 
> Open code it in __bpf_map_area_alloc, which is the only caller.  Also
> clean up __bpf_map_area_alloc to have a single vmalloc call with
> slightly different flags instead of the current two different calls.
> 
> For this to compile for the nommu case add a __vmalloc_node_range stub
> to nommu.c.
> 
> Signed-off-by: Christoph Hellwig <hch@xxxxxx>
> ---
>  include/linux/vmalloc.h |  1 -
>  kernel/bpf/syscall.c    | 23 +++++++++++++----------
>  mm/nommu.c              | 14 ++++++++------
>  mm/vmalloc.c            | 20 --------------------
>  4 files changed, 21 insertions(+), 37 deletions(-)
> 
> diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
> index 108f49b47756..f90f2946aac2 100644
> --- a/include/linux/vmalloc.h
> +++ b/include/linux/vmalloc.h
> @@ -106,7 +106,6 @@ extern void *vzalloc(unsigned long size);
>  extern void *vmalloc_user(unsigned long size);
>  extern void *vmalloc_node(unsigned long size, int node);
>  extern void *vzalloc_node(unsigned long size, int node);
> -extern void *vmalloc_user_node_flags(unsigned long size, int node, gfp_t flags);
>  extern void *vmalloc_exec(unsigned long size);
>  extern void *vmalloc_32(unsigned long size);
>  extern void *vmalloc_32_user(unsigned long size);
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 48d98ea8fad6..249d9bd43321 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -281,26 +281,29 @@ static void *__bpf_map_area_alloc(u64 size, int numa_node, bool mmapable)
>  	 * __GFP_RETRY_MAYFAIL to avoid such situations.
>  	 */
>  
> -	const gfp_t flags = __GFP_NOWARN | __GFP_ZERO;
> +	const gfp_t gfp = __GFP_NOWARN | __GFP_ZERO;
> +	unsigned int flags = 0;
> +	unsigned long align = 1;
>  	void *area;
>  
>  	if (size >= SIZE_MAX)
>  		return NULL;
>  
>  	/* kmalloc()'ed memory can't be mmap()'ed */
> -	if (!mmapable && size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) {
> -		area = kmalloc_node(size, GFP_USER | __GFP_NORETRY | flags,
> +	if (mmapable) {
> +		BUG_ON(!PAGE_ALIGNED(size));
> +		align = SHMLBA;
> +		flags = VM_USERMAP;
> +	} else if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) {
> +		area = kmalloc_node(size, gfp | GFP_USER | __GFP_NORETRY,
>  				    numa_node);
>  		if (area != NULL)
>  			return area;
>  	}
> -	if (mmapable) {
> -		BUG_ON(!PAGE_ALIGNED(size));
> -		return vmalloc_user_node_flags(size, numa_node, GFP_KERNEL |
> -					       __GFP_RETRY_MAYFAIL | flags);
> -	}
> -	return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_RETRY_MAYFAIL | flags,
> -			      numa_node, __builtin_return_address(0));
> +
> +	return __vmalloc_node_range(size, align, VMALLOC_START, VMALLOC_END,
> +			gfp | GFP_KERNEL | __GFP_RETRY_MAYFAIL, PAGE_KERNEL,

Dunno if __GFP_ZERO needs to be added to match the current 
vmalloc_user_node_flags().

> +			flags, numa_node, __builtin_return_address(0));
>  }
>  
>  void *bpf_map_area_alloc(u64 size, int numa_node)
> diff --git a/mm/nommu.c b/mm/nommu.c
> index 81a86cd85893..b42cd6003d7d 100644
> --- a/mm/nommu.c
> +++ b/mm/nommu.c
> @@ -150,6 +150,14 @@ void *__vmalloc(unsigned long size, gfp_t gfp_mask)
>  }
>  EXPORT_SYMBOL(__vmalloc);
>  
> +void *__vmalloc_node_range(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,
> +		const void *caller)
> +{
> +	return __vmalloc(size, flags);
> +}
> +
>  void *__vmalloc_node(unsigned long size, unsigned long align, gfp_t gfp_mask,
>  		int node, const void *caller)
>  {
> @@ -180,12 +188,6 @@ void *vmalloc_user(unsigned long size)
>  }
>  EXPORT_SYMBOL(vmalloc_user);
>  
> -void *vmalloc_user_node_flags(unsigned long size, int node, gfp_t flags)
> -{
> -	return __vmalloc_user_flags(size, flags | __GFP_ZERO);
> -}
> -EXPORT_SYMBOL(vmalloc_user_node_flags);
> -
>  struct page *vmalloc_to_page(const void *addr)
>  {
>  	return virt_to_page(addr);
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 333fbe77255a..f6f2acdaf70c 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -2658,26 +2658,6 @@ void *vzalloc_node(unsigned long size, int node)
>  }
>  EXPORT_SYMBOL(vzalloc_node);
>  
> -/**
> - * vmalloc_user_node_flags - allocate memory for userspace on a specific node
> - * @size: allocation size
> - * @node: numa node
> - * @flags: flags for the page level allocator
> - *
> - * The resulting memory area is zeroed so it can be mapped to userspace
> - * without leaking data.
> - *
> - * Return: pointer to the allocated memory or %NULL on error
> - */
> -void *vmalloc_user_node_flags(unsigned long size, int node, gfp_t flags)
> -{
> -	return __vmalloc_node_range(size, SHMLBA,  VMALLOC_START, VMALLOC_END,
> -				    flags | __GFP_ZERO, PAGE_KERNEL,
> -				    VM_USERMAP, node,
> -				    __builtin_return_address(0));
> -}
> -EXPORT_SYMBOL(vmalloc_user_node_flags);
> -
>  /**
>   * vmalloc_exec - allocate virtually contiguous, executable memory
>   * @size:	  allocation size
> -- 
> 2.25.1





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux