All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>, <bpf@vger.kernel.org>
Cc: <daniel@iogearbox.net>, <toke@redhat.com>
Subject: Re: [PATCH] bpf: selftests: test_verifier: mask bpf_csum_diff() return value to 16 bits
Date: Sun, 28 Feb 2021 21:18:34 -0800	[thread overview]
Message-ID: <acf00517-6129-869b-cd2a-03715de5fc61@fb.com> (raw)
In-Reply-To: <20210228103017.320240-1-yauheni.kaliuta@redhat.com>



On 2/28/21 2:30 AM, Yauheni Kaliuta wrote:
> The verifier test labelled "valid read map access into a read-only array
> 2" calls the bpf_csum_diff() helper and checks its return value.
> However, architecture implementations of csum_partial() (which is what
> the helper uses) differ in whether they fold the return value to 16 bit
> or not. For example, x86 version has:
> 
> 	if (unlikely(odd)) {
> 		result = from32to16(result);
> 		result = ((result >> 8) & 0xff) | ((result & 0xff) << 8);
> 	}
> 
> while generic lib/checksum.c does:
> 
> 	result = from32to16(result);
> 	if (odd)
> 		result = ((result >> 8) & 0xff) | ((result & 0xff) << 8);
> 
> This makes the helper return different values on different
> architectures, breaking the test on non-x86. To fix this, add an

I remember there is a previous discussion for this issue, csum_diff()
returns different results for different architecture? Daniel?
Any conclusion how to deal with this?

> additional instruction to always mask the return value to 16 bits, and
> update the expected return value accordingly.
> 
> Fixes: fb2abb73e575 ("bpf, selftest: test {rd, wr}only flags and direct value access")
> Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
> ---
>   tools/testing/selftests/bpf/verifier/array_access.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/bpf/verifier/array_access.c b/tools/testing/selftests/bpf/verifier/array_access.c
> index bed53b561e04..1b138cd2b187 100644
> --- a/tools/testing/selftests/bpf/verifier/array_access.c
> +++ b/tools/testing/selftests/bpf/verifier/array_access.c
> @@ -250,12 +250,13 @@
>   	BPF_MOV64_IMM(BPF_REG_5, 0),
>   	BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
>   		     BPF_FUNC_csum_diff),
> +	BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 0xffff),
>   	BPF_EXIT_INSN(),
>   	},
>   	.prog_type = BPF_PROG_TYPE_SCHED_CLS,
>   	.fixup_map_array_ro = { 3 },
>   	.result = ACCEPT,
> -	.retval = -29,
> +	.retval = 65507,
>   },
>   {
>   	"invalid write map access into a read-only array 1",
> 

  reply	other threads:[~2021-03-01  5:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-28 10:30 [PATCH] bpf: selftests: test_verifier: mask bpf_csum_diff() return value to 16 bits Yauheni Kaliuta
2021-03-01  5:18 ` Yonghong Song [this message]
2021-03-02 11:14   ` Daniel Borkmann
2021-03-02 10:50 ` patchwork-bot+netdevbpf

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=acf00517-6129-869b-cd2a-03715de5fc61@fb.com \
    --to=yhs@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=toke@redhat.com \
    --cc=yauheni.kaliuta@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.