From b3f51f00246b54f7c795acd2f4835ada546b4c35 Mon Sep 17 00:00:00 2001 From: Tim Zimmermann Date: Wed, 10 Jan 2024 06:24:54 +0100 Subject: [PATCH] kernel: bpf: devmap: Create __dev_map_alloc_node * Like in https://github.com/torvalds/linux/commit/fca16e51078e8e5c0af839426b3d2dcd2bede135 Change-Id: I95915b56f381c8f5851b6e7827eed6064aefe586 Signed-off-by: Ruchit --- kernel/bpf/devmap.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c index 1a846a636ae1..2f36791368e4 100755 --- a/kernel/bpf/devmap.c +++ b/kernel/bpf/devmap.c @@ -317,6 +317,30 @@ static int dev_map_delete_elem(struct bpf_map *map, void *key) return 0; } +static struct bpf_dtab_netdev *__dev_map_alloc_node(struct net *net, + struct bpf_dtab *dtab, + u32 ifindex, + unsigned int idx) +{ + gfp_t gfp = GFP_ATOMIC | __GFP_NOWARN; + struct bpf_dtab_netdev *dev; + + dev = kmalloc_node(sizeof(*dev), gfp, dtab->map.numa_node); + if (!dev) + return ERR_PTR(-ENOMEM); + + dev->dev = dev_get_by_index(net, ifindex); + if (!dev->dev) { + kfree(dev); + return ERR_PTR(-EINVAL); + } + + dev->bit = idx; + dev->dtab = dtab; + + return dev; +} + static int dev_map_update_elem(struct bpf_map *map, void *key, void *value, u64 map_flags) { @@ -336,19 +360,9 @@ static int dev_map_update_elem(struct bpf_map *map, void *key, void *value, if (!ifindex) { dev = NULL; } else { - dev = kmalloc_node(sizeof(*dev), GFP_ATOMIC | __GFP_NOWARN, - map->numa_node); - if (!dev) - return -ENOMEM; - - dev->dev = dev_get_by_index(net, ifindex); - if (!dev->dev) { - kfree(dev); - return -EINVAL; - } - - dev->bit = i; - dev->dtab = dtab; + dev = __dev_map_alloc_node(net, dtab, ifindex, i); + if (IS_ERR(dev)) + return PTR_ERR(dev); } /* Use call_rcu() here to ensure rcu critical sections have completed