selftests/bpf: networking test cleanups and build fix
Subsystems (3)
cover selftests/bpf: networking test cleanups and build fix
This series refactors several networking-related BPF selftests and fixes a toolchain propagation issue in runqslower.
The first four patches simplify networking selftests by removing custom IPv4/IPv6 address wrappers, migrating to sockaddr_storage, dropping duplicated TCP helpers, and replacing open-coded congestion-control string checks with bpf_strncmp(). These changes reduce duplication and improve consistency without altering test behavior.
The final patch fixes a build issue where the runqslower sub-make does not inherit the LLVM toolchain selected for the main selftests build. By forwarding CLANG and LLVM_STRIP, the intended toolchain will be used for the nested build.
Hoyeon Lee (5):
selftests/bpf: use sockaddr_storage instead of addr_port in
cls_redirect test
selftests/bpf: use sockaddr_storage instead of sa46 in
select_reuseport test
selftests/bpf: move common TCP helpers into bpf_tracing_net.h selftests/bpf: replace TCP CC string comparisons with bpf_strncmp selftests/bpf: propagate LLVM toolchain to runqslower build
tools/testing/selftests/bpf/Makefile | 1 + .../selftests/bpf/prog_tests/cls_redirect.c | 95 ++++++------------- .../bpf/prog_tests/select_reuseport.c | 67 ++++++------- .../selftests/bpf/progs/bpf_cc_cubic.c | 9 -- tools/testing/selftests/bpf/progs/bpf_cubic.c | 7 -- tools/testing/selftests/bpf/progs/bpf_dctcp.c | 6 -- .../selftests/bpf/progs/bpf_iter_setsockopt.c | 17 +--- .../selftests/bpf/progs/bpf_tracing_net.h | 11 +++ .../selftests/bpf/progs/connect4_prog.c | 21 ++-- .../bpf/progs/tcp_ca_write_sk_pacing.c | 2 - tools/testing/selftests/lib.mk | 1 + 11 files changed, 87 insertions(+), 150 deletions(-)
Signature · 1 line
2.51.1
PATCH 1/5 selftests/bpf: use sockaddr_storage instead of addr_port in cls_redirect test
The cls_redirect test uses a custom addr_port structure to represent IPv4/IPv6 addresses and ports. This custom wrapper requires extra conversion logic and specific helpers such as fill_addr_port(), which are no longer necessary when using standard socket address structures.
This commit replaces addr_port with the standard sockaddr_storage so that test handles address families and ports using the native socket types. This removes the custom helper, eliminates redundant casts, and simplifies tuple handling without functional changes.
--- .../selftests/bpf/prog_tests/cls_redirect.c | 95 ++++++------------- 1 file changed, 30 insertions(+), 65 deletions(-)
tools/testing/selftests/bpf/prog_tests/cls_redirect.c +30 -65
@@ -22,79 +22,42 @@static int duration =0 ; -struct addr_port { -in_port_t port; -union { -struct in_addr in_addr; -struct in6_addr in6_addr; - }; -}; -struct tuple {int family; -struct addr_port src; -struct addr_port dst; +struct sockaddr_storage src; +struct sockaddr_storage dst; }; -static bool fill_addr_port (const struct sockaddr *sa,struct addr_port *ap) -{ -const struct sockaddr_in6 *in6; -const struct sockaddr_in *in; - -switch (sa->sa_family) { -case AF_INET : - in = (const struct sockaddr_in *)sa; - ap->in_addr = in->sin_addr; - ap->port = in->sin_port; -return true; - -case AF_INET6 : - in6 = (const struct sockaddr_in6 *)sa; - ap->in6_addr = in6->sin6_addr; - ap->port = in6->sin6_port; -return true; - -default : -return false; - } -} -static bool set_up_conn (const struct sockaddr *addr,socklen_t len,int type, +static bool set_up_conn (const struct sockaddr_storage *addr,socklen_t len,int type,int *server,int *conn,struct tuple *tuple) {struct sockaddr_storage ss;socklen_t slen =sizeof (ss); -struct sockaddr *sa = (struct sockaddr *)&ss; - *server =start_server_addr (type, (struct sockaddr_storage *)addr, len,NULL ); + *server =start_server_addr (type, addr, len,NULL );if (*server <0 )return false; -if (CHECK_FAIL (getsockname (*server, sa, &slen))) +if (CHECK_FAIL (getsockname (*server, (struct sockaddr *)&ss, &slen))) goto close_server; - *conn =connect_to_addr (type, (struct sockaddr_storage *)sa, slen,NULL ); + *conn =connect_to_addr (type, &ss, slen,NULL );if (*conn <0 ) goto close_server;/* We want to simulate packets arriving at conn, so we have to * swap src and dst. */ - slen =sizeof (ss); -if (CHECK_FAIL (getsockname (*conn, sa, &slen))) + slen =sizeof (tuple->dst); +if (CHECK_FAIL (getsockname (*conn, (struct sockaddr *)&tuple->dst, &slen))) goto close_conn; -if (CHECK_FAIL (!fill_addr_port (sa, &tuple->dst))) + slen =sizeof (tuple->src); +if (CHECK_FAIL (getpeername (*conn, (struct sockaddr *)&tuple->src, &slen))) goto close_conn; - slen =sizeof (ss); -if (CHECK_FAIL (getpeername (*conn, sa, &slen))) - goto close_conn; - -if (CHECK_FAIL (!fill_addr_port (sa, &tuple->src))) - goto close_conn; - - tuple->family = ss.ss_family; + tuple->family = tuple->dst.ss_family;return true; close_conn:
@@ -110,17 +73,16 @@ static socklen_t prepare_addr(struct sockaddr_storage *addr, int family) {struct sockaddr_in *addr4;struct sockaddr_in6 *addr6; +memset (addr,0 ,sizeof (*addr));switch (family) {case AF_INET : addr4 = (struct sockaddr_in *)addr; -memset (addr4,0 ,sizeof (*addr4)); addr4->sin_family = family; addr4->sin_addr.s_addr =htonl (INADDR_LOOPBACK );return sizeof (*addr4);case AF_INET6 : addr6 = (struct sockaddr_in6 *)addr; -memset (addr6,0 ,sizeof (*addr6)); addr6->sin6_family = family; addr6->sin6_addr = in6addr_loopback;return sizeof (*addr6);
@@ -244,7 +206,11 @@ static void encap_init(encap_headers_t *encap, uint8_t hop_count, uint8_t proto)static size_t build_input (const struct test_cfg *test,void *const buf,const struct tuple *tuple) { -in_port_t sport = tuple->src.port; +struct sockaddr_in6 *src_in6 = (struct sockaddr_in6 *)&tuple->src; +struct sockaddr_in6 *dst_in6 = (struct sockaddr_in6 *)&tuple->dst; +struct sockaddr_in *src_in = (struct sockaddr_in *)&tuple->src; +struct sockaddr_in *dst_in = (struct sockaddr_in *)&tuple->dst; +in_port_t sport, dport;encap_headers_t encap;struct iphdr ip;struct ipv6hdr ipv6;
@@ -254,6 +220,9 @@ static size_t build_input(const struct test_cfg *test, void *const buf,uint8_t *p = buf;int proto; + sport = (tuple->family ==AF_INET ) ? src_in->sin_port : src_in6->sin6_port; + dport = (tuple->family ==AF_INET ) ? dst_in->sin_port : dst_in6->sin6_port; + proto =IPPROTO_IPIP ;if (tuple->family ==AF_INET6 ) proto =IPPROTO_IPV6 ;
@@ -277,8 +246,8 @@ static size_t build_input(const struct test_cfg *test, void *const buf, .version = 4, .ttl = IPDEFTTL, .protocol = proto, - .saddr = tuple->src.in_addr.s_addr, - .daddr = tuple->dst.in_addr.s_addr, + .saddr = src_in->sin_addr.s_addr, + .daddr = dst_in->sin_addr.s_addr, }; p =mempcpy (p, &ip,sizeof (ip));break ;
@@ -287,8 +256,8 @@ static size_t build_input(const struct test_cfg *test, void *const buf, .version = 6, .hop_limit = IPDEFTTL, .nexthdr = proto, - .saddr = tuple->src.in6_addr, - .daddr = tuple->dst.in6_addr, + .saddr = src_in6->sin6_addr, + .daddr = dst_in6->sin6_addr, }; p =mempcpy (p, &ipv6,sizeof (ipv6));break ;
@@ -303,18 +272,16 @@ static size_t build_input(const struct test_cfg *test, void *const buf,case TCP : tcp = (struct tcphdr ){ .source = sport, - .dest = tuple->dst.port, + .dest = dport, + .syn = (test->flags ==SYN ), + .ack = (test->flags ==ACK ), }; -if (test->flags ==SYN ) - tcp.syn = true; -if (test->flags ==ACK ) - tcp.ack = true; p =mempcpy (p, &tcp,sizeof (tcp));break ;case UDP : udp = (struct udphdr ){ .source = sport, - .dest = tuple->dst.port, + .dest = dport, }; p =mempcpy (p, &udp,sizeof (udp));break ;
@@ -339,25 +306,23 @@ static void test_cls_redirect_common(struct bpf_program *prog)LIBBPF_OPTS (bpf_test_run_opts, tattr);int families[] = {AF_INET ,AF_INET6 };struct sockaddr_storage ss; -struct sockaddr *addr;socklen_t slen;int i, j, err, prog_fd;int servers[__NR_KIND][ARRAY_SIZE (families)] = {};int conns[__NR_KIND][ARRAY_SIZE (families)] = {};struct tuple tuples[__NR_KIND][ARRAY_SIZE (families)]; - addr = (struct sockaddr *)&ss;for (i =0 ; i <ARRAY_SIZE (families); i++) { slen =prepare_addr (&ss, families[i]);if (CHECK_FAIL (!slen)) goto cleanup; -if (CHECK_FAIL (!set_up_conn (addr, slen,SOCK_DGRAM , +if (CHECK_FAIL (!set_up_conn (&ss, slen,SOCK_DGRAM , &servers[UDP ][i], &conns[UDP ][i], &tuples[UDP ][i]))) goto cleanup; -if (CHECK_FAIL (!set_up_conn (addr, slen,SOCK_STREAM , +if (CHECK_FAIL (!set_up_conn (&ss, slen,SOCK_STREAM , &servers[TCP ][i], &conns[TCP ][i], &tuples[TCP ][i]))) goto cleanup;
Signature · 1 line
2.51.1
Martin KaFai Lau
reviewerRe: [bpf-next v1 1/5] selftests/bpf: use sockaddr_storage instead of addr_port in cls_redirect test
Quoted 2 lines · Hoyeon Lee
struct tuple {
int family;The "family" is not needed either. Just use the ss_family from src or dst. The 'struct tuple' can be removed also?
I'm on the fence about whether this "struct sockaddr_storage" change is worth the code churn. Are patch 1 and 2 the only tests that need this change?
Patch 3 and 4 make sense. Patch 3 and 4 are applied.
Please post patch 5 as a separate patch on its own.
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/cls_redirect.c +2
-2-struct addr_port src; -struct addr_port dst; +struct sockaddr_storage src; +struct sockaddr_storage dst; };
Re: [bpf-next v1 1/5] selftests/bpf: use sockaddr_storage instead of addr_port in cls_redirect test
Quoted 6 lines · Martin KaFai Lau
Quoted 2 lines · Hoyeon Lee
struct tuple { int family;
Quoted 7 lines
The "family" is not needed either. Just use the
ss_familyfrom src or dst. The 'struct tuple' can be removed also?I'm on the fence about whether this "struct
sockaddr_storage" change is worth the code churn. Are patch 1 and 2 the only tests that need this change?
Thanks for the feedback.
Yes, patches 1 and 2 are the only tests that use a custom address/port representation. These are the last remaining cases, and no further changes are needed elsewhere. The code churn is fully contained within these two patches.
For the “family” field, agreed. ss_family is sufficient, and the tuple wrapper can be removed. If you're okay with that direction, I can drop the family field and resend patches 1 and 2 with that cleanup applied.
Quoted 4 lines
Patch 3 and 4 make sense. Patch 3 and 4 are applied.
Please post patch 5 as a separate patch on its own.
Thanks for applying patches 3 and 4. I will send patch 5 separately as requested.
Thanks again for your time.
Quoted 6 lines
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/cls_redirect.c +2
-2-struct addr_port src; -struct addr_port dst; +struct sockaddr_storage src; +struct sockaddr_storage dst; };
Martin KaFai Lau
reviewerRe: [bpf-next v1 1/5] selftests/bpf: use sockaddr_storage instead of addr_port in cls_redirect test
Quoted 3 lines · Hoyeon Lee
For the “family” field, agreed.
ss_familyis sufficient, and the tuple wrapper can be removed. If you're okay with that direction, I can drop the family field and resend patches 1 and 2 with that cleanup applied.
Please re-spin patch 1 and 2 with the 'struct tuple' cleanup. The patch's title should have "PATCH bpf-next v???". Take a look at other patches posted in the mailing list.
PATCH 2/5 selftests/bpf: use sockaddr_storage instead of sa46 in select_reuseport test
In reply to Hoyeon LeeThe select_reuseport selftest uses a custom sa46 union to represent IPv4 and IPv6 addresses. This custom wrapper requires extra manual handling for address family and field extraction.
Replace sa46 with sockaddr_storage and update the helper functions to operate on native socket structures. This simplifies the code and removes unnecessary custom address-handling logic. No functional changes intended.
--- .../bpf/prog_tests/select_reuseport.c | 67 ++++++++++--------- 1 file changed, 34 insertions(+), 33 deletions(-)
tools/testing/selftests/bpf/prog_tests/select_reuseport.c +34 -33
@@ -41,11 +41,7 @@ static struct bpf_object *obj;static __u32 index_zero;static int epfd; -static union sa46 { -struct sockaddr_in6 v6; -struct sockaddr_in v4; -sa_family_t family; -} srv_sa; +static struct sockaddr_storage srv_sa; #define RET_IF(condition, tag, format...) ({ \ if (CHECK_FAIL(condition)) { \
@@ -135,24 +131,24 @@ static int prepare_bpf_obj(void)return 0 ; } -static void sa46_init_loopback (union sa46 *sa,sa_family_t family) +static void ss_init_loopback (struct sockaddr_storage *sa,sa_family_t family) {memset (sa,0 ,sizeof (*sa)); - sa->family = family; -if (sa->family ==AF_INET6 ) - sa->v6.sin6_addr = in6addr_loopback; + sa->ss_family = family; +if (sa->ss_family ==AF_INET6 ) + ((struct sockaddr_in6 *)sa)->sin6_addr = in6addr_loopback;else - sa->v4.sin_addr.s_addr =htonl (INADDR_LOOPBACK ); + ((struct sockaddr_in *)sa)->sin_addr.s_addr =htonl (INADDR_LOOPBACK ); } -static void sa46_init_inany (union sa46 *sa,sa_family_t family) +static void ss_init_inany (struct sockaddr_storage *sa,sa_family_t family) {memset (sa,0 ,sizeof (*sa)); - sa->family = family; -if (sa->family ==AF_INET6 ) - sa->v6.sin6_addr = in6addr_any; + sa->ss_family = family; +if (sa->ss_family ==AF_INET6 ) + ((struct sockaddr_in6 *)sa)->sin6_addr = in6addr_any;else - sa->v4.sin_addr.s_addr =INADDR_ANY ; + ((struct sockaddr_in *)sa)->sin_addr.s_addr =INADDR_ANY ; }static int read_int_sysctl (const char *sysctl)
@@ -228,7 +224,7 @@ static void check_data(int type, sa_family_t family, const struct cmd *cmd, int cli_fd) {struct data_check expected = {}, result; -union sa46 cli_sa; +struct sockaddr_storage cli_sa;socklen_t addrlen;int err;
@@ -251,26 +247,32 @@ static void check_data(int type, sa_family_t family, const struct cmd *cmd, }if (family ==AF_INET6 ) { +struct sockaddr_in6 *srv_v6 = (struct sockaddr_in6 *)&srv_sa; +struct sockaddr_in6 *cli_v6 = (struct sockaddr_in6 *)&cli_sa; + expected.eth_protocol =htons (ETH_P_IPV6 ); - expected.bind_inany = !srv_sa.v6.sin6_addr.s6_addr32[3 ] && - !srv_sa.v6.sin6_addr.s6_addr32[2 ] && - !srv_sa.v6.sin6_addr.s6_addr32[1 ] && - !srv_sa.v6.sin6_addr.s6_addr32[0 ]; + expected.bind_inany = !srv_v6->sin6_addr.s6_addr32[3 ] && + !srv_v6->sin6_addr.s6_addr32[2 ] && + !srv_v6->sin6_addr.s6_addr32[1 ] && + !srv_v6->sin6_addr.s6_addr32[0 ]; -memcpy (&expected.skb_addrs[0 ], cli_sa.v6.sin6_addr.s6_addr32, -sizeof (cli_sa.v6.sin6_addr)); +memcpy (&expected.skb_addrs[0 ], cli_v6->sin6_addr.s6_addr32, +sizeof (cli_v6->sin6_addr));memcpy (&expected.skb_addrs[4 ], &in6addr_loopback,sizeof (in6addr_loopback)); - expected.skb_ports[0 ] = cli_sa.v6.sin6_port; - expected.skb_ports[1 ] = srv_sa.v6.sin6_port; + expected.skb_ports[0 ] = cli_v6->sin6_port; + expected.skb_ports[1 ] = srv_v6->sin6_port; }else { +struct sockaddr_in *srv_v4 = (struct sockaddr_in *)&srv_sa; +struct sockaddr_in *cli_v4 = (struct sockaddr_in *)&cli_sa; + expected.eth_protocol =htons (ETH_P_IP ); - expected.bind_inany = !srv_sa.v4.sin_addr.s_addr; + expected.bind_inany = !srv_v4->sin_addr.s_addr; - expected.skb_addrs[0 ] = cli_sa.v4.sin_addr.s_addr; + expected.skb_addrs[0 ] = cli_v4->sin_addr.s_addr; expected.skb_addrs[1 ] =htonl (INADDR_LOOPBACK ); - expected.skb_ports[0 ] = cli_sa.v4.sin_port; - expected.skb_ports[1 ] = srv_sa.v4.sin_port; + expected.skb_ports[0 ] = cli_v4->sin_port; + expected.skb_ports[1 ] = srv_v4->sin_port; } if (memcmp(&result, &expected, offsetof(struct data_check,
@@ -364,16 +366,15 @@ static void check_results(void)static int send_data (int type,sa_family_t family,void *data,size_t len,enum result expected) { -union sa46 cli_sa; +struct sockaddr_storage cli_sa;int fd, err; fd =socket (family, type,0 );RET_ERR (fd ==-1 ,"socket()" ,"fd:%d errno:%d\n" , fd, errno); -sa46_init_loopback (&cli_sa, family); +ss_init_loopback (&cli_sa, family); err =bind (fd, (struct sockaddr *)&cli_sa,sizeof (cli_sa));RET_ERR (fd ==-1 ,"bind(cli_sa)" ,"err:%d errno:%d\n" , err, errno); - err =sendto (fd, data, len,MSG_FASTOPEN , (struct sockaddr *)&srv_sa,sizeof (srv_sa)); RET_ERR(err != len && expected >= PASS,
@@ -589,9 +590,9 @@ static void prepare_sk_fds(int type, sa_family_t family, bool inany)socklen_t addrlen;if (inany) -sa46_init_inany (&srv_sa, family); +ss_init_inany (&srv_sa, family);else -sa46_init_loopback (&srv_sa, family); +ss_init_loopback (&srv_sa, family); addrlen =sizeof (srv_sa);/*
Signature · 1 line
2.51.1
PATCH 3/5 selftests/bpf: move common TCP helpers into bpf_tracing_net.h
In reply to Hoyeon LeeSome BPF selftests contain identical copies of the min(), max(), before(), and after() helpers. These repeated snippets are the same across the tests and do not need to be defined separately.
Move these helpers into bpf_tracing_net.h so they can be shared by TCP related BPF programs. This removes repeated code and keeps the helpers in a single place.
--- tools/testing/selftests/bpf/progs/bpf_cc_cubic.c | 9 --------- tools/testing/selftests/bpf/progs/bpf_cubic.c | 7 ------- tools/testing/selftests/bpf/progs/bpf_dctcp.c | 6 ------ tools/testing/selftests/bpf/progs/bpf_tracing_net.h | 11 +++++++++++ .../selftests/bpf/progs/tcp_ca_write_sk_pacing.c | 2 -- 5 files changed, 11 insertions(+), 24 deletions(-)
tools/testing/selftests/bpf/progs/bpf_cc_cubic.c +0 -9
@@ -22,10 +22,6 @@#define TCP_PACING_CA_RATIO (120)#define TCP_REORDERING (12) -#define min (a, b) ((a) < (b) ? (a) : (b)) -#define max (a, b) ((a) > (b) ? (a) : (b)) -#define after (seq2, seq1) before(seq1, seq2) - extern void cubictcp_init(struct sock *sk) __ksym; extern void cubictcp_cwnd_event(struct sock *sk, enum tcp_ca_event event) __ksym; extern __u32 cubictcp_recalc_ssthresh(struct sock *sk) __ksym;
@@ -34,11 +30,6 @@ extern __u32 tcp_reno_undo_cwnd(struct sock *sk) __ksym; extern void cubictcp_acked(struct sock *sk, const struct ack_sample *sample) __ksym; extern void cubictcp_cong_avoid(struct sock *sk, __u32 ack, __u32 acked) __ksym; -static bool before (__u32 seq1,__u32 seq2) -{ -return (__s32)(seq1-seq2) <0 ; -} -static __u64 div64_u64 (__u64 dividend,__u64 divisor) {return dividend / divisor;
tools/testing/selftests/bpf/progs/bpf_cubic.c +0 -7
@@ -20,13 +20,6 @@ char _license[] SEC("license") = "GPL";#define clamp (val, lo, hi) min((typeof(val))max(val, lo), hi) -#define min (a, b) ((a) < (b) ? (a) : (b)) -#define max (a, b) ((a) > (b) ? (a) : (b)) -static bool before (__u32 seq1,__u32 seq2) -{ -return (__s32)(seq1-seq2) <0 ; -} -#define after (seq2, seq1) before(seq1, seq2) extern __u32 tcp_slow_start(struct tcp_sock *tp, __u32 acked) __ksym; extern void tcp_cong_avoid_ai(struct tcp_sock *tp, __u32 w, __u32 acked) __ksym;
tools/testing/selftests/bpf/progs/bpf_dctcp.c +0 -6
@@ -13,16 +13,10 @@#ifndef EBUSY #define EBUSY 16#endif -#define min (a, b) ((a) < (b) ? (a) : (b)) -#define max (a, b) ((a) > (b) ? (a) : (b))#define min_not_zero (x, y) ({ \ typeof(x) __x = (x); \ typeof(y) __y = (y); \ __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) -static bool before (__u32 seq1,__u32 seq2) -{ -return (__s32)(seq1-seq2) <0 ; -} char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/progs/bpf_tracing_net.h +11 -0
@@ -5,6 +5,17 @@#include <vmlinux.h> #include <bpf/bpf_core_read.h> +#define min (a, b) ((a) < (b) ? (a) : (b)) +#define max (a, b) ((a) > (b) ? (a) : (b)) + +static inline bool before (__u32 seq1,__u32 seq2) +{ +return (__s32)(seq1 - seq2) <0 ; +} + +#define after (seq2, seq1) before(seq1, seq2) + +#define AF_INET 2#define AF_INET6 10
tools/testing/selftests/bpf/progs/tcp_ca_write_sk_pacing.c +0 -2
@@ -8,8 +8,6 @@ char _license[] SEC("license") = "GPL";#define USEC_PER_SEC 1000000UL -#define min (a, b) ((a) < (b) ? (a) : (b)) -static unsigned int tcp_left_out (const struct tcp_sock *tp) {return tp->sacked_out + tp->lost_out;
Signature · 1 line
2.51.1
PATCH 4/5 selftests/bpf: replace TCP CC string comparisons with bpf_strncmp
In reply to Hoyeon LeeThe connect4_prog and bpf_iter_setsockopt tests duplicate the same open-coded TCP congestion control string comparison logic. Since bpf_strncmp() provides the same functionality, use it instead to avoid repeated open-coded loops.
This change applies only to functional BPF tests and does not affect the verifier performance benchmarks (veristat.cfg). No functional changes intended.
--- .../selftests/bpf/progs/bpf_iter_setsockopt.c | 17 ++------------- .../selftests/bpf/progs/connect4_prog.c | 21 +++++++------------ 2 files changed, 10 insertions(+), 28 deletions(-)
tools/testing/selftests/bpf/progs/bpf_iter_setsockopt.c +2 -15
@@ -18,23 +18,10 @@unsigned short reuse_listen_hport =0 ;unsigned short listen_hport =0 ; -char cubic_cc[TCP_CA_NAME_MAX ] ="bpf_cubic" ; +const char cubic_cc[] ="bpf_cubic" ;char dctcp_cc[TCP_CA_NAME_MAX ] ="bpf_dctcp" ;bool random_retry = false; -static bool tcp_cc_eq (const char *a,const char *b) -{ -int i; - -for (i =0 ; i <TCP_CA_NAME_MAX ; i++) { -if (a[i] != b[i]) -return false; -if (!a[i]) -break ; - } - -return true; -} SEC("iter/tcp")int change_tcp_cc (struct bpf_iter__tcp *ctx)
@@ -58,7 +45,7 @@ int change_tcp_cc(struct bpf_iter__tcp *ctx) cur_cc, sizeof(cur_cc)))return 0 ; -if (!tcp_cc_eq (cur_cc, cubic_cc)) +if (bpf_strncmp (cur_cc,TCP_CA_NAME_MAX , cubic_cc))return 0 ;if (random_retry &&bpf_get_prandom_u32 () %4 ==1 )
tools/testing/selftests/bpf/progs/connect4_prog.c +8 -13
@@ -34,6 +34,9 @@#define SOL_TCP 6#endif +const char reno[] ="reno" ; +const char cubic[] ="cubic" ; + __attribute__ ((noinline))__weak int do_bind (struct bpf_sock_addr *ctx) {
@@ -50,35 +53,27 @@ int do_bind(struct bpf_sock_addr *ctx) }static __inlineint verify_cc (struct bpf_sock_addr *ctx, -char expected[TCP_CA_NAME_MAX ]) +const char expected[]) {char buf[TCP_CA_NAME_MAX ]; -int i;if (bpf_getsockopt (ctx,SOL_TCP ,TCP_CONGESTION , &buf,sizeof (buf)))return 1 ; -for (i =0 ; i <TCP_CA_NAME_MAX ; i++) { -if (buf[i] != expected[i]) -return 1 ; -if (buf[i] ==0 ) -break ; - } +if (bpf_strncmp (buf,TCP_CA_NAME_MAX , expected)) +return 1 ;return 0 ; }static __inlineint set_cc (struct bpf_sock_addr *ctx) { -char reno[TCP_CA_NAME_MAX ] ="reno" ; -char cubic[TCP_CA_NAME_MAX ] ="cubic" ; - -if (bpf_setsockopt (ctx,SOL_TCP ,TCP_CONGESTION , &reno,sizeof (reno))) +if (bpf_setsockopt (ctx,SOL_TCP ,TCP_CONGESTION , (void *)reno,sizeof (reno)))return 1 ;if (verify_cc (ctx, reno))return 1 ; -if (bpf_setsockopt (ctx,SOL_TCP ,TCP_CONGESTION , &cubic,sizeof (cubic))) +if (bpf_setsockopt (ctx,SOL_TCP ,TCP_CONGESTION , (void *)cubic,sizeof (cubic)))return 1 ;if (verify_cc (ctx, cubic))return 1 ;
Signature · 1 line
2.51.1
PATCH 5/5 selftests/bpf: propagate LLVM toolchain to runqslower build
In reply to Hoyeon LeeThe selftests/bpf invokes a nested make when building runqslower, but LLVM toolchain version (clang/llvm-strip) is not propagated. As a result, runqslower is built with system default clang, not respecting specified LLVM version.
# LLVM=-21 make -C tools/testing/selftests/bpf
...
make feature_display=0 -C /bpf/tools/bpf/runqslower \
OUTPUT=/bpf/tools/testing/selftests/bpf/tools/build/runqslower/ \
BPFOBJ_OUTPUT=/bpf/tools/testing/selftests/bpf/tools/build/libbpf/ \
BPFOBJ=/bpf/tools/testing/selftests/bpf/tools/build/libbpf/libbpf.a \
BPF_INCLUDE=/bpf/tools/testing/selftests/bpf/tools/include \
BPFTOOL_OUTPUT=/bpf/tools/testing/selftests/bpf/tools/build/bpftool/ \
VMLINUX_BTF=/sys/kernel/btf/vmlinux BPF_TARGET_ENDIAN=--target=bpfel \
EXTRA_CFLAGS='-g -O0 ' EXTRA_LDFLAGS=' ' && \
cp /bpf/tools/testing/selftests/bpf/tools/build/runqslower/runqslower \
/bpf/tools/testing/selftests/bpf/runqslower
clang -g -O2 --target=bpfel -I/bpf/tools/testing/selftests/bpf/tools/build/runqslower/ \
-I/bpf/tools/testing/selftests/bpf/tools/include -I/bpf/tools/include/uapi \
-c runqslower.bpf.c -o /bpf/tools/testing/selftests/bpf/tools/build/runqslower/runqslower.bpf.o && \
llvm-strip -g /bpf/tools/testing/selftests/bpf/tools/build/runqslower//runqslower.bpf.o
/bin/sh: 1: clang: not foundExplicitly propagate CLANG and LLVM_STRIP to the runqslower sub-make so that the LLVM toolchain selection from lib.mk is preserved.
--- tools/testing/selftests/bpf/Makefile | 1 + tools/testing/selftests/lib.mk | 1 + 2 files changed, 2 insertions(+)
tools/testing/selftests/bpf/Makefile +1 -0
@@ -306,6 +306,7 @@ endif $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL) $(RUNQSLOWER_OUTPUT) $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/runqslower \ + CLANG=$(CLANG) LLVM_STRIP=$(LLVM_STRIP) \ OUTPUT=$(RUNQSLOWER_OUTPUT) VMLINUX_BTF=$(VMLINUX_BTF) \ BPFTOOL_OUTPUT=$(HOST_BUILD_DIR)/bpftool/ \ BPFOBJ_OUTPUT=$(BUILD_DIR)/libbpf/ \
tools/testing/selftests/lib.mk +1 -0
@@ -8,6 +8,7 @@ LLVM_SUFFIX := $(LLVM) endif CLANG := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) +LLVM_STRIP := $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX) CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu
Signature · 1 line
2.51.1
Yonghong Song
reviewerRe: [bpf-next v1 5/5] selftests/bpf: propagate LLVM toolchain to runqslower build
Quoted 14 lines · Hoyeon Lee
The selftests/bpf invokes a nested make when building runqslower, but LLVM toolchain version (clang/llvm-strip) is not propagated. As a result, runqslower is built with system default clang, not respecting specified LLVM version.
# LLVM=-21 make -C tools/testing/selftests/bpf ... make feature_display=0 -C /bpf/tools/bpf/runqslower \ OUTPUT=/bpf/tools/testing/selftests/bpf/tools/build/runqslower/ \ BPFOBJ_OUTPUT=/bpf/tools/testing/selftests/bpf/tools/build/libbpf/ \ BPFOBJ=/bpf/tools/testing/selftests/bpf/tools/build/libbpf/libbpf.a \ BPF_INCLUDE=/bpf/tools/testing/selftests/bpf/tools/include \ BPFTOOL_OUTPUT=/bpf/tools/testing/selftests/bpf/tools/build/bpftool/ \ VMLINUX_BTF=/sys/kernel/btf/vmlinux BPF_TARGET_ENDIAN=--target=bpfel \
Quoted 8 lines
EXTRA_CFLAGS='-g -O0 ' EXTRA_LDFLAGS=' ' && \
cp /bpf/tools/testing/selftests/bpf/tools/build/runqslower/runqslower \
/bpf/tools/testing/selftests/bpf/runqslower
clang -g -O2 --target=bpfel -I/bpf/tools/testing/selftests/bpf/tools/build/runqslower/ \
-I/bpf/tools/testing/selftests/bpf/tools/include -I/bpf/tools/include/uapi \
-c runqslower.bpf.c -o /bpf/tools/testing/selftests/bpf/tools/build/runqslower/runqslower.bpf.o && \
llvm-strip -g /bpf/tools/testing/selftests/bpf/tools/build/runqslower//runqslower.bpf.o
/bin/sh: 1: clang: not foundI tried with LLVM=-20 make -C tools/testing/selftests/bpf in my system and there is no build error.
Also could you try with command line
make -C tools/testing/selftests/bpf LLVM=1
for clang build kernel or selftests, LLVM=1 is recommended as it encodes a bunch of clang command lines:
CC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX) LD = $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX) AR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX) NM = $(LLVM_PREFIX)llvm-nm$(LLVM_SUFFIX) OBJCOPY = $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX) OBJDUMP = $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX) READELF = $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX) STRIP = $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)
Quoted 34 lines
Explicitly propagate CLANG and
LLVM_STRIPto the runqslower sub-make so that the LLVM toolchain selection from lib.mk is preserved.Signed-off-by Hoyeon Lee <[email protected]>--- tools/testing/selftests/bpf/Makefile | 1 + tools/testing/selftests/lib.mk | 1 + 2 files changed, 2 insertions(+)tools/testing/selftests/bpf/Makefile +1
-0@@ -306,6 +306,7 @@ endif $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL) $(RUNQSLOWER_OUTPUT) $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/runqslower \ + CLANG=$(CLANG) LLVM_STRIP=$(LLVM_STRIP) \ OUTPUT=$(RUNQSLOWER_OUTPUT) VMLINUX_BTF=$(VMLINUX_BTF) \ BPFTOOL_OUTPUT=$(HOST_BUILD_DIR)/bpftool/ \ BPFOBJ_OUTPUT=$(BUILD_DIR)/libbpf/ \tools/testing/selftests/lib.mk +1
-0@@ -8,6 +8,7 @@ LLVM_SUFFIX := $(LLVM) endif CLANG := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) +LLVM_STRIP := $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX) CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu
Re: [bpf-next v1 5/5] selftests/bpf: propagate LLVM toolchain to runqslower build
Quoted 34 lines · Yonghong Song
Quoted 14 lines · Hoyeon Lee
The selftests/bpf invokes a nested make when building runqslower, but LLVM toolchain version (clang/llvm-strip) is not propagated. As a result, runqslower is built with system default clang, not respecting specified LLVM version.
# LLVM=-21 make -C tools/testing/selftests/bpf ... make feature_display=0 -C /bpf/tools/bpf/runqslower \ OUTPUT=/bpf/tools/testing/selftests/bpf/tools/build/runqslower/ \ BPFOBJ_OUTPUT=/bpf/tools/testing/selftests/bpf/tools/build/libbpf/ \ BPFOBJ=/bpf/tools/testing/selftests/bpf/tools/build/libbpf/libbpf.a \ BPF_INCLUDE=/bpf/tools/testing/selftests/bpf/tools/include \ BPFTOOL_OUTPUT=/bpf/tools/testing/selftests/bpf/tools/build/bpftool/ \ VMLINUX_BTF=/sys/kernel/btf/vmlinux BPF_TARGET_ENDIAN=--target=bpfel \Quoted 8 lines
EXTRA_CFLAGS='-g -O0 ' EXTRA_LDFLAGS=' ' && \ cp /bpf/tools/testing/selftests/bpf/tools/build/runqslower/runqslower \ /bpf/tools/testing/selftests/bpf/runqslower clang -g -O2 --target=bpfel -I/bpf/tools/testing/selftests/bpf/tools/build/runqslower/ \ -I/bpf/tools/testing/selftests/bpf/tools/include -I/bpf/tools/include/uapi \ -c runqslower.bpf.c -o /bpf/tools/testing/selftests/bpf/tools/build/runqslower/runqslower.bpf.o && \ llvm-strip -g /bpf/tools/testing/selftests/bpf/tools/build/runqslower//runqslower.bpf.o /bin/sh: 1: clang: not foundI tried with LLVM=-20 make -C
tools/testing/selftests/bpfin my system and there is no build error.Also could you try with command line
make -Ctools/testing/selftests/bpfLLVM=1
for clang build kernel or selftests, LLVM=1 is recommended as it encodes a bunch of clang command lines:
Quoted 10 lines
CC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX) LD = $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX) AR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX) NM = $(LLVM_PREFIX)llvm-nm$(LLVM_SUFFIX) OBJCOPY = $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX) OBJDUMP = $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX) READELF = $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX) STRIP = $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)
Thanks for the review.
Just to clarify, the issue is not the build failure itself. The error "clang: not found" only appeared because I intentionally did not set update-alternatives to avoid falling back to the system default compiler.
The real issue is that the runqslower sub-make invokes "clang" instead of "clang-21" when LLVM=-21 is specified. This shows that the selected LLVM toolchain version is not being propagated into the nested build.
LLVM=1 works well for general builds, but in this case the intention is to verify that a specific LLVM version is consistently applied across all sub-makes. That propagation does not currently happen, and the patch addresses exactly that.
Thanks again for taking a look.
Quoted 37 lines
Quoted 36 lines
Explicitly propagate CLANG and
LLVM_STRIPto the runqslower sub-make so that the LLVM toolchain selection from lib.mk is preserved.Signed-off-by Hoyeon Lee <[email protected]>--- tools/testing/selftests/bpf/Makefile | 1 + tools/testing/selftests/lib.mk | 1 + 2 files changed, 2 insertions(+)tools/testing/selftests/bpf/Makefile +1
-0@@ -306,6 +306,7 @@ endif $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL) $(RUNQSLOWER_OUTPUT) $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/runqslower \ + CLANG=$(CLANG) LLVM_STRIP=$(LLVM_STRIP) \ OUTPUT=$(RUNQSLOWER_OUTPUT) VMLINUX_BTF=$(VMLINUX_BTF) \ BPFTOOL_OUTPUT=$(HOST_BUILD_DIR)/bpftool/ \ BPFOBJ_OUTPUT=$(BUILD_DIR)/libbpf/ \tools/testing/selftests/lib.mk +1
-0@@ -8,6 +8,7 @@ LLVM_SUFFIX := $(LLVM) endif CLANG := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) +LLVM_STRIP := $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX) CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu
Quoted 9 lines · Hoyeon Lee
This series refactors several networking-related BPF selftests and fixes a toolchain propagation issue in runqslower.
The first four patches simplify networking selftests by removing custom IPv4/IPv6 address wrappers, migrating to
sockaddr_storage, dropping duplicated TCP helpers, and replacing open-coded congestion-control string checks withbpf_strncmp(). These changes reduce duplication and improve consistency without altering test behavior.
Patch 1-4 look good to me. All selftests changed also passed on my test VM.
Quoted 32 lines
The final patch fixes a build issue where the runqslower sub-make does not inherit the LLVM toolchain selected for the main selftests build. By forwarding CLANG and
LLVM_STRIP, the intended toolchain will be used for the nested build.Hoyeon Lee (5):
selftests/bpf: usesockaddr_storageinstead ofaddr_portin
cls_redirecttest
selftests/bpf: usesockaddr_storageinstead of sa46 in
select_reuseporttest
selftests/bpf: move common TCP helpers intobpf_tracing_net.hselftests/bpf: replace TCP CC string comparisons withbpf_strncmpselftests/bpf: propagate LLVM toolchain to runqslower buildtools/testing/selftests/bpf/Makefile | 1 + .../selftests/bpf/prog_tests/cls_redirect.c | 95 ++++++------------- .../bpf/prog_tests/select_reuseport.c | 67 ++++++------- .../selftests/bpf/progs/bpf_cc_cubic.c | 9 -- tools/testing/selftests/bpf/progs/bpf_cubic.c | 7 -- tools/testing/selftests/bpf/progs/bpf_dctcp.c | 6 -- .../selftests/bpf/progs/bpf_iter_setsockopt.c | 17 +--- .../selftests/bpf/progs/bpf_tracing_net.h | 11 +++ .../selftests/bpf/progs/connect4_prog.c | 21 ++-- .../bpf/progs/tcp_ca_write_sk_pacing.c | 2 - tools/testing/selftests/lib.mk | 1 + 11 files changed, 87 insertions(+), 150 deletions(-)--
2.51.1
This series was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:
Quoted 10 lines · On Sun, 16 Nov 2025 07:55:35 +0900 you wrote:
This series refactors several networking-related BPF selftests and fixes a toolchain propagation issue in runqslower.
The first four patches simplify networking selftests by removing custom IPv4/IPv6 address wrappers, migrating to
sockaddr_storage, dropping duplicated TCP helpers, and replacing open-coded congestion-control string checks withbpf_strncmp(). These changes reduce duplication and improve consistency without altering test behavior.[...]
Here is the summary with links:
- [bpf-next,v1,1/5] selftests/bpf: use sockaddr_storage instead of addr_port in cls_redirect test (no matching commit)
- [bpf-next,v1,2/5] selftests/bpf: use sockaddr_storage instead of sa46 in select_reuseport test (no matching commit)
- [bpf-next,v1,3/5] selftests/bpf: move common TCP helpers into bpf_tracing_net.h
https://git.kernel.org/bpf/bpf-next/c/f700b37314d9 - [bpf-next,v1,4/5] selftests/bpf: replace TCP CC string comparisons with bpf_strncmp https://git.kernel.org/bpf/bpf-next/c/ec12ab2cda66
- [bpf-next,v1,5/5] selftests/bpf: propagate LLVM toolchain to runqslower build (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html