bpf: offload: allow array map offload
authorJakub Kicinski <jakub.kicinski@netronome.com>
Thu, 18 Jan 2018 03:13:27 +0000 (19:13 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 18 Jan 2018 21:54:25 +0000 (22:54 +0100)
The special handling of different map types is left to the driver.
Allow offload of array maps by simply adding it to accepted types.
For nfp we have to make sure array elements are not deleted.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
drivers/net/ethernet/netronome/nfp/bpf/offload.c
kernel/bpf/offload.c

index c452bf9462e0e04592b8050cc25842b1467128cf..1a357aacc444bc2f5bb0d5095863f44eca0157e1 100644 (file)
@@ -176,6 +176,8 @@ nfp_bpf_map_get_next_key(struct bpf_offloaded_map *offmap,
 static int
 nfp_bpf_map_delete_elem(struct bpf_offloaded_map *offmap, void *key)
 {
+       if (offmap->map.map_type == BPF_MAP_TYPE_ARRAY)
+               return -EINVAL;
        return nfp_bpf_ctrl_del_entry(offmap, key);
 }
 
index 6c0baa1cf8f8b1437e0f0fbdfa2ee7ec60e5fc53..2657976aec2a8aff3873b938d07a23019d8f3ce6 100644 (file)
@@ -299,7 +299,8 @@ struct bpf_map *bpf_map_offload_map_alloc(union bpf_attr *attr)
 
        if (!capable(CAP_SYS_ADMIN))
                return ERR_PTR(-EPERM);
-       if (attr->map_type != BPF_MAP_TYPE_HASH)
+       if (attr->map_type != BPF_MAP_TYPE_ARRAY &&
+           attr->map_type != BPF_MAP_TYPE_HASH)
                return ERR_PTR(-EINVAL);
 
        offmap = kzalloc(sizeof(*offmap), GFP_USER);