Skip to contentSkip to conversation

selftests/bpf: fix "alu with different scalars 1" on s390

PATCH Superseded Ilya Leoshkevich 4 participants 4 messages Jul 4, 2019 – Jul 15, 2019

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

---

v1->v2:
- use __BYTE_ORDER instead of __BYTE_ORDER__.

 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
index c3de1a2c9dc5..e5940c4e8b8f 100644
@@ -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 == __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),
Signature · 1 line
2.21.0
Acked-by Yonghong Song on v2 1/1
#1 lore raw
Quoted 8 lines · Ilya Leoshkevich

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.

Quoted 27 lines

---

v1->v2:
- use __BYTE_ORDER instead of __BYTE_ORDER__.

 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
index c3de1a2c9dc5..e5940c4e8b8f 100644
@@ -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 == __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

#2 lore raw
In reply to Ilya Leoshkevich
Quoted 21 lines · Ilya Leoshkevich

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.

---

v1->v2:
- use __BYTE_ORDER instead of __BYTE_ORDER__.

 tools/testing/selftests/bpf/verifier/value_ptr_arith.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/bpf/verifier/value_ptr_arith.c +0 -0
index c3de1a2c9dc5..e5940c4e8b8f 100644

tools/testing/selftests/bpf/verifier/value_ptr_arith.c line 190

Quoted 8 lines
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 == __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

I think tests should be arch and endian independent where possible. In this case test_val.index is 4 byte and 4 byte load should work just as well.

maintainer
#3 lore raw
Quoted 17 lines · Alexei Starovoitov
Quoted 16 lines · Ilya Leoshkevich

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.

---

v1->v2:
- use __BYTE_ORDER instead of __BYTE_ORDER__.

 tools/testing/selftests/bpf/verifier/value_ptr_arith.c | 4 ++++
 1 file changed, 4 insertions(+)
Quoted 16 lines

tools/testing/selftests/bpf/verifier/value_ptr_arith.c line 190

Quoted 13 lines
tools/testing/selftests/bpf/verifier/value_ptr_arith.c +4 -0
index c3de1a2c9dc5..e5940c4e8b8f 100644
@@ -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 == __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

I think tests should be arch and endian independent where possible. In this case test_val.index is 4 byte and 4 byte load should work just as well.

Yes, agree, this should be fixed with BPF_W as load.

Thanks,
Daniel