Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Add testcase where 7th argment is struct

Add testcase where 7th argument is struct for architectures with 8 argument
registers, and increase the complexity of the struct.

Signed-off-by: Pu Lehui <pulehui@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Björn Töpel <bjorn@rivosinc.com>
Acked-by: Björn Töpel <bjorn@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/bpf/20240702121944.1091530-4-pulehui@huaweicloud.com

authored by

Pu Lehui and committed by
Daniel Borkmann
9474f72c 5d52ad36

+69
+1
tools/testing/selftests/bpf/DENYLIST.aarch64
··· 6 6 module_attach # prog 'kprobe_multi': failed to auto-attach: -95 7 7 fentry_test/fentry_many_args # fentry_many_args:FAIL:fentry_many_args_attach unexpected error: -524 8 8 fexit_test/fexit_many_args # fexit_many_args:FAIL:fexit_many_args_attach unexpected error: -524 9 + tracing_struct/struct_many_args # struct_many_args:FAIL:tracing_struct_many_args__attach unexpected error: -524 9 10 fill_link_info/kprobe_multi_link_info # bpf_program__attach_kprobe_multi_opts unexpected error: -95 10 11 fill_link_info/kretprobe_multi_link_info # bpf_program__attach_kprobe_multi_opts unexpected error: -95 11 12 fill_link_info/kprobe_multi_invalid_ubuff # bpf_program__attach_kprobe_multi_opts unexpected error: -95
+19
tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
··· 53 53 int b; 54 54 }; 55 55 56 + struct bpf_testmod_struct_arg_5 { 57 + char a; 58 + short b; 59 + int c; 60 + long d; 61 + }; 62 + 56 63 __bpf_hook_start(); 57 64 58 65 noinline int ··· 114 107 { 115 108 bpf_testmod_test_struct_arg_result = a + (long)b + c + d + 116 109 (long)e + f.a + f.b + g; 110 + return bpf_testmod_test_struct_arg_result; 111 + } 112 + 113 + noinline int 114 + bpf_testmod_test_struct_arg_9(u64 a, void *b, short c, int d, void *e, char f, 115 + short g, struct bpf_testmod_struct_arg_5 h, long i) 116 + { 117 + bpf_testmod_test_struct_arg_result = a + (long)b + c + d + (long)e + 118 + f + g + h.a + h.b + h.c + h.d + i; 117 119 return bpf_testmod_test_struct_arg_result; 118 120 } 119 121 ··· 321 305 struct bpf_testmod_struct_arg_2 struct_arg2 = {2, 3}; 322 306 struct bpf_testmod_struct_arg_3 *struct_arg3; 323 307 struct bpf_testmod_struct_arg_4 struct_arg4 = {21, 22}; 308 + struct bpf_testmod_struct_arg_5 struct_arg5 = {23, 24, 25, 26}; 324 309 int i = 1; 325 310 326 311 while (bpf_testmod_return_ptr(i)) ··· 336 319 (void *)20, struct_arg4); 337 320 (void)bpf_testmod_test_struct_arg_8(16, (void *)17, 18, 19, 338 321 (void *)20, struct_arg4, 23); 322 + (void)bpf_testmod_test_struct_arg_9(16, (void *)17, 18, 19, (void *)20, 323 + 21, 22, struct_arg5, 27); 339 324 340 325 (void)bpf_testmod_test_arg_ptr_to_struct(&struct_arg1_2); 341 326
+14
tools/testing/selftests/bpf/prog_tests/tracing_struct.c
··· 94 94 ASSERT_EQ(skel->bss->t8_g, 23, "t8:g"); 95 95 ASSERT_EQ(skel->bss->t8_ret, 156, "t8 ret"); 96 96 97 + ASSERT_EQ(skel->bss->t9_a, 16, "t9:a"); 98 + ASSERT_EQ(skel->bss->t9_b, 17, "t9:b"); 99 + ASSERT_EQ(skel->bss->t9_c, 18, "t9:c"); 100 + ASSERT_EQ(skel->bss->t9_d, 19, "t9:d"); 101 + ASSERT_EQ(skel->bss->t9_e, 20, "t9:e"); 102 + ASSERT_EQ(skel->bss->t9_f, 21, "t9:f"); 103 + ASSERT_EQ(skel->bss->t9_g, 22, "t9:f"); 104 + ASSERT_EQ(skel->bss->t9_h_a, 23, "t9:h.a"); 105 + ASSERT_EQ(skel->bss->t9_h_b, 24, "t9:h.b"); 106 + ASSERT_EQ(skel->bss->t9_h_c, 25, "t9:h.c"); 107 + ASSERT_EQ(skel->bss->t9_h_d, 26, "t9:h.d"); 108 + ASSERT_EQ(skel->bss->t9_i, 27, "t9:i"); 109 + ASSERT_EQ(skel->bss->t9_ret, 258, "t9 ret"); 110 + 97 111 destroy_skel: 98 112 tracing_struct_many_args__destroy(skel); 99 113 }
+35
tools/testing/selftests/bpf/progs/tracing_struct_many_args.c
··· 8 8 int b; 9 9 }; 10 10 11 + struct bpf_testmod_struct_arg_5 { 12 + char a; 13 + short b; 14 + int c; 15 + long d; 16 + }; 17 + 11 18 long t7_a, t7_b, t7_c, t7_d, t7_e, t7_f_a, t7_f_b, t7_ret; 12 19 long t8_a, t8_b, t8_c, t8_d, t8_e, t8_f_a, t8_f_b, t8_g, t8_ret; 20 + long t9_a, t9_b, t9_c, t9_d, t9_e, t9_f, t9_g, t9_h_a, t9_h_b, t9_h_c, t9_h_d, t9_i, t9_ret; 13 21 14 22 SEC("fentry/bpf_testmod_test_struct_arg_7") 15 23 int BPF_PROG2(test_struct_many_args_1, __u64, a, void *, b, short, c, int, d, ··· 62 54 int, ret) 63 55 { 64 56 t8_ret = ret; 57 + return 0; 58 + } 59 + 60 + SEC("fentry/bpf_testmod_test_struct_arg_9") 61 + int BPF_PROG2(test_struct_many_args_5, __u64, a, void *, b, short, c, int, d, void *, e, 62 + char, f, short, g, struct bpf_testmod_struct_arg_5, h, long, i) 63 + { 64 + t9_a = a; 65 + t9_b = (long)b; 66 + t9_c = c; 67 + t9_d = d; 68 + t9_e = (long)e; 69 + t9_f = f; 70 + t9_g = g; 71 + t9_h_a = h.a; 72 + t9_h_b = h.b; 73 + t9_h_c = h.c; 74 + t9_h_d = h.d; 75 + t9_i = i; 76 + return 0; 77 + } 78 + 79 + SEC("fexit/bpf_testmod_test_struct_arg_9") 80 + int BPF_PROG2(test_struct_many_args_6, __u64, a, void *, b, short, c, int, d, void *, e, 81 + char, f, short, g, struct bpf_testmod_struct_arg_5, h, long, i, int, ret) 82 + { 83 + t9_ret = ret; 65 84 return 0; 66 85 } 67 86