History

bpf: Switch bpf_map_{area_alloc,area_mmapable_alloc}() to u64 size

Given we recently extended the original bpf_map_area_alloc() helper in commit fc9702273e2e ("bpf: Add mmap() support for BPF_MAP_TYPE_ARRAY"), we need to apply the same logic as in ff1c08e1f74b ("bpf: Change size to u64 for bpf_map_{area_alloc, charge_init}()"). To avoid conflicts, extend it for bpf-next.

Daniel Borkmann committed 6 years ago

Commit 196e8ca1 parent 91e60152 files · +10 −7Browse files

Unified · Split

2 files
  1. include/linux/bpf.h +3 −3
  2. kernel/bpf/syscall.c +7 −4
include/linux/bpf.h+3−3
@@ -794,12 +794,12 @@ void bpf_map_put_with_uref(struct bpf_map *map); · 793 unmodified lines
794794 void bpf_map_put(struct bpf_map *map);
795795 int bpf_map_charge_memlock(struct bpf_map *map, u32 pages);
796796 void bpf_map_uncharge_memlock(struct bpf_map *map, u32 pages);
797−int bpf_map_charge_init(struct bpf_map_memory *mem, size_t size);
797+int bpf_map_charge_init(struct bpf_map_memory *mem, u64 size);
798798 void bpf_map_charge_finish(struct bpf_map_memory *mem);
799799 void bpf_map_charge_move(struct bpf_map_memory *dst,
800800 struct bpf_map_memory *src);
801−void *bpf_map_area_alloc(size_t size, int numa_node);
802−void *bpf_map_area_mmapable_alloc(size_t size, int numa_node);
801+void *bpf_map_area_alloc(u64 size, int numa_node);
802+void *bpf_map_area_mmapable_alloc(u64 size, int numa_node);
803803 void bpf_map_area_free(void *base);
804804 void bpf_map_init_from_attr(struct bpf_map *map, union bpf_attr *attr);
805805
kernel/bpf/syscall.c+7−4
@@ -128,7 +128,7 @@ static struct bpf_map *find_and_alloc_map(union bpf_attr *attr) · 127 unmodified lines
128128 return map;
129129 }
130130
131−static void *__bpf_map_area_alloc(size_t size, int numa_node, bool mmapable)
131+static void *__bpf_map_area_alloc(u64 size, int numa_node, bool mmapable)
132132 {
133133 /* We really just want to fail instead of triggering OOM killer
134134 * under memory pressure, therefore we set __GFP_NORETRY to kmalloc,
@@ -143,6 +143,9 @@ static void *__bpf_map_area_alloc(size_t size, int numa_node, bool mmapable) · 8 unmodified lines
143143 const gfp_t flags = __GFP_NOWARN | __GFP_ZERO;
144144 void *area;
145145
146+ if (size >= SIZE_MAX)
147+ return NULL;
148+
146149 /* kmalloc()'ed memory can't be mmap()'ed */
147150 if (!mmapable && size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) {
148151 area = kmalloc_node(size, GFP_USER | __GFP_NORETRY | flags,
@@ -160,12 +163,12 @@ static void *__bpf_map_area_alloc(size_t size, int numa_node, bool mmapable) · 11 unmodified lines
160163 flags, __builtin_return_address(0));
161164 }
162165
163−void *bpf_map_area_alloc(size_t size, int numa_node)
166+void *bpf_map_area_alloc(u64 size, int numa_node)
164167 {
165168 return __bpf_map_area_alloc(size, numa_node, false);
166169 }
167170
168−void *bpf_map_area_mmapable_alloc(size_t size, int numa_node)
171+void *bpf_map_area_mmapable_alloc(u64 size, int numa_node)
169172 {
170173 return __bpf_map_area_alloc(size, numa_node, true);
171174 }
@@ -214,7 +217,7 @@ static void bpf_uncharge_memlock(struct user_struct *user, u32 pages) · 42 unmodified lines
214217 atomic_long_sub(pages, &user->locked_vm);
215218 }
216219
217−int bpf_map_charge_init(struct bpf_map_memory *mem, size_t size)
220+int bpf_map_charge_init(struct bpf_map_memory *mem, u64 size)
218221 {
219222 u32 pages = round_up(size, PAGE_SIZE) >> PAGE_SHIFT;
220223 struct user_struct *user;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t