Commit 7ff5fea
libbpf: fix error when st-prefix_ops and ops from differ btf
When a struct_ops named xxx_ops was registered by a module, and
it will be used in both built-in modules and the module itself,
so that the btf_type of xxx_ops will be present in btf_vmlinux
instead of in btf_mod, which means that the btf_type of
bpf_struct_ops_xxx_ops and xxx_ops will not be in the same btf.
Here are four possible case:
+--------+---------------+-------------+---------------------------------+
| | st_ops_xxx_ops| xxx_ops | |
+--------+---------------+-------------+---------------------------------+
| case 0 | btf_vmlinux | bft_vmlinux | be used and reg only in vmlinux |
+--------+---------------+-------------+---------------------------------+
| case 1 | btf_vmlinux | bpf_mod | INVALID |
+--------+---------------+-------------+---------------------------------+
| case 2 | btf_mod | btf_vmlinux | reg in mod but be used both in |
| | | | vmlinux and mod. |
+--------+---------------+-------------+---------------------------------+
| case 3 | btf_mod | btf_mod | be used and reg only in mod |
+--------+---------------+-------------+---------------------------------+
At present, cases 0, 1, and 3 can be correctly identified, because
st_ops_xxx_ops is searched from the same btf with xxx_ops. In order to
handle case 2 correctly without affecting other cases, we cannot simply
change the search method for st_ops_xxx_ops from find_btf_by_prefix_kind()
to find_ksym_btf_id(), because in this way, case 1 will not be
recognized anymore.
To address the issue, we always look for st_ops_xxx_ops first,
figure out the btf, and then look for xxx_ops with the very btf to avoid
such issue.
Fixes: 590a008 ("bpf: libbpf: Add STRUCT_OPS support")
Signed-off-by: D. Wythe <[email protected]>
Acked-by: Andrii Nakryiko <[email protected]>1 parent 2b4961e commit 7ff5fea
1 file changed
+18
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1013 | 1013 | | |
1014 | 1014 | | |
1015 | 1015 | | |
1016 | | - | |
| 1016 | + | |
1017 | 1017 | | |
1018 | 1018 | | |
1019 | 1019 | | |
1020 | 1020 | | |
1021 | 1021 | | |
1022 | | - | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
1026 | | - | |
1027 | | - | |
1028 | | - | |
1029 | | - | |
| 1022 | + | |
| 1023 | + | |
1030 | 1024 | | |
1031 | | - | |
1032 | | - | |
1033 | | - | |
1034 | | - | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
1035 | 1029 | | |
1036 | | - | |
1037 | | - | |
| 1030 | + | |
1038 | 1031 | | |
1039 | | - | |
1040 | | - | |
| 1032 | + | |
1041 | 1033 | | |
1042 | 1034 | | |
1043 | 1035 | | |
1044 | 1036 | | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
1045 | 1044 | | |
1046 | 1045 | | |
1047 | 1046 | | |
| |||
1054 | 1053 | | |
1055 | 1054 | | |
1056 | 1055 | | |
1057 | | - | |
1058 | | - | |
| 1056 | + | |
| 1057 | + | |
1059 | 1058 | | |
1060 | 1059 | | |
1061 | 1060 | | |
| |||
0 commit comments