Skip to content

Commit ce606bb

Browse files
LorenzoBianconiNobody
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]>
1 parent b40dea9 commit ce606bb

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
@@ -493,7 +493,7 @@ static int veth_xdp_xmit(struct net_device *dev, int n,
493493
struct xdp_frame *frame = frames[i];
494494
void *ptr = veth_xdp_to_ptr(frame);
495495

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

857-
stats->xdp_bytes += frame->len;
857+
stats->xdp_bytes += xdp_get_frame_len(frame);
858858
frame = veth_xdp_rcv_one(rq, frame, bq, stats);
859859
if (frame) {
860860
/* 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)