csum_partial() on different archs (selftest/bpf)
Al Viro
viro at zeniv.linux.org.uk
Fri Nov 13 07:42:04 EST 2020
On Fri, Nov 13, 2020 at 11:36:08AM +0100, Björn Töpel wrote:
> I was running the selftest/bpf on riscv, and had a closer look at one
> of the failing cases:
>
> #14/p valid read map access into a read-only array 2 FAIL retval
> 65507 != -29 (run 1/1)
>
> The test does a csum_partial() call via a BPF helper. riscv uses the
> generic implementation. arm64 uses the generic csum_partial() and fail
> in the same way [1]. arm (32-bit) has a arch specfic implementation,
> and fail in another way (FAIL retval 131042 != -29) [2].
>
> I mimicked the test case in a userland program, comparing the generic
> csum_partial() to the x86 implementation [3], and the generic and x86
> implementation does yield a different result.
>
> x86 : -29 : 0xffffffe3
> generic : 65507 : 0x0000ffe3
> arm : 131042 : 0x0001ffe2
>
> Who is correct? :-) It would be nice to get rid of this failed case...
Don't expose unfolded csums to *anything* that might care about the
specific bit pattern. All you are guaranteed is the value mod 0xffff.
Full 32bit value is not just arch-specific - it can change from moving
the area you are giving it by two bytes. Yes, really.
It's *NOT* suitable for passig to userland. Or for sending over the
wire. Or for storing in filesystem metadata (as reiserfs xattrs have
done).
__wsum is purely internal thing; BPF has no business sticking its
fingers there, let alone exposing it as part of any kind of stable ABI.
More information about the linux-riscv
mailing list