@@ -75,6 +75,12 @@ struct kfunc_btf_id_pair {
75
75
int insn_idx ;
76
76
};
77
77
78
+ struct ldx_offset {
79
+ const char * strct ;
80
+ const char * field ;
81
+ int insn_idx ;
82
+ };
83
+
78
84
struct bpf_test {
79
85
const char * descr ;
80
86
struct bpf_insn insns [MAX_INSNS ];
@@ -102,6 +108,7 @@ struct bpf_test {
102
108
int fixup_map_ringbuf [MAX_FIXUPS ];
103
109
int fixup_map_timer [MAX_FIXUPS ];
104
110
struct kfunc_btf_id_pair fixup_kfunc_btf_id [MAX_FIXUPS ];
111
+ struct ldx_offset fixup_ldx [MAX_FIXUPS ];
105
112
/* Expected verifier log output for result REJECT or VERBOSE_ACCEPT.
106
113
* Can be a tab-separated sequence of expected strings. An empty string
107
114
* means no log verification.
@@ -755,6 +762,7 @@ static void do_test_fixup(struct bpf_test *test, enum bpf_prog_type prog_type,
755
762
int * fixup_map_ringbuf = test -> fixup_map_ringbuf ;
756
763
int * fixup_map_timer = test -> fixup_map_timer ;
757
764
struct kfunc_btf_id_pair * fixup_kfunc_btf_id = test -> fixup_kfunc_btf_id ;
765
+ struct ldx_offset * fixup_ldx = test -> fixup_ldx ;
758
766
759
767
if (test -> fill_helper ) {
760
768
test -> fill_insns = calloc (MAX_TEST_INSNS , sizeof (struct bpf_insn ));
@@ -967,6 +975,50 @@ static void do_test_fixup(struct bpf_test *test, enum bpf_prog_type prog_type,
967
975
fixup_kfunc_btf_id ++ ;
968
976
} while (fixup_kfunc_btf_id -> kfunc );
969
977
}
978
+
979
+ if (fixup_ldx -> strct ) {
980
+ const struct btf_member * memb ;
981
+ const struct btf_type * tp ;
982
+ const char * name ;
983
+ struct btf * btf ;
984
+ int btf_id ;
985
+ int off ;
986
+ int i ;
987
+
988
+ btf = btf__load_vmlinux_btf ();
989
+
990
+ do {
991
+ off = -1 ;
992
+ if (!btf )
993
+ goto next_ldx ;
994
+
995
+ btf_id = btf__find_by_name_kind (btf ,
996
+ fixup_ldx -> strct ,
997
+ BTF_KIND_STRUCT );
998
+ if (btf_id < 0 )
999
+ goto next_ldx ;
1000
+
1001
+ tp = btf__type_by_id (btf , btf_id );
1002
+ memb = btf_members (tp );
1003
+
1004
+ for (i = 0 ; i < btf_vlen (tp ); i ++ ) {
1005
+ name = btf__name_by_offset (btf ,
1006
+ memb -> name_off );
1007
+ if (strcmp (fixup_ldx -> field , name ) == 0 ) {
1008
+ off = memb -> offset / 8 ;
1009
+ break ;
1010
+ }
1011
+ memb ++ ;
1012
+ }
1013
+
1014
+ next_ldx :
1015
+ prog [fixup_ldx -> insn_idx ].off = off ;
1016
+ fixup_ldx ++ ;
1017
+
1018
+ } while (fixup_ldx -> strct );
1019
+
1020
+ btf__free (btf );
1021
+ }
970
1022
}
971
1023
972
1024
struct libcap {
@@ -1131,7 +1183,7 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
1131
1183
opts .log_level = 4 ;
1132
1184
opts .prog_flags = pflags ;
1133
1185
1134
- if (prog_type == BPF_PROG_TYPE_TRACING && test -> kfunc ) {
1186
+ if (test -> kfunc ) {
1135
1187
int attach_btf_id ;
1136
1188
1137
1189
attach_btf_id = libbpf_find_vmlinux_btf_id (test -> kfunc ,
0 commit comments