nfp: bpf: pass raw data buffer to nfp_bpf_event_output()
authorJakub Kicinski <jakub.kicinski@netronome.com>
Thu, 26 Jul 2018 02:53:32 +0000 (19:53 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 27 Jul 2018 05:14:35 +0000 (07:14 +0200)
In preparation for SKB-less perf event handling make
nfp_bpf_event_output() take buffer address and length,
not SKB as parameters.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Dirk van der Merwe <dirk.vandermerwe@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
drivers/net/ethernet/netronome/nfp/bpf/cmsg.c
drivers/net/ethernet/netronome/nfp/bpf/main.h
drivers/net/ethernet/netronome/nfp/bpf/offload.c

index cb87fccb9f6a2b369e3832bde74a536a65b432e1..0a89b53962aaae86432bf74d236b5023ceae4bb3 100644 (file)
@@ -441,7 +441,10 @@ void nfp_bpf_ctrl_msg_rx(struct nfp_app *app, struct sk_buff *skb)
        }
 
        if (nfp_bpf_cmsg_get_type(skb) == CMSG_TYPE_BPF_EVENT) {
-               nfp_bpf_event_output(bpf, skb);
+               if (!nfp_bpf_event_output(bpf, skb->data, skb->len))
+                       dev_consume_skb_any(skb);
+               else
+                       dev_kfree_skb_any(skb);
                return;
        }
 
index bec935468f90ab1f13da2832ed463d73e4b86884..e25d3c0c7e4306fe0ce9252bd85935e41761b3bb 100644 (file)
@@ -501,7 +501,8 @@ int nfp_bpf_ctrl_lookup_entry(struct bpf_offloaded_map *offmap,
 int nfp_bpf_ctrl_getnext_entry(struct bpf_offloaded_map *offmap,
                               void *key, void *next_key);
 
-int nfp_bpf_event_output(struct nfp_app_bpf *bpf, struct sk_buff *skb);
+int nfp_bpf_event_output(struct nfp_app_bpf *bpf, const void *data,
+                        unsigned int len);
 
 void nfp_bpf_ctrl_msg_rx(struct nfp_app *app, struct sk_buff *skb);
 #endif
index 49b03f7dbf4625de7cd1d03eb0d5bc448da9de14..293dda84818f29c8e92fd029bf54599d3336b10f 100644 (file)
@@ -453,23 +453,24 @@ nfp_bpf_perf_event_copy(void *dst, const void *src,
        return 0;
 }
 
-int nfp_bpf_event_output(struct nfp_app_bpf *bpf, struct sk_buff *skb)
+int nfp_bpf_event_output(struct nfp_app_bpf *bpf, const void *data,
+                        unsigned int len)
 {
-       struct cmsg_bpf_event *cbe = (void *)skb->data;
+       struct cmsg_bpf_event *cbe = (void *)data;
        u32 pkt_size, data_size;
        struct bpf_map *map;
 
-       if (skb->len < sizeof(struct cmsg_bpf_event))
-               goto err_drop;
+       if (len < sizeof(struct cmsg_bpf_event))
+               return -EINVAL;
 
        pkt_size = be32_to_cpu(cbe->pkt_size);
        data_size = be32_to_cpu(cbe->data_size);
        map = (void *)(unsigned long)be64_to_cpu(cbe->map_ptr);
 
-       if (skb->len < sizeof(struct cmsg_bpf_event) + pkt_size + data_size)
-               goto err_drop;
+       if (len < sizeof(struct cmsg_bpf_event) + pkt_size + data_size)
+               return -EINVAL;
        if (cbe->hdr.ver != CMSG_MAP_ABI_VERSION)
-               goto err_drop;
+               return -EINVAL;
 
        rcu_read_lock();
        if (!rhashtable_lookup_fast(&bpf->maps_neutral, &map,
@@ -477,7 +478,7 @@ int nfp_bpf_event_output(struct nfp_app_bpf *bpf, struct sk_buff *skb)
                rcu_read_unlock();
                pr_warn("perf event: dest map pointer %px not recognized, dropping event\n",
                        map);
-               goto err_drop;
+               return -EINVAL;
        }
 
        bpf_event_output(map, be32_to_cpu(cbe->cpu_id),
@@ -485,11 +486,7 @@ int nfp_bpf_event_output(struct nfp_app_bpf *bpf, struct sk_buff *skb)
                         cbe->data, pkt_size, nfp_bpf_perf_event_copy);
        rcu_read_unlock();
 
-       dev_consume_skb_any(skb);
        return 0;
-err_drop:
-       dev_kfree_skb_any(skb);
-       return -EINVAL;
 }
 
 static int