Skip to contentSkip to conversation

bpf: fix "unresolved symbol" build error with resolve_btfids

PATCH Superseded Yonghong Song 3 participants 8 messages Sep 30, 2020 – Oct 1, 2020

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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, omit the above two types for BTF_SOCK_TYPE_xxx macro if CONFIG_INET is not defined.

Fixes fce557bcef11 ("bpf: Make btf_sock_ids global")
---
 include/linux/btf_ids.h | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
include/linux/btf_ids.h +16 -4
index 4867d549e3c1..d9a1e18d0921 100644
@@ -102,24 +102,36 @@ asm(							\
  * skc_to_*_sock() helpers. All these sockets should have
  * sock_common as the first argument in its memory layout.
  */
-#define BTF_SOCK_TYPE_xxx \
+
+#define __BTF_SOCK_TYPE_xxx \
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock)			\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock)	\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock)	\
-	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)	\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock)			\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock)				\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common)		\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock)			\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock)		\
-	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)		\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock)			\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock)			\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)
 
+#define __BTF_SOCK_TW_TYPE_xxx \
+	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)	\
+	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)
+
+#ifdef CONFIG_INET
+#define BTF_SOCK_TYPE_xxx						\
+	__BTF_SOCK_TYPE_xxx						\
+	__BTF_SOCK_TW_TYPE_xxx
+#else
+#define BTF_SOCK_TYPE_xxx	__BTF_SOCK_TYPE_xxx
+#endif
+
 enum {
 #define BTF_SOCK_TYPE(name, str) name,
-BTF_SOCK_TYPE_xxx
+__BTF_SOCK_TYPE_xxx
+__BTF_SOCK_TW_TYPE_xxx
 #undef BTF_SOCK_TYPE
 MAX_BTF_SOCK_TYPE,
 };
Signature · 1 line
2.24.1
#1 lore raw
Quoted 53 lines · Yonghong Song

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, omit the above two types for BTF_SOCK_TYPE_xxx macro if CONFIG_INET is not defined.

Fixes fce557bcef11 ("bpf: Make btf_sock_ids global")
---
 include/linux/btf_ids.h | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
include/linux/btf_ids.h +9 -3
index 4867d549e3c1..d9a1e18d0921 100644
@@ -102,24 +102,36 @@ asm(                                                      \
  * skc_to_*_sock() helpers. All these sockets should have
  * sock_common as the first argument in its memory layout.
  */
-#define BTF_SOCK_TYPE_xxx \
+
+#define __BTF_SOCK_TYPE_xxx \
        BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock)                    \
        BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock)    \
        BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock)        \
-       BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)        \
        BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock)                  \
        BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock)                         \
        BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common)           \
        BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock)                      \
        BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock)          \
-       BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)          \
        BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock)                    \
        BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock)                      \
        BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)
 
+#define __BTF_SOCK_TW_TYPE_xxx \
+       BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)        \
+       BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)
+
+#ifdef CONFIG_INET
+#define BTF_SOCK_TYPE_xxx                                              \
+       __BTF_SOCK_TYPE_xxx                                             \

include/linux/btf_ids.h asm( \ · line 134

Quoted 10 lines
include/linux/btf_ids.h +7 -1
+       __BTF_SOCK_TW_TYPE_xxx
+#else
+#define BTF_SOCK_TYPE_xxx      __BTF_SOCK_TYPE_xxx
+#endif
+
 enum {
 #define BTF_SOCK_TYPE(name, str) name,
-BTF_SOCK_TYPE_xxx
+__BTF_SOCK_TYPE_xxx
+__BTF_SOCK_TW_TYPE_xxx

Why BTF_SOCK_TYPE_xxx doesn't still work here after the above changes?

Quoted 6 lines
include/linux/btf_ids.h +0 -1
 #undef BTF_SOCK_TYPE
 MAX_BTF_SOCK_TYPE,
 };
--

2.24.1

#2 lore raw
Quoted 58 lines · Andrii Nakryiko
Quoted 57 lines · Yonghong Song

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, omit the above two types for BTF_SOCK_TYPE_xxx macro if CONFIG_INET is not defined.

Fixes fce557bcef11 ("bpf: Make btf_sock_ids global")
---
  include/linux/btf_ids.h | 20 ++++++++++++++++----
  1 file changed, 16 insertions(+), 4 deletions(-)
include/linux/btf_ids.h +13 -3
index 4867d549e3c1..d9a1e18d0921 100644
@@ -102,24 +102,36 @@ asm(                                                      \
   * skc_to_*_sock() helpers. All these sockets should have
   * sock_common as the first argument in its memory layout.
   */
-#define BTF_SOCK_TYPE_xxx \
+
+#define __BTF_SOCK_TYPE_xxx \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock)                    \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock)    \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock)        \
-       BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)        \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock)                  \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock)                         \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common)           \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock)                      \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock)          \
-       BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)          \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock)                    \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock)                      \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)
 
+#define __BTF_SOCK_TW_TYPE_xxx \
+       BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)        \
+       BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)
+
+#ifdef CONFIG_INET
+#define BTF_SOCK_TYPE_xxx                                              \
+       __BTF_SOCK_TYPE_xxx                                             \
+       __BTF_SOCK_TW_TYPE_xxx
+#else
+#define BTF_SOCK_TYPE_xxx      __BTF_SOCK_TYPE_xxx
+#endif
Quoted 8 lines

include/linux/btf_ids.h asm( \ · line 134

Quoted 6 lines
include/linux/btf_ids.h +3 -1
+
  enum {
  #define BTF_SOCK_TYPE(name, str) name,
-BTF_SOCK_TYPE_xxx
+__BTF_SOCK_TYPE_xxx
+__BTF_SOCK_TW_TYPE_xxx

Why BTF_SOCK_TYPE_xxx doesn't still work here after the above changes?

The macro, e.g., BTF_SOCK_TYPE_TCP_TW, still needed to be defined as it is used to get the location for btf_id.

const struct bpf_func_proto bpf_skc_to_tcp_timewait_sock_proto = {

        .func                   = bpf_skc_to_tcp_timewait_sock,
        .gpl_only               = false,
        .ret_type               = RET_PTR_TO_BTF_ID_OR_NULL,
        .arg1_type              = ARG_PTR_TO_BTF_ID_SOCK_COMMON,
        .ret_btf_id             = &btf_sock_ids[BTF_SOCK_TYPE_TCP_TW],

};

If CONFIG_INET is not defined, bpf_sock_ids[BTF_SOCK_TYPE_TCP_TW] will be 0.

Quoted 7 lines
Quoted 7 lines
include/linux/btf_ids.h +0 -1
  #undef BTF_SOCK_TYPE
  MAX_BTF_SOCK_TYPE,
  };
--

2.24.1

#3 lore raw
Quoted 71 lines · Yonghong Song
Quoted 58 lines · Andrii Nakryiko
Quoted 57 lines · Yonghong Song

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, omit the above two types for BTF_SOCK_TYPE_xxx macro if CONFIG_INET is not defined.

Fixes fce557bcef11 ("bpf: Make btf_sock_ids global")
---
  include/linux/btf_ids.h | 20 ++++++++++++++++----
  1 file changed, 16 insertions(+), 4 deletions(-)
include/linux/btf_ids.h +13 -3
index 4867d549e3c1..d9a1e18d0921 100644
@@ -102,24 +102,36 @@ asm(                                                      \
   * skc_to_*_sock() helpers. All these sockets should have
   * sock_common as the first argument in its memory layout.
   */
-#define BTF_SOCK_TYPE_xxx \
+
+#define __BTF_SOCK_TYPE_xxx \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock)                    \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock)    \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock)        \
-       BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)        \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock)                  \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock)                         \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common)           \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock)                      \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock)          \
-       BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)          \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock)                    \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock)                      \
         BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)
 
+#define __BTF_SOCK_TW_TYPE_xxx \
+       BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)        \
+       BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)
+
+#ifdef CONFIG_INET
+#define BTF_SOCK_TYPE_xxx                                              \
+       __BTF_SOCK_TYPE_xxx                                             \
+       __BTF_SOCK_TW_TYPE_xxx
+#else
+#define BTF_SOCK_TYPE_xxx      __BTF_SOCK_TYPE_xxx
+#endif
Quoted 8 lines

include/linux/btf_ids.h asm( \ · line 134

Quoted 6 lines
include/linux/btf_ids.h +3 -1
+
  enum {
  #define BTF_SOCK_TYPE(name, str) name,
-BTF_SOCK_TYPE_xxx
+__BTF_SOCK_TYPE_xxx
+__BTF_SOCK_TW_TYPE_xxx

Why BTF_SOCK_TYPE_xxx doesn't still work here after the above changes?

Quoted 2 lines

The macro, e.g., BTF_SOCK_TYPE_TCP_TW, still needed to be defined as it is used to get the location for btf_id.

Ah, right, so you want those here unconditionally, even if CONFIG_INET is not defined. Missed that. Might be worth leaving a short comment.

Otherwise LGTM.

Quoted 19 lines

const struct bpf_func_proto bpf_skc_to_tcp_timewait_sock_proto = {

         .func                   = bpf_skc_to_tcp_timewait_sock,
         .gpl_only               = false,
         .ret_type               = RET_PTR_TO_BTF_ID_OR_NULL,
         .arg1_type              = ARG_PTR_TO_BTF_ID_SOCK_COMMON,
         .ret_btf_id             = &btf_sock_ids[BTF_SOCK_TYPE_TCP_TW],

};

If CONFIG_INET is not defined, bpf_sock_ids[BTF_SOCK_TYPE_TCP_TW] will be 0.

Quoted 7 lines
Quoted 7 lines
include/linux/btf_ids.h +0 -1
  #undef BTF_SOCK_TYPE
  MAX_BTF_SOCK_TYPE,
  };
--

2.24.1

#4 lore raw
In reply to Yonghong Song
Quoted 45 lines · Yonghong Song

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, omit the above two types for BTF_SOCK_TYPE_xxx macro if CONFIG_INET is not defined.

Fixes fce557bcef11 ("bpf: Make btf_sock_ids global")
---
 include/linux/btf_ids.h | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
include/linux/btf_ids.h +2 -3
index 4867d549e3c1..d9a1e18d0921 100644
@@ -102,24 +102,36 @@ asm(							\
  * skc_to_*_sock() helpers. All these sockets should have
  * sock_common as the first argument in its memory layout.
  */
-#define BTF_SOCK_TYPE_xxx \
+
+#define __BTF_SOCK_TYPE_xxx \
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock)			\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock)	\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock)	\
-	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)	\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock)			\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock)				\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common)		\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock)			\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock)		\
-	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)		\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock)			\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock)			\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)
 

include/linux/btf_ids.h asm( \ · line 128

Quoted 10 lines
include/linux/btf_ids.h +10 -0
+#define __BTF_SOCK_TW_TYPE_xxx \
+	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)	\
+	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)
+
+#ifdef CONFIG_INET
+#define BTF_SOCK_TYPE_xxx						\
+	__BTF_SOCK_TYPE_xxx						\
+	__BTF_SOCK_TW_TYPE_xxx
+#else
+#define BTF_SOCK_TYPE_xxx	__BTF_SOCK_TYPE_xxx

BTF_SOCK_TYPE_xxx is used in BTF_ID_LIST_GLOBAL(btf_sock_ids) in filter.c which does not include BTF_SOCK_TYPE_TCP_TW.
However, btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] is still used
in bpf_skc_to_tcp_timewait_sock_proto.

include/linux/btf_ids.h asm( \ · line 134

Quoted 7 lines
include/linux/btf_ids.h +4 -1
+#endif
+
 enum {
 #define BTF_SOCK_TYPE(name, str) name,
-BTF_SOCK_TYPE_xxx
+__BTF_SOCK_TYPE_xxx
+__BTF_SOCK_TW_TYPE_xxx

BTF_SOCK_TYPE_TCP_TW is at the end of this enum.

Would btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] always be 0?

Quoted 6 lines
include/linux/btf_ids.h +0 -0
 #undef BTF_SOCK_TYPE
 MAX_BTF_SOCK_TYPE,
 };
Signature · 1 line
2.24.1
#5 lore raw
Quoted 70 lines · Martin KaFai Lau
Quoted 45 lines · Yonghong Song

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, omit the above two types for BTF_SOCK_TYPE_xxx macro if CONFIG_INET is not defined.

Fixes fce557bcef11 ("bpf: Make btf_sock_ids global")
---
  include/linux/btf_ids.h | 20 ++++++++++++++++----
  1 file changed, 16 insertions(+), 4 deletions(-)
include/linux/btf_ids.h +2 -3
index 4867d549e3c1..d9a1e18d0921 100644
@@ -102,24 +102,36 @@ asm(							\
   * skc_to_*_sock() helpers. All these sockets should have
   * sock_common as the first argument in its memory layout.
   */
-#define BTF_SOCK_TYPE_xxx \
+
+#define __BTF_SOCK_TYPE_xxx \
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock)			\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock)	\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock)	\
-	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)	\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock)			\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock)				\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common)		\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock)			\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock)		\
-	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)		\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock)			\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock)			\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)
 

include/linux/btf_ids.h asm( \ · line 128

Quoted 10 lines
include/linux/btf_ids.h +10 -0
+#define __BTF_SOCK_TW_TYPE_xxx \
+	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)	\
+	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)
+
+#ifdef CONFIG_INET
+#define BTF_SOCK_TYPE_xxx						\
+	__BTF_SOCK_TYPE_xxx						\
+	__BTF_SOCK_TW_TYPE_xxx
+#else
+#define BTF_SOCK_TYPE_xxx	__BTF_SOCK_TYPE_xxx

BTF_SOCK_TYPE_xxx is used in BTF_ID_LIST_GLOBAL(btf_sock_ids) in filter.c which does not include BTF_SOCK_TYPE_TCP_TW.
However, btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] is still used
in bpf_skc_to_tcp_timewait_sock_proto.

include/linux/btf_ids.h asm( \ · line 134

Quoted 7 lines
include/linux/btf_ids.h +4 -1
+#endif
+
  enum {
  #define BTF_SOCK_TYPE(name, str) name,
-BTF_SOCK_TYPE_xxx
+__BTF_SOCK_TYPE_xxx
+__BTF_SOCK_TW_TYPE_xxx

BTF_SOCK_TYPE_TCP_TW is at the end of this enum.

Quoted 1 line

Would btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] always be 0?

No. If CONFIG_INET is y, the above BTF_SOCK_TYPE_xxx contains
__BTF_SOCK_TW_TYPE_xxx
and
btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] will be calculated properly.

But if CONFIG_INET is n, then BTF_SOCK_TYPE_xxx will not contain
__BTF_SOCK_TW_TYPE_xxx
so btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] will have default value 0 as btf_sock_ids is a global.

Will send v2 to add some comments to make it easy to understand.

Quoted 7 lines
Quoted 7 lines
include/linux/btf_ids.h +0 -0
  #undef BTF_SOCK_TYPE
  MAX_BTF_SOCK_TYPE,
  };
Signature · 1 line
2.24.1
#6 lore raw
Quoted 79 lines · Yonghong Song
Quoted 69 lines · Martin KaFai Lau
Quoted 44 lines · Yonghong Song

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, omit the above two types for BTF_SOCK_TYPE_xxx macro if CONFIG_INET is not defined.

Fixes fce557bcef11 ("bpf: Make btf_sock_ids global")
---
  include/linux/btf_ids.h | 20 ++++++++++++++++----
  1 file changed, 16 insertions(+), 4 deletions(-)
include/linux/btf_ids.h +2 -3
index 4867d549e3c1..d9a1e18d0921 100644
@@ -102,24 +102,36 @@ asm(							\
   * skc_to_*_sock() helpers. All these sockets should have
   * sock_common as the first argument in its memory layout.
   */
-#define BTF_SOCK_TYPE_xxx \
+
+#define __BTF_SOCK_TYPE_xxx \
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock)			\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock)	\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock)	\
-	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)	\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock)			\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock)				\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common)		\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock)			\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock)		\
-	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)		\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock)			\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock)			\
  	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)

include/linux/btf_ids.h asm( \ · line 127

Quoted 10 lines
include/linux/btf_ids.h +10 -0
+#define __BTF_SOCK_TW_TYPE_xxx \
+	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)	\
+	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)
+
+#ifdef CONFIG_INET
+#define BTF_SOCK_TYPE_xxx						\
+	__BTF_SOCK_TYPE_xxx						\
+	__BTF_SOCK_TW_TYPE_xxx
+#else
+#define BTF_SOCK_TYPE_xxx	__BTF_SOCK_TYPE_xxx

BTF_SOCK_TYPE_xxx is used in BTF_ID_LIST_GLOBAL(btf_sock_ids) in filter.c which does not include BTF_SOCK_TYPE_TCP_TW.
However, btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] is still used
in bpf_skc_to_tcp_timewait_sock_proto.

include/linux/btf_ids.h asm( \ · line 134

Quoted 7 lines
include/linux/btf_ids.h +4 -1
+#endif
+
  enum {
  #define BTF_SOCK_TYPE(name, str) name,
-BTF_SOCK_TYPE_xxx
+__BTF_SOCK_TYPE_xxx
+__BTF_SOCK_TW_TYPE_xxx

BTF_SOCK_TYPE_TCP_TW is at the end of this enum.

Quoted 1 line

Would btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] always be 0?

No. If CONFIG_INET is y, the above BTF_SOCK_TYPE_xxx contains
__BTF_SOCK_TW_TYPE_xxx
and
btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] will be calculated properly.

Quoted 4 lines

But if CONFIG_INET is n, then BTF_SOCK_TYPE_xxx will not contain
__BTF_SOCK_TW_TYPE_xxx
so btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] will have default value 0 as btf_sock_ids is a global.

I could be missing something here.
Why btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] must be 0? How does BTF_ID_LIST_GLOBAL() know there is a btf_sock_ids[BTF_SOCK_TYPE_TCP_TW]?
I would expect at least BTF_ID_UNUSED is required. Otherwise, the value will be whatever follow the last btf_sock_ids[BTF_SOCK_TYPE_UDP6].

Quoted 10 lines

Will send v2 to add some comments to make it easy to understand.

Quoted 7 lines
Quoted 7 lines
include/linux/btf_ids.h +0 -0
  #undef BTF_SOCK_TYPE
  MAX_BTF_SOCK_TYPE,
  };
Signature · 1 line
2.24.1
#7 lore raw
Quoted 84 lines · Martin KaFai Lau
Quoted 79 lines · Yonghong Song
Quoted 69 lines · Martin KaFai Lau
Quoted 44 lines · Yonghong Song

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, omit the above two types for BTF_SOCK_TYPE_xxx macro if CONFIG_INET is not defined.

Fixes fce557bcef11 ("bpf: Make btf_sock_ids global")
---
   include/linux/btf_ids.h | 20 ++++++++++++++++----
   1 file changed, 16 insertions(+), 4 deletions(-)
include/linux/btf_ids.h +2 -3
index 4867d549e3c1..d9a1e18d0921 100644
@@ -102,24 +102,36 @@ asm(							\
    * skc_to_*_sock() helpers. All these sockets should have
    * sock_common as the first argument in its memory layout.
    */
-#define BTF_SOCK_TYPE_xxx \
+
+#define __BTF_SOCK_TYPE_xxx \
   	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock)			\
   	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock)	\
   	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock)	\
-	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)	\
   	BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock)			\
   	BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock)				\
   	BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common)		\
   	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock)			\
   	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock)		\
-	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)		\
   	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock)			\
   	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock)			\
   	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)

include/linux/btf_ids.h asm( \ · line 127

Quoted 10 lines
include/linux/btf_ids.h +10 -0
+#define __BTF_SOCK_TW_TYPE_xxx \
+	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)	\
+	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)
+
+#ifdef CONFIG_INET
+#define BTF_SOCK_TYPE_xxx						\
+	__BTF_SOCK_TYPE_xxx						\
+	__BTF_SOCK_TW_TYPE_xxx
+#else
+#define BTF_SOCK_TYPE_xxx	__BTF_SOCK_TYPE_xxx

BTF_SOCK_TYPE_xxx is used in BTF_ID_LIST_GLOBAL(btf_sock_ids) in filter.c which does not include BTF_SOCK_TYPE_TCP_TW.
However, btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] is still used
in bpf_skc_to_tcp_timewait_sock_proto.

include/linux/btf_ids.h asm( \ · line 134

Quoted 7 lines
include/linux/btf_ids.h +4 -1
+#endif
+
   enum {
   #define BTF_SOCK_TYPE(name, str) name,
-BTF_SOCK_TYPE_xxx
+__BTF_SOCK_TYPE_xxx
+__BTF_SOCK_TW_TYPE_xxx

BTF_SOCK_TYPE_TCP_TW is at the end of this enum.

Quoted 1 line

Would btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] always be 0?

No. If CONFIG_INET is y, the above BTF_SOCK_TYPE_xxx contains
__BTF_SOCK_TW_TYPE_xxx
and
btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] will be calculated properly.

Quoted 4 lines

But if CONFIG_INET is n, then BTF_SOCK_TYPE_xxx will not contain

    __BTF_SOCK_TW_TYPE_xxx

so btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] will have default value 0 as btf_sock_ids is a global.

Quoted 7 lines

I could be missing something here.
Why btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] must be 0? How does BTF_ID_LIST_GLOBAL() know there is a btf_sock_ids[BTF_SOCK_TYPE_TCP_TW]?
I would expect at least BTF_ID_UNUSED is required. Otherwise, the value will be whatever follow the last btf_sock_ids[BTF_SOCK_TYPE_UDP6].

Right, I realized later on when I prepare v2. Will send patch v2 shortly.

Quoted 11 lines
Quoted 11 lines

Will send v2 to add some comments to make it easy to understand.

Quoted 7 lines
Quoted 7 lines
include/linux/btf_ids.h +0 -0
   #undef BTF_SOCK_TYPE
   MAX_BTF_SOCK_TYPE,
   };
Signature · 1 line
2.24.1