Skip to content

Commit 5142239

Browse files
LorenzoBianconiborkmann
authored andcommitted
net: veth: Account total xdp_frame len running ndo_xdp_xmit
Even if this is a theoretical issue since it is not possible to perform XDP_REDIRECT on a non-linear xdp_frame, veth driver does not account paged area in ndo_xdp_xmit function pointer. Introduce xdp_get_frame_len utility routine to get the xdp_frame full length and account total frame size running XDP_REDIRECT of a non-linear xdp frame into a veth device. Signed-off-by: Lorenzo Bianconi <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Toke Hoiland-Jorgensen <[email protected]> Acked-by: John Fastabend <[email protected]> Link: https://lore.kernel.org/bpf/54f9fd3bb65d190daf2c0bbae2f852ff16cfbaa0.1646989407.git.lorenzo@kernel.org
1 parent ad13baf commit 5142239

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

drivers/net/veth.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ static int veth_xdp_xmit(struct net_device *dev, int n,
494494
struct xdp_frame *frame = frames[i];
495495
void *ptr = veth_xdp_to_ptr(frame);
496496

497-
if (unlikely(frame->len > max_len ||
497+
if (unlikely(xdp_get_frame_len(frame) > max_len ||
498498
__ptr_ring_produce(&rq->xdp_ring, ptr)))
499499
break;
500500
nxmit++;
@@ -855,7 +855,7 @@ static int veth_xdp_rcv(struct veth_rq *rq, int budget,
855855
/* ndo_xdp_xmit */
856856
struct xdp_frame *frame = veth_ptr_to_xdp(ptr);
857857

858-
stats->xdp_bytes += frame->len;
858+
stats->xdp_bytes += xdp_get_frame_len(frame);
859859
frame = veth_xdp_rcv_one(rq, frame, bq, stats);
860860
if (frame) {
861861
/* XDP_PASS */

include/net/xdp.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,20 @@ static inline void xdp_release_frame(struct xdp_frame *xdpf)
343343
__xdp_release_frame(xdpf->data, mem);
344344
}
345345

346+
static __always_inline unsigned int xdp_get_frame_len(struct xdp_frame *xdpf)
347+
{
348+
struct skb_shared_info *sinfo;
349+
unsigned int len = xdpf->len;
350+
351+
if (likely(!xdp_frame_has_frags(xdpf)))
352+
goto out;
353+
354+
sinfo = xdp_get_shared_info_from_frame(xdpf);
355+
len += sinfo->xdp_frags_size;
356+
out:
357+
return len;
358+
}
359+
346360
int __xdp_rxq_info_reg(struct xdp_rxq_info *xdp_rxq,
347361
struct net_device *dev, u32 queue_index,
348362
unsigned int napi_id, u32 frag_size);

0 commit comments

Comments
 (0)