All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] samples/bpf: fix possible hang in xdpsock with multiple threads
@ 2020-12-10 15:36 Magnus Karlsson
  2020-12-10 16:03 ` Daniel Borkmann
  0 siblings, 1 reply; 3+ messages in thread
From: Magnus Karlsson @ 2020-12-10 15:36 UTC (permalink / raw)
  To: magnus.karlsson, bjorn.topel, ast, daniel, netdev
  Cc: bpf, jonathan.lemon, maciej.fijalkowski, maciejromanfijalkowski

From: Magnus Karlsson <magnus.karlsson@intel.com>

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, exit the loop.

Fixes: cd9e72b6f210 ("samples/bpf: xdpsock: Add option to specify batch size")
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
---
 samples/bpf/xdpsock_user.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c
index 568f9815bb1b..813f7eaabf82 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)
+			break;
 	}
 
 	for (i = 0; i < batch_size; i++) {

base-commit: 08c6a2f620e427e879d6ec9329143d6fcd810cd8
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] samples/bpf: fix possible hang in xdpsock with multiple threads
  2020-12-10 15:36 [PATCH bpf-next] samples/bpf: fix possible hang in xdpsock with multiple threads Magnus Karlsson
@ 2020-12-10 16:03 ` Daniel Borkmann
  2020-12-10 16:25   ` Magnus Karlsson
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Borkmann @ 2020-12-10 16:03 UTC (permalink / raw)
  To: Magnus Karlsson, magnus.karlsson, bjorn.topel, ast, netdev
  Cc: bpf, jonathan.lemon, maciej.fijalkowski, maciejromanfijalkowski

On 12/10/20 4:36 PM, Magnus Karlsson wrote:
> From: Magnus Karlsson <magnus.karlsson@intel.com>
> 
> 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, exit the loop.
> 
> Fixes: cd9e72b6f210 ("samples/bpf: xdpsock: Add option to specify batch size")
> Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>

With the patch applied, I'm getting a new warning:

   CC  /home/darkstar/trees/bpf-next/samples/bpf/xdpsock_user.o
/home/darkstar/trees/bpf-next/samples/bpf/xdpsock_user.c: In function ‘main’:
/home/darkstar/trees/bpf-next/samples/bpf/xdpsock_user.c:1272:6: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  1272 |  u32 idx;
       |      ^~~

Previously compiling w/o issues:

  [...]
   CC  /home/darkstar/trees/bpf-next/samples/bpf/xdpsock_ctrl_proc.o
   CC  /home/darkstar/trees/bpf-next/samples/bpf/xdpsock_user.o
   CC  /home/darkstar/trees/bpf-next/samples/bpf/xsk_fwd.o
   LD  /home/darkstar/trees/bpf-next/samples/bpf/fds_example
  [...]

For testing, I used:

   gcc --version
   gcc (GCC) 9.0.1 20190312 (Red Hat 9.0.1-0.10)

Ptal, thx!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] samples/bpf: fix possible hang in xdpsock with multiple threads
  2020-12-10 16:03 ` Daniel Borkmann
@ 2020-12-10 16:25   ` Magnus Karlsson
  0 siblings, 0 replies; 3+ messages in thread
From: Magnus Karlsson @ 2020-12-10 16:25 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: Karlsson, Magnus, Björn Töpel, Alexei Starovoitov,
	Network Development, bpf, Jonathan Lemon, Fijalkowski, Maciej,
	Maciej Fijalkowski

On Thu, Dec 10, 2020 at 5:03 PM Daniel Borkmann <daniel@iogearbox.net> wrote:
>
> On 12/10/20 4:36 PM, Magnus Karlsson wrote:
> > From: Magnus Karlsson <magnus.karlsson@intel.com>
> >
> > 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, exit the loop.
> >
> > Fixes: cd9e72b6f210 ("samples/bpf: xdpsock: Add option to specify batch size")
> > Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
>
> With the patch applied, I'm getting a new warning:
>
>    CC  /home/darkstar/trees/bpf-next/samples/bpf/xdpsock_user.o
> /home/darkstar/trees/bpf-next/samples/bpf/xdpsock_user.c: In function ‘main’:
> /home/darkstar/trees/bpf-next/samples/bpf/xdpsock_user.c:1272:6: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>   1272 |  u32 idx;
>        |      ^~~

Sorry, I get it too. It was just masked with the other warnings I get
these days when compiling the bpf samples. Regardless, it is the
compiler trying to tell me I have done something stupid :-(. It should
really be a return instead of a break, sigh. Will send a v2.

> Previously compiling w/o issues:
>
>   [...]
>    CC  /home/darkstar/trees/bpf-next/samples/bpf/xdpsock_ctrl_proc.o
>    CC  /home/darkstar/trees/bpf-next/samples/bpf/xdpsock_user.o
>    CC  /home/darkstar/trees/bpf-next/samples/bpf/xsk_fwd.o
>    LD  /home/darkstar/trees/bpf-next/samples/bpf/fds_example
>   [...]
>
> For testing, I used:
>
>    gcc --version
>    gcc (GCC) 9.0.1 20190312 (Red Hat 9.0.1-0.10)
>
> Ptal, thx!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-10 16:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-10 15:36 [PATCH bpf-next] samples/bpf: fix possible hang in xdpsock with multiple threads Magnus Karlsson
2020-12-10 16:03 ` Daniel Borkmann
2020-12-10 16:25   ` Magnus Karlsson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.