hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/tools/testing/selftests/bpf/prog_tests/align.c
....@@ -2,7 +2,7 @@
22 #include <test_progs.h>
33
44 #define MAX_INSNS 512
5
-#define MAX_MATCHES 16
5
+#define MAX_MATCHES 24
66
77 struct bpf_reg_match {
88 unsigned int line;
....@@ -267,6 +267,7 @@
267267 */
268268 BPF_MOV64_REG(BPF_REG_5, BPF_REG_2),
269269 BPF_ALU64_REG(BPF_ADD, BPF_REG_5, BPF_REG_6),
270
+ BPF_MOV64_REG(BPF_REG_4, BPF_REG_5),
270271 BPF_ALU64_IMM(BPF_ADD, BPF_REG_5, 14),
271272 BPF_MOV64_REG(BPF_REG_4, BPF_REG_5),
272273 BPF_ALU64_IMM(BPF_ADD, BPF_REG_4, 4),
....@@ -280,6 +281,7 @@
280281 BPF_MOV64_REG(BPF_REG_5, BPF_REG_2),
281282 BPF_ALU64_IMM(BPF_ADD, BPF_REG_5, 14),
282283 BPF_ALU64_REG(BPF_ADD, BPF_REG_5, BPF_REG_6),
284
+ BPF_MOV64_REG(BPF_REG_4, BPF_REG_5),
283285 BPF_ALU64_IMM(BPF_ADD, BPF_REG_5, 4),
284286 BPF_ALU64_REG(BPF_ADD, BPF_REG_5, BPF_REG_6),
285287 BPF_MOV64_REG(BPF_REG_4, BPF_REG_5),
....@@ -311,44 +313,52 @@
311313 {15, "R4=pkt(id=1,off=18,r=18,umax_value=1020,var_off=(0x0; 0x3fc))"},
312314 {15, "R5=pkt(id=1,off=14,r=18,umax_value=1020,var_off=(0x0; 0x3fc))"},
313315 /* Variable offset is added to R5 packet pointer,
314
- * resulting in auxiliary alignment of 4.
316
+ * resulting in auxiliary alignment of 4. To avoid BPF
317
+ * verifier's precision backtracking logging
318
+ * interfering we also have a no-op R4 = R5
319
+ * instruction to validate R5 state. We also check
320
+ * that R4 is what it should be in such case.
315321 */
316
- {18, "R5_w=pkt(id=2,off=0,r=0,umax_value=1020,var_off=(0x0; 0x3fc))"},
322
+ {19, "R4_w=pkt(id=2,off=0,r=0,umax_value=1020,var_off=(0x0; 0x3fc))"},
323
+ {19, "R5_w=pkt(id=2,off=0,r=0,umax_value=1020,var_off=(0x0; 0x3fc))"},
317324 /* Constant offset is added to R5, resulting in
318325 * reg->off of 14.
319326 */
320
- {19, "R5_w=pkt(id=2,off=14,r=0,umax_value=1020,var_off=(0x0; 0x3fc))"},
327
+ {20, "R5_w=pkt(id=2,off=14,r=0,umax_value=1020,var_off=(0x0; 0x3fc))"},
321328 /* At the time the word size load is performed from R5,
322329 * its total fixed offset is NET_IP_ALIGN + reg->off
323330 * (14) which is 16. Then the variable offset is 4-byte
324331 * aligned, so the total offset is 4-byte aligned and
325332 * meets the load's requirements.
326333 */
327
- {23, "R4=pkt(id=2,off=18,r=18,umax_value=1020,var_off=(0x0; 0x3fc))"},
328
- {23, "R5=pkt(id=2,off=14,r=18,umax_value=1020,var_off=(0x0; 0x3fc))"},
334
+ {24, "R4=pkt(id=2,off=18,r=18,umax_value=1020,var_off=(0x0; 0x3fc))"},
335
+ {24, "R5=pkt(id=2,off=14,r=18,umax_value=1020,var_off=(0x0; 0x3fc))"},
329336 /* Constant offset is added to R5 packet pointer,
330337 * resulting in reg->off value of 14.
331338 */
332
- {26, "R5_w=pkt(id=0,off=14,r=8"},
339
+ {27, "R5_w=pkt(id=0,off=14,r=8"},
333340 /* Variable offset is added to R5, resulting in a
334
- * variable offset of (4n).
341
+ * variable offset of (4n). See comment for insn #19
342
+ * for R4 = R5 trick.
335343 */
336
- {27, "R5_w=pkt(id=3,off=14,r=0,umax_value=1020,var_off=(0x0; 0x3fc))"},
344
+ {29, "R4_w=pkt(id=3,off=14,r=0,umax_value=1020,var_off=(0x0; 0x3fc))"},
345
+ {29, "R5_w=pkt(id=3,off=14,r=0,umax_value=1020,var_off=(0x0; 0x3fc))"},
337346 /* Constant is added to R5 again, setting reg->off to 18. */
338
- {28, "R5_w=pkt(id=3,off=18,r=0,umax_value=1020,var_off=(0x0; 0x3fc))"},
347
+ {30, "R5_w=pkt(id=3,off=18,r=0,umax_value=1020,var_off=(0x0; 0x3fc))"},
339348 /* And once more we add a variable; resulting var_off
340349 * is still (4n), fixed offset is not changed.
341350 * Also, we create a new reg->id.
342351 */
343
- {29, "R5_w=pkt(id=4,off=18,r=0,umax_value=2040,var_off=(0x0; 0x7fc)"},
352
+ {32, "R4_w=pkt(id=4,off=18,r=0,umax_value=2040,var_off=(0x0; 0x7fc)"},
353
+ {32, "R5_w=pkt(id=4,off=18,r=0,umax_value=2040,var_off=(0x0; 0x7fc)"},
344354 /* At the time the word size load is performed from R5,
345355 * its total fixed offset is NET_IP_ALIGN + reg->off (18)
346356 * which is 20. Then the variable offset is (4n), so
347357 * the total offset is 4-byte aligned and meets the
348358 * load's requirements.
349359 */
350
- {33, "R4=pkt(id=4,off=22,r=22,umax_value=2040,var_off=(0x0; 0x7fc)"},
351
- {33, "R5=pkt(id=4,off=18,r=22,umax_value=2040,var_off=(0x0; 0x7fc)"},
360
+ {35, "R4=pkt(id=4,off=22,r=22,umax_value=2040,var_off=(0x0; 0x7fc)"},
361
+ {35, "R5=pkt(id=4,off=18,r=22,umax_value=2040,var_off=(0x0; 0x7fc)"},
352362 },
353363 },
354364 {