On Wed, Jul 3, 2019 at 9:06 AM Ilya Leoshkevich <iii@xxxxxxxxxxxxx> wrote: > > BPF_LDX_MEM is used to load the least significant byte of the retrieved > test_val.index, however, on big-endian machines it ends up retrieving > the most significant byte. > > Use the correct least significant byte offset on big-endian machines. > > Signed-off-by: Ilya Leoshkevich <iii@xxxxxxxxxxxxx> > --- > tools/testing/selftests/bpf/verifier/value_ptr_arith.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/tools/testing/selftests/bpf/verifier/value_ptr_arith.c b/tools/testing/selftests/bpf/verifier/value_ptr_arith.c > index c3de1a2c9dc5..3b221bb4b317 100644 > --- a/tools/testing/selftests/bpf/verifier/value_ptr_arith.c > +++ b/tools/testing/selftests/bpf/verifier/value_ptr_arith.c > @@ -183,7 +183,11 @@ > BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem), > BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1), > BPF_EXIT_INSN(), > +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ > BPF_LDX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, 0), > +#else > + BPF_LDX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, sizeof(int) - 1), > +#endif > BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0, 3), > BPF_MOV64_IMM(BPF_REG_2, 0), > BPF_MOV64_IMM(BPF_REG_3, 0x100000), > -- > 2.21.0 > In verifier directory, we mostly use __BYTE_ORDER macros. -bash-4.4$ pwd /home/yhs/work/net-next/tools/testing/selftests/bpf/verifier -bash-4.4$ grep __BYTE_ORDER * ctx_skb.c:#if __BYTE_ORDER == __LITTLE_ENDIAN ctx_skb.c:#if __BYTE_ORDER == __LITTLE_ENDIAN ctx_skb.c:#if __BYTE_ORDER == __LITTLE_ENDIAN ctx_skb.c:#if __BYTE_ORDER == __LITTLE_ENDIAN ctx_skb.c:#if __BYTE_ORDER == __LITTLE_ENDIAN ctx_skb.c:#if __BYTE_ORDER == __LITTLE_ENDIAN ctx_skb.c:#if __BYTE_ORDER == __LITTLE_ENDIAN lwt.c:#if __BYTE_ORDER == __LITTLE_ENDIAN perf_event_sample_period.c:#if __BYTE_ORDER == __LITTLE_ENDIAN perf_event_sample_period.c:#if __BYTE_ORDER == __LITTLE_ENDIAN perf_event_sample_period.c:#if __BYTE_ORDER == __LITTLE_ENDIAN -bash-4.4$ Your code above should also work (it requires gcc 4.6 and later, but we require newer gcc compiler anyway). Maybe if the above __BYTE_ORDER works for s360, maybe using that is better for consistency?