LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: do not invoke the XDP dispatcher for PROG_RUN with single repeat
@ 2021-09-28  9:30 Lorenz Bauer
  2021-09-29 21:17 ` Alexei Starovoitov
  0 siblings, 1 reply; 2+ messages in thread
From: Lorenz Bauer @ 2021-09-28  9:30 UTC (permalink / raw)
  To: bjorn, David S. Miller, Jakub Kicinski, Alexei Starovoitov,
	Daniel Borkmann, Andrii Nakryiko, Jesper Dangaard Brouer,
	John Fastabend
  Cc: kernel-team, Lorenz Bauer, netdev, bpf, linux-kernel

We have a unit test that invokes an XDP program with 1m different
inputs, aka 1m BPF_PROG_RUN syscalls. We run this test concurrently
with slight variations in how we generated the input.

Since commit f23c4b3924d2 ("bpf: Start using the BPF dispatcher in BPF_TEST_RUN")
the unit test has slowed down significantly. Digging deeper reveals that
the concurrent tests are serialised in the kernel on the XDP dispatcher.
This is a global resource that is protected by a mutex, on which we contend.

Fix this by not calling into the XDP dispatcher if we only want to perform
a single run of the BPF program.

See: https://lore.kernel.org/bpf/CACAyw9_y4QumOW35qpgTbLsJ532uGq-kVW-VESJzGyiZkypnvw@mail.gmail.com/

Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
---
 net/bpf/test_run.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index fcb2f493f710..6593a71dba5f 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -803,7 +803,8 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
 	if (ret)
 		goto free_data;
 
-	bpf_prog_change_xdp(NULL, prog);
+	if (repeat > 1)
+		bpf_prog_change_xdp(NULL, prog);
 	ret = bpf_test_run(prog, &xdp, repeat, &retval, &duration, true);
 	/* We convert the xdp_buff back to an xdp_md before checking the return
 	 * code so the reference count of any held netdevice will be decremented
@@ -824,7 +825,8 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
 				     sizeof(struct xdp_md));
 
 out:
-	bpf_prog_change_xdp(prog, NULL);
+	if (repeat > 1)
+		bpf_prog_change_xdp(prog, NULL);
 free_data:
 	kfree(data);
 free_ctx:
-- 
2.30.2


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

* Re: [PATCH bpf-next] bpf: do not invoke the XDP dispatcher for PROG_RUN with single repeat
  2021-09-28  9:30 [PATCH bpf-next] bpf: do not invoke the XDP dispatcher for PROG_RUN with single repeat Lorenz Bauer
@ 2021-09-29 21:17 ` Alexei Starovoitov
  0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2021-09-29 21:17 UTC (permalink / raw)
  To: Lorenz Bauer
  Cc: Björn Töpel, David S. Miller, Jakub Kicinski,
	Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Jesper Dangaard Brouer, John Fastabend, kernel-team,
	Network Development, bpf, LKML

On Tue, Sep 28, 2021 at 2:31 AM Lorenz Bauer <lmb@cloudflare.com> wrote:
>
> We have a unit test that invokes an XDP program with 1m different
> inputs, aka 1m BPF_PROG_RUN syscalls. We run this test concurrently
> with slight variations in how we generated the input.
>
> Since commit f23c4b3924d2 ("bpf: Start using the BPF dispatcher in BPF_TEST_RUN")
> the unit test has slowed down significantly. Digging deeper reveals that
> the concurrent tests are serialised in the kernel on the XDP dispatcher.
> This is a global resource that is protected by a mutex, on which we contend.
>
> Fix this by not calling into the XDP dispatcher if we only want to perform
> a single run of the BPF program.
>
> See: https://lore.kernel.org/bpf/CACAyw9_y4QumOW35qpgTbLsJ532uGq-kVW-VESJzGyiZkypnvw@mail.gmail.com/
>
> Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>

Applied. Thanks

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

end of thread, other threads:[~2021-09-29 21:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-28  9:30 [PATCH bpf-next] bpf: do not invoke the XDP dispatcher for PROG_RUN with single repeat Lorenz Bauer
2021-09-29 21:17 ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).