Lines Matching refs:dtab
68 struct bpf_dtab *dtab; member
105 static inline struct hlist_head *dev_map_index_hash(struct bpf_dtab *dtab, in dev_map_index_hash() argument
108 return &dtab->dev_index_head[idx & (dtab->n_buckets - 1)]; in dev_map_index_hash()
111 static int dev_map_init_map(struct bpf_dtab *dtab, union bpf_attr *attr) in dev_map_init_map() argument
131 bpf_map_init_from_attr(&dtab->map, attr); in dev_map_init_map()
134 dtab->n_buckets = roundup_pow_of_two(dtab->map.max_entries); in dev_map_init_map()
136 if (!dtab->n_buckets) /* Overflow check */ in dev_map_init_map()
141 dtab->dev_index_head = dev_map_create_hash(dtab->n_buckets, in dev_map_init_map()
142 dtab->map.numa_node); in dev_map_init_map()
143 if (!dtab->dev_index_head) in dev_map_init_map()
146 spin_lock_init(&dtab->index_lock); in dev_map_init_map()
148 dtab->netdev_map = bpf_map_area_alloc((u64) dtab->map.max_entries * in dev_map_init_map()
150 dtab->map.numa_node); in dev_map_init_map()
151 if (!dtab->netdev_map) in dev_map_init_map()
160 struct bpf_dtab *dtab; in dev_map_alloc() local
166 dtab = bpf_map_area_alloc(sizeof(*dtab), NUMA_NO_NODE); in dev_map_alloc()
167 if (!dtab) in dev_map_alloc()
170 err = dev_map_init_map(dtab, attr); in dev_map_alloc()
172 bpf_map_area_free(dtab); in dev_map_alloc()
177 list_add_tail_rcu(&dtab->list, &dev_map_list); in dev_map_alloc()
180 return &dtab->map; in dev_map_alloc()
185 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in dev_map_free() local
199 list_del_rcu(&dtab->list); in dev_map_free()
208 if (dtab->map.map_type == BPF_MAP_TYPE_DEVMAP_HASH) { in dev_map_free()
209 for (i = 0; i < dtab->n_buckets; i++) { in dev_map_free()
214 head = dev_map_index_hash(dtab, i); in dev_map_free()
225 bpf_map_area_free(dtab->dev_index_head); in dev_map_free()
227 for (i = 0; i < dtab->map.max_entries; i++) { in dev_map_free()
230 dev = rcu_dereference_raw(dtab->netdev_map[i]); in dev_map_free()
240 bpf_map_area_free(dtab->netdev_map); in dev_map_free()
243 bpf_map_area_free(dtab); in dev_map_free()
248 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in dev_map_get_next_key() local
252 if (index >= dtab->map.max_entries) { in dev_map_get_next_key()
257 if (index == dtab->map.max_entries - 1) in dev_map_get_next_key()
269 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in __dev_map_hash_lookup_elem() local
270 struct hlist_head *head = dev_map_index_hash(dtab, key); in __dev_map_hash_lookup_elem()
274 lockdep_is_held(&dtab->index_lock)) in __dev_map_hash_lookup_elem()
284 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in dev_map_hash_get_next_key() local
307 i = idx & (dtab->n_buckets - 1); in dev_map_hash_get_next_key()
311 for (; i < dtab->n_buckets; i++) { in dev_map_hash_get_next_key()
312 head = dev_map_index_hash(dtab, i); in dev_map_hash_get_next_key()
431 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in __dev_map_lookup_elem() local
437 obj = rcu_dereference_check(dtab->netdev_map[key], in __dev_map_lookup_elem()
588 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in dev_map_enqueue_multi() local
603 dst = rcu_dereference_check(dtab->netdev_map[i], in dev_map_enqueue_multi()
624 for (i = 0; i < dtab->n_buckets; i++) { in dev_map_enqueue_multi()
625 head = dev_map_index_hash(dtab, i); in dev_map_enqueue_multi()
627 lockdep_is_held(&dtab->index_lock)) { in dev_map_enqueue_multi()
705 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in dev_map_redirect_multi() local
721 dst = rcu_dereference_check(dtab->netdev_map[i], in dev_map_redirect_multi()
743 for (i = 0; i < dtab->n_buckets; i++) { in dev_map_redirect_multi()
744 head = dev_map_index_hash(dtab, i); in dev_map_redirect_multi()
804 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in dev_map_delete_elem() local
811 old_dev = unrcu_pointer(xchg(&dtab->netdev_map[k], NULL)); in dev_map_delete_elem()
819 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in dev_map_hash_delete_elem() local
825 spin_lock_irqsave(&dtab->index_lock, flags); in dev_map_hash_delete_elem()
829 dtab->items--; in dev_map_hash_delete_elem()
834 spin_unlock_irqrestore(&dtab->index_lock, flags); in dev_map_hash_delete_elem()
840 struct bpf_dtab *dtab, in __dev_map_alloc_node() argument
847 dev = bpf_map_kmalloc_node(&dtab->map, sizeof(*dev), in __dev_map_alloc_node()
849 dtab->map.numa_node); in __dev_map_alloc_node()
863 !bpf_prog_map_compatible(&dtab->map, prog)) in __dev_map_alloc_node()
868 dev->dtab = dtab; in __dev_map_alloc_node()
891 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in __dev_map_update_elem() local
898 if (unlikely(i >= dtab->map.max_entries)) in __dev_map_update_elem()
912 dev = __dev_map_alloc_node(net, dtab, &val, i); in __dev_map_update_elem()
921 old_dev = unrcu_pointer(xchg(&dtab->netdev_map[i], RCU_INITIALIZER(dev))); in __dev_map_update_elem()
938 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); in __dev_map_hash_update_elem() local
951 spin_lock_irqsave(&dtab->index_lock, flags); in __dev_map_hash_update_elem()
957 dev = __dev_map_alloc_node(net, dtab, &val, idx); in __dev_map_hash_update_elem()
966 if (dtab->items >= dtab->map.max_entries) { in __dev_map_hash_update_elem()
967 spin_unlock_irqrestore(&dtab->index_lock, flags); in __dev_map_hash_update_elem()
971 dtab->items++; in __dev_map_hash_update_elem()
975 dev_map_index_hash(dtab, idx)); in __dev_map_hash_update_elem()
976 spin_unlock_irqrestore(&dtab->index_lock, flags); in __dev_map_hash_update_elem()
984 spin_unlock_irqrestore(&dtab->index_lock, flags); in __dev_map_hash_update_elem()
1036 static void dev_map_hash_remove_netdev(struct bpf_dtab *dtab, in dev_map_hash_remove_netdev() argument
1042 spin_lock_irqsave(&dtab->index_lock, flags); in dev_map_hash_remove_netdev()
1043 for (i = 0; i < dtab->n_buckets; i++) { in dev_map_hash_remove_netdev()
1048 head = dev_map_index_hash(dtab, i); in dev_map_hash_remove_netdev()
1054 dtab->items--; in dev_map_hash_remove_netdev()
1059 spin_unlock_irqrestore(&dtab->index_lock, flags); in dev_map_hash_remove_netdev()
1066 struct bpf_dtab *dtab; in dev_map_notification() local
1089 list_for_each_entry_rcu(dtab, &dev_map_list, list) { in dev_map_notification()
1090 if (dtab->map.map_type == BPF_MAP_TYPE_DEVMAP_HASH) { in dev_map_notification()
1091 dev_map_hash_remove_netdev(dtab, netdev); in dev_map_notification()
1095 for (i = 0; i < dtab->map.max_entries; i++) { in dev_map_notification()
1098 dev = rcu_dereference(dtab->netdev_map[i]); in dev_map_notification()
1101 odev = unrcu_pointer(cmpxchg(&dtab->netdev_map[i], RCU_INITIALIZER(dev), NULL)); in dev_map_notification()