From: Daniel Borkmann <daniel@iogearbox.net>
To: Ilya Leoshkevich <iii@linux.ibm.com>,
Alexei Starovoitov <ast@kernel.org>
Cc: bpf@vger.kernel.org, Yonghong Song <yhs@fb.com>,
Andrey Ignatov <rdna@fb.com>,
Heiko Carstens <heiko.carstens@de.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>
Subject: Re: [PATCH bpf v2] selftests/bpf: fix endianness issues in test_sysctl
Date: Wed, 21 Aug 2019 21:52:56 +0200 [thread overview]
Message-ID: <40d41e83-61c3-5e08-f44d-4800763b1785@iogearbox.net> (raw)
In-Reply-To: <20190819105908.64863-1-iii@linux.ibm.com>
On 8/19/19 12:59 PM, Ilya Leoshkevich wrote:
> A lot of test_sysctl sub-tests fail due to handling strings as a bunch
> of immediate values in a little-endian-specific manner.
>
> Fix by wrapping all immediates in bpf_ntohl and the new bpf_be64_to_cpu.
>
> Also, sometimes tests fail because sysctl() unexpectedly succeeds with
> an inappropriate "Unexpected failure" message and a random errno. Zero
> out errno before calling sysctl() and replace the message with
> "Unexpected success".
>
> Fixes: 1f5fa9ab6e2e ("selftests/bpf: Test BPF_CGROUP_SYSCTL")
> Fixes: 9a1027e52535 ("selftests/bpf: Test file_pos field in bpf_sysctl ctx")
> Fixes: 6041c67f28d8 ("selftests/bpf: Test bpf_sysctl_get_name helper")
> Fixes: 11ff34f74e32 ("selftests/bpf: Test sysctl_get_current_value helper")
> Fixes: 786047dd08de ("selftests/bpf: Test bpf_sysctl_{get,set}_new_value helpers")
> Fixes: 8549ddc832d6 ("selftests/bpf: Test bpf_strtol and bpf_strtoul helpers")
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
> v1->v2: Use bpf_ntohl and bpf_be64_to_cpu, drop __bpf_le64_to_cpu.
>
> tools/testing/selftests/bpf/bpf_endian.h | 7 ++
> tools/testing/selftests/bpf/test_sysctl.c | 130 ++++++++++++++--------
> 2 files changed, 92 insertions(+), 45 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/bpf_endian.h b/tools/testing/selftests/bpf/bpf_endian.h
> index 05f036df8a4c..f3be9322e89c 100644
> --- a/tools/testing/selftests/bpf/bpf_endian.h
> +++ b/tools/testing/selftests/bpf/bpf_endian.h
> @@ -29,6 +29,8 @@
> # define __bpf_htonl(x) __builtin_bswap32(x)
> # define __bpf_constant_ntohl(x) ___constant_swab32(x)
> # define __bpf_constant_htonl(x) ___constant_swab32(x)
> +# define __bpf_be64_to_cpu(x) __builtin_bswap64(x)
> +# define __bpf_constant_be64_to_cpu(x) ___constant_swab64(x)
> #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
> # define __bpf_ntohs(x) (x)
> # define __bpf_htons(x) (x)
> @@ -38,6 +40,8 @@
> # define __bpf_htonl(x) (x)
> # define __bpf_constant_ntohl(x) (x)
> # define __bpf_constant_htonl(x) (x)
> +# define __bpf_be64_to_cpu(x) (x)
> +# define __bpf_constant_be64_to_cpu(x) (x)
> #else
> # error "Fix your compiler's __BYTE_ORDER__?!"
> #endif
> @@ -54,5 +58,8 @@
> #define bpf_ntohl(x) \
> (__builtin_constant_p(x) ? \
> __bpf_constant_ntohl(x) : __bpf_ntohl(x))
> +#define bpf_be64_to_cpu(x) \
> + (__builtin_constant_p(x) ? \
> + __bpf_constant_be64_to_cpu(x) : __bpf_be64_to_cpu(x))
>
> #endif /* __BPF_ENDIAN__ */
By the way, looks like progs/test_lwt_seg6local.c defines its own ntohll()/htonll(),
could we make this two patches: i) consolidating the former by adding proper variants
to bpf_endian.h (I mean generically) and ii) fixing test_sysctl.c by using them? Thinking
addition of i) as plan for bpf-next would be to move bpf_endian.h as proper API into
libbpf in near future such that BPF progs don't need to redefine them.
Thanks,
Daniel
prev parent reply other threads:[~2019-08-21 19:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-19 10:59 [PATCH bpf v2] selftests/bpf: fix endianness issues in test_sysctl Ilya Leoshkevich
2019-08-19 16:48 ` Yonghong Song
2019-08-21 19:52 ` Daniel Borkmann [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=40d41e83-61c3-5e08-f44d-4800763b1785@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=gor@linux.ibm.com \
--cc=heiko.carstens@de.ibm.com \
--cc=iii@linux.ibm.com \
--cc=rdna@fb.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).