diff options
Diffstat (limited to 'kernel/bpf/hashtab.c')
-rw-r--r-- | kernel/bpf/hashtab.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index 15bf228d2e98..b0bdc7b040ad 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c | |||
@@ -364,10 +364,9 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr) | |||
364 | /* make sure page count doesn't overflow */ | 364 | /* make sure page count doesn't overflow */ |
365 | goto free_htab; | 365 | goto free_htab; |
366 | 366 | ||
367 | htab->map.memory.pages = round_up(cost, PAGE_SIZE) >> PAGE_SHIFT; | 367 | /* if map size is larger than memlock limit, reject it */ |
368 | 368 | err = bpf_map_charge_init(&htab->map.memory, | |
369 | /* if map size is larger than memlock limit, reject it early */ | 369 | round_up(cost, PAGE_SIZE) >> PAGE_SHIFT); |
370 | err = bpf_map_precharge_memlock(htab->map.memory.pages); | ||
371 | if (err) | 370 | if (err) |
372 | goto free_htab; | 371 | goto free_htab; |
373 | 372 | ||
@@ -376,7 +375,7 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr) | |||
376 | sizeof(struct bucket), | 375 | sizeof(struct bucket), |
377 | htab->map.numa_node); | 376 | htab->map.numa_node); |
378 | if (!htab->buckets) | 377 | if (!htab->buckets) |
379 | goto free_htab; | 378 | goto free_charge; |
380 | 379 | ||
381 | if (htab->map.map_flags & BPF_F_ZERO_SEED) | 380 | if (htab->map.map_flags & BPF_F_ZERO_SEED) |
382 | htab->hashrnd = 0; | 381 | htab->hashrnd = 0; |
@@ -409,6 +408,8 @@ free_prealloc: | |||
409 | prealloc_destroy(htab); | 408 | prealloc_destroy(htab); |
410 | free_buckets: | 409 | free_buckets: |
411 | bpf_map_area_free(htab->buckets); | 410 | bpf_map_area_free(htab->buckets); |
411 | free_charge: | ||
412 | bpf_map_charge_finish(&htab->map.memory); | ||
412 | free_htab: | 413 | free_htab: |
413 | kfree(htab); | 414 | kfree(htab); |
414 | return ERR_PTR(err); | 415 | return ERR_PTR(err); |