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. [akpm@linux-foundation.org: fix nommu.c build] Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Cc: Christian Borntraeger <borntraeger@de.ibm.com> Cc: Christophe Leroy <christophe.leroy@c-s.fr> Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Cc: David Airlie <airlied@linux.ie> Cc: Gao Xiang <xiang@kernel.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Haiyang Zhang <haiyangz@microsoft.com> Cc: "K. Y. Srinivasan" <kys@microsoft.com> Cc: Laura Abbott <labbott@redhat.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Michael Kelley <mikelley@microsoft.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Nitin Gupta <ngupta@vflare.org> Cc: Robin Murphy <robin.murphy@arm.com> Cc: Sakari Ailus <sakari.ailus@linux.intel.com> Cc: Stephen Hemminger <sthemmin@microsoft.com> Cc: Sumit Semwal <sumit.semwal@linaro.org> Cc: Wei Liu <wei.liu@kernel.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Paul Mackerras <paulus@ozlabs.org> Cc: Vasily Gorbik <gor@linux.ibm.com> Cc: Will Deacon <will@kernel.org> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Link: http://lkml.kernel.org/r/20200414131348.444715-27-hch@lst.de Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing the changes to kernel (1 of 4 files). Show all
Unified · Split
| @@ -25,6 +25,7 @@ · 24 unmodified lines | |||
| 25 | #include <linux/nospec.h> | 25 | #include <linux/nospec.h> |
| 26 | #include <linux/audit.h> | 26 | #include <linux/audit.h> |
| 27 | #include <uapi/linux/btf.h> | 27 | #include <uapi/linux/btf.h> |
| 28 | #include <asm/pgtable.h> | ||
| 28 | #include <linux/bpf_lsm.h> | 29 | #include <linux/bpf_lsm.h> |
| 29 | 30 | ||
| 30 | #define IS_FD_ARRAY(map) ((map)->map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY || \ | 31 | #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) · 250 unmodified lines | |||
| 281 | * __GFP_RETRY_MAYFAIL to avoid such situations. | 282 | * __GFP_RETRY_MAYFAIL to avoid such situations. |
| 282 | */ | 283 | */ |
| 283 | 284 | ||
| 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; | ||
| 285 | void *area; | 288 | void *area; |
| 286 | 289 | ||
| 287 | if (size >= SIZE_MAX) | 290 | if (size >= SIZE_MAX) |
| 288 | return NULL; | 291 | return NULL; |
| 289 | 292 | ||
| 290 | /* kmalloc()'ed memory can't be mmap()'ed */ | 293 | /* kmalloc()'ed memory can't be mmap()'ed */ |
| 291 | if (!mmapable && size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) { | 294 | if (mmapable) { |
| 292 | area = kmalloc_node(size, GFP_USER | __GFP_NORETRY | flags, | 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, | ||
| 293 | numa_node); | 300 | numa_node); |
| 294 | if (area != NULL) | 301 | if (area != NULL) |
| 295 | return area; | 302 | return area; |
| 296 | } | 303 | } |
| 297 | if (mmapable) { | 304 | |
| 298 | BUG_ON(!PAGE_ALIGNED(size)); | 305 | return __vmalloc_node_range(size, align, VMALLOC_START, VMALLOC_END, |
| 299 | return vmalloc_user_node_flags(size, numa_node, GFP_KERNEL | | 306 | gfp | GFP_KERNEL | __GFP_RETRY_MAYFAIL, PAGE_KERNEL, |
| 300 | __GFP_RETRY_MAYFAIL | flags); | 307 | flags, numa_node, __builtin_return_address(0)); |
| 301 | } | ||
| 302 | return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_RETRY_MAYFAIL | flags, | ||
| 303 | numa_node, __builtin_return_address(0)); | ||
| 304 | } | 308 | } |
| 305 | 309 | ||
| 306 | void *bpf_map_area_alloc(u64 size, int numa_node) | 310 | void *bpf_map_area_alloc(u64 size, int numa_node) |