From: Magnus Karlsson Date: Thu, 10 Dec 2020 16:34:07 +0000 (+0100) Subject: samples/bpf: Fix possible hang in xdpsock with multiple threads X-Git-Tag: v5.11-rc1~169^2~26^2~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=092fde0f863b72b67c4d6dc03844f5658fc00a35;p=thirdparty%2Flinux.git samples/bpf: Fix possible hang in xdpsock with multiple threads Fix a possible hang in xdpsock that can occur when using multiple threads. In this case, one or more of the threads might get stuck in the while-loop in tx_only after the user has signaled the main thread to stop execution. In this case, no more Tx packets will be sent, so a thread might get stuck in the aforementioned while-loop. Fix this by introducing a test inside the while-loop to check if the benchmark has been terminated. If so, return from the function. Fixes: cd9e72b6f210 ("samples/bpf: xdpsock: Add option to specify batch size") Signed-off-by: Magnus Karlsson Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20201210163407.22066-1-magnus.karlsson@gmail.com --- diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c index 568f9815bb1bd..db0cb73513a58 100644 --- a/samples/bpf/xdpsock_user.c +++ b/samples/bpf/xdpsock_user.c @@ -1275,6 +1275,8 @@ static void tx_only(struct xsk_socket_info *xsk, u32 *frame_nb, int batch_size) while (xsk_ring_prod__reserve(&xsk->tx, batch_size, &idx) < batch_size) { complete_tx_only(xsk, batch_size); + if (benchmark_done) + return; } for (i = 0; i < batch_size; i++) {