selftests/bpf: fix "alu with different scalars 1" on s390
Subsystems (5)
PATCH 1/1 selftests/bpf: fix "alu with different scalars 1" on s390
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.
--- tools/testing/selftests/bpf/verifier/value_ptr_arith.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/testing/selftests/bpf/verifier/value_ptr_arith.c +4 -0
@@ -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 ), +#endifBPF_JMP_IMM (BPF_JEQ ,BPF_REG_1 ,0 ,3 ),BPF_MOV64_IMM (BPF_REG_2 ,0 ), BPF_MOV64_IMM(BPF_REG_3, 0x100000),
Signature · 1 line
2.21.0
Quoted 29 lines · Ilya Leoshkevich
BPF_LDX_MEMis 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 <[email protected]>--- tools/testing/selftests/bpf/verifier/value_ptr_arith.c | 4 ++++ 1 file changed, 4 insertions(+)tools/testing/selftests/bpf/verifier/value_ptr_arith.c +4
-1@@ -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 ), +#endifBPF_JMP_IMM (BPF_JEQ ,BPF_REG_1 ,0 ,3 ),BPF_MOV64_IMM (BPF_REG_2 ,0 ), BPF_MOV64_IMM(BPF_REG_3, 0x100000), --
Quoted 2 lines
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?