Lines Matching refs:dtab
103 static inline struct hlist_head *dev_map_index_hash(struct bpf_dtab *dtab, in dev_map_index_hash() argument
106 return &dtab->dev_index_head[idx & (dtab->n_buckets - 1)]; in dev_map_index_hash()
134 static int dev_map_init_map(struct bpf_dtab *dtab, union bpf_attr *attr) in dev_map_init_map() argument
140 bpf_map_init_from_attr(&dtab->map, attr); in dev_map_init_map()
144 dtab->n_buckets = roundup_pow_of_two(dtab->map.max_entries); in dev_map_init_map()
145 dtab->dev_index_head = dev_map_create_hash(dtab->n_buckets, in dev_map_init_map()
146 dtab->map.numa_node); in dev_map_init_map()
147 if (!dtab->dev_index_head) in dev_map_init_map()
150 spin_lock_init(&dtab->index_lock); in dev_map_init_map()
152 dtab->netdev_map = bpf_map_area_alloc((u64) dtab->map.max_entries * in dev_map_init_map()
154 dtab->map.numa_node); in dev_map_init_map()
155 if (!dtab->netdev_map) in dev_map_init_map()
164 struct bpf_dtab *dtab; in dev_map_alloc() local
167 dtab = bpf_map_area_alloc(sizeof(*dtab), NUMA_NO_NODE); in dev_map_alloc()
168 if (!dtab) in dev_map_alloc()
171 err = dev_map_init_map(dtab, attr); in dev_map_alloc()
173 bpf_map_area_free(dtab); in dev_map_alloc()
178 list_add_tail_rcu(&dtab->list, &dev_map_list); in dev_map_alloc()
181 return &dtab->map; in dev_map_alloc()
186 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in dev_map_free() local
200 list_del_rcu(&dtab->list); in dev_map_free()
216 if (dtab->map.map_type == BPF_MAP_TYPE_DEVMAP_HASH) { in dev_map_free()
217 for (i = 0; i < dtab->n_buckets; i++) { in dev_map_free()
222 head = dev_map_index_hash(dtab, i); in dev_map_free()
233 bpf_map_area_free(dtab->dev_index_head); in dev_map_free()
235 for (i = 0; i < dtab->map.max_entries; i++) { in dev_map_free()
238 dev = rcu_dereference_raw(dtab->netdev_map[i]); in dev_map_free()
248 bpf_map_area_free(dtab->netdev_map); in dev_map_free()
251 bpf_map_area_free(dtab); in dev_map_free()
256 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in dev_map_get_next_key() local
260 if (index >= dtab->map.max_entries) { in dev_map_get_next_key()
265 if (index == dtab->map.max_entries - 1) in dev_map_get_next_key()
277 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in __dev_map_hash_lookup_elem() local
278 struct hlist_head *head = dev_map_index_hash(dtab, key); in __dev_map_hash_lookup_elem()
282 lockdep_is_held(&dtab->index_lock)) in __dev_map_hash_lookup_elem()
292 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in dev_map_hash_get_next_key() local
315 i = idx & (dtab->n_buckets - 1); in dev_map_hash_get_next_key()
319 for (; i < dtab->n_buckets; i++) { in dev_map_hash_get_next_key()
320 head = dev_map_index_hash(dtab, i); in dev_map_hash_get_next_key()
441 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in __dev_map_lookup_elem() local
447 obj = rcu_dereference_check(dtab->netdev_map[key], in __dev_map_lookup_elem()
609 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in dev_map_enqueue_multi() local
624 dst = rcu_dereference_check(dtab->netdev_map[i], in dev_map_enqueue_multi()
645 for (i = 0; i < dtab->n_buckets; i++) { in dev_map_enqueue_multi()
646 head = dev_map_index_hash(dtab, i); in dev_map_enqueue_multi()
648 lockdep_is_held(&dtab->index_lock)) { in dev_map_enqueue_multi()
726 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in dev_map_redirect_multi() local
742 dst = rcu_dereference_check(dtab->netdev_map[i], in dev_map_redirect_multi()
764 for (i = 0; i < dtab->n_buckets; i++) { in dev_map_redirect_multi()
765 head = dev_map_index_hash(dtab, i); in dev_map_redirect_multi()
822 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in dev_map_delete_elem() local
829 old_dev = unrcu_pointer(xchg(&dtab->netdev_map[k], NULL)); in dev_map_delete_elem()
832 atomic_dec((atomic_t *)&dtab->items); in dev_map_delete_elem()
839 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in dev_map_hash_delete_elem() local
845 spin_lock_irqsave(&dtab->index_lock, flags); in dev_map_hash_delete_elem()
849 dtab->items--; in dev_map_hash_delete_elem()
854 spin_unlock_irqrestore(&dtab->index_lock, flags); in dev_map_hash_delete_elem()
860 struct bpf_dtab *dtab, in __dev_map_alloc_node() argument
867 dev = bpf_map_kmalloc_node(&dtab->map, sizeof(*dev), in __dev_map_alloc_node()
869 dtab->map.numa_node); in __dev_map_alloc_node()
883 !bpf_prog_map_compatible(&dtab->map, prog)) in __dev_map_alloc_node()
910 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in __dev_map_update_elem() local
917 if (unlikely(i >= dtab->map.max_entries)) in __dev_map_update_elem()
931 dev = __dev_map_alloc_node(net, dtab, &val, i); in __dev_map_update_elem()
940 old_dev = unrcu_pointer(xchg(&dtab->netdev_map[i], RCU_INITIALIZER(dev))); in __dev_map_update_elem()
944 atomic_inc((atomic_t *)&dtab->items); in __dev_map_update_elem()
959 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in __dev_map_hash_update_elem() local
972 spin_lock_irqsave(&dtab->index_lock, flags); in __dev_map_hash_update_elem()
978 dev = __dev_map_alloc_node(net, dtab, &val, idx); in __dev_map_hash_update_elem()
987 if (dtab->items >= dtab->map.max_entries) { in __dev_map_hash_update_elem()
988 spin_unlock_irqrestore(&dtab->index_lock, flags); in __dev_map_hash_update_elem()
992 dtab->items++; in __dev_map_hash_update_elem()
996 dev_map_index_hash(dtab, idx)); in __dev_map_hash_update_elem()
997 spin_unlock_irqrestore(&dtab->index_lock, flags); in __dev_map_hash_update_elem()
1005 spin_unlock_irqrestore(&dtab->index_lock, flags); in __dev_map_hash_update_elem()
1032 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in dev_map_mem_usage() local
1036 usage += (u64)dtab->n_buckets * sizeof(struct hlist_head); in dev_map_mem_usage()
1039 usage += atomic_read((atomic_t *)&dtab->items) * in dev_map_mem_usage()
1075 static void dev_map_hash_remove_netdev(struct bpf_dtab *dtab, in dev_map_hash_remove_netdev() argument
1081 spin_lock_irqsave(&dtab->index_lock, flags); in dev_map_hash_remove_netdev()
1082 for (i = 0; i < dtab->n_buckets; i++) { in dev_map_hash_remove_netdev()
1087 head = dev_map_index_hash(dtab, i); in dev_map_hash_remove_netdev()
1093 dtab->items--; in dev_map_hash_remove_netdev()
1098 spin_unlock_irqrestore(&dtab->index_lock, flags); in dev_map_hash_remove_netdev()
1105 struct bpf_dtab *dtab; in dev_map_notification() local
1128 list_for_each_entry_rcu(dtab, &dev_map_list, list) { in dev_map_notification()
1129 if (dtab->map.map_type == BPF_MAP_TYPE_DEVMAP_HASH) { in dev_map_notification()
1130 dev_map_hash_remove_netdev(dtab, netdev); in dev_map_notification()
1134 for (i = 0; i < dtab->map.max_entries; i++) { in dev_map_notification()
1137 dev = rcu_dereference(dtab->netdev_map[i]); in dev_map_notification()
1140 odev = unrcu_pointer(cmpxchg(&dtab->netdev_map[i], RCU_INITIALIZER(dev), NULL)); in dev_map_notification()
1144 atomic_dec((atomic_t *)&dtab->items); in dev_map_notification()