@@ -107,7 +107,7 @@ static inline struct hlist_head *dev_map_index_hash(struct bpf_dtab *dtab,
107
107
return & dtab -> dev_index_head [idx & (dtab -> n_buckets - 1 )];
108
108
}
109
109
110
- static int dev_map_init_map ( struct bpf_dtab * dtab , union bpf_attr * attr )
110
+ static int dev_map_alloc_check ( union bpf_attr * attr )
111
111
{
112
112
u32 valsize = attr -> value_size ;
113
113
@@ -121,23 +121,28 @@ static int dev_map_init_map(struct bpf_dtab *dtab, union bpf_attr *attr)
121
121
attr -> map_flags & ~DEV_CREATE_FLAG_MASK )
122
122
return - EINVAL ;
123
123
124
+ if (attr -> map_type == BPF_MAP_TYPE_DEVMAP_HASH ) {
125
+ /* Hash table size must be power of 2; roundup_pow_of_two()
126
+ * can overflow into UB on 32-bit arches
127
+ */
128
+ if (attr -> max_entries > 1UL << 31 )
129
+ return - EINVAL ;
130
+ }
131
+
132
+ return 0 ;
133
+ }
134
+
135
+ static int dev_map_init_map (struct bpf_dtab * dtab , union bpf_attr * attr )
136
+ {
124
137
/* Lookup returns a pointer straight to dev->ifindex, so make sure the
125
138
* verifier prevents writes from the BPF side
126
139
*/
127
140
attr -> map_flags |= BPF_F_RDONLY_PROG ;
128
-
129
-
130
141
bpf_map_init_from_attr (& dtab -> map , attr );
131
142
132
143
if (attr -> map_type == BPF_MAP_TYPE_DEVMAP_HASH ) {
133
- /* hash table size must be power of 2; roundup_pow_of_two() can
134
- * overflow into UB on 32-bit arches, so check that first
135
- */
136
- if (dtab -> map .max_entries > 1UL << 31 )
137
- return - EINVAL ;
138
-
144
+ /* Hash table size must be power of 2 */
139
145
dtab -> n_buckets = roundup_pow_of_two (dtab -> map .max_entries );
140
-
141
146
dtab -> dev_index_head = dev_map_create_hash (dtab -> n_buckets ,
142
147
dtab -> map .numa_node );
143
148
if (!dtab -> dev_index_head )
@@ -1040,6 +1045,7 @@ static u64 dev_map_mem_usage(const struct bpf_map *map)
1040
1045
BTF_ID_LIST_SINGLE (dev_map_btf_ids , struct , bpf_dtab )
1041
1046
const struct bpf_map_ops dev_map_ops = {
1042
1047
.map_meta_equal = bpf_map_meta_equal ,
1048
+ .map_alloc_check = dev_map_alloc_check ,
1043
1049
.map_alloc = dev_map_alloc ,
1044
1050
.map_free = dev_map_free ,
1045
1051
.map_get_next_key = dev_map_get_next_key ,
@@ -1054,6 +1060,7 @@ const struct bpf_map_ops dev_map_ops = {
1054
1060
1055
1061
const struct bpf_map_ops dev_map_hash_ops = {
1056
1062
.map_meta_equal = bpf_map_meta_equal ,
1063
+ .map_alloc_check = dev_map_alloc_check ,
1057
1064
.map_alloc = dev_map_alloc ,
1058
1065
.map_free = dev_map_free ,
1059
1066
.map_get_next_key = dev_map_hash_get_next_key ,
0 commit comments