Re: [PATCH bpf-next v2 1/8] selftests/bpf: Add unshare_netns helper

2024-05-29 Thread Martin KaFai Lau
On 5/15/24 6:13 PM, Geliang Tang wrote: From: Geliang Tang Many BPF selftests create new test network namespaces by using CLONE_NEWNET flag to unshare the network namespace, so that the calling process is moved into a new network namespace which is not shared with any previously existing

Re: [PATCH bpf-next v5 6/7] selftests/bpf: Use connect_to_fd_opts in do_test in bpf_tcp_ca

2024-05-28 Thread Martin KaFai Lau
On 5/25/24 5:08 AM, Geliang Tang wrote: From: Geliang Tang This patch uses connect_to_fd_opts() instead of using connect_fd_to_fd() and settcpca() in do_test() in prog_tests/bpf_tcp_ca.c to accept a struct network_helper_opts argument. Then define a dctcp dedicated post_socket_cb callback

Re: [PATCH bpf-next v4 0/6] use network helpers, part 5

2024-05-24 Thread Martin KaFai Lau
On 5/23/24 8:21 PM, Geliang Tang wrote: From: Geliang Tang This patchset uses post_socket_cb and post_connect_cb callbacks of struct network_helper_opts to refactor do_test() in bpf_tcp_ca.c to move dctcp test dedicated code out of do_test() into test_dctcp(). Overall looks good. It needs

Re: [PATCH bpf-next v4 4/6] selftests/bpf: Use start_server_str in bpf_tcp_ca

2024-05-24 Thread Martin KaFai Lau
On 5/23/24 8:21 PM, Geliang Tang wrote: From: Geliang Tang This patch uses new helper start_server_str() in do_test() in bpf_tcp_ca.c to accept a struct network_helper_opts argument instead of using start_server() and settcpca(). Then change the type of the first paramenter I think it missed

Re: [PATCH bpf-next v4 3/6] selftests/bpf: Use post_socket_cb in connect_to_fd_opts

2024-05-24 Thread Martin KaFai Lau
On 5/23/24 8:21 PM, Geliang Tang wrote: +static int cc_cb(int fd, void *opts) +{ + struct cb_opts *cb_opts = (struct cb_opts *)opts; + + return setsockopt(fd, SOL_TCP, TCP_CONGESTION, cb_opts->cc, + strlen(cb_opts->cc) + 1); Since this cc_cb is in the test

Re: [PATCH bpf-next v3 2/8] selftests/bpf: Drop type parameter of start_server_addr

2024-05-23 Thread Martin KaFai Lau
On 5/22/24 2:23 AM, Geliang Tang wrote: diff --git a/tools/testing/selftests/bpf/prog_tests/sk_assign.c b/tools/testing/selftests/bpf/prog_tests/sk_assign.c index 0b9bd1d6f7cc..517d1186e386 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_assign.c +++

Re: [PATCH bpf-next v2 2/4] selftests/bpf: Use start_server_addr in bpf_tcp_ca

2024-05-21 Thread Martin KaFai Lau
On 5/14/24 9:20 PM, Geliang Tang wrote: From: Geliang Tang This patch uses start_server_addr() in do_test() in prog_tests/bpf_tcp_ca.c to accept a struct network_helper_opts argument instead of using start_server() and settcpca(). Then change the type of the first paramenter of do_test() into

Re: [PATCH bpf-next v2 1/4] selftests/bpf: Use post_socket_cb in connect_to_fd_opts

2024-05-21 Thread Martin KaFai Lau
On 5/14/24 9:20 PM, Geliang Tang wrote: From: Geliang Tang Since the post_socket_cb() callback is added in struct network_helper_opts, it's make sense to use it not only in __start_server(), but also in connect_to_fd_opts(). Then it can be used to set TCP_CONGESTION sockopt. Add a

Re: [PATCH bpf-next 2/6] selftests/bpf: Use start_server_addr in sockopt_inherit

2024-05-09 Thread Martin KaFai Lau
On 5/5/24 4:35 AM, Geliang Tang wrote: From: Geliang Tang Include network_helpers.h in prog_tests/sockopt_inherit.c, use public helper start_server_addr() instead of the local defined function start_server(). This can avoid duplicate code. Add a helper custom_cb() to set SOL_CUSTOM sockopt

Re: [PATCH bpf-next 1/6] selftests/bpf: Add post_socket_cb for network_helper_opts

2024-05-09 Thread Martin KaFai Lau
On 5/5/24 4:35 AM, Geliang Tang wrote: From: Geliang Tang __start_server() sets SO_REUSPORT through setsockopt() when the parameter 'reuseport' is set. This patch makes it more flexible by adding a function pointer post_socket_cb, together with 'struct post_socket_opts cb_opts' for future

Re: [PATCH bpf-next 4/6] selftests/bpf: Add setsockopt for network_helper_opts

2024-04-30 Thread Martin KaFai Lau
On 4/24/24 8:23 PM, Geliang Tang wrote: +static int setsockopt_reuseport(int fd, const void *optval, socklen_t optlen) +{ + return setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, optval, optlen); } [ ... ] void free_fds(int *fds, unsigned int nr_close_fds) diff --git

Re: [PATCH v2 bpf-next 4/6] selftests/bpf: Add IPv4 and IPv6 sockaddr test cases

2024-04-29 Thread Martin KaFai Lau
On 4/28/24 10:47 AM, Jordan Rife wrote: Also, all this setup (and test) has to be done in a new netns. Anything blocking the kfunc in patch 2 using the current task netns instead of the init_net? Add nodad to the "ip -6 addr add...". just in case it may add unnecessary delay. This

Re: [PATCH v2 bpf-next 4/6] selftests/bpf: Add IPv4 and IPv6 sockaddr test cases

2024-04-22 Thread Martin KaFai Lau
On 4/18/24 9:37 AM, Jordan Rife wrote: The test_sock_addr.{c,sh} can be retired as long as all its tests are migrated to sock_addr.c test_sock_addr.c has a few more test dimensions than prog_tests/sock_addr.c currently does, so it covers a few more scenarios. struct sock_addr_test {

Re: [PATCH v2 bpf-next 4/6] selftests/bpf: Add IPv4 and IPv6 sockaddr test cases

2024-04-17 Thread Martin KaFai Lau
On 4/17/24 10:08 AM, Jordan Rife wrote: Can the test_sock_addr.{c,sh} be retired after this patch? I know it's not used in the BPF CI tests, but is it still used in any other contexts? If anyone depends on the test_sock_addr binary, it will have to start using "./test_progs -t sock_addr".

Re: [PATCH bpf-next v4 09/14] selftests/bpf: Use log_err in network_helpers

2024-04-17 Thread Martin KaFai Lau
On 4/16/24 3:13 AM, Geliang Tang wrote: From: Geliang Tang The helpers ASSERT_OK/GE/OK_PTR should avoid using in public functions. This patch uses log_err() to replace them in network_helpers.c, then uses ASSERT_OK_PTR() to check the return values of all open_netns(). Signed-off-by: Geliang

Re: [PATCH bpf-next v4 06/14] selftests/bpf: Use connect_to_addr in sk_assign

2024-04-17 Thread Martin KaFai Lau
On 4/16/24 3:13 AM, Geliang Tang wrote: From: Geliang Tang This patch uses public helper connect_to_addr() exported in network_helpers.h instead of the local defined function connect_to_server() in prog_tests/sk_assign.c. This can avoid duplicate code. The code that sets SO_SNDTIMEO timeout

Re: [PATCH bpf-next v4 02/14] selftests/bpf: Add start_server_addr* helpers

2024-04-17 Thread Martin KaFai Lau
On 4/16/24 3:13 AM, Geliang Tang wrote: From: Geliang Tang In order to pair up with connect_to_addr(), this patch adds a new helper start_server_addr(), and another one start_server_addr_opts(), which is a wrapper of __start_server(), only added a network_helper_opts arg at the end. They all

Re: [PATCH v2 bpf-next 4/6] selftests/bpf: Add IPv4 and IPv6 sockaddr test cases

2024-04-16 Thread Martin KaFai Lau
On 4/12/24 9:52 AM, Jordan Rife wrote: This patch lays the groundwork for testing IPv4 and IPv6 sockaddr hooks and their interaction with both socket syscalls and kernel functions (e.g. kernel_connect, kernel_bind, etc.) and moves the test cases from the old-style bpf/test_sock_addr.c self test

Re: [PATCH v2 bpf-next 2/6] selftests/bpf: Implement socket kfuncs for bpf_testmod

2024-04-16 Thread Martin KaFai Lau
On 4/12/24 9:52 AM, Jordan Rife wrote: This patch adds a set of kfuncs to bpf_testmod that can be used to manipulate a socket from kernel space. Signed-off-by: Jordan Rife --- .../selftests/bpf/bpf_testmod/bpf_testmod.c | 139 ++ .../bpf/bpf_testmod/bpf_testmod_kfunc.h

Re: [PATCH v2 bpf-next 4/6] selftests/bpf: Add IPv4 and IPv6 sockaddr test cases

2024-04-16 Thread Martin KaFai Lau
On 4/12/24 9:52 AM, Jordan Rife wrote: This patch lays the groundwork for testing IPv4 and IPv6 sockaddr hooks and their interaction with both socket syscalls and kernel functions (e.g. kernel_connect, kernel_bind, etc.) and moves the test cases from the old-style bpf/test_sock_addr.c self test

Re: [PATCH bpf-next v2 11/14] selftests/bpf: Use start_server_setsockopt in sockopt_inherit

2024-04-11 Thread Martin KaFai Lau
On 4/10/24 6:03 PM, Geliang Tang wrote: From: Geliang Tang Include network_helpers.h in prog_tests/sockopt_inherit.c, use public helpers make_sockaddr() and start_server_setsockopt() instead of the local defined function start_server(). This can avoid duplicate code. Add a helper

Re: [PATCH bpf-next v2 01/14] selftests/bpf: Add start_server_addr helper

2024-04-11 Thread Martin KaFai Lau
On 4/10/24 6:03 PM, Geliang Tang wrote: From: Geliang Tang In order to pair up with connect_to addr(), this patch adds a new helper start_server_addr(), which is a wrapper of __start_server(), and accepts an argument 'addr' of 'struct sockaddr' type instead of a string type argument like

Re: [PATCH bpf-next v5 2/2] selftests/bpf: Export send_recv_data helper

2024-04-11 Thread Martin KaFai Lau
On 4/10/24 10:43 PM, Geliang Tang wrote: +static void *send_recv_server(void *arg) +{ + struct send_recv_arg *a = (struct send_recv_arg *)arg; + ssize_t nr_sent = 0, bytes = 0; + char batch[1500]; + int err = 0, fd; + + fd = accept(a->fd, NULL, NULL); + while

Re: [PATCH bpf-next v4 3/3] selftests/bpf: Support nonblock for send_recv_data

2024-04-10 Thread Martin KaFai Lau
On 4/9/24 11:13 PM, Geliang Tang wrote: From: Geliang Tang Some tests, such as the MPTCP bpf tests, require send_recv_data helper to run in nonblock mode. This patch adds nonblock support for send_recv_data(). Check if it is currently in nonblock mode, and if so, ignore EWOULDBLOCK to

Re: [PATCH bpf-next v4 2/3] selftests/bpf: Export send_recv_data helper

2024-04-10 Thread Martin KaFai Lau
On 4/9/24 11:13 PM, Geliang Tang wrote: +int send_recv_data(int lfd, int fd, uint32_t total_bytes) +{ + ssize_t nr_recv = 0, bytes = 0; + struct send_recv_arg arg = { + .fd = lfd, + .bytes = total_bytes, + .stop = 0, + }; +

Re: [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net

2024-04-09 Thread Martin KaFai Lau
are needed. Acked-by: Martin KaFai Lau

Re: [PATCH bpf-next v2 2/2] selftests/bpf: Export send_recv_data helper

2024-04-08 Thread Martin KaFai Lau
On 4/8/24 8:51 PM, Geliang Tang wrote: +static void *send_recv_server(void *arg) +{ + struct send_recv_arg *a = (struct send_recv_arg *)arg; + ssize_t nr_sent = 0, bytes = 0; + char batch[1500]; + int err = 0, fd; + + fd = accept(a->fd, NULL, NULL); + while

Re: [PATCH v1 bpf-next 5/8] selftests/bpf: Factor out load_path and defines from test_sock_addr

2024-04-02 Thread Martin KaFai Lau
On 3/29/24 12:18 PM, Jordan Rife wrote: diff --git a/tools/testing/selftests/bpf/sock_addr_helpers.c b/tools/testing/selftests/bpf/sock_addr_helpers.c new file mode 100644 index 0..ff2eb09870f16 --- /dev/null +++ b/tools/testing/selftests/bpf/sock_addr_helpers.c @@ -0,0 +1,46 @@ +//

Re: [PATCH v1 bpf-next 4/8] selftests/bpf: Add recv_msg_from_client to network helpers

2024-04-02 Thread Martin KaFai Lau
On 3/29/24 12:18 PM, Jordan Rife wrote: +int recvmsg_from_client(int sockfd, struct sockaddr_storage *src_addr) +{ + struct timeval tv; + struct msghdr hdr; + struct iovec iov; + char data[64]; + fd_set rfds; + + FD_ZERO(); + FD_SET(sockfd, ); + +

Re: [PATCH v1 bpf-next 1/8] selftests/bpf: Introduce sock_addr_testmod

2024-04-02 Thread Martin KaFai Lau
On 3/29/24 12:18 PM, Jordan Rife wrote: +static int do_sock_op(int op, struct sockaddr *addr, int addrlen) This function can be made as a new kfunc in bpf_testmod.c. The sock_create_kern() could be moved to here also. Take a look at the register_btf_kfunc_id_set() usage in bpf_testmod.c and

Re: [PATCH] tools/testing/selftests/bpf/test_tc_tunnel.sh: Prevent client connect before server bind

2024-03-13 Thread Martin KaFai Lau
On 3/10/24 1:45 AM, Alessandro Carminati wrote: Hi Martin, Thanks for the review. Il giorno ven 8 mar 2024 alle ore 02:03 Martin KaFai Lau ha scritto: On 2/29/24 6:00 AM, Alessandro Carminati (Red Hat) wrote: In some systems, the netcat server can incur in delay to start listening. When

Re: [PATCH] tools/testing/selftests/bpf/test_tc_tunnel.sh: Prevent client connect before server bind

2024-03-07 Thread Martin KaFai Lau
On 2/29/24 6:00 AM, Alessandro Carminati (Red Hat) wrote: In some systems, the netcat server can incur in delay to start listening. When this happens, the test can randomly fail in various points. This is an example error message: # ip gre none gso # encap 192.168.1.1 to 192.168.1.2,

Re: [PATCH RFC bpf-next v2 02/10] bpf/helpers: introduce sleepable timers

2024-02-15 Thread Martin KaFai Lau
On 2/14/24 9:18 AM, Benjamin Tissoires wrote: +static void bpf_timer_work_cb(struct work_struct *work) +{ + struct bpf_hrtimer *t = container_of(work, struct bpf_hrtimer, work); + struct bpf_map *map = t->map; + void *value = t->value; + bpf_callback_t callback_fn; +

Re: [PATCH] bpf: Separate bpf_local_storage_lookup() fast and slow paths

2024-02-06 Thread Martin KaFai Lau
On 2/6/24 9:04 AM, Marco Elver wrote: On Mon, Feb 05, 2024 at 03:24PM -0800, Martin KaFai Lau wrote: [...] Or can you suggest different functions to hook to for the recursion test? I don't prefer to add another tracepoint for the selftest. Ok - I also checked, even though it should

Re: [PATCH] bpf: Separate bpf_local_storage_lookup() fast and slow paths

2024-02-05 Thread Martin KaFai Lau
On 2/5/24 7:00 AM, Marco Elver wrote: On Wed, 31 Jan 2024 at 20:52, Martin KaFai Lau wrote: [...] | num_maps: 1000 | local_storage cache sequential get: | | | hits throughput: 0.357 ± 0.005 M ops/s | 0.325 ± 0.005 M ops/s

Re: [PATCH] selftests/bpf: Use ARRAY_SIZE for array length

2024-02-02 Thread Martin KaFai Lau
On 2/2/24 1:06 AM, Jiapeng Chong wrote: Use of macro ARRAY_SIZE to calculate array size minimizes the redundant code and improves code reusability. ./tools/testing/selftests/bpf/progs/syscall.c:122:26-27: WARNING: Use ARRAY_SIZE. Reported-by: Abaci Robot Closes:

Re: [PATCH] bpf: Separate bpf_local_storage_lookup() fast and slow paths

2024-01-31 Thread Martin KaFai Lau
On 1/31/24 6:18 AM, Marco Elver wrote: To allow the compiler to inline the bpf_local_storage_lookup() fast- path, factor it out by making bpf_local_storage_lookup() a static inline function and move the slow-path to bpf_local_storage_lookup_slowpath(). Base on results from

Re: [PATCH bpf-next] bpf: Allow setting SO_TIMESTAMPING* with bpf_setsockopt()

2024-01-17 Thread Martin KaFai Lau
On 1/17/24 7:55 AM, Willem de Bruijn wrote: Martin KaFai Lau wrote: On 1/16/24 7:17 AM, Willem de Bruijn wrote: Jörn-Thorben Hinz wrote: A BPF application, e.g., a TCP congestion control, might benefit from or even require precise (=hardware) packet timestamps. These timestamps are already

Re: [PATCH bpf-next] bpf: Allow setting SO_TIMESTAMPING* with bpf_setsockopt()

2024-01-16 Thread Martin KaFai Lau
On 1/16/24 7:17 AM, Willem de Bruijn wrote: Jörn-Thorben Hinz wrote: A BPF application, e.g., a TCP congestion control, might benefit from or even require precise (=hardware) packet timestamps. These timestamps are already available through __sk_buff.hwtstamp and bpf_sock_ops.skb_hwtstamp, but

Re: [PATCH bpf-next 0/2] bpf: add csum/ip_summed fields to __sk_buff

2024-01-02 Thread Martin KaFai Lau
On 1/2/24 10:11 AM, Stanislav Fomichev wrote: On 12/29, Menglong Dong wrote: For now, we have to call some helpers when we need to update the csum, such as bpf_l4_csum_replace, bpf_l3_csum_replace, etc. These helpers are not inlined, which causes poor performance. In fact, we can define our

Re: [PATCH bpf-next v5 5/9] bpf: selftests: Add verifier tests for CO-RE bitfield writes

2023-12-13 Thread Martin KaFai Lau
On 12/11/23 12:20 PM, Daniel Xu wrote: Add some tests that exercise BPF_CORE_WRITE_BITFIELD() macro. Since some non-trivial bit fiddling is going on, make sure various edge cases (such as adjacent bitfields and bitfields at the edge of structs) are exercised. Hi DanielXu, I have pushed the

Re: [PATCH v7 11/11] selftests/bpf/sockopt: Add io_uring support

2023-10-19 Thread Martin KaFai Lau
g two tests. This is going to help to exercise the io_uring subsystem: * getsockopt: read ctx->optlen * getsockopt: support smaller ctx->optlen Acked-by: Martin KaFai Lau

Re: [PATCH bpf-next v2 2/2] selftests/bpf: Add pairs_redir_to_connected helper

2023-10-05 Thread Martin KaFai Lau
On 10/5/23 12:21 AM, Geliang Tang wrote: --- a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c @@ -1336,32 +1336,22 @@ static void test_redir(struct test_sockmap_listen *skel, struct bpf_map *map, } } -static

Re: [PATCH v6 8/8] selftests/bpf/sockopt: Add io_uring support

2023-09-13 Thread Martin KaFai Lau
On 9/13/23 8:27 AM, Breno Leitao wrote: Expand the BPF sockopt test to use also check for io_uring {g,s}etsockopt commands operations. Create infrastructure to run io_uring tests using the mini_liburing helpers, so, the {g,s}etsockopt operation could either be called from system calls, or, via