Skip to content

Commit 0bd939b

Browse files
alobakinborkmann
authored andcommitted
ice: Fix XDP Tx ring overrun
Sometimes, under heavy XDP Tx traffic, e.g. when using XDP traffic generator (%BPF_F_TEST_XDP_LIVE_FRAMES), the machine can catch OOM due to the driver not freeing all of the pages passed to it by .ndo_xdp_xmit(). Turned out that during the development of the tagged commit, the check, which ensures that we have a free descriptor to queue a frame, moved into the branch happening only when a buffer has frags. Otherwise, we only run a cleaning cycle, but don't check anything. ATST, there can be situations when the driver gets new frames to send, but there are no buffers that can be cleaned/completed and the ring has no free slots. It's very rare, but still possible (> 6.5 Mpps per ring). The driver then fills the next buffer/descriptor, effectively overwriting the data, which still needs to be freed. Restore the check after the cleaning routine to make sure there is a slot to queue a new frame. When there are frags, there still will be a separate check that we can place all of them, but if the ring is full, there's no point in wasting any more time. (minor: make `!ready_frames` unlikely since it happens ~1-2 times per billion of frames) Fixes: 3246a10 ("ice: Add support for XDP multi-buffer on Tx side") Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> Link: https://lore.kernel.org/bpf/20230210170618.1973430-3-alexandr.lobakin@intel.com
1 parent bc4db83 commit 0bd939b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

drivers/net/ethernet/intel/ice/ice_txrx_lib.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ static u32 ice_clean_xdp_irq(struct ice_tx_ring *xdp_ring)
260260
ready_frames = idx + cnt - ntc + 1;
261261
}
262262

263-
if (!ready_frames)
263+
if (unlikely(!ready_frames))
264264
return 0;
265265
ret = ready_frames;
266266

@@ -322,17 +322,17 @@ int __ice_xmit_xdp_ring(struct xdp_buff *xdp, struct ice_tx_ring *xdp_ring)
322322
u32 frag = 0;
323323

324324
free_space = ICE_DESC_UNUSED(xdp_ring);
325-
326-
if (ICE_DESC_UNUSED(xdp_ring) < ICE_RING_QUARTER(xdp_ring))
325+
if (free_space < ICE_RING_QUARTER(xdp_ring))
327326
free_space += ice_clean_xdp_irq(xdp_ring);
328327

328+
if (unlikely(!free_space))
329+
goto busy;
330+
329331
if (unlikely(xdp_buff_has_frags(xdp))) {
330332
sinfo = xdp_get_shared_info_from_buff(xdp);
331333
nr_frags = sinfo->nr_frags;
332-
if (free_space < nr_frags + 1) {
333-
xdp_ring->ring_stats->tx_stats.tx_busy++;
334-
return ICE_XDP_CONSUMED;
335-
}
334+
if (free_space < nr_frags + 1)
335+
goto busy;
336336
}
337337

338338
tx_desc = ICE_TX_DESC(xdp_ring, ntu);
@@ -396,6 +396,11 @@ int __ice_xmit_xdp_ring(struct xdp_buff *xdp, struct ice_tx_ring *xdp_ring)
396396
ntu--;
397397
}
398398
return ICE_XDP_CONSUMED;
399+
400+
busy:
401+
xdp_ring->ring_stats->tx_stats.tx_busy++;
402+
403+
return ICE_XDP_CONSUMED;
399404
}
400405

401406
/**

0 commit comments

Comments
 (0)