summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/core/bpf_sk_storage.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c
index cc9597a87770..9a8aaf8e235d 100644
--- a/net/core/bpf_sk_storage.c
+++ b/net/core/bpf_sk_storage.c
@@ -626,7 +626,9 @@ static struct bpf_map *bpf_sk_storage_map_alloc(union bpf_attr *attr)
626 struct bpf_sk_storage_map *smap; 626 struct bpf_sk_storage_map *smap;
627 unsigned int i; 627 unsigned int i;
628 u32 nbuckets; 628 u32 nbuckets;
629 u32 pages;
629 u64 cost; 630 u64 cost;
631 int ret;
630 632
631 smap = kzalloc(sizeof(*smap), GFP_USER | __GFP_NOWARN); 633 smap = kzalloc(sizeof(*smap), GFP_USER | __GFP_NOWARN);
632 if (!smap) 634 if (!smap)
@@ -635,13 +637,19 @@ static struct bpf_map *bpf_sk_storage_map_alloc(union bpf_attr *attr)
635 637
636 smap->bucket_log = ilog2(roundup_pow_of_two(num_possible_cpus())); 638 smap->bucket_log = ilog2(roundup_pow_of_two(num_possible_cpus()));
637 nbuckets = 1U << smap->bucket_log; 639 nbuckets = 1U << smap->bucket_log;
640 cost = sizeof(*smap->buckets) * nbuckets + sizeof(*smap);
641 pages = round_up(cost, PAGE_SIZE) >> PAGE_SHIFT;
642
643 ret = bpf_map_precharge_memlock(pages);
644 if (ret < 0)
645 return ERR_PTR(ret);
646
638 smap->buckets = kvcalloc(sizeof(*smap->buckets), nbuckets, 647 smap->buckets = kvcalloc(sizeof(*smap->buckets), nbuckets,
639 GFP_USER | __GFP_NOWARN); 648 GFP_USER | __GFP_NOWARN);
640 if (!smap->buckets) { 649 if (!smap->buckets) {
641 kfree(smap); 650 kfree(smap);
642 return ERR_PTR(-ENOMEM); 651 return ERR_PTR(-ENOMEM);
643 } 652 }
644 cost = sizeof(*smap->buckets) * nbuckets + sizeof(*smap);
645 653
646 for (i = 0; i < nbuckets; i++) { 654 for (i = 0; i < nbuckets; i++) {
647 INIT_HLIST_HEAD(&smap->buckets[i].list); 655 INIT_HLIST_HEAD(&smap->buckets[i].list);
@@ -651,7 +659,7 @@ static struct bpf_map *bpf_sk_storage_map_alloc(union bpf_attr *attr)
651 smap->elem_size = sizeof(struct bpf_sk_storage_elem) + attr->value_size; 659 smap->elem_size = sizeof(struct bpf_sk_storage_elem) + attr->value_size;
652 smap->cache_idx = (unsigned int)atomic_inc_return(&cache_idx) % 660 smap->cache_idx = (unsigned int)atomic_inc_return(&cache_idx) %
653 BPF_SK_STORAGE_CACHE_SIZE; 661 BPF_SK_STORAGE_CACHE_SIZE;
654 smap->map.pages = round_up(cost, PAGE_SIZE) >> PAGE_SHIFT; 662 smap->map.pages = pages;
655 663
656 return &smap->map; 664 return &smap->map;
657} 665}