Merge tag 'staging-5.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[linux-2.6-block.git] / kernel / bpf / reuseport_array.c
index 18e225de80ff0edf1b12845b32a0f7098f2457be..50c083ba978c85dd399699bb3ad61710da842f37 100644 (file)
@@ -151,7 +151,8 @@ static struct bpf_map *reuseport_array_alloc(union bpf_attr *attr)
 {
        int err, numa_node = bpf_map_attr_numa_node(attr);
        struct reuseport_array *array;
-       u64 cost, array_size;
+       struct bpf_map_memory mem;
+       u64 array_size;
 
        if (!capable(CAP_SYS_ADMIN))
                return ERR_PTR(-EPERM);
@@ -159,24 +160,20 @@ static struct bpf_map *reuseport_array_alloc(union bpf_attr *attr)
        array_size = sizeof(*array);
        array_size += (u64)attr->max_entries * sizeof(struct sock *);
 
-       /* make sure there is no u32 overflow later in round_up() */
-       cost = array_size;
-       if (cost >= U32_MAX - PAGE_SIZE)
-               return ERR_PTR(-ENOMEM);
-       cost = round_up(cost, PAGE_SIZE) >> PAGE_SHIFT;
-
-       err = bpf_map_precharge_memlock(cost);
+       err = bpf_map_charge_init(&mem, array_size);
        if (err)
                return ERR_PTR(err);
 
        /* allocate all map elements and zero-initialize them */
        array = bpf_map_area_alloc(array_size, numa_node);
-       if (!array)
+       if (!array) {
+               bpf_map_charge_finish(&mem);
                return ERR_PTR(-ENOMEM);
+       }
 
        /* copy mandatory map attributes */
        bpf_map_init_from_attr(&array->map, attr);
-       array->map.pages = cost;
+       bpf_map_charge_move(&array->map.memory, &mem);
 
        return &array->map;
 }