Lines Matching refs:map

26 	for (i = 0; i < array->map.max_entries; i++) {  in bpf_array_free_percpu()
37 for (i = 0; i < array->map.max_entries; i++) { in bpf_array_alloc_percpu()
38 ptr = bpf_map_alloc_percpu(&array->map, array->elem_size, 8, in bpf_array_alloc_percpu()
143 array->map.bypass_spec_v1 = bypass_spec_v1; in array_map_alloc()
146 bpf_map_init_from_attr(&array->map, attr); in array_map_alloc()
154 return &array->map; in array_map_alloc()
163 static void *array_map_lookup_elem(struct bpf_map *map, void *key) in array_map_lookup_elem() argument
165 struct bpf_array *array = container_of(map, struct bpf_array, map); in array_map_lookup_elem()
168 if (unlikely(index >= array->map.max_entries)) in array_map_lookup_elem()
174 static int array_map_direct_value_addr(const struct bpf_map *map, u64 *imm, in array_map_direct_value_addr() argument
177 struct bpf_array *array = container_of(map, struct bpf_array, map); in array_map_direct_value_addr()
179 if (map->max_entries != 1) in array_map_direct_value_addr()
181 if (off >= map->value_size) in array_map_direct_value_addr()
188 static int array_map_direct_value_meta(const struct bpf_map *map, u64 imm, in array_map_direct_value_meta() argument
191 struct bpf_array *array = container_of(map, struct bpf_array, map); in array_map_direct_value_meta()
195 if (map->max_entries != 1) in array_map_direct_value_meta()
205 static int array_map_gen_lookup(struct bpf_map *map, struct bpf_insn *insn_buf) in array_map_gen_lookup() argument
207 struct bpf_array *array = container_of(map, struct bpf_array, map); in array_map_gen_lookup()
214 if (map->map_flags & BPF_F_INNER_MAP) in array_map_gen_lookup()
219 if (!map->bypass_spec_v1) { in array_map_gen_lookup()
220 *insn++ = BPF_JMP_IMM(BPF_JGE, ret, map->max_entries, 4); in array_map_gen_lookup()
223 *insn++ = BPF_JMP_IMM(BPF_JGE, ret, map->max_entries, 3); in array_map_gen_lookup()
238 static void *percpu_array_map_lookup_elem(struct bpf_map *map, void *key) in percpu_array_map_lookup_elem() argument
240 struct bpf_array *array = container_of(map, struct bpf_array, map); in percpu_array_map_lookup_elem()
243 if (unlikely(index >= array->map.max_entries)) in percpu_array_map_lookup_elem()
249 static void *percpu_array_map_lookup_percpu_elem(struct bpf_map *map, void *key, u32 cpu) in percpu_array_map_lookup_percpu_elem() argument
251 struct bpf_array *array = container_of(map, struct bpf_array, map); in percpu_array_map_lookup_percpu_elem()
257 if (unlikely(index >= array->map.max_entries)) in percpu_array_map_lookup_percpu_elem()
263 int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value) in bpf_percpu_array_copy() argument
265 struct bpf_array *array = container_of(map, struct bpf_array, map); in bpf_percpu_array_copy()
271 if (unlikely(index >= array->map.max_entries)) in bpf_percpu_array_copy()
282 copy_map_value_long(map, value + off, per_cpu_ptr(pptr, cpu)); in bpf_percpu_array_copy()
283 check_and_init_map_value(map, value + off); in bpf_percpu_array_copy()
291 static int array_map_get_next_key(struct bpf_map *map, void *key, void *next_key) in array_map_get_next_key() argument
293 struct bpf_array *array = container_of(map, struct bpf_array, map); in array_map_get_next_key()
297 if (index >= array->map.max_entries) { in array_map_get_next_key()
302 if (index == array->map.max_entries - 1) in array_map_get_next_key()
310 static long array_map_update_elem(struct bpf_map *map, void *key, void *value, in array_map_update_elem() argument
313 struct bpf_array *array = container_of(map, struct bpf_array, map); in array_map_update_elem()
321 if (unlikely(index >= array->map.max_entries)) in array_map_update_elem()
330 !btf_record_has_field(map->record, BPF_SPIN_LOCK))) in array_map_update_elem()
333 if (array->map.map_type == BPF_MAP_TYPE_PERCPU_ARRAY) { in array_map_update_elem()
335 copy_map_value(map, val, value); in array_map_update_elem()
336 bpf_obj_free_fields(array->map.record, val); in array_map_update_elem()
341 copy_map_value_locked(map, val, value, false); in array_map_update_elem()
343 copy_map_value(map, val, value); in array_map_update_elem()
344 bpf_obj_free_fields(array->map.record, val); in array_map_update_elem()
349 int bpf_percpu_array_update(struct bpf_map *map, void *key, void *value, in bpf_percpu_array_update() argument
352 struct bpf_array *array = container_of(map, struct bpf_array, map); in bpf_percpu_array_update()
362 if (unlikely(index >= array->map.max_entries)) in bpf_percpu_array_update()
380 copy_map_value_long(map, per_cpu_ptr(pptr, cpu), value + off); in bpf_percpu_array_update()
381 bpf_obj_free_fields(array->map.record, per_cpu_ptr(pptr, cpu)); in bpf_percpu_array_update()
389 static long array_map_delete_elem(struct bpf_map *map, void *key) in array_map_delete_elem() argument
399 static void array_map_free_timers(struct bpf_map *map) in array_map_free_timers() argument
401 struct bpf_array *array = container_of(map, struct bpf_array, map); in array_map_free_timers()
405 if (!btf_record_has_field(map->record, BPF_TIMER)) in array_map_free_timers()
408 for (i = 0; i < array->map.max_entries; i++) in array_map_free_timers()
409 bpf_obj_free_timer(map->record, array_map_elem_ptr(array, i)); in array_map_free_timers()
413 static void array_map_free(struct bpf_map *map) in array_map_free() argument
415 struct bpf_array *array = container_of(map, struct bpf_array, map); in array_map_free()
418 if (!IS_ERR_OR_NULL(map->record)) { in array_map_free()
419 if (array->map.map_type == BPF_MAP_TYPE_PERCPU_ARRAY) { in array_map_free()
420 for (i = 0; i < array->map.max_entries; i++) { in array_map_free()
425 bpf_obj_free_fields(map->record, per_cpu_ptr(pptr, cpu)); in array_map_free()
430 for (i = 0; i < array->map.max_entries; i++) in array_map_free()
431 bpf_obj_free_fields(map->record, array_map_elem_ptr(array, i)); in array_map_free()
435 if (array->map.map_type == BPF_MAP_TYPE_PERCPU_ARRAY) in array_map_free()
438 if (array->map.map_flags & BPF_F_MMAPABLE) in array_map_free()
444 static void array_map_seq_show_elem(struct bpf_map *map, void *key, in array_map_seq_show_elem() argument
451 value = array_map_lookup_elem(map, key); in array_map_seq_show_elem()
457 if (map->btf_key_type_id) in array_map_seq_show_elem()
459 btf_type_seq_show(map->btf, map->btf_value_type_id, value, m); in array_map_seq_show_elem()
465 static void percpu_array_map_seq_show_elem(struct bpf_map *map, void *key, in percpu_array_map_seq_show_elem() argument
468 struct bpf_array *array = container_of(map, struct bpf_array, map); in percpu_array_map_seq_show_elem()
479 btf_type_seq_show(map->btf, map->btf_value_type_id, in percpu_array_map_seq_show_elem()
488 static int array_map_check_btf(const struct bpf_map *map, in array_map_check_btf() argument
497 if (map->map_type != BPF_MAP_TYPE_ARRAY || in array_map_check_btf()
498 map->max_entries != 1) in array_map_check_btf()
520 static int array_map_mmap(struct bpf_map *map, struct vm_area_struct *vma) in array_map_mmap() argument
522 struct bpf_array *array = container_of(map, struct bpf_array, map); in array_map_mmap()
525 if (!(map->map_flags & BPF_F_MMAPABLE)) in array_map_mmap()
529 PAGE_ALIGN((u64)array->map.max_entries * array->elem_size)) in array_map_mmap()
546 struct bpf_map *map; member
554 struct bpf_map *map = info->map; in bpf_array_map_seq_start() local
558 if (info->index >= map->max_entries) in bpf_array_map_seq_start()
563 array = container_of(map, struct bpf_array, map); in bpf_array_map_seq_start()
573 struct bpf_map *map = info->map; in bpf_array_map_seq_next() local
579 if (info->index >= map->max_entries) in bpf_array_map_seq_next()
582 array = container_of(map, struct bpf_array, map); in bpf_array_map_seq_next()
593 struct bpf_map *map = info->map; in __bpf_array_map_seq_show() local
594 struct bpf_array *array = container_of(map, struct bpf_array, map); in __bpf_array_map_seq_show()
607 ctx.map = info->map; in __bpf_array_map_seq_show()
617 copy_map_value_long(map, info->percpu_value_buf + off, in __bpf_array_map_seq_show()
619 check_and_init_map_value(map, info->percpu_value_buf + off); in __bpf_array_map_seq_show()
644 struct bpf_map *map = aux->map; in bpf_iter_init_array_map() local
645 struct bpf_array *array = container_of(map, struct bpf_array, map); in bpf_iter_init_array_map()
649 if (map->map_type == BPF_MAP_TYPE_PERCPU_ARRAY) { in bpf_iter_init_array_map()
662 bpf_map_inc_with_uref(map); in bpf_iter_init_array_map()
663 seq_info->map = map; in bpf_iter_init_array_map()
671 bpf_map_put_with_uref(seq_info->map); in bpf_iter_fini_array_map()
689 static long bpf_for_each_array_elem(struct bpf_map *map, bpf_callback_t callback_fn, in bpf_for_each_array_elem() argument
701 is_percpu = map->map_type == BPF_MAP_TYPE_PERCPU_ARRAY; in bpf_for_each_array_elem()
702 array = container_of(map, struct bpf_array, map); in bpf_for_each_array_elem()
705 for (i = 0; i < map->max_entries; i++) { in bpf_for_each_array_elem()
712 ret = callback_fn((u64)(long)map, (u64)(long)&key, in bpf_for_each_array_elem()
724 static u64 array_map_mem_usage(const struct bpf_map *map) in array_map_mem_usage() argument
726 struct bpf_array *array = container_of(map, struct bpf_array, map); in array_map_mem_usage()
727 bool percpu = map->map_type == BPF_MAP_TYPE_PERCPU_ARRAY; in array_map_mem_usage()
729 u64 entries = map->max_entries; in array_map_mem_usage()
736 if (map->map_flags & BPF_F_MMAPABLE) { in array_map_mem_usage()
804 static void fd_array_map_free(struct bpf_map *map) in fd_array_map_free() argument
806 struct bpf_array *array = container_of(map, struct bpf_array, map); in fd_array_map_free()
810 for (i = 0; i < array->map.max_entries; i++) in fd_array_map_free()
816 static void *fd_array_map_lookup_elem(struct bpf_map *map, void *key) in fd_array_map_lookup_elem() argument
822 int bpf_fd_array_map_lookup_elem(struct bpf_map *map, void *key, u32 *value) in bpf_fd_array_map_lookup_elem() argument
827 if (!map->ops->map_fd_sys_lookup_elem) in bpf_fd_array_map_lookup_elem()
831 elem = array_map_lookup_elem(map, key); in bpf_fd_array_map_lookup_elem()
833 *value = map->ops->map_fd_sys_lookup_elem(ptr); in bpf_fd_array_map_lookup_elem()
842 int bpf_fd_array_map_update_elem(struct bpf_map *map, struct file *map_file, in bpf_fd_array_map_update_elem() argument
845 struct bpf_array *array = container_of(map, struct bpf_array, map); in bpf_fd_array_map_update_elem()
852 if (index >= array->map.max_entries) in bpf_fd_array_map_update_elem()
856 new_ptr = map->ops->map_fd_get_ptr(map, map_file, ufd); in bpf_fd_array_map_update_elem()
860 if (map->ops->map_poke_run) { in bpf_fd_array_map_update_elem()
863 map->ops->map_poke_run(map, index, old_ptr, new_ptr); in bpf_fd_array_map_update_elem()
870 map->ops->map_fd_put_ptr(map, old_ptr, true); in bpf_fd_array_map_update_elem()
874 static long __fd_array_map_delete_elem(struct bpf_map *map, void *key, bool need_defer) in __fd_array_map_delete_elem() argument
876 struct bpf_array *array = container_of(map, struct bpf_array, map); in __fd_array_map_delete_elem()
880 if (index >= array->map.max_entries) in __fd_array_map_delete_elem()
883 if (map->ops->map_poke_run) { in __fd_array_map_delete_elem()
886 map->ops->map_poke_run(map, index, old_ptr, NULL); in __fd_array_map_delete_elem()
893 map->ops->map_fd_put_ptr(map, old_ptr, need_defer); in __fd_array_map_delete_elem()
900 static long fd_array_map_delete_elem(struct bpf_map *map, void *key) in fd_array_map_delete_elem() argument
902 return __fd_array_map_delete_elem(map, key, true); in fd_array_map_delete_elem()
905 static void *prog_fd_array_get_ptr(struct bpf_map *map, in prog_fd_array_get_ptr() argument
913 if (!bpf_prog_map_compatible(map, prog)) { in prog_fd_array_get_ptr()
921 static void prog_fd_array_put_ptr(struct bpf_map *map, void *ptr, bool need_defer) in prog_fd_array_put_ptr() argument
933 static void bpf_fd_array_map_clear(struct bpf_map *map, bool need_defer) in bpf_fd_array_map_clear() argument
935 struct bpf_array *array = container_of(map, struct bpf_array, map); in bpf_fd_array_map_clear()
938 for (i = 0; i < array->map.max_entries; i++) in bpf_fd_array_map_clear()
939 __fd_array_map_delete_elem(map, &i, need_defer); in bpf_fd_array_map_clear()
942 static void prog_array_map_seq_show_elem(struct bpf_map *map, void *key, in prog_array_map_seq_show_elem() argument
950 elem = array_map_lookup_elem(map, key); in prog_array_map_seq_show_elem()
956 btf_type_seq_show(map->btf, map->btf_value_type_id, in prog_array_map_seq_show_elem()
970 static int prog_array_map_poke_track(struct bpf_map *map, in prog_array_map_poke_track() argument
977 aux = container_of(map, struct bpf_array, map)->aux; in prog_array_map_poke_track()
1003 static void prog_array_map_poke_untrack(struct bpf_map *map, in prog_array_map_poke_untrack() argument
1009 aux = container_of(map, struct bpf_array, map)->aux; in prog_array_map_poke_untrack()
1027 static void prog_array_map_poke_run(struct bpf_map *map, u32 key, in prog_array_map_poke_run() argument
1034 aux = container_of(map, struct bpf_array, map)->aux; in prog_array_map_poke_run()
1067 if (poke->tail_call.map != map || in prog_array_map_poke_run()
1078 struct bpf_map *map = container_of(work, struct bpf_array_aux, in prog_array_map_clear_deferred() local
1079 work)->map; in prog_array_map_clear_deferred()
1080 bpf_fd_array_map_clear(map, true); in prog_array_map_clear_deferred()
1081 bpf_map_put(map); in prog_array_map_clear_deferred()
1084 static void prog_array_map_clear(struct bpf_map *map) in prog_array_map_clear() argument
1086 struct bpf_array_aux *aux = container_of(map, struct bpf_array, in prog_array_map_clear()
1087 map)->aux; in prog_array_map_clear()
1088 bpf_map_inc(map); in prog_array_map_clear()
1095 struct bpf_map *map; in prog_array_map_alloc() local
1105 map = array_map_alloc(attr); in prog_array_map_alloc()
1106 if (IS_ERR(map)) { in prog_array_map_alloc()
1108 return map; in prog_array_map_alloc()
1111 container_of(map, struct bpf_array, map)->aux = aux; in prog_array_map_alloc()
1112 aux->map = map; in prog_array_map_alloc()
1114 return map; in prog_array_map_alloc()
1117 static void prog_array_map_free(struct bpf_map *map) in prog_array_map_free() argument
1122 aux = container_of(map, struct bpf_array, map)->aux; in prog_array_map_free()
1128 fd_array_map_free(map); in prog_array_map_free()
1184 static void *perf_event_fd_array_get_ptr(struct bpf_map *map, in perf_event_fd_array_get_ptr() argument
1210 static void perf_event_fd_array_put_ptr(struct bpf_map *map, void *ptr, bool need_defer) in perf_event_fd_array_put_ptr() argument
1216 static void perf_event_fd_array_release(struct bpf_map *map, in perf_event_fd_array_release() argument
1219 struct bpf_array *array = container_of(map, struct bpf_array, map); in perf_event_fd_array_release()
1223 if (map->map_flags & BPF_F_PRESERVE_ELEMS) in perf_event_fd_array_release()
1227 for (i = 0; i < array->map.max_entries; i++) { in perf_event_fd_array_release()
1230 __fd_array_map_delete_elem(map, &i, true); in perf_event_fd_array_release()
1235 static void perf_event_fd_array_map_free(struct bpf_map *map) in perf_event_fd_array_map_free() argument
1237 if (map->map_flags & BPF_F_PRESERVE_ELEMS) in perf_event_fd_array_map_free()
1238 bpf_fd_array_map_clear(map, false); in perf_event_fd_array_map_free()
1239 fd_array_map_free(map); in perf_event_fd_array_map_free()
1259 static void *cgroup_fd_array_get_ptr(struct bpf_map *map, in cgroup_fd_array_get_ptr() argument
1266 static void cgroup_fd_array_put_ptr(struct bpf_map *map, void *ptr, bool need_defer) in cgroup_fd_array_put_ptr() argument
1272 static void cgroup_fd_array_free(struct bpf_map *map) in cgroup_fd_array_free() argument
1274 bpf_fd_array_map_clear(map, false); in cgroup_fd_array_free()
1275 fd_array_map_free(map); in cgroup_fd_array_free()
1296 struct bpf_map *map, *inner_map_meta; in array_of_map_alloc() local
1302 map = array_map_alloc(attr); in array_of_map_alloc()
1303 if (IS_ERR(map)) { in array_of_map_alloc()
1305 return map; in array_of_map_alloc()
1308 map->inner_map_meta = inner_map_meta; in array_of_map_alloc()
1310 return map; in array_of_map_alloc()
1313 static void array_of_map_free(struct bpf_map *map) in array_of_map_free() argument
1318 bpf_map_meta_free(map->inner_map_meta); in array_of_map_free()
1319 bpf_fd_array_map_clear(map, false); in array_of_map_free()
1320 fd_array_map_free(map); in array_of_map_free()
1323 static void *array_of_map_lookup_elem(struct bpf_map *map, void *key) in array_of_map_lookup_elem() argument
1325 struct bpf_map **inner_map = array_map_lookup_elem(map, key); in array_of_map_lookup_elem()
1333 static int array_of_map_gen_lookup(struct bpf_map *map, in array_of_map_gen_lookup() argument
1336 struct bpf_array *array = container_of(map, struct bpf_array, map); in array_of_map_gen_lookup()
1345 if (!map->bypass_spec_v1) { in array_of_map_gen_lookup()
1346 *insn++ = BPF_JMP_IMM(BPF_JGE, ret, map->max_entries, 6); in array_of_map_gen_lookup()
1349 *insn++ = BPF_JMP_IMM(BPF_JGE, ret, map->max_entries, 5); in array_of_map_gen_lookup()