Merge https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
[sfrench/cifs-2.6.git] / kernel / bpf / hashtab.c
index da7578426a4656acde41cb50d6bf813e0fc595e4..b301a63afa2f39387db66b8a75a82afbcfe64adb 100644 (file)
@@ -311,12 +311,8 @@ static struct htab_elem *prealloc_lru_pop(struct bpf_htab *htab, void *key,
        struct htab_elem *l;
 
        if (node) {
-               u32 key_size = htab->map.key_size;
-
                l = container_of(node, struct htab_elem, lru_node);
-               memcpy(l->key, key, key_size);
-               check_and_init_map_value(&htab->map,
-                                        l->key + round_up(key_size, 8));
+               memcpy(l->key, key, htab->map.key_size);
                return l;
        }
 
@@ -495,7 +491,7 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr)
        struct bpf_htab *htab;
        int err, i;
 
-       htab = kzalloc(sizeof(*htab), GFP_USER | __GFP_ACCOUNT);
+       htab = bpf_map_area_alloc(sizeof(*htab), NUMA_NO_NODE);
        if (!htab)
                return ERR_PTR(-ENOMEM);
 
@@ -579,7 +575,7 @@ free_map_locked:
        bpf_map_area_free(htab->buckets);
 free_htab:
        lockdep_unregister_key(&htab->lockdep_key);
-       kfree(htab);
+       bpf_map_area_free(htab);
        return ERR_PTR(err);
 }
 
@@ -1496,7 +1492,7 @@ static void htab_map_free(struct bpf_map *map)
        for (i = 0; i < HASHTAB_MAP_LOCK_COUNT; i++)
                free_percpu(htab->map_locked[i]);
        lockdep_unregister_key(&htab->lockdep_key);
-       kfree(htab);
+       bpf_map_area_free(htab);
 }
 
 static void htab_map_seq_show_elem(struct bpf_map *map, void *key,
@@ -2064,6 +2060,7 @@ static int bpf_iter_init_hash_map(void *priv_data,
                seq_info->percpu_value_buf = value_buf;
        }
 
+       bpf_map_inc_with_uref(map);
        seq_info->map = map;
        seq_info->htab = container_of(map, struct bpf_htab, map);
        return 0;
@@ -2073,6 +2070,7 @@ static void bpf_iter_fini_hash_map(void *priv_data)
 {
        struct bpf_iter_seq_hash_map_info *seq_info = priv_data;
 
+       bpf_map_put_with_uref(seq_info->map);
        kfree(seq_info->percpu_value_buf);
 }