Skip to content

Commit 041de93

Browse files
Christoph Hellwigtorvalds
authored andcommitted
mm: remove vmalloc_user_node_flags
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. [[email protected]: fix nommu.c build] Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Johannes Weiner <[email protected]> Cc: Christian Borntraeger <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: Daniel Vetter <[email protected]> Cc: David Airlie <[email protected]> Cc: Gao Xiang <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Haiyang Zhang <[email protected]> Cc: "K. Y. Srinivasan" <[email protected]> Cc: Laura Abbott <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Michael Kelley <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Nitin Gupta <[email protected]> Cc: Robin Murphy <[email protected]> Cc: Sakari Ailus <[email protected]> Cc: Stephen Hemminger <[email protected]> Cc: Sumit Semwal <[email protected]> Cc: Wei Liu <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: Will Deacon <[email protected]> Cc: Stephen Rothwell <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent c3f896d commit 041de93

File tree

4 files changed

+22
-37
lines changed

4 files changed

+22
-37
lines changed

include/linux/vmalloc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ extern void *vzalloc(unsigned long size);
106106
extern void *vmalloc_user(unsigned long size);
107107
extern void *vmalloc_node(unsigned long size, int node);
108108
extern void *vzalloc_node(unsigned long size, int node);
109-
extern void *vmalloc_user_node_flags(unsigned long size, int node, gfp_t flags);
110109
extern void *vmalloc_exec(unsigned long size);
111110
extern void *vmalloc_32(unsigned long size);
112111
extern void *vmalloc_32_user(unsigned long size);

kernel/bpf/syscall.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/nospec.h>
2626
#include <linux/audit.h>
2727
#include <uapi/linux/btf.h>
28+
#include <asm/pgtable.h>
2829
#include <linux/bpf_lsm.h>
2930

3031
#define IS_FD_ARRAY(map) ((map)->map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY || \
@@ -281,26 +282,29 @@ static void *__bpf_map_area_alloc(u64 size, int numa_node, bool mmapable)
281282
* __GFP_RETRY_MAYFAIL to avoid such situations.
282283
*/
283284

284-
const gfp_t flags = __GFP_NOWARN | __GFP_ZERO;
285+
const gfp_t gfp = __GFP_NOWARN | __GFP_ZERO;
286+
unsigned int flags = 0;
287+
unsigned long align = 1;
285288
void *area;
286289

287290
if (size >= SIZE_MAX)
288291
return NULL;
289292

290293
/* kmalloc()'ed memory can't be mmap()'ed */
291-
if (!mmapable && size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) {
292-
area = kmalloc_node(size, GFP_USER | __GFP_NORETRY | flags,
294+
if (mmapable) {
295+
BUG_ON(!PAGE_ALIGNED(size));
296+
align = SHMLBA;
297+
flags = VM_USERMAP;
298+
} else if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) {
299+
area = kmalloc_node(size, gfp | GFP_USER | __GFP_NORETRY,
293300
numa_node);
294301
if (area != NULL)
295302
return area;
296303
}
297-
if (mmapable) {
298-
BUG_ON(!PAGE_ALIGNED(size));
299-
return vmalloc_user_node_flags(size, numa_node, GFP_KERNEL |
300-
__GFP_RETRY_MAYFAIL | flags);
301-
}
302-
return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_RETRY_MAYFAIL | flags,
303-
numa_node, __builtin_return_address(0));
304+
305+
return __vmalloc_node_range(size, align, VMALLOC_START, VMALLOC_END,
306+
gfp | GFP_KERNEL | __GFP_RETRY_MAYFAIL, PAGE_KERNEL,
307+
flags, numa_node, __builtin_return_address(0));
304308
}
305309

306310
void *bpf_map_area_alloc(u64 size, int numa_node)

mm/nommu.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ void *__vmalloc(unsigned long size, gfp_t gfp_mask)
150150
}
151151
EXPORT_SYMBOL(__vmalloc);
152152

153+
void *__vmalloc_node_range(unsigned long size, unsigned long align,
154+
unsigned long start, unsigned long end, gfp_t gfp_mask,
155+
pgprot_t prot, unsigned long vm_flags, int node,
156+
const void *caller)
157+
{
158+
return __vmalloc(size, gfp_mask);
159+
}
160+
153161
void *__vmalloc_node(unsigned long size, unsigned long align, gfp_t gfp_mask,
154162
int node, const void *caller)
155163
{
@@ -180,12 +188,6 @@ void *vmalloc_user(unsigned long size)
180188
}
181189
EXPORT_SYMBOL(vmalloc_user);
182190

183-
void *vmalloc_user_node_flags(unsigned long size, int node, gfp_t flags)
184-
{
185-
return __vmalloc_user_flags(size, flags | __GFP_ZERO);
186-
}
187-
EXPORT_SYMBOL(vmalloc_user_node_flags);
188-
189191
struct page *vmalloc_to_page(const void *addr)
190192
{
191193
return virt_to_page(addr);

mm/vmalloc.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,26 +2659,6 @@ void *vzalloc_node(unsigned long size, int node)
26592659
}
26602660
EXPORT_SYMBOL(vzalloc_node);
26612661

2662-
/**
2663-
* vmalloc_user_node_flags - allocate memory for userspace on a specific node
2664-
* @size: allocation size
2665-
* @node: numa node
2666-
* @flags: flags for the page level allocator
2667-
*
2668-
* The resulting memory area is zeroed so it can be mapped to userspace
2669-
* without leaking data.
2670-
*
2671-
* Return: pointer to the allocated memory or %NULL on error
2672-
*/
2673-
void *vmalloc_user_node_flags(unsigned long size, int node, gfp_t flags)
2674-
{
2675-
return __vmalloc_node_range(size, SHMLBA, VMALLOC_START, VMALLOC_END,
2676-
flags | __GFP_ZERO, PAGE_KERNEL,
2677-
VM_USERMAP, node,
2678-
__builtin_return_address(0));
2679-
}
2680-
EXPORT_SYMBOL(vmalloc_user_node_flags);
2681-
26822662
/**
26832663
* vmalloc_exec - allocate virtually contiguous, executable memory
26842664
* @size: allocation size

0 commit comments

Comments
 (0)