diff options
Diffstat (limited to 'kernel/bpf/hashtab.c')
-rw-r--r-- | kernel/bpf/hashtab.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index 4fb463172aa8..47ae748c3a49 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c | |||
@@ -18,6 +18,9 @@ | |||
18 | #include "bpf_lru_list.h" | 18 | #include "bpf_lru_list.h" |
19 | #include "map_in_map.h" | 19 | #include "map_in_map.h" |
20 | 20 | ||
21 | #define HTAB_CREATE_FLAG_MASK \ | ||
22 | (BPF_F_NO_PREALLOC | BPF_F_NO_COMMON_LRU | BPF_F_NUMA_NODE) | ||
23 | |||
21 | struct bucket { | 24 | struct bucket { |
22 | struct hlist_nulls_head head; | 25 | struct hlist_nulls_head head; |
23 | raw_spinlock_t lock; | 26 | raw_spinlock_t lock; |
@@ -138,7 +141,8 @@ static int prealloc_init(struct bpf_htab *htab) | |||
138 | if (!htab_is_percpu(htab) && !htab_is_lru(htab)) | 141 | if (!htab_is_percpu(htab) && !htab_is_lru(htab)) |
139 | num_entries += num_possible_cpus(); | 142 | num_entries += num_possible_cpus(); |
140 | 143 | ||
141 | htab->elems = bpf_map_area_alloc(htab->elem_size * num_entries); | 144 | htab->elems = bpf_map_area_alloc(htab->elem_size * num_entries, |
145 | htab->map.numa_node); | ||
142 | if (!htab->elems) | 146 | if (!htab->elems) |
143 | return -ENOMEM; | 147 | return -ENOMEM; |
144 | 148 | ||
@@ -233,6 +237,7 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr) | |||
233 | */ | 237 | */ |
234 | bool percpu_lru = (attr->map_flags & BPF_F_NO_COMMON_LRU); | 238 | bool percpu_lru = (attr->map_flags & BPF_F_NO_COMMON_LRU); |
235 | bool prealloc = !(attr->map_flags & BPF_F_NO_PREALLOC); | 239 | bool prealloc = !(attr->map_flags & BPF_F_NO_PREALLOC); |
240 | int numa_node = bpf_map_attr_numa_node(attr); | ||
236 | struct bpf_htab *htab; | 241 | struct bpf_htab *htab; |
237 | int err, i; | 242 | int err, i; |
238 | u64 cost; | 243 | u64 cost; |
@@ -248,7 +253,7 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr) | |||
248 | */ | 253 | */ |
249 | return ERR_PTR(-EPERM); | 254 | return ERR_PTR(-EPERM); |
250 | 255 | ||
251 | if (attr->map_flags & ~(BPF_F_NO_PREALLOC | BPF_F_NO_COMMON_LRU)) | 256 | if (attr->map_flags & ~HTAB_CREATE_FLAG_MASK) |
252 | /* reserved bits should not be used */ | 257 | /* reserved bits should not be used */ |
253 | return ERR_PTR(-EINVAL); | 258 | return ERR_PTR(-EINVAL); |
254 | 259 | ||
@@ -258,6 +263,9 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr) | |||
258 | if (lru && !prealloc) | 263 | if (lru && !prealloc) |
259 | return ERR_PTR(-ENOTSUPP); | 264 | return ERR_PTR(-ENOTSUPP); |
260 | 265 | ||
266 | if (numa_node != NUMA_NO_NODE && (percpu || percpu_lru)) | ||
267 | return ERR_PTR(-EINVAL); | ||
268 | |||
261 | htab = kzalloc(sizeof(*htab), GFP_USER); | 269 | htab = kzalloc(sizeof(*htab), GFP_USER); |
262 | if (!htab) | 270 | if (!htab) |
263 | return ERR_PTR(-ENOMEM); | 271 | return ERR_PTR(-ENOMEM); |
@@ -268,6 +276,7 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr) | |||
268 | htab->map.value_size = attr->value_size; | 276 | htab->map.value_size = attr->value_size; |
269 | htab->map.max_entries = attr->max_entries; | 277 | htab->map.max_entries = attr->max_entries; |
270 | htab->map.map_flags = attr->map_flags; | 278 | htab->map.map_flags = attr->map_flags; |
279 | htab->map.numa_node = numa_node; | ||
271 | 280 | ||
272 | /* check sanity of attributes. | 281 | /* check sanity of attributes. |
273 | * value_size == 0 may be allowed in the future to use map as a set | 282 | * value_size == 0 may be allowed in the future to use map as a set |
@@ -346,7 +355,8 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr) | |||
346 | 355 | ||
347 | err = -ENOMEM; | 356 | err = -ENOMEM; |
348 | htab->buckets = bpf_map_area_alloc(htab->n_buckets * | 357 | htab->buckets = bpf_map_area_alloc(htab->n_buckets * |
349 | sizeof(struct bucket)); | 358 | sizeof(struct bucket), |
359 | htab->map.numa_node); | ||
350 | if (!htab->buckets) | 360 | if (!htab->buckets) |
351 | goto free_htab; | 361 | goto free_htab; |
352 | 362 | ||
@@ -689,7 +699,8 @@ static struct htab_elem *alloc_htab_elem(struct bpf_htab *htab, void *key, | |||
689 | atomic_dec(&htab->count); | 699 | atomic_dec(&htab->count); |
690 | return ERR_PTR(-E2BIG); | 700 | return ERR_PTR(-E2BIG); |
691 | } | 701 | } |
692 | l_new = kmalloc(htab->elem_size, GFP_ATOMIC | __GFP_NOWARN); | 702 | l_new = kmalloc_node(htab->elem_size, GFP_ATOMIC | __GFP_NOWARN, |
703 | htab->map.numa_node); | ||
693 | if (!l_new) | 704 | if (!l_new) |
694 | return ERR_PTR(-ENOMEM); | 705 | return ERR_PTR(-ENOMEM); |
695 | } | 706 | } |