Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add BPF_F_PERMANENT flag for sockmap skmsg redirect #599

Open
wants to merge 7 commits into
base: bpf-next_base
Choose a base branch
from

Conversation

danielocfb
Copy link
Owner

Pull request for series with
subject: add BPF_F_PERMANENT flag for sockmap skmsg redirect
version: 6
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=793216

@danielocfb
Copy link
Owner Author

Upstream branch: 99c9991
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=793216
version: 6

@danielocfb
Copy link
Owner Author

Upstream branch: 99c9991
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=793216
version: 6

@danielocfb
Copy link
Owner Author

Upstream branch: 99c9991
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=793216
version: 6

@danielocfb danielocfb force-pushed the series/779022=>bpf-next branch from 46480af to e5c5221 Compare October 16, 2023 18:27
@danielocfb danielocfb force-pushed the bpf-next_base branch 3 times, most recently from 5d0a354 to 6c38f9e Compare October 17, 2023 17:38
@danielocfb
Copy link
Owner Author

Upstream branch: 44cb03f
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=793216
version: 6

Pull request is NOT updated. Failed to apply https://patchwork.kernel.org/project/netdevbpf/list/?series=793216
error message:

Cmd('git') failed due to: exit code(128)
  cmdline: git am --3way
  stdout: 'Applying: bpf, sockmap: add BPF_F_PERMANENT flag for skmsg redirect
Applying: selftests/bpf: Add txmsg permanently test for sockmap
Applying: selftests/bpf: Add txmsg redir permanently test for sockmap
Applying: selftests/bpf: add skmsg verdict tests
Using index info to reconstruct a base tree...
M	tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
Falling back to patching base and 3-way merge...
Auto-merging tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
CONFLICT (content): Merge conflict in tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
Patch failed at 0004 selftests/bpf: add skmsg verdict tests
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".'
  stderr: 'error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch'

conflict:

diff --cc tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
index f75f84d,e9ec68..0000000
--- a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
+++ b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
@@@ -475,53 -476,70 +476,117 @@@ out
  		test_sockmap_drop_prog__destroy(drop);
  }
  
++<<<<<<< HEAD
 +static void test_sockmap_skb_verdict_peek(void)
 +{
 +	int err, map, verdict, s, c1, p1, zero = 0, sent, recvd, avail;
 +	struct test_sockmap_pass_prog *pass;
 +	char snd[256] = "0123456789";
 +	char rcv[256] = "0";
 +
 +	pass = test_sockmap_pass_prog__open_and_load();
 +	if (!ASSERT_OK_PTR(pass, "open_and_load"))
 +		return;
 +	verdict = bpf_program__fd(pass->progs.prog_skb_verdict);
 +	map = bpf_map__fd(pass->maps.sock_map_rx);
 +
 +	err = bpf_prog_attach(verdict, map, BPF_SK_SKB_STREAM_VERDICT, 0);
++=======
+ static void test_sockmap_msg_verdict(bool is_ingress)
+ {
+ 	int key, sent, recvd, recv_fd;
+ 	int err, map, verdict, s, c0, c1, p0, p1;
+ 	struct test_sockmap_msg_verdict *skel;
+ 	char buf[256] = "0123456789";
+ 
+ 	skel = test_sockmap_msg_verdict__open_and_load();
+ 	if (!ASSERT_OK_PTR(skel, "open_and_load"))
+ 		return;
+ 	verdict = bpf_program__fd(skel->progs.prog_skmsg_verdict);
+ 	map = bpf_map__fd(skel->maps.sock_map);
+ 
+ 
+ 	err = bpf_prog_attach(verdict, map, BPF_SK_MSG_VERDICT, 0);
++>>>>>>> selftests/bpf: add skmsg verdict tests
  	if (!ASSERT_OK(err, "bpf_prog_attach"))
  		goto out;
  
  	s = socket_loopback(AF_INET, SOCK_STREAM);
  	if (!ASSERT_GT(s, -1, "socket_loopback(s)"))
  		goto out;
++<<<<<<< HEAD
 +
 +	err = create_pair(s, AF_INET, SOCK_STREAM, &c1, &p1);
 +	if (!ASSERT_OK(err, "create_pairs(s)"))
 +		goto out;
 +
 +	err = bpf_map_update_elem(map, &zero, &c1, BPF_NOEXIST);
 +	if (!ASSERT_OK(err, "bpf_map_update_elem(c1)"))
 +		goto out_close;
 +
 +	sent = xsend(p1, snd, sizeof(snd), 0);
 +	ASSERT_EQ(sent, sizeof(snd), "xsend(p1)");
 +	recvd = recv(c1, rcv, sizeof(rcv), MSG_PEEK);
 +	ASSERT_EQ(recvd, sizeof(rcv), "recv(c1)");
 +	err = ioctl(c1, FIONREAD, &avail);
 +	ASSERT_OK(err, "ioctl(FIONREAD) error");
 +	ASSERT_EQ(avail, sizeof(snd), "after peek ioctl(FIONREAD)");
 +	recvd = recv(c1, rcv, sizeof(rcv), 0);
 +	ASSERT_EQ(recvd, sizeof(rcv), "recv(p0)");
 +	err = ioctl(c1, FIONREAD, &avail);
 +	ASSERT_OK(err, "ioctl(FIONREAD) error");
 +	ASSERT_EQ(avail, 0, "after read ioctl(FIONREAD)");
 +
 +out_close:
 +	close(c1);
 +	close(p1);
 +out:
 +	test_sockmap_pass_prog__destroy(pass);
++=======
+ 	err = create_socket_pairs(s, AF_INET, SOCK_STREAM, &c0, &c1, &p0, &p1);
+ 	if (!ASSERT_OK(err, "create_socket_pairs(s)"))
+ 		goto out;
+ 
+ 	key = 0;
+ 	err = bpf_map_update_elem(map, &key, &p1, BPF_NOEXIST);
+ 	if (!ASSERT_OK(err, "bpf_map_update_elem(key0)"))
+ 		goto out_close;
+ 	key = 1;
+ 	err = bpf_map_update_elem(map, &key, &c1, BPF_NOEXIST);
+ 	if (!ASSERT_OK(err, "bpf_map_update_elem(key1)"))
+ 		goto out_close;
+ 	key = 2;
+ 	err = bpf_map_update_elem(map, &key, &p0, BPF_NOEXIST);
+ 	if (!ASSERT_OK(err, "bpf_map_update_elem(key2)"))
+ 		goto out_close;
+ 	key = 3;
+ 	err = bpf_map_update_elem(map, &key, &c0, BPF_NOEXIST);
+ 	if (!ASSERT_OK(err, "bpf_map_update_elem(key3)"))
+ 		goto out_close;
+ 
+ 	if (is_ingress) {
+ 		recv_fd = c1;
+ 		skel->bss->skmsg_redir_flags = BPF_F_INGRESS;
+ 		skel->bss->skmsg_redir_key = 1;
+ 	} else {
+ 		recv_fd = c0;
+ 		skel->bss->skmsg_redir_flags = 0;
+ 		skel->bss->skmsg_redir_key = 2;
+ 	}
+ 
+ 	sent = xsend(p1, &buf, sizeof(buf), 0);
+ 	ASSERT_EQ(sent, sizeof(buf), "xsend(p1)");
+ 	recvd = recv_timeout(recv_fd, &buf, sizeof(buf), SOCK_NONBLOCK, IO_TIMEOUT_SEC);
+ 	ASSERT_EQ(recvd, sizeof(buf), "recv_timeout(recv_fd)");
+ 
+ out_close:
+ 	close(c0);
+ 	close(p0);
+ 	close(c1);
+ 	close(p1);
+ out:
+ 	test_sockmap_msg_verdict__destroy(skel);
++>>>>>>> selftests/bpf: add skmsg verdict tests
  }
  
  void test_sockmap_basic(void)
@@@ -564,6 -582,8 +629,13 @@@
  		test_sockmap_skb_verdict_fionread(true);
  	if (test__start_subtest("sockmap skb_verdict fionread on drop"))
  		test_sockmap_skb_verdict_fionread(false);
++<<<<<<< HEAD
 +	if (test__start_subtest("sockmap skb_verdict msg_f_peek"))
 +		test_sockmap_skb_verdict_peek();
++=======
+ 	if (test__start_subtest("sockmap msg_verdict"))
+ 		test_sockmap_msg_verdict(false);
+ 	if (test__start_subtest("sockmap msg_verdict ingress"))
+ 		test_sockmap_msg_verdict(true);
++>>>>>>> selftests/bpf: add skmsg verdict tests
  }

@danielocfb
Copy link
Owner Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=793216 expired. Closing PR.

@danielocfb
Copy link
Owner Author

Upstream branch: f2fbb90
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=797297
version: 7

@danielocfb
Copy link
Owner Author

Upstream branch: e80742d
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=797297
version: 7

@danielocfb
Copy link
Owner Author

Upstream branch: e80742d
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=797297
version: 7

@danielocfb
Copy link
Owner Author

Upstream branch: e80742d
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=797297
version: 7

@danielocfb
Copy link
Owner Author

Upstream branch: 155addf
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=797297
version: 7

@danielocfb
Copy link
Owner Author

Upstream branch: 689b097
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=797297
version: 7

If the sockmap msg redirection function is used only to forward packets
and no other operation, the execution result of the BPF_SK_MSG_VERDICT
program is the same each time. In this case, the BPF program only needs to
be run once. Add BPF_F_PERMANENT flag to bpf_msg_redirect_map() and
bpf_msg_redirect_hash() to implement this ability.

Then we can enable this function in the bpf program as follows:
bpf_msg_redirect_hash(xx, xx, xx, BPF_F_INGRESS | BPF_F_PERMANENT);

Test results using netperf  TCP_STREAM mode:
for i in 1 64 128 512 1k 2k 32k 64k 100k 500k 1m;then
netperf -T 1,2 -t TCP_STREAM -H 127.0.0.1 -l 20 -- -m $i -s 100m,100m -S 100m,100m
done

before:
3.84 246.52 496.89 1885.03 3415.29 6375.03 40749.09 48764.40 51611.34 55678.26 55992.78
after:
4.43 279.20 555.82 2080.79 3870.70 7105.44 41836.41 49709.75 51861.56 55211.00 54566.85

Signed-off-by: Liu Jian <liujian56@huawei.com>
Tested-by: Jakub Sitnicki <jakub@cloudflare.com>
Add one test for txmsg ingress permanently test for sockmap.

Signed-off-by: Liu Jian <liujian56@huawei.com>
Add one test for txmsg redir permanently test for sockmap.

Signed-off-by: Liu Jian <liujian56@huawei.com>
Add two normal skmsg verdict tests in sockmap_basic.c

Signed-off-by: Liu Jian <liujian56@huawei.com>
Add two tests for BPF_F_PERMANENT flag in sockmap_basic.c.

Signed-off-by: Liu Jian <liujian56@huawei.com>
Add tests for verdict skmsg to itself in sockmap_basic.c

Signed-off-by: Liu Jian <liujian56@huawei.com>
@danielocfb
Copy link
Owner Author

Upstream branch: 9241176
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=797297
version: 7

Add four tests for verdict skmsg to closed socket in sockmap_basic.c.

Signed-off-by: Liu Jian <liujian56@huawei.com>
@danielocfb danielocfb force-pushed the series/779022=>bpf-next branch from 6099857 to e9f6c31 Compare November 10, 2023 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants