Skip to content

Commit e848869

Browse files
yonghong-songkernel-patches-bot
authored andcommitted
bpf: fix "unresolved symbol" build error with resolve_btfids
Michal reported a build failure likes below: BTFIDS vmlinux FAILED unresolved symbol tcp_timewait_sock make[1]: *** [/.../linux-5.9-rc7/Makefile:1176: vmlinux] Error 255 This error can be triggered when config has CONFIG_NET enabled but CONFIG_INET disabled. In this case, there is no user of structs inet_timewait_sock and tcp_timewait_sock and hence vmlinux BTF types are not generated for these two structures. To fix the problem, for two timewait structures, if CONFIG_INET=n, use BTF_ID_UNUSED instead of BTF_ID to skip btf id generation in resolve_btfids. Fixes: fce557b ("bpf: Make btf_sock_ids global") Reported-by: Michal Kubecek <[email protected]> Signed-off-by: Yonghong Song <[email protected]>
1 parent 584f2ed commit e848869

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

include/linux/btf_ids.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,23 +159,37 @@ extern struct btf_id_set name;
159159
* skc_to_*_sock() helpers. All these sockets should have
160160
* sock_common as the first argument in its memory layout.
161161
*/
162-
#define BTF_SOCK_TYPE_xxx \
162+
163+
#define __BTF_SOCK_TYPE_xxx \
163164
BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \
164165
BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \
165166
BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \
166-
BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \
167167
BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \
168168
BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \
169169
BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \
170170
BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \
171171
BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \
172-
BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \
173172
BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \
174173
BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \
175174
BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)
176175

176+
#ifdef CONFIG_INET
177+
#define __BTF_SOCK_TW_TYPE_xxx \
178+
BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \
179+
BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)
180+
#else
181+
#define __BTF_SOCK_TW_TYPE_xxx \
182+
BTF_SOCK_TYPE_UNUSED(BTF_SOCK_TYPE_INET_TW) \
183+
BTF_SOCK_TYPE_UNUSED(BTF_SOCK_TYPE_TCP_TW)
184+
#endif
185+
186+
#define BTF_SOCK_TYPE_xxx \
187+
__BTF_SOCK_TYPE_xxx \
188+
__BTF_SOCK_TW_TYPE_xxx
189+
177190
enum {
178191
#define BTF_SOCK_TYPE(name, str) name,
192+
#define BTF_SOCK_TYPE_UNUSED(name) name,
179193
BTF_SOCK_TYPE_xxx
180194
#undef BTF_SOCK_TYPE
181195
MAX_BTF_SOCK_TYPE,

net/core/filter.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10158,6 +10158,7 @@ void bpf_prog_change_xdp(struct bpf_prog *prev_prog, struct bpf_prog *prog)
1015810158
#ifdef CONFIG_DEBUG_INFO_BTF
1015910159
BTF_ID_LIST_GLOBAL(btf_sock_ids)
1016010160
#define BTF_SOCK_TYPE(name, type) BTF_ID(struct, type)
10161+
#define BTF_SOCK_TYPE_UNUSED(name) BTF_ID_UNUSED
1016110162
BTF_SOCK_TYPE_xxx
1016210163
#undef BTF_SOCK_TYPE
1016310164
#else

0 commit comments

Comments
 (0)