9b16fc00b7e55b4d5be32fba3e4d7871b748aa7f
[openwrt/staging/jow.git] /
1 commit 5142239a22219921a7863cf00c9ab853c00689d8
2 Author: Lorenzo Bianconi <lorenzo@kernel.org>
3 Date: Fri Mar 11 10:14:18 2022 +0100
4
5 net: veth: Account total xdp_frame len running ndo_xdp_xmit
6
7 Even if this is a theoretical issue since it is not possible to perform
8 XDP_REDIRECT on a non-linear xdp_frame, veth driver does not account
9 paged area in ndo_xdp_xmit function pointer.
10 Introduce xdp_get_frame_len utility routine to get the xdp_frame full
11 length and account total frame size running XDP_REDIRECT of a
12 non-linear xdp frame into a veth device.
13
14 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
15 Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
16 Acked-by: Toke Hoiland-Jorgensen <toke@redhat.com>
17 Acked-by: John Fastabend <john.fastabend@gmail.com>
18 Link: https://lore.kernel.org/bpf/54f9fd3bb65d190daf2c0bbae2f852ff16cfbaa0.1646989407.git.lorenzo@kernel.org
19
20 --- a/drivers/net/veth.c
21 +++ b/drivers/net/veth.c
22 @@ -501,7 +501,7 @@ static int veth_xdp_xmit(struct net_devi
23 struct xdp_frame *frame = frames[i];
24 void *ptr = veth_xdp_to_ptr(frame);
25
26 - if (unlikely(frame->len > max_len ||
27 + if (unlikely(xdp_get_frame_len(frame) > max_len ||
28 __ptr_ring_produce(&rq->xdp_ring, ptr)))
29 break;
30 nxmit++;
31 @@ -862,7 +862,7 @@ static int veth_xdp_rcv(struct veth_rq *
32 /* ndo_xdp_xmit */
33 struct xdp_frame *frame = veth_ptr_to_xdp(ptr);
34
35 - stats->xdp_bytes += frame->len;
36 + stats->xdp_bytes += xdp_get_frame_len(frame);
37 frame = veth_xdp_rcv_one(rq, frame, bq, stats);
38 if (frame) {
39 /* XDP_PASS */
40 --- a/include/net/xdp.h
41 +++ b/include/net/xdp.h
42 @@ -295,6 +295,20 @@ out:
43 __xdp_release_frame(xdpf->data, mem);
44 }
45
46 +static __always_inline unsigned int xdp_get_frame_len(struct xdp_frame *xdpf)
47 +{
48 + struct skb_shared_info *sinfo;
49 + unsigned int len = xdpf->len;
50 +
51 + if (likely(!xdp_frame_has_frags(xdpf)))
52 + goto out;
53 +
54 + sinfo = xdp_get_shared_info_from_frame(xdpf);
55 + len += sinfo->xdp_frags_size;
56 +out:
57 + return len;
58 +}
59 +
60 int xdp_rxq_info_reg(struct xdp_rxq_info *xdp_rxq,
61 struct net_device *dev, u32 queue_index, unsigned int napi_id);
62 void xdp_rxq_info_unreg(struct xdp_rxq_info *xdp_rxq);