selftests/bpf: Improve libc portability / musl support (part 1)
Subsystems (3)
cover selftests/bpf: Improve libc portability / musl support (part 1)
Hello all,
This series includes the bulk of libc-related compile fixes accumulated to support systems using musl, with smaller numbers to follow. These patches are simple and straightforward, and the series has been tested with the kernel-patches/bpf CI and locally using mips64el-gcc/musl-libc and QEMU with an OpenWrt rootfs.
The patches address a few general categories of libc portability issues:
- missing, redundant or incorrect include headers
- disabled GNU header extensions (i.e. missing #define _GNU_SOURCE)
- issues with types and casting
Feedback and suggestions for improvement are welcome!
Thanks,
Tony
Tony Ambardar (19):
selftests/bpf: Use pid_t consistently in test_progs.c selftests/bpf: Fix compile error from rlim_t in sk_storage_map.c selftests/bpf: Fix error compiling bpf_iter_setsockopt.c with musl
libc
selftests/bpf: Drop unneeded include in unpriv_helpers.c selftests/bpf: Drop unneeded include in sk_lookup.c selftests/bpf: Drop unneeded include in flow_dissector.c selftests/bpf: Fix missing ARRAY_SIZE() definition in bench.c selftests/bpf: Fix missing UINT_MAX definitions in benchmarks selftests/bpf: Fix missing BUILD_BUG_ON() declaration selftests/bpf: Fix include of <sys/fcntl.h>
selftests/bpf: Fix compiling parse_tcp_hdr_opt.c with musl-libc selftests/bpf: Fix compiling kfree_skb.c with musl-libc selftests/bpf: Fix compiling flow_dissector.c with musl-libc selftests/bpf: Fix compiling tcp_rtt.c with musl-libc selftests/bpf: Fix compiling core_reloc.c with musl-libc selftests/bpf: Fix errors compiling lwt_redirect.c with musl libc selftests/bpf: Fix errors compiling decap_sanity.c with musl libc selftests/bpf: Fix errors compiling crypto_sanity.c with musl libc selftests/bpf: Fix errors compiling cg_storage_multi.h with musl libc
tools/testing/selftests/bpf/bench.c | 1 + tools/testing/selftests/bpf/bench.h | 1 + tools/testing/selftests/bpf/map_tests/sk_storage_map.c | 2 +- tools/testing/selftests/bpf/prog_tests/bpf_iter_setsockopt.c | 2 +- tools/testing/selftests/bpf/prog_tests/core_reloc.c | 1 + tools/testing/selftests/bpf/prog_tests/crypto_sanity.c | 1 - tools/testing/selftests/bpf/prog_tests/decap_sanity.c | 1 - tools/testing/selftests/bpf/prog_tests/flow_dissector.c | 2 +- tools/testing/selftests/bpf/prog_tests/kfree_skb.c | 1 + tools/testing/selftests/bpf/prog_tests/lwt_redirect.c | 1 - tools/testing/selftests/bpf/prog_tests/ns_current_pid_tgid.c | 2 +- tools/testing/selftests/bpf/prog_tests/parse_tcp_hdr_opt.c | 1 + tools/testing/selftests/bpf/prog_tests/sk_lookup.c | 1 - tools/testing/selftests/bpf/prog_tests/tcp_rtt.c | 1 + tools/testing/selftests/bpf/prog_tests/user_ringbuf.c | 1 + tools/testing/selftests/bpf/progs/cg_storage_multi.h | 2 -- tools/testing/selftests/bpf/test_progs.c | 2 +- tools/testing/selftests/bpf/unpriv_helpers.c | 1 - 18 files changed, 12 insertions(+), 12 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/19 selftests/bpf: Use pid_t consistently in test_progs.c
Use pid_t rather than __pid_t when allocating memory for 'worker_pids' in 'struct test_env', as this is its declared type and also avoids compile errors seen building against musl libc on mipsel64:
test_progs.c:1738:49: error: '__pid_t' undeclared (first use in this function); did you mean 'pid_t'?
1738 | env.worker_pids = calloc(sizeof(__pid_t), env.workers);
| ^~~~~~~
| pid_ttest_progs.c:1738:49: note: each undeclared identifier is reported only once for each function it appears in
--- tools/testing/selftests/bpf/test_progs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/test_progs.c +1 -1
@@ -1738,7 +1738,7 @@ int main(int argc, char **argv)/* launch workers if requested */ env.worker_id =-1 ;/* main process */ if (env.workers) { - env.worker_pids =calloc (sizeof (__pid_t), env.workers); + env.worker_pids =calloc (sizeof (pid_t), env.workers); env.worker_socks =calloc (sizeof (int ), env.workers);if (env.debug)fprintf (stdout,"Launching %d workers.\n" , env.workers);
Signature · 1 line
2.34.1
PATCH 2/19 selftests/bpf: Fix compile error from rlim_t in sk_storage_map.c
In reply to Tony AmbardarCast 'rlim_t' argument to match expected type of printf() format and avoid compile errors seen building for mips64el/musl-libc:
In file included from map_tests/sk_storage_map.c:20:
map_tests/sk_storage_map.c: In function 'test_sk_storage_map_stress_free':
map_tests/sk_storage_map.c:414:56: error: format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'rlim_t' {aka 'long long unsigned int'} [-Werror=format=]
414 | CHECK(err, "setrlimit(RLIMIT_NOFILE)", "rlim_new:%lu errno:%d",
| ^~~~~~~~~~~~~~~~~~~~~~~
415 | rlim_new.rlim_cur, errno);
| ~~~~~~~~~~~~~~~~~
| |
| rlim_t {aka long long unsigned int}
./test_maps.h:12:24: note: in definition of macro 'CHECK'
12 | printf(format); \
| ^~~~~~
map_tests/sk_storage_map.c:414:68: note: format string is defined here
414 | CHECK(err, "setrlimit(RLIMIT_NOFILE)", "rlim_new:%lu errno:%d",
| ~~^
| |
| long unsigned int
| %llucc1: all warnings being treated as errors
--- tools/testing/selftests/bpf/map_tests/sk_storage_map.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/map_tests/sk_storage_map.c +1 -1
@@ -412,7 +412,7 @@ static void test_sk_storage_map_stress_free(void) rlim_new.rlim_max = rlim_new.rlim_cur +128 ; err =setrlimit (RLIMIT_NOFILE , &rlim_new);CHECK (err,"setrlimit(RLIMIT_NOFILE)" ,"rlim_new:%lu errno:%d" , - rlim_new.rlim_cur, errno); + (unsigned long ) rlim_new.rlim_cur, errno); } err =do_sk_storage_map_stress_free ();
Signature · 1 line
2.34.1
PATCH 3/19 selftests/bpf: Fix error compiling bpf_iter_setsockopt.c with musl libc
In reply to Tony AmbardarExisting code calls getsockname() with a 'struct sockaddr_in6 *' argument where a 'struct sockaddr *' argument is declared, yielding compile errors when building for mips64el/musl-libc:
bpf_iter_setsockopt.c: In function 'get_local_port':
bpf_iter_setsockopt.c:98:30: error: passing argument 2 of 'getsockname' from incompatible pointer type [-Werror=incompatible-pointer-types]
98 | if (!getsockname(fd, &addr, &addrlen))
| ^~~~~
| |
| struct sockaddr_in6 *
In file included from .../netinet/in.h:10,
from .../arpa/inet.h:9,
from ./test_progs.h:17,
from bpf_iter_setsockopt.c:5:
.../sys/socket.h:391:23: note: expected 'struct sockaddr * restrict' but argument is of type 'struct sockaddr_in6 *'
391 | int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict);
| ^cc1: all warnings being treated as errors
This compiled under glibc only because the argument is declared to be a "funky" transparent union which includes both types above. Explicitly cast the argument to allow compiling for both musl and glibc.
--- tools/testing/selftests/bpf/prog_tests/bpf_iter_setsockopt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/bpf_iter_setsockopt.c +1 -1
@@ -95,7 +95,7 @@ static unsigned short get_local_port(int fd)struct sockaddr_in6 addr;socklen_t addrlen =sizeof (addr); -if (!getsockname (fd, &addr, &addrlen)) +if (!getsockname (fd, (struct sockaddr *) &addr, &addrlen))return ntohs (addr.sin6_port);return 0 ;
Signature · 1 line
2.34.1
PATCH 4/19 selftests/bpf: Drop unneeded include in unpriv_helpers.c
In reply to Tony AmbardarThe addition of general support for unprivileged tests in test_loader.c breaks building test_verifier on non-glibc (e.g. musl) systems, due to the inclusion of glibc extension '<error.h>' in 'unpriv_helpers.c'. However, the header is actually not needed, so remove it to restore building.
--- tools/testing/selftests/bpf/unpriv_helpers.c | 1 - 1 file changed, 1 deletion(-)
tools/testing/selftests/bpf/unpriv_helpers.c +0 -1
@@ -2,7 +2,6 @@#include <stdbool.h> #include <stdlib.h> -#include <error.h> #include <stdio.h> #include <string.h> #include <unistd.h>
Signature · 1 line
2.34.1
PATCH 5/19 selftests/bpf: Drop unneeded include in sk_lookup.c
In reply to Tony AmbardarTest prog sk_lookup.c includes glibc extension '<error.h>' and fails to build for non-glibc (i.e. musl) systems. However, the header is actually not needed, so remove it to allow more portable compilation.
--- tools/testing/selftests/bpf/prog_tests/sk_lookup.c | 1 - 1 file changed, 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/sk_lookup.c +0 -1
@@ -18,7 +18,6 @@#include <arpa/inet.h> #include <assert.h> #include <errno.h> -#include <error.h> #include <fcntl.h> #include <sched.h> #include <stdio.h>
Signature · 1 line
2.34.1
PATCH 6/19 selftests/bpf: Drop unneeded include in flow_dissector.c
In reply to Tony AmbardarTest prog flow_dissector.c includes glibc extension '<error.h>' and fails to build for non-glibc (i.e. musl) systems. However, the header is actually not needed, so remove it to allow more portable compilation.
--- tools/testing/selftests/bpf/prog_tests/flow_dissector.c | 1 - 1 file changed, 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/flow_dissector.c +0 -1
@@ -1,7 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <test_progs.h> #include <network_helpers.h> -#include <error.h> #include <linux/if_tun.h> #include <sys/uio.h>
Signature · 1 line
2.34.1
PATCH 7/19 selftests/bpf: Fix missing ARRAY_SIZE() definition in bench.c
In reply to Tony AmbardarAdd a "bpf_util.h" include to avoid the following error seen compiling for mips64el with musl libc:
bench.c: In function 'find_benchmark':
bench.c:590:25: error: implicit declaration of function 'ARRAY_SIZE' [-Werror=implicit-function-declaration]
590 | for (i = 0; i < ARRAY_SIZE(benchs); i++) {
| ^~~~~~~~~~cc1: all warnings being treated as errors
--- tools/testing/selftests/bpf/bench.c | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/bpf/bench.c +1 -0
@@ -10,6 +10,7 @@#include <sys/sysinfo.h> #include <signal.h> #include "bench.h" +#include "bpf_util.h" #include "testing_helpers.h" struct env env = {
Signature · 1 line
2.34.1
PATCH 8/19 selftests/bpf: Fix missing UINT_MAX definitions in benchmarks
In reply to Tony AmbardarInclude <limits.h> in 'bench.h' to provide a UINT_MAX definition and avoid multiple compile errors against mips64el/musl-libc like:
benchs/bench_local_storage.c: In function 'parse_arg':
benchs/bench_local_storage.c:40:38: error: 'UINT_MAX' undeclared (first use in this function)
40 | if (ret < 1 || ret > UINT_MAX) {
| ^~~~~~~~
benchs/bench_local_storage.c:11:1: note: 'UINT_MAX' is defined in header '<limits.h>'; did you forget to '#include <limits.h>'?
10 | #include <test_btf.h>
+++ |+#include <limits.h>
11 |seen with bench_local_storage.c, bench_local_storage_rcu_tasks_trace.c, and bench_bpf_hashmap_lookup.c.
--- tools/testing/selftests/bpf/bench.h | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/bpf/bench.h +1 -0
@@ -10,6 +10,7 @@#include <math.h> #include <time.h> #include <sys/syscall.h> +#include <limits.h> struct cpu_set {bool *cpus;
Signature · 1 line
2.34.1
PATCH 9/19 selftests/bpf: Fix missing BUILD_BUG_ON() declaration
In reply to Tony AmbardarExplicitly include '<linux/build_bug.h>' to fix errors seen compiling with gcc targeting mips64el/musl-libc:
user_ringbuf.c: In function 'test_user_ringbuf_loop':
user_ringbuf.c:426:9: error: implicit declaration of function 'BUILD_BUG_ON' [-Werror=implicit-function-declaration]
426 | BUILD_BUG_ON(total_samples <= c_max_entries);
| ^~~~~~~~~~~~cc1: all warnings being treated as errors
--- tools/testing/selftests/bpf/prog_tests/user_ringbuf.c | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/bpf/prog_tests/user_ringbuf.c +1 -0
@@ -4,6 +4,7 @@#define _GNU_SOURCE#include <linux/compiler.h> #include <linux/ring_buffer.h> +#include <linux/build_bug.h> #include <pthread.h> #include <stdio.h> #include <stdlib.h>
Signature · 1 line
2.34.1
PATCH 10/19 selftests/bpf: Fix include of <sys/fcntl.h>
In reply to Tony AmbardarUpdate ns_current_pid_tgid.c to use '#include <fcntl.h>' and avoid compile error against mips64el/musl libc:
In file included from .../prog_tests/ns_current_pid_tgid.c:14:
.../include/sys/fcntl.h:1:2: error: #warning redirecting incorrect #include <sys/fcntl.h> to <fcntl.h> [-Werror=cpp]
1 | #warning redirecting incorrect #include <sys/fcntl.h> to <fcntl.h>
| ^~~~~~~
cc1: all warnings being treated as errors
--- tools/testing/selftests/bpf/prog_tests/ns_current_pid_tgid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/ns_current_pid_tgid.c +1 -1
@@ -11,7 +11,7 @@#include <sched.h> #include <sys/wait.h> #include <sys/mount.h> -#include <sys/fcntl.h> +#include <fcntl.h> #include "network_helpers.h" #define STACK_SIZE (1024 * 1024)
Signature · 1 line
2.34.1
PATCH 11/19 selftests/bpf: Fix compiling parse_tcp_hdr_opt.c with musl-libc
In reply to Tony AmbardarThe GNU version of 'struct tcphdr', with members 'doff' and 'urg_ptr', is not exposed by musl headers unless _GNU_SOURCE is defined.
Add this definition to fix errors seen compiling for mips64el/musl-libc:
parse_tcp_hdr_opt.c:18:21: error: 'struct tcphdr' has no member named 'urg_ptr'
18 | .pk6_v6.tcp.urg_ptr = 123,
| ^~~~~~~
parse_tcp_hdr_opt.c:19:21: error: 'struct tcphdr' has no member named 'doff'
19 | .pk6_v6.tcp.doff = 9, /* 16 bytes of options */
| ^~~~--- tools/testing/selftests/bpf/prog_tests/parse_tcp_hdr_opt.c | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/bpf/prog_tests/parse_tcp_hdr_opt.c +1 -0
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE#include <test_progs.h> #include <network_helpers.h> #include "test_parse_tcp_hdr_opt.skel.h"
Signature · 1 line
2.34.1
PATCH 12/19 selftests/bpf: Fix compiling kfree_skb.c with musl-libc
In reply to Tony AmbardarThe GNU version of 'struct tcphdr' with member 'doff' is not exposed by musl headers unless _GNU_SOURCE is defined. Add this definition to fix errors seen compiling for mips64el/musl-libc:
In file included from kfree_skb.c:2:
kfree_skb.c: In function 'on_sample':
kfree_skb.c:45:30: error: 'struct tcphdr' has no member named 'doff'
45 | if (CHECK(pkt_v6->tcp.doff != 5, "check_tcp",
| ^--- tools/testing/selftests/bpf/prog_tests/kfree_skb.c | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/bpf/prog_tests/kfree_skb.c +1 -0
@@ -1,4 +1,5 @@// SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE#include <test_progs.h> #include <network_helpers.h> #include "kfree_skb.skel.h"
Signature · 1 line
2.34.1
PATCH 13/19 selftests/bpf: Fix compiling flow_dissector.c with musl-libc
In reply to Tony AmbardarThe GNU version of 'struct tcphdr' has members 'doff', 'source' and 'dest', which are not exposed by musl libc headers unless _GNU_SOURCE is defined.
Add this definition to fix errors seen compiling for mips64el/musl-libc:
flow_dissector.c:118:30: error: 'struct tcphdr' has no member named 'doff'
118 | .tcp.doff = 5,
| ^~~~
flow_dissector.c:119:30: error: 'struct tcphdr' has no member named 'source'
119 | .tcp.source = 80,
| ^~~~~~
flow_dissector.c:120:30: error: 'struct tcphdr' has no member named 'dest'
120 | .tcp.dest = 8080,
| ^~~~--- tools/testing/selftests/bpf/prog_tests/flow_dissector.c | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/bpf/prog_tests/flow_dissector.c +1 -0
@@ -1,4 +1,5 @@// SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE#include <test_progs.h> #include <network_helpers.h> #include <linux/if_tun.h>
Signature · 1 line
2.34.1
PATCH 14/19 selftests/bpf: Fix compiling tcp_rtt.c with musl-libc
In reply to Tony AmbardarThe GNU version of 'struct tcp_info' in 'netinet/tcp.h' is not exposed by musl headers unless _GNU_SOURCE is defined.
Add this definition to fix errors seen compiling for mips64el/musl-libc:
tcp_rtt.c: In function 'wait_for_ack':
tcp_rtt.c:24:25: error: storage size of 'info' isn't known
24 | struct tcp_info info;
| ^~~~ tcp_rtt.c:24:25: error: unused variable 'info' [-Werror=unused-variable]
cc1: all warnings being treated as errors
--- tools/testing/selftests/bpf/prog_tests/tcp_rtt.c | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/bpf/prog_tests/tcp_rtt.c +1 -0
@@ -1,4 +1,5 @@// SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE#include <test_progs.h> #include "cgroup_helpers.h" #include "network_helpers.h"
Signature · 1 line
2.34.1
PATCH 15/19 selftests/bpf: Fix compiling core_reloc.c with musl-libc
In reply to Tony AmbardarThe type 'loff_t' is a GNU extension and not exposed by the musl 'fcntl.h' header unless _GNU_SOURCE is defined. Add this definition to fix errors seen compiling for mips64el/musl-libc:
In file included from tools/testing/selftests/bpf/prog_tests/core_reloc.c:4:
./bpf_testmod/bpf_testmod.h:10:9: error: unknown type name 'loff_t'
10 | loff_t off;
| ^~~~~~
./bpf_testmod/bpf_testmod.h:16:9: error: unknown type name 'loff_t'
16 | loff_t off;
| ^~~~~~--- tools/testing/selftests/bpf/prog_tests/core_reloc.c | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/bpf/prog_tests/core_reloc.c +1 -0
@@ -1,4 +1,5 @@// SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE#include <test_progs.h> #include "progs/core_reloc_types.h" #include "bpf_testmod/bpf_testmod.h"
Signature · 1 line
2.34.1
PATCH 16/19 selftests/bpf: Fix errors compiling lwt_redirect.c with musl libc
In reply to Tony AmbardarRemove a redundant include of '<linux/icmp.h>' which is already provided in 'lwt_helpers.h'. This avoids errors seen compiling for mips64el/musl-libc:
In file included from .../arpa/inet.h:9,
from lwt_redirect.c:51:
.../netinet/in.h:23:8: error: redefinition of 'struct in6_addr'
23 | struct in6_addr {
| ^~~~~~~~
In file included from .../linux/icmp.h:24,
from lwt_redirect.c:50:
.../linux/in6.h:33:8: note: originally defined here
33 | struct in6_addr {
| ^~~~~~~~
.../netinet/in.h:34:8: error: redefinition of 'struct sockaddr_in6'
34 | struct sockaddr_in6 {
| ^~~~~~~~~~~~
.../linux/in6.h:50:8: note: originally defined here
50 | struct sockaddr_in6 {
| ^~~~~~~~~~~~
.../netinet/in.h:42:8: error: redefinition of 'struct ipv6_mreq'
42 | struct ipv6_mreq {
| ^~~~~~~~~
.../linux/in6.h:60:8: note: originally defined here
60 | struct ipv6_mreq {
| ^~~~~~~~~--- tools/testing/selftests/bpf/prog_tests/lwt_redirect.c | 1 - 1 file changed, 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/lwt_redirect.c +0 -1
@@ -47,7 +47,6 @@#include <linux/if_ether.h> #include <linux/if_packet.h> #include <linux/if_tun.h> -#include <linux/icmp.h> #include <arpa/inet.h> #include <unistd.h> #include <errno.h>
Signature · 1 line
2.34.1
PATCH 17/19 selftests/bpf: Fix errors compiling decap_sanity.c with musl libc
In reply to Tony AmbardarRemove a redundant include of '<linux/in6.h>', whose needed definitions are already provided by 'test_progs.h'. This avoids errors seen compiling for mips64el/musl-libc:
In file included from .../arpa/inet.h:9,
from ./test_progs.h:17,
from prog_tests/decap_sanity.c:9:
.../netinet/in.h:23:8: error: redefinition of 'struct in6_addr'
23 | struct in6_addr {
| ^~~~~~~~
In file included from decap_sanity.c:7:
.../linux/in6.h:33:8: note: originally defined here
33 | struct in6_addr {
| ^~~~~~~~
.../netinet/in.h:34:8: error: redefinition of 'struct sockaddr_in6'
34 | struct sockaddr_in6 {
| ^~~~~~~~~~~~
.../linux/in6.h:50:8: note: originally defined here
50 | struct sockaddr_in6 {
| ^~~~~~~~~~~~
.../netinet/in.h:42:8: error: redefinition of 'struct ipv6_mreq'
42 | struct ipv6_mreq {
| ^~~~~~~~~
.../linux/in6.h:60:8: note: originally defined here
60 | struct ipv6_mreq {
| ^~~~~~~~~--- tools/testing/selftests/bpf/prog_tests/decap_sanity.c | 1 - 1 file changed, 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/decap_sanity.c +0 -1
@@ -4,7 +4,6 @@#include <sys/types.h> #include <sys/socket.h> #include <net/if.h> -#include <linux/in6.h> #include "test_progs.h" #include "network_helpers.h"
Signature · 1 line
2.34.1
PATCH 18/19 selftests/bpf: Fix errors compiling crypto_sanity.c with musl libc
In reply to Tony AmbardarRemove a redundant include of '<linux/in6.h>', whose needed definitions are already provided by 'test_progs.h'. This avoids errors seen compiling for mips64el/musl-libc:
In file included from .../arpa/inet.h:9,
from ./test_progs.h:17,
from prog_tests/crypto_sanity.c:10:
.../netinet/in.h:23:8: error: redefinition of 'struct in6_addr'
23 | struct in6_addr {
| ^~~~~~~~
In file included from crypto_sanity.c:7:
.../linux/in6.h:33:8: note: originally defined here
33 | struct in6_addr {
| ^~~~~~~~
.../netinet/in.h:34:8: error: redefinition of 'struct sockaddr_in6'
34 | struct sockaddr_in6 {
| ^~~~~~~~~~~~
.../linux/in6.h:50:8: note: originally defined here
50 | struct sockaddr_in6 {
| ^~~~~~~~~~~~
.../netinet/in.h:42:8: error: redefinition of 'struct ipv6_mreq'
42 | struct ipv6_mreq {
| ^~~~~~~~~
.../linux/in6.h:60:8: note: originally defined here
60 | struct ipv6_mreq {
| ^~~~~~~~~--- tools/testing/selftests/bpf/prog_tests/crypto_sanity.c | 1 - 1 file changed, 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/crypto_sanity.c +0 -1
@@ -4,7 +4,6 @@#include <sys/types.h> #include <sys/socket.h> #include <net/if.h> -#include <linux/in6.h> #include <linux/if_alg.h> #include "test_progs.h"
Signature · 1 line
2.34.1
PATCH 19/19 selftests/bpf: Fix errors compiling cg_storage_multi.h with musl libc
In reply to Tony AmbardarRemove a redundant include of '<asm/types.h>', whose needed definitions are already included (via '<linux/types.h>') in cg_storage_multi_egress_only.c, cg_storage_multi_isolated.c, and cg_storage_multi_shared.c. This avoids redefinition errors seen compiling for mips64el/musl-libc like:
In file included from progs/cg_storage_multi_egress_only.c:13:
In file included from progs/cg_storage_multi.h:6:
In file included from /usr/mips64el-linux-gnuabi64/include/asm/types.h:23:
/usr/include/asm-generic/int-l64.h:29:25: error: typedef redefinition with different types ('long' vs 'long long')
29 | typedef __signed__ long __s64;
| ^
/usr/include/asm-generic/int-ll64.h:30:44: note: previous definition is here
30 | __extension__ typedef __signed__ long long __s64;
| ^--- tools/testing/selftests/bpf/progs/cg_storage_multi.h | 2 -- 1 file changed, 2 deletions(-)
tools/testing/selftests/bpf/progs/cg_storage_multi.h +0 -2
@@ -3,8 +3,6 @@ #ifndef __PROGS_CG_STORAGE_MULTI_H #define __PROGS_CG_STORAGE_MULTI_H -#include <asm/types.h> - struct cgroup_value { __u32 egress_pkts; __u32 ingress_pkts;
Signature · 1 line
2.34.1
CI has tested the following submission:
Dear patch submitter,
CI has tested the following submission:
Status: SUCCESS Name: [bpf-next,v1,00/19] selftests/bpf: Improve libc portability / musl support (part 1) Patchwork: https://patchwork.kernel.org/project/netdevbpf/list/?series=873126&state=* Matrix: https://github.com/kernel-patches/bpf/actions/runs/10053605528
No further action is necessary on your part.
Please note: this email is coming from an unmonitored mailbox. If you have questions or feedback, please reach out to the Meta Kernel CI team at [email protected].
Re: [PATCH bpf-next v1 18/19] selftests/bpf: Fix errors compiling crypto_sanity.c with musl libc
In reply to Tony AmbardarQuoted 38 lines · Tony Ambardar
Remove a redundant include of '<
linux/in6.h>', whose needed definitions are already provided by 'test_progs.h'. This avoids errors seen compiling for mips64el/musl-libc:In file included from .../arpa/inet.h:9, from ./test_progs.h:17, from prog_tests/crypto_sanity.c:10: .../netinet/in.h:23:8: error: redefinition of 'struct in6_addr' 23 | struct in6_addr { | ^~~~~~~~ In file included from crypto_sanity.c:7: .../linux/in6.h:33:8: note: originally defined here 33 | struct in6_addr { | ^~~~~~~~ .../netinet/in.h:34:8: error: redefinition of 'struct sockaddr_in6' 34 | struct sockaddr_in6 { | ^~~~~~~~~~~~ .../linux/in6.h:50:8: note: originally defined here 50 | struct sockaddr_in6 { | ^~~~~~~~~~~~ .../netinet/in.h:42:8: error: redefinition of 'struct ipv6_mreq' 42 | struct ipv6_mreq { | ^~~~~~~~~ .../linux/in6.h:60:8: note: originally defined here 60 | struct ipv6_mreq { | ^~~~~~~~~Fixes 91541ab192fc ("selftests: bpf: crypto skcipher algo selftests")Signed-off-by Tony Ambardar <[email protected]>--- tools/testing/selftests/bpf/prog_tests/crypto_sanity.c | 1 - 1 file changed, 1 deletion(-)tools/testing/selftests/bpf/prog_tests/crypto_sanity.c +0
-0
tools/testing/selftests/bpf/prog_tests/crypto_sanity.c line 9
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/crypto_sanity.c +0
-1@@ -4,7 +4,6 @@#include <sys/types.h> #include <sys/socket.h> #include <net/if.h> -#include <linux/in6.h> #include <linux/if_alg.h> #include "test_progs.h"
Re: [PATCH bpf-next v1 19/19] selftests/bpf: Fix errors compiling cg_storage_multi.h with musl libc
In reply to Tony AmbardarQuoted 36 lines · Tony Ambardar
Remove a redundant include of '<
asm/types.h>', whose needed definitions are already included (via '<linux/types.h>') incg_storage_multi_egress_only.c,cg_storage_multi_isolated.c, andcg_storage_multi_shared.c. This avoids redefinition errors seen compiling for mips64el/musl-libc like:In file included from
progs/cg_storage_multi_egress_only.c:13:
In file included fromprogs/cg_storage_multi.h:6:
In file included from/usr/mips64el-linux-gnuabi64/include/asm/types.h:23:
/usr/include/asm-generic/int-l64.h:29:25: error: typedef redefinition with different types ('long' vs 'long long')29 | typedef __signed__ long __s64; | ^ /usr/include/asm-generic/int-ll64.h:30:44: note: previous definition is here 30 | __extension__ typedef __signed__ long long __s64; | ^Fixes 9e5bd1f7633b ("selftests/bpf: Test CGROUP_STORAGE map can't be used by multiple progs")Signed-off-by Tony Ambardar <[email protected]>--- tools/testing/selftests/bpf/progs/cg_storage_multi.h | 2 -- 1 file changed, 2 deletions(-)tools/testing/selftests/bpf/progs/cg_storage_multi.h +0
-3@@ -3,8 +3,6 @@ #ifndef __PROGS_CG_STORAGE_MULTI_H #define __PROGS_CG_STORAGE_MULTI_H -#include <asm/types.h> - struct cgroup_value { __u32 egress_pkts; __u32 ingress_pkts; --
Quoted 2 lines
2.34.1
Hmm, some linter checks prefer headers themselves include everything they use. This header uses __u32 and after this patch it would include no headers. Would it be okay to include <linux/types.h> or we don't care?
YiFei Zhu
Re: [PATCH bpf-next v1 01/19] selftests/bpf: Use pid_t consistently in test_progs.c
In reply to Tony AmbardarQuoted 33 lines · Tony Ambardar
Use
pid_trather than__pid_twhen allocating memory for 'worker_pids' in
'structtest_env', as this is its declared type and also avoids compile
errors seen building against musl libc on mipsel64:test_progs.c:1738:49: error: '
__pid_t' undeclared (first use in this function); did you mean 'pid_t'?
1738 | env.worker_pids =calloc(sizeof(__pid_t), env.workers);
| ^~~~~~~ |pid_ttest_progs.c:1738:49: note: each undeclared identifier is reported only once for each function it appears inFixes 91b2c0afd00c ("selftests/bpf: Add parallelism to test_progs")Signed-off-by Tony Ambardar <[email protected]>---
tools/testing/selftests/bpf/test_progs.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/bpf/test_progs.c +0
-0@@ -1738,7 +1738,7 @@ int main(int argc, char **argv) /* launch workers if requested */env.worker_id = -1; /* main process */
if (env.workers) {tools/testing/selftests/bpf/test_progs.c +0
-1- env.worker_pids = calloc(sizeof(__pid_t),env.workers);
tools/testing/selftests/bpf/test_progs.c +1
-0+ env.worker_pids = calloc(sizeof(pid_t),
Quoted 1 line
env.workers);
Yes, "pid_t" is much better. "worker_pids" dose define as "pid_t" in test_progs.h:
struct test_env {
... ...
pid_t *worker_pids; /* array of worker pids */
... ...
};Quoted 4 lines
env.worker_socks =
calloc(sizeof(int), env.workers); if (env.debug)
fprintf(stdout, "Launching %d workers.\n", env.workers);
Re: [PATCH bpf-next v1 03/19] selftests/bpf: Fix error compiling bpf_iter_setsockopt.c with musl libc
In reply to Tony AmbardarQuoted 48 lines · Tony Ambardar
Existing code calls
getsockname()with a 'structsockaddr_in6*' argument
where a 'struct sockaddr *' argument is declared, yielding compile errors
when building for mips64el/musl-libc:
bpf_iter_setsockopt.c: In function 'get_local_port':
bpf_iter_setsockopt.c:98:30: error: passing argument 2 of 'getsockname' from incompatible pointer type [-Werror=incompatible- pointer-types]
98 | if (!getsockname(fd, &addr, &addrlen))| ^~~~~ | | | struct sockaddr_in6 *In file included from
.../netinet/in.h:10,
from.../arpa/inet.h:9,
from ./test_progs.h:17,
from bpf_iter_setsockopt.c:5:
.../sys/socket.h:391:23: note: expected 'struct sockaddr * restrict' but argument is of type 'structsockaddr_in6*' 391 | int getsockname (int, struct sockaddr*__restrict,socklen_t*__restrict);
| ^
cc1: all warnings being treated as errorsThis compiled under glibc only because the argument is declared to be a
"funky" transparent union which includes both types above. Explicitly cast
the argument to allow compiling for both musl and glibc.Fixes eed92afdd14c ("bpf: selftest: Test batching andbpf_(get|set)sockopt in bpf tcp iter")
Signed-off-by Tony Ambardar <[email protected]>---
tools/testing/selftests/bpf/prog_tests/bpf_iter_setsockopt.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)diff --git
a/tools/testing/selftests/bpf/prog_tests/bpf_iter_setsockopt.cb/tools/testing/selftests/bpf/prog_tests/bpf_iter_setsockopt.cindexb52ff8ce34db..35363b104dd2100644tools/testing/selftests/bpf/prog_tests/bpf_iter_setsockopt.c +0
-0@@ -95,7 +95,7 @@ static unsigned short get_local_port(int fd) struct sockaddr_in6 addr; socklen_t addrlen = sizeof(addr);
tools/testing/selftests/bpf/prog_tests/bpf_iter_setsockopt.c static unsigned short get_local_port(int fd) · line 98
Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/bpf_iter_setsockopt.c +1
-1-if (!getsockname (fd, &addr, &addrlen)) +if (!getsockname (fd, (struct sockaddr *) &addr, &addrlen))
nit: Generally, a space is not required when casting:
(struct sockaddr *)&addr
not
(struct sockaddr *) &addr.
See here:
$ grep -r "struct sockaddr \*) \&" tools/testing/selftests/bpf/prog_tests | wc -l 1 $ grep -r "struct sockaddr \*)\&" tools/testing/selftests/bpf/prog_tests | wc -l 33
Except this, LGTM.
Quoted 3 lines
return
ntohs(addr.sin6_port);
return 0;
Re: [PATCH bpf-next v1 07/19] selftests/bpf: Fix missing ARRAY_SIZE() definition in bench.c
In reply to Tony AmbardarQuoted 10 lines · Tony Ambardar
Add a "
bpf_util.h" include to avoid the following error seen compiling for
mips64el with musl libc:
bench.c: In function 'find_benchmark':
bench.c:590:25: error: implicit declaration of function 'ARRAY_SIZE' [-Werror=implicit-function-declaration] 590 | for (i = 0; i <ARRAY_SIZE(benchs); i++) { | ^~~~~~~~~~
cc1: all warnings being treated as errors
I'm curious why this error doesn't occur on other platforms. ARRAY_SIZE is actually defined in linux/kernel.h (tools/include/linux/kernel.h). I think you should find out why this file is not included on your platform.
Quoted 21 lines
Fixes 8e7c2a023ac0 ("selftests/bpf: Add benchmark runnerinfrastructure")
Signed-off-by Tony Ambardar <[email protected]>---
tools/testing/selftests/bpf/bench.c | 1 +1 file changed, 1 insertion(+)tools/testing/selftests/bpf/bench.c +1
-0@@ -10,6 +10,7 @@ #include <sys/sysinfo.h> #include <signal.h> #include "bench.h" +#include "bpf_util.h" #include "testing_helpers.h"
struct env env = {
Re: [PATCH bpf-next v1 19/19] selftests/bpf: Fix errors compiling cg_storage_multi.h with musl libc
In reply to YiFei ZhuQuoted 32 lines · YiFei Zhu
Quoted 30 lines · Tony Ambardar
Remove a redundant include of '<
asm/types.h>', whose needed definitions are already included (via '<linux/types.h>') incg_storage_multi_egress_only.c,cg_storage_multi_isolated.c, andcg_storage_multi_shared.c. This avoids redefinition errors seen compiling for mips64el/musl-libc like:In file included from
progs/cg_storage_multi_egress_only.c:13:
In file included fromprogs/cg_storage_multi.h:6:
In file included from/usr/mips64el-linux-gnuabi64/include/asm/types.h:23:
/usr/include/asm-generic/int-l64.h:29:25: error: typedef redefinition with different types ('long' vs 'long long')29 | typedef __signed__ long __s64; | ^ /usr/include/asm-generic/int-ll64.h:30:44: note: previous definition is here 30 | __extension__ typedef __signed__ long long __s64; | ^Fixes 9e5bd1f7633b ("selftests/bpf: Test CGROUP_STORAGE map can't be used by multiple progs")Signed-off-by Tony Ambardar <[email protected]>--- tools/testing/selftests/bpf/progs/cg_storage_multi.h | 2 -- 1 file changed, 2 deletions(-)tools/testing/selftests/bpf/progs/cg_storage_multi.h +0
-0@@ -3,8 +3,6 @@#ifndef __PROGS_CG_STORAGE_MULTI_H#define __PROGS_CG_STORAGE_MULTI_H
Quoted 14 lines
Quoted 8 lines
tools/testing/selftests/bpf/progs/cg_storage_multi.h +0
-3-#include <asm/types.h> -struct cgroup_value {__u32 egress_pkts;__u32 ingress_pkts; --2.34.1
Hmm, some linter checks prefer headers themselves include everything they use. This header uses
__u32and after this patch it would include no headers. Would it be okay to include <linux/types.h> or we don't care?
This header seems to be included both from user space code and BPF code, so it probably is for the better to not include specific headers and rely on respective code to provide "basic" type definitions like __u32. (For BPF side they might be coming from vmlinux.h, for example, which won't be compatible with anything included in user space code).
Quoted 1 line
YiFei Zhu
Andrii Nakryiko
AppliedQuoted 20 lines · Tony Ambardar
Hello all,
This series includes the bulk of libc-related compile fixes accumulated to support systems using musl, with smaller numbers to follow. These patches are simple and straightforward, and the series has been tested with the kernel-patches/bpf CI and locally using mips64el-gcc/musl-libc and QEMU with an OpenWrt rootfs.
The patches address a few general categories of libc portability issues:
- missing, redundant or incorrect include headers
- disabled GNU header extensions (i.e. missing #define_GNU_SOURCE)
- issues with types and castingFeedback and suggestions for improvement are welcome!
Thanks,
Tony
Quoted 8 lines
Tony Ambardar (19):
selftests/bpf: Usepid_tconsistently intest_progs.cselftests/bpf: Fix compile error fromrlim_tinsk_storage_map.cselftests/bpf: Fix error compilingbpf_iter_setsockopt.cwith musl
libc
selftests/bpf: Drop unneeded include inunpriv_helpers.cselftests/bpf: Drop unneeded include insk_lookup.cselftests/bpf: Drop unneeded include inflow_dissector.c
I squashed the above three patches into one, as they are the same kind of fix with the same reasoning. The rest at least have a specific error example, so I didn't touch them.
But generally speaking, I think it's fair to combine the same kind of fixes across a few files (for the future).
Applied to bpf-next, thanks.
Quoted 37 lines
selftests/bpf: Fix missing
ARRAY_SIZE()definition inbench.cselftests/bpf: Fix missingUINT_MAXdefinitions in benchmarks selftests/bpf: Fix missingBUILD_BUG_ON()declaration selftests/bpf: Fix include of <sys/fcntl.h>
selftests/bpf: Fix compilingparse_tcp_hdr_opt.cwith musl-libc selftests/bpf: Fix compilingkfree_skb.cwith musl-libc selftests/bpf: Fix compilingflow_dissector.cwith musl-libc selftests/bpf: Fix compilingtcp_rtt.cwith musl-libc selftests/bpf: Fix compilingcore_reloc.cwith musl-libc selftests/bpf: Fix errors compilinglwt_redirect.cwith musl libc selftests/bpf: Fix errors compilingdecap_sanity.cwith musl libc selftests/bpf: Fix errors compilingcrypto_sanity.cwith musl libc selftests/bpf: Fix errors compilingcg_storage_multi.hwith musl libctools/testing/selftests/bpf/bench.c | 1 + tools/testing/selftests/bpf/bench.h | 1 + tools/testing/selftests/bpf/map_tests/sk_storage_map.c | 2 +- tools/testing/selftests/bpf/prog_tests/bpf_iter_setsockopt.c | 2 +- tools/testing/selftests/bpf/prog_tests/core_reloc.c | 1 + tools/testing/selftests/bpf/prog_tests/crypto_sanity.c | 1 - tools/testing/selftests/bpf/prog_tests/decap_sanity.c | 1 - tools/testing/selftests/bpf/prog_tests/flow_dissector.c | 2 +- tools/testing/selftests/bpf/prog_tests/kfree_skb.c | 1 + tools/testing/selftests/bpf/prog_tests/lwt_redirect.c | 1 - tools/testing/selftests/bpf/prog_tests/ns_current_pid_tgid.c | 2 +- tools/testing/selftests/bpf/prog_tests/parse_tcp_hdr_opt.c | 1 + tools/testing/selftests/bpf/prog_tests/sk_lookup.c | 1 - tools/testing/selftests/bpf/prog_tests/tcp_rtt.c | 1 + tools/testing/selftests/bpf/prog_tests/user_ringbuf.c | 1 + tools/testing/selftests/bpf/progs/cg_storage_multi.h | 2 -- tools/testing/selftests/bpf/test_progs.c | 2 +- tools/testing/selftests/bpf/unpriv_helpers.c | 1 - 18 files changed, 12 insertions(+), 12 deletions(-)--
2.34.1
Re: [PATCH bpf-next v1 19/19] selftests/bpf: Fix errors compiling cg_storage_multi.h with musl libc
In reply to YiFei ZhuQuoted 45 lines · YiFei Zhu
Quoted 36 lines · Tony Ambardar
Remove a redundant include of '<
asm/types.h>', whose needed definitions are already included (via '<linux/types.h>') incg_storage_multi_egress_only.c,cg_storage_multi_isolated.c, andcg_storage_multi_shared.c. This avoids redefinition errors seen compiling for mips64el/musl-libc like:In file included from
progs/cg_storage_multi_egress_only.c:13:
In file included fromprogs/cg_storage_multi.h:6:
In file included from/usr/mips64el-linux-gnuabi64/include/asm/types.h:23:
/usr/include/asm-generic/int-l64.h:29:25: error: typedef redefinition with different types ('long' vs 'long long')29 | typedef __signed__ long __s64; | ^ /usr/include/asm-generic/int-ll64.h:30:44: note: previous definition is here 30 | __extension__ typedef __signed__ long long __s64; | ^Fixes 9e5bd1f7633b ("selftests/bpf: Test CGROUP_STORAGE map can't be used by multiple progs")Signed-off-by Tony Ambardar <[email protected]>--- tools/testing/selftests/bpf/progs/cg_storage_multi.h | 2 -- 1 file changed, 2 deletions(-)tools/testing/selftests/bpf/progs/cg_storage_multi.h +0
-3@@ -3,8 +3,6 @@ #ifndef __PROGS_CG_STORAGE_MULTI_H #define __PROGS_CG_STORAGE_MULTI_H -#include <asm/types.h> - struct cgroup_value { __u32 egress_pkts; __u32 ingress_pkts; --Quoted 2 lines
2.34.1
Hmm, some linter checks prefer headers themselves include everything they use. This header uses
__u32and after this patch it would include no headers. Would it be okay to include <linux/types.h> or we don't care?
Quoted 1 line
YiFei Zhu
Good point, I agree even the readability suffers without headers. Replacing <asm/types.h> with <linux/types.h> makes more sense, and guards in the latter avoid the conflicts noted above. I'll queue this change for a v2. Appreciate the feedback!
Cheers,
Tony Ambardar
This series was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Quoted 9 lines · On Mon, 22 Jul 2024 22:54:27 -0700 you wrote:
Hello all,
This series includes the bulk of libc-related compile fixes accumulated to support systems using musl, with smaller numbers to follow. These patches are simple and straightforward, and the series has been tested with the kernel-patches/bpf CI and locally using mips64el-gcc/musl-libc and QEMU with an OpenWrt rootfs.
[...]
Here is the summary with links:
- [bpf-next,v1,01/19] selftests/bpf: Use pid_t consistently in test_progs.c
https://git.kernel.org/bpf/bpf-next/c/afd8169d2724 - [bpf-next,v1,02/19] selftests/bpf: Fix compile error from rlim_t in sk_storage_map.c https://git.kernel.org/bpf/bpf-next/c/bb3b965ee3a0 - [bpf-next,v1,03/19] selftests/bpf: Fix error compiling bpf_iter_setsockopt.c with musl libc https://git.kernel.org/bpf/bpf-next/c/6c3a808171a2 - [bpf-next,v1,04/19] selftests/bpf: Drop unneeded include in unpriv_helpers.c https://git.kernel.org/bpf/bpf-next/c/80fd6c991e95 - [bpf-next,v1,05/19] selftests/bpf: Drop unneeded include in sk_lookup.c (no matching commit) - [bpf-next,v1,06/19] selftests/bpf: Drop unneeded include in flow_dissector.c (no matching commit) - [bpf-next,v1,07/19] selftests/bpf: Fix missing ARRAY_SIZE() definition in bench.c https://git.kernel.org/bpf/bpf-next/c/9dc46fdb679b - [bpf-next,v1,08/19] selftests/bpf: Fix missing UINT_MAX definitions in benchmarks https://git.kernel.org/bpf/bpf-next/c/6898506ee0ae - [bpf-next,v1,09/19] selftests/bpf: Fix missing BUILD_BUG_ON() declaration https://git.kernel.org/bpf/bpf-next/c/b855ef609329 - [bpf-next,v1,10/19] selftests/bpf: Fix include of <sys/fcntl.h> https://git.kernel.org/bpf/bpf-next/c/f9d6628b2f54 - [bpf-next,v1,11/19] selftests/bpf: Fix compiling parse_tcp_hdr_opt.c with musl-libc https://git.kernel.org/bpf/bpf-next/c/81c60e36c31b - [bpf-next,v1,12/19] selftests/bpf: Fix compiling kfree_skb.c with musl-libc https://git.kernel.org/bpf/bpf-next/c/787a2e4f1b9e - [bpf-next,v1,13/19] selftests/bpf: Fix compiling flow_dissector.c with musl-libc https://git.kernel.org/bpf/bpf-next/c/c2e6d8c605ac - [bpf-next,v1,14/19] selftests/bpf: Fix compiling tcp_rtt.c with musl-libc https://git.kernel.org/bpf/bpf-next/c/2a6a6956f616 - [bpf-next,v1,15/19] selftests/bpf: Fix compiling core_reloc.c with musl-libc https://git.kernel.org/bpf/bpf-next/c/231c5446bfbc - [bpf-next,v1,16/19] selftests/bpf: Fix errors compiling lwt_redirect.c with musl libc https://git.kernel.org/bpf/bpf-next/c/7ce34ba2b21a - [bpf-next,v1,17/19] selftests/bpf: Fix errors compiling decap_sanity.c with musl libc https://git.kernel.org/bpf/bpf-next/c/352d541fae2d - [bpf-next,v1,18/19] selftests/bpf: Fix errors compiling crypto_sanity.c with musl libc https://git.kernel.org/bpf/bpf-next/c/a88580ba22aa - [bpf-next,v1,19/19] selftests/bpf: Fix errors compiling cg_storage_multi.h with musl libc https://git.kernel.org/bpf/bpf-next/c/56b0ab53657b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Hi Andrii,
Quoted 1 line · Andrii Nakryiko
On Mon, Jul 22, 2024 at 10:55 PM Tony Ambardar <[email protected]> wrote:
[...]
Quoted 10 lines
Quoted 9 lines
Tony Ambardar (19):
selftests/bpf: Usepid_tconsistently intest_progs.cselftests/bpf: Fix compile error fromrlim_tinsk_storage_map.cselftests/bpf: Fix error compilingbpf_iter_setsockopt.cwith musl
libc
selftests/bpf: Drop unneeded include inunpriv_helpers.cselftests/bpf: Drop unneeded include insk_lookup.cselftests/bpf: Drop unneeded include inflow_dissector.c
Quoted 6 lines
I squashed the above three patches into one, as they are the same kind of fix with the same reasoning. The rest at least have a specific error example, so I didn't touch them.
But generally speaking, I think it's fair to combine the same kind of fixes across a few files (for the future).
Thanks for clarifying this and reviewing. My concern earlier was that squashing "Fixes:" tags could hinder backporting. Is that a non-issue?
Quoted 2 lines
Applied to bpf-next, thanks.
And thanks to Geliang Tang, YiFei Zhu, and Vadim Fedorenko for their feedback.
Cheers,
Tony Ambardar
[...]
Quoted 20 lines · Tony Ambardar
Hi Andrii,
Quoted 1 line · Andrii Nakryiko
On Mon, Jul 22, 2024 at 10:55 PM Tony Ambardar <[email protected]> wrote:
[...]
Quoted 14 lines
Quoted 9 lines
Tony Ambardar (19):
selftests/bpf: Usepid_tconsistently intest_progs.cselftests/bpf: Fix compile error fromrlim_tinsk_storage_map.cselftests/bpf: Fix error compilingbpf_iter_setsockopt.cwith musl
libc
selftests/bpf: Drop unneeded include inunpriv_helpers.cselftests/bpf: Drop unneeded include insk_lookup.cselftests/bpf: Drop unneeded include inflow_dissector.cI squashed the above three patches into one, as they are the same kind of fix with the same reasoning. The rest at least have a specific error example, so I didn't touch them.
Quoted 6 lines
Quoted 2 lines
But generally speaking, I think it's fair to combine the same kind of fixes across a few files (for the future).
Thanks for clarifying this and reviewing. My concern earlier was that squashing "Fixes:" tags could hinder backporting. Is that a non-issue?
The fixes are small, so probably not. It's also fixes for selftests, so I'm not even sure how much that matters (for backporting).
Quoted 10 lines
Quoted 2 lines
Applied to bpf-next, thanks.
And thanks to Geliang Tang, YiFei Zhu, and Vadim Fedorenko for their feedback.
Cheers,
Tony Ambardar[...]
Re: [PATCH bpf-next v1 07/19] selftests/bpf: Fix missing ARRAY_SIZE() definition in bench.c
In reply to Geliang TangQuoted 12 lines · Geliang Tang
Quoted 10 lines · Tony Ambardar
Add a "
bpf_util.h" include to avoid the following error seen compiling for
mips64el with musl libc:
bench.c: In function 'find_benchmark':
bench.c:590:25: error: implicit declaration of function 'ARRAY_SIZE' [-Werror=implicit-function-declaration] 590 | for (i = 0; i <ARRAY_SIZE(benchs); i++) { | ^~~~~~~~~~
cc1: all warnings being treated as errors
Quoted 4 lines
I'm curious why this error doesn't occur on other platforms.
ARRAY_SIZEis actually defined inlinux/kernel.h(tools/include/linux/kernel.h). I think you should find out why this file is not included on your platform.
The surprising reason is that it compiles on glibc systems by accident, due to bench.c using get_nprocs() and needing to include <sys/sysinfo.h>. On musl systems this header defines 'struct sysinfo', but the glibc header version pulls in <linux/kernel.h> for this struct, which in turn drags in ARRAY_SIZE and the rest of the kitchen sink. So not very portable...
Quoted 22 lines
Quoted 21 lines
Fixes 8e7c2a023ac0 ("selftests/bpf: Add benchmark runnerinfrastructure")
Signed-off-by Tony Ambardar <[email protected]>---
tools/testing/selftests/bpf/bench.c | 1 +1 file changed, 1 insertion(+)tools/testing/selftests/bpf/bench.c +1
-0@@ -10,6 +10,7 @@ #include <sys/sysinfo.h> #include <signal.h> #include "bench.h" +#include "bpf_util.h" #include "testing_helpers.h"
struct env env = {