Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Fix sk_assign on s390x

sk_assign is failing on an s390x machine running Debian "bookworm" for
2 reasons: legacy server_map definition and uninitialized addrlen in
recvfrom() call.

Fix by adding a new-style server_map definition and dropping addrlen
(recvfrom() allows NULL values for src_addr and addrlen).

Since the test should support tc built without libbpf, build the prog
twice: with the old-style definition and with the new-style definition,
then select the right one at runtime. This could be done at compile
time too, but this would not be cross-compilation friendly.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20230129190501.1624747-2-iii@linux.ibm.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Ilya Leoshkevich and committed by
Alexei Starovoitov
7ce878ca 07dcbd73

+33 -6
+19 -6
tools/testing/selftests/bpf/prog_tests/sk_assign.c
··· 29 29 static bool 30 30 configure_stack(void) 31 31 { 32 + char tc_version[128]; 32 33 char tc_cmd[BUFSIZ]; 34 + char *prog; 35 + FILE *tc; 36 + 37 + /* Check whether tc is built with libbpf. */ 38 + tc = popen("tc -V", "r"); 39 + if (CHECK_FAIL(!tc)) 40 + return false; 41 + if (CHECK_FAIL(!fgets(tc_version, sizeof(tc_version), tc))) 42 + return false; 43 + if (strstr(tc_version, ", libbpf ")) 44 + prog = "test_sk_assign_libbpf.bpf.o"; 45 + else 46 + prog = "test_sk_assign.bpf.o"; 47 + if (CHECK_FAIL(pclose(tc))) 48 + return false; 33 49 34 50 /* Move to a new networking namespace */ 35 51 if (CHECK_FAIL(unshare(CLONE_NEWNET))) ··· 62 46 /* Load qdisc, BPF program */ 63 47 if (CHECK_FAIL(system("tc qdisc add dev lo clsact"))) 64 48 return false; 65 - sprintf(tc_cmd, "%s %s %s %s", "tc filter add dev lo ingress bpf", 66 - "direct-action object-file ./test_sk_assign.bpf.o", 49 + sprintf(tc_cmd, "%s %s %s %s %s", "tc filter add dev lo ingress bpf", 50 + "direct-action object-file", prog, 67 51 "section tc", 68 52 (env.verbosity < VERBOSE_VERY) ? " 2>/dev/null" : "verbose"); 69 53 if (CHECK(system(tc_cmd), "BPF load failed;", ··· 145 129 static ssize_t 146 130 rcv_msg(int srv_client, int type) 147 131 { 148 - struct sockaddr_storage ss; 149 132 char buf[BUFSIZ]; 150 - socklen_t slen; 151 133 152 134 if (type == SOCK_STREAM) 153 135 return read(srv_client, &buf, sizeof(buf)); 154 136 else 155 - return recvfrom(srv_client, &buf, sizeof(buf), 0, 156 - (struct sockaddr *)&ss, &slen); 137 + return recvfrom(srv_client, &buf, sizeof(buf), 0, NULL, NULL); 157 138 } 158 139 159 140 static int
+11
tools/testing/selftests/bpf/progs/test_sk_assign.c
··· 16 16 #include <bpf/bpf_helpers.h> 17 17 #include <bpf/bpf_endian.h> 18 18 19 + #if defined(IPROUTE2_HAVE_LIBBPF) 20 + /* Use a new-style map definition. */ 21 + struct { 22 + __uint(type, BPF_MAP_TYPE_SOCKMAP); 23 + __type(key, int); 24 + __type(value, __u64); 25 + __uint(pinning, LIBBPF_PIN_BY_NAME); 26 + __uint(max_entries, 1); 27 + } server_map SEC(".maps"); 28 + #else 19 29 /* Pin map under /sys/fs/bpf/tc/globals/<map name> */ 20 30 #define PIN_GLOBAL_NS 2 21 31 ··· 45 35 .max_elem = 1, 46 36 .pinning = PIN_GLOBAL_NS, 47 37 }; 38 + #endif 48 39 49 40 char _license[] SEC("license") = "GPL"; 50 41
+3
tools/testing/selftests/bpf/progs/test_sk_assign_libbpf.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #define IPROUTE2_HAVE_LIBBPF 3 + #include "test_sk_assign.c"