Skip to content

Commit d4b8568

Browse files
weqaargregkh
authored andcommitted
samples/bpf: Fix to xdpsock to avoid recycling frames
[ Upstream commit b69e56c ] The txpush program in the xdpsock sample application is supposed to send out all packets in the umem in a round-robin fashion. The problem is that it only cycled through the first BATCH_SIZE worth of packets. Fixed this so that it cycles through all buffers in the umem as intended. Fixes: 248c7f9 ("samples/bpf: convert xdpsock to use libbpf for AF_XDP access") Signed-off-by: Weqaar Janjua <weqaar.a.janjua@intel.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Björn Töpel <bjorn.topel@intel.com> Link: https://lore.kernel.org/bpf/20200828161717.42705-1-weqaar.a.janjua@intel.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent eecfb4f commit d4b8568

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

samples/bpf/xdpsock_user.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ static void rx_drop_all(void)
10041004
}
10051005
}
10061006

1007-
static void tx_only(struct xsk_socket_info *xsk, u32 frame_nb, int batch_size)
1007+
static void tx_only(struct xsk_socket_info *xsk, u32 *frame_nb, int batch_size)
10081008
{
10091009
u32 idx;
10101010
unsigned int i;
@@ -1017,14 +1017,14 @@ static void tx_only(struct xsk_socket_info *xsk, u32 frame_nb, int batch_size)
10171017
for (i = 0; i < batch_size; i++) {
10181018
struct xdp_desc *tx_desc = xsk_ring_prod__tx_desc(&xsk->tx,
10191019
idx + i);
1020-
tx_desc->addr = (frame_nb + i) << XSK_UMEM__DEFAULT_FRAME_SHIFT;
1020+
tx_desc->addr = (*frame_nb + i) << XSK_UMEM__DEFAULT_FRAME_SHIFT;
10211021
tx_desc->len = PKT_SIZE;
10221022
}
10231023

10241024
xsk_ring_prod__submit(&xsk->tx, batch_size);
10251025
xsk->outstanding_tx += batch_size;
1026-
frame_nb += batch_size;
1027-
frame_nb %= NUM_FRAMES;
1026+
*frame_nb += batch_size;
1027+
*frame_nb %= NUM_FRAMES;
10281028
complete_tx_only(xsk, batch_size);
10291029
}
10301030

@@ -1080,7 +1080,7 @@ static void tx_only_all(void)
10801080
}
10811081

10821082
for (i = 0; i < num_socks; i++)
1083-
tx_only(xsks[i], frame_nb[i], batch_size);
1083+
tx_only(xsks[i], &frame_nb[i], batch_size);
10841084

10851085
pkt_cnt += batch_size;
10861086

0 commit comments

Comments
 (0)