Re: [PATCH] selftests/bpf: Fix sockopt selftest failure on powerpc

Venkat Rao Bagalkote
2025-03-12T07:18:07Z

On 11/03/25 2:16 pm, Saket Kumar Bhaskar wrote:
> The SO_RCVLOWAT option is defined as 18 in the selftest header,
> which matches the generic definition. However, on powerpc,
> SO_RCVLOWAT is defined as 16. This discrepancy causes
> sol_socket_sockopt() to fail with the default switch case on powerpc.
>
> This commit fixes by defining SO_RCVLOWAT as 16 for powerpc.
>
> Signed-off-by: Saket Kumar Bhaskar <skb99@linux.ibm.com>
> ---
> tools/testing/selftests/bpf/progs/bpf_tracing_net.h | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/progs/bpf_tracing_net.h b/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
> index 59843b430f76..bcd44d5018bf 100644
> --- a/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
> +++ b/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
> @@ -15,7 +15,11 @@
> #define SO_KEEPALIVE 9
> #define SO_PRIORITY 12
> #define SO_REUSEPORT 15
> +#if defined(__TARGET_ARCH_powerpc)
> +#define SO_RCVLOWAT 16
> +#else
> #define SO_RCVLOWAT 18
> +#endif
> #define SO_BINDTODEVICE 25
> #define SO_MARK 36
> #define SO_MAX_PACING_RATE 47

Applied this patch on linux-mainline and tested. It fixes the issue.

Without this patch:

#define SO_RCVBUF               8
#define SO_KEEPALIVE            9
#define SO_PRIORITY             12
#define SO_REUSEPORT            15
#define SO_RCVLOWAT             18
#define SO_BINDTODEVICE         25
#define SO_MARK                 36

./test_progs -t sockopt
#20      bpf_iter_setsockopt:OK
#21      bpf_iter_setsockopt_unix:OK
create_netns:PASS:create netns 0 nsec
create_netns:PASS:set lo up 0 nsec
create_netns:PASS:add veth 0 nsec
create_netns:PASS:bring veth up 0 nsec
test_setget_sockopt:PASS:open skel 0 nsec
test_setget_sockopt:PASS:if_nametoindex 0 nsec
test_setget_sockopt:PASS:load skel 0 nsec
test_setget_sockopt:PASS:attach cgroup 0 nsec
test_setget_sockopt:PASS:attach_cgroup 0 nsec
test_tcp:PASS:start_server 0 nsec
test_tcp:PASS:connect_to_fd_server 0 nsec
test_tcp:FAIL:nr_listen unexpected nr_listen: actual 0 != expected 1
test_tcp:FAIL:nr_connect unexpected nr_connect: actual 0 != expected 1
test_tcp:FAIL:nr_active unexpected nr_active: actual 0 != expected 1
test_tcp:FAIL:nr_passive unexpected nr_passive: actual 0 != expected 1
test_tcp:FAIL:nr_socket_post_create unexpected nr_socket_post_create:
actual 0 != expected 2
test_tcp:PASS:nr_bind 0 nsec
test_tcp:PASS:start_server 0 nsec
test_tcp:PASS:connect_to_fd_server 0 nsec
test_tcp:FAIL:nr_listen unexpected nr_listen: actual 0 != expected 1
test_tcp:FAIL:nr_connect unexpected nr_connect: actual 0 != expected 1
test_tcp:FAIL:nr_active unexpected nr_active: actual 0 != expected 1
test_tcp:FAIL:nr_passive unexpected nr_passive: actual 0 != expected 1
test_tcp:FAIL:nr_socket_post_create unexpected nr_socket_post_create:
actual 0 != expected 2
test_tcp:PASS:nr_bind 0 nsec
test_udp:PASS:start_server 0 nsec
test_udp:FAIL:nr_socket_post_create unexpected nr_socket_post_create:
actual 0 < expected 1
test_udp:PASS:nr_bind 0 nsec
test_udp:PASS:start_server 0 nsec
test_udp:FAIL:nr_socket_post_create unexpected nr_socket_post_create:
actual 0 < expected 1
test_udp:PASS:nr_bind 0 nsec
test_ktls:PASS:start_server 0 nsec
test_ktls:PASS:connect_to_fd 0 nsec
test_ktls:PASS:accept 0 nsec
test_ktls:PASS:setsockopt 0 nsec
test_ktls:PASS:setsockopt 0 nsec
test_ktls:PASS:setsockopt 0 nsec
test_ktls:PASS:setsockopt 0 nsec
test_ktls:PASS:read 0 nsec
test_ktls:FAIL:nr_listen unexpected nr_listen: actual 0 != expected 1
test_ktls:FAIL:nr_connect unexpected nr_connect: actual 0 != expected 1
test_ktls:FAIL:nr_active unexpected nr_active: actual 0 != expected 1
test_ktls:FAIL:nr_passive unexpected nr_passive: actual 0 != expected 1
test_ktls:FAIL:nr_socket_post_create unexpected nr_socket_post_create:
actual 0 != expected 2
test_ktls:PASS:nr_bind 0 nsec
test_ktls:FAIL:nr_fin_wait1 unexpected nr_fin_wait1: actual 0 != expected 1
test_ktls:PASS:start_server 0 nsec
test_ktls:PASS:connect_to_fd 0 nsec
test_ktls:PASS:accept 0 nsec
test_ktls:PASS:setsockopt 0 nsec
test_ktls:PASS:setsockopt 0 nsec
test_ktls:PASS:setsockopt 0 nsec
test_ktls:PASS:setsockopt 0 nsec
test_ktls:PASS:read 0 nsec
test_ktls:FAIL:nr_listen unexpected nr_listen: actual 0 != expected 1
test_ktls:FAIL:nr_connect unexpected nr_connect: actual 0 != expected 1
test_ktls:FAIL:nr_active unexpected nr_active: actual 0 != expected 1
test_ktls:FAIL:nr_passive unexpected nr_passive: actual 0 != expected 1
test_ktls:FAIL:nr_socket_post_create unexpected nr_socket_post_create:
actual 0 != expected 2
test_ktls:PASS:nr_bind 0 nsec
test_ktls:FAIL:nr_fin_wait1 unexpected nr_fin_wait1: actual 0 != expected 1
test_nonstandard_opt:PASS:start_server 0 nsec
test_nonstandard_opt:PASS:connect_to_fd_server 0 nsec
test_nonstandard_opt:PASS:getsockopt prog 0 nsec
test_nonstandard_opt:PASS:accept 0 nsec
test_nonstandard_opt:PASS:getsockopt_flags 0 nsec
test_nonstandard_opt:PASS:cb_flags_set 0 nsec
test_nonstandard_opt:PASS:start_server 0 nsec
test_nonstandard_opt:PASS:connect_to_fd_server 0 nsec
test_nonstandard_opt:PASS:getsockopt prog 0 nsec
test_nonstandard_opt:PASS:accept 0 nsec
test_nonstandard_opt:PASS:getsockopt_flags 0 nsec
test_nonstandard_opt:PASS:cb_flags_set 0 nsec
#303     setget_sockopt:FAIL
#326/1   sockopt/getsockopt: no expected_attach_type:OK
#326/2   sockopt/getsockopt: wrong expected_attach_type:OK
#326/3   sockopt/getsockopt: bypass bpf hook:OK
#326/4   sockopt/getsockopt: return EPERM from bpf hook:OK
#326/5   sockopt/getsockopt: no optval bounds check, deny loading:OK
#326/6   sockopt/getsockopt: read ctx->level:OK
#326/7   sockopt/getsockopt: deny writing to ctx->level:OK
#326/8   sockopt/getsockopt: read ctx->optname:OK
#326/9   sockopt/getsockopt: read ctx->retval:OK
#326/10  sockopt/getsockopt: deny writing to ctx->optname:OK
#326/11  sockopt/getsockopt: read ctx->optlen:OK
#326/12  sockopt/getsockopt: deny bigger ctx->optlen:OK
#326/13  sockopt/getsockopt: ignore >PAGE_SIZE optlen:OK
#326/14  sockopt/getsockopt: support smaller ctx->optlen:OK
#326/15  sockopt/getsockopt: deny writing to ctx->optval:OK
#326/16  sockopt/getsockopt: deny writing to ctx->optval_end:OK
#326/17  sockopt/getsockopt: rewrite value:OK
#326/18  sockopt/setsockopt: no expected_attach_type:OK
#326/19  sockopt/setsockopt: wrong expected_attach_type:OK
#326/20  sockopt/setsockopt: bypass bpf hook:OK
#326/21  sockopt/setsockopt: return EPERM from bpf hook:OK
#326/22  sockopt/setsockopt: no optval bounds check, deny loading:OK
#326/23  sockopt/setsockopt: read ctx->level:OK
#326/24  sockopt/setsockopt: allow changing ctx->level:OK
#326/25  sockopt/setsockopt: read ctx->optname:OK
#326/26  sockopt/setsockopt: allow changing ctx->optname:OK
#326/27  sockopt/setsockopt: read ctx->optlen:OK
#326/28  sockopt/setsockopt: ctx->optlen == -1 is ok:OK
#326/29  sockopt/setsockopt: deny ctx->optlen < 0 (except -1):OK
#326/30  sockopt/setsockopt: deny ctx->optlen > input optlen:OK
#326/31  sockopt/setsockopt: ignore >PAGE_SIZE optlen:OK
#326/32  sockopt/setsockopt: allow changing ctx->optlen within bounds:OK
#326/33  sockopt/setsockopt: deny write ctx->retval:OK
#326/34  sockopt/setsockopt: deny read ctx->retval:OK
#326/35  sockopt/setsockopt: deny writing to ctx->optval:OK
#326/36  sockopt/setsockopt: deny writing to ctx->optval_end:OK
#326/37  sockopt/setsockopt: allow IP_TOS <= 128:OK
#326/38  sockopt/setsockopt: deny IP_TOS > 128:OK
#326/39  sockopt/can attach only BPF_CGROUP_SETSOCKOP:OK
#326/40  sockopt/can attach only BPF_CGROUP_GETSOCKOP:OK
#326     sockopt:OK
#327     sockopt_inherit:OK
#328     sockopt_multi:OK
#329     sockopt_qos_to_cc:OK
#330     sockopt_sk:OK

All error logs:
create_netns:PASS:create netns 0 nsec
create_netns:PASS:set lo up 0 nsec
create_netns:PASS:add veth 0 nsec
create_netns:PASS:bring veth up 0 nsec
test_setget_sockopt:PASS:open skel 0 nsec
test_setget_sockopt:PASS:if_nametoindex 0 nsec
test_setget_sockopt:PASS:load skel 0 nsec
test_setget_sockopt:PASS:attach cgroup 0 nsec
test_setget_sockopt:PASS:attach_cgroup 0 nsec
test_tcp:PASS:start_server 0 nsec
test_tcp:PASS:connect_to_fd_server 0 nsec
test_tcp:FAIL:nr_listen unexpected nr_listen: actual 0 != expected 1
test_tcp:FAIL:nr_connect unexpected nr_connect: actual 0 != expected 1
test_tcp:FAIL:nr_active unexpected nr_active: actual 0 != expected 1
test_tcp:FAIL:nr_passive unexpected nr_passive: actual 0 != expected 1
test_tcp:FAIL:nr_socket_post_create unexpected nr_socket_post_create:
actual 0 != expected 2
test_tcp:PASS:nr_bind 0 nsec
test_tcp:PASS:start_server 0 nsec
test_tcp:PASS:connect_to_fd_server 0 nsec
test_tcp:FAIL:nr_listen unexpected nr_listen: actual 0 != expected 1
test_tcp:FAIL:nr_connect unexpected nr_connect: actual 0 != expected 1
test_tcp:FAIL:nr_active unexpected nr_active: actual 0 != expected 1
test_tcp:FAIL:nr_passive unexpected nr_passive: actual 0 != expected 1
test_tcp:FAIL:nr_socket_post_create unexpected nr_socket_post_create:
actual 0 != expected 2
test_tcp:PASS:nr_bind 0 nsec
test_udp:PASS:start_server 0 nsec
test_udp:FAIL:nr_socket_post_create unexpected nr_socket_post_create:
actual 0 < expected 1
test_udp:PASS:nr_bind 0 nsec
test_udp:PASS:start_server 0 nsec
test_udp:FAIL:nr_socket_post_create unexpected nr_socket_post_create:
actual 0 < expected 1
test_udp:PASS:nr_bind 0 nsec
test_ktls:PASS:start_server 0 nsec
test_ktls:PASS:connect_to_fd 0 nsec
test_ktls:PASS:accept 0 nsec
test_ktls:PASS:setsockopt 0 nsec
test_ktls:PASS:setsockopt 0 nsec
test_ktls:PASS:setsockopt 0 nsec
test_ktls:PASS:setsockopt 0 nsec
test_ktls:PASS:read 0 nsec
test_ktls:FAIL:nr_listen unexpected nr_listen: actual 0 != expected 1
test_ktls:FAIL:nr_connect unexpected nr_connect: actual 0 != expected 1
test_ktls:FAIL:nr_active unexpected nr_active: actual 0 != expected 1
test_ktls:FAIL:nr_passive unexpected nr_passive: actual 0 != expected 1
test_ktls:FAIL:nr_socket_post_create unexpected nr_socket_post_create:
actual 0 != expected 2
test_ktls:PASS:nr_bind 0 nsec
test_ktls:FAIL:nr_fin_wait1 unexpected nr_fin_wait1: actual 0 != expected 1
test_ktls:PASS:start_server 0 nsec
test_ktls:PASS:connect_to_fd 0 nsec
test_ktls:PASS:accept 0 nsec
test_ktls:PASS:setsockopt 0 nsec
test_ktls:PASS:setsockopt 0 nsec
test_ktls:PASS:setsockopt 0 nsec
test_ktls:PASS:setsockopt 0 nsec
test_ktls:PASS:read 0 nsec
test_ktls:FAIL:nr_listen unexpected nr_listen: actual 0 != expected 1
test_ktls:FAIL:nr_connect unexpected nr_connect: actual 0 != expected 1
test_ktls:FAIL:nr_active unexpected nr_active: actual 0 != expected 1
test_ktls:FAIL:nr_passive unexpected nr_passive: actual 0 != expected 1
test_ktls:FAIL:nr_socket_post_create unexpected nr_socket_post_create:
actual 0 != expected 2
test_ktls:PASS:nr_bind 0 nsec
test_ktls:FAIL:nr_fin_wait1 unexpected nr_fin_wait1: actual 0 != expected 1
test_nonstandard_opt:PASS:start_server 0 nsec
test_nonstandard_opt:PASS:connect_to_fd_server 0 nsec
test_nonstandard_opt:PASS:getsockopt prog 0 nsec
test_nonstandard_opt:PASS:accept 0 nsec
test_nonstandard_opt:PASS:getsockopt_flags 0 nsec
test_nonstandard_opt:PASS:cb_flags_set 0 nsec
test_nonstandard_opt:PASS:start_server 0 nsec
test_nonstandard_opt:PASS:connect_to_fd_server 0 nsec
test_nonstandard_opt:PASS:getsockopt prog 0 nsec
test_nonstandard_opt:PASS:accept 0 nsec
test_nonstandard_opt:PASS:getsockopt_flags 0 nsec
test_nonstandard_opt:PASS:cb_flags_set 0 nsec
#303     setget_sockopt:FAIL
Summary: 7/40 PASSED, 0 SKIPPED, 1 FAILED

With this patch:

#if defined(__TARGET_ARCH_powerpc)
#define SO_RCVLOWAT             16
#else
#define SO_RCVLOWAT             18
#endif
#define SO_BINDTODEVICE         25
#define SO_MARK                 36
#define SO_MAX_PACING_RATE      47

./test_progs -t sockopt
#20      bpf_iter_setsockopt:OK
#21      bpf_iter_setsockopt_unix:OK
#303     setget_sockopt:OK
#326/1   sockopt/getsockopt: no expected_attach_type:OK
#326/2   sockopt/getsockopt: wrong expected_attach_type:OK
#326/3   sockopt/getsockopt: bypass bpf hook:OK
#326/4   sockopt/getsockopt: return EPERM from bpf hook:OK
#326/5   sockopt/getsockopt: no optval bounds check, deny loading:OK
#326/6   sockopt/getsockopt: read ctx->level:OK
#326/7   sockopt/getsockopt: deny writing to ctx->level:OK
#326/8   sockopt/getsockopt: read ctx->optname:OK
#326/9   sockopt/getsockopt: read ctx->retval:OK
#326/10  sockopt/getsockopt: deny writing to ctx->optname:OK
#326/11  sockopt/getsockopt: read ctx->optlen:OK
#326/12  sockopt/getsockopt: deny bigger ctx->optlen:OK
#326/13  sockopt/getsockopt: ignore >PAGE_SIZE optlen:OK
#326/14  sockopt/getsockopt: support smaller ctx->optlen:OK
#326/15  sockopt/getsockopt: deny writing to ctx->optval:OK
#326/16  sockopt/getsockopt: deny writing to ctx->optval_end:OK
#326/17  sockopt/getsockopt: rewrite value:OK
#326/18  sockopt/setsockopt: no expected_attach_type:OK
#326/19  sockopt/setsockopt: wrong expected_attach_type:OK
#326/20  sockopt/setsockopt: bypass bpf hook:OK
#326/21  sockopt/setsockopt: return EPERM from bpf hook:OK
#326/22  sockopt/setsockopt: no optval bounds check, deny loading:OK
#326/23  sockopt/setsockopt: read ctx->level:OK
#326/24  sockopt/setsockopt: allow changing ctx->level:OK
#326/25  sockopt/setsockopt: read ctx->optname:OK
#326/26  sockopt/setsockopt: allow changing ctx->optname:OK
#326/27  sockopt/setsockopt: read ctx->optlen:OK
#326/28  sockopt/setsockopt: ctx->optlen == -1 is ok:OK
#326/29  sockopt/setsockopt: deny ctx->optlen < 0 (except -1):OK
#326/30  sockopt/setsockopt: deny ctx->optlen > input optlen:OK
#326/31  sockopt/setsockopt: ignore >PAGE_SIZE optlen:OK
#326/32  sockopt/setsockopt: allow changing ctx->optlen within bounds:OK
#326/33  sockopt/setsockopt: deny write ctx->retval:OK
#326/34  sockopt/setsockopt: deny read ctx->retval:OK
#326/35  sockopt/setsockopt: deny writing to ctx->optval:OK
#326/36  sockopt/setsockopt: deny writing to ctx->optval_end:OK
#326/37  sockopt/setsockopt: allow IP_TOS <= 128:OK
#326/38  sockopt/setsockopt: deny IP_TOS > 128:OK
#326/39  sockopt/can attach only BPF_CGROUP_SETSOCKOP:OK
#326/40  sockopt/can attach only BPF_CGROUP_GETSOCKOP:OK
#326     sockopt:OK
#327     sockopt_inherit:OK
#328     sockopt_multi:OK
#329     sockopt_qos_to_cc:OK
#330     sockopt_sk:OK
Summary: 8/40 PASSED, 0 SKIPPED, 0 FAILED

Please add below tag.

Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>

Regards,

Venkat.