Skip to content

Commit d9847eb

Browse files
kkdwivedianakryiko
authored andcommitted
bpf: Make CONFIG_DEBUG_INFO_BTF depend upon CONFIG_BPF_SYSCALL
Vinicius Costa Gomes reported [0] that build fails when CONFIG_DEBUG_INFO_BTF is enabled and CONFIG_BPF_SYSCALL is disabled. This leads to btf.c not being compiled, and then no symbol being present in vmlinux for the declarations in btf.h. Since BTF is not useful without enabling BPF subsystem, disallow this combination. However, theoretically disabling both now could still fail, as the symbol for kfunc_btf_id_list variables is not available. This isn't a problem as the compiler usually optimizes the whole register/unregister call, but at lower optimization levels it can fail the build in linking stage. Fix that by adding dummy variables so that modules taking address of them still work, but the whole thing is a noop. [0]: https://lore.kernel.org/bpf/[email protected] Fixes: 14f267d ("bpf: btf: Introduce helpers for dynamic BTF set registration") Reported-by: Vinicius Costa Gomes <[email protected]> Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Song Liu <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 099f83a commit d9847eb

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

include/linux/btf.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,10 @@ struct kfunc_btf_id_set {
245245
struct module *owner;
246246
};
247247

248-
struct kfunc_btf_id_list;
248+
struct kfunc_btf_id_list {
249+
struct list_head list;
250+
struct mutex mutex;
251+
};
249252

250253
#ifdef CONFIG_DEBUG_INFO_BTF_MODULES
251254
void register_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
@@ -254,6 +257,9 @@ void unregister_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
254257
struct kfunc_btf_id_set *s);
255258
bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist, u32 kfunc_id,
256259
struct module *owner);
260+
261+
extern struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list;
262+
extern struct kfunc_btf_id_list prog_test_kfunc_list;
257263
#else
258264
static inline void register_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
259265
struct kfunc_btf_id_set *s)
@@ -268,13 +274,13 @@ static inline bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist,
268274
{
269275
return false;
270276
}
277+
278+
static struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list __maybe_unused;
279+
static struct kfunc_btf_id_list prog_test_kfunc_list __maybe_unused;
271280
#endif
272281

273282
#define DEFINE_KFUNC_BTF_ID_SET(set, name) \
274283
struct kfunc_btf_id_set name = { LIST_HEAD_INIT(name.list), (set), \
275284
THIS_MODULE }
276285

277-
extern struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list;
278-
extern struct kfunc_btf_id_list prog_test_kfunc_list;
279-
280286
#endif

kernel/bpf/btf.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6346,11 +6346,6 @@ BTF_ID_LIST_GLOBAL_SINGLE(btf_task_struct_ids, struct, task_struct)
63466346

63476347
/* BTF ID set registration API for modules */
63486348

6349-
struct kfunc_btf_id_list {
6350-
struct list_head list;
6351-
struct mutex mutex;
6352-
};
6353-
63546349
#ifdef CONFIG_DEBUG_INFO_BTF_MODULES
63556350

63566351
void register_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
@@ -6389,12 +6384,12 @@ bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist, u32 kfunc_id,
63896384
return false;
63906385
}
63916386

6392-
#endif
6393-
63946387
#define DEFINE_KFUNC_BTF_ID_LIST(name) \
63956388
struct kfunc_btf_id_list name = { LIST_HEAD_INIT(name.list), \
63966389
__MUTEX_INITIALIZER(name.mutex) }; \
63976390
EXPORT_SYMBOL_GPL(name)
63986391

63996392
DEFINE_KFUNC_BTF_ID_LIST(bpf_tcp_ca_kfunc_list);
64006393
DEFINE_KFUNC_BTF_ID_LIST(prog_test_kfunc_list);
6394+
6395+
#endif

lib/Kconfig.debug

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ config DEBUG_INFO_BTF
316316
bool "Generate BTF typeinfo"
317317
depends on !DEBUG_INFO_SPLIT && !DEBUG_INFO_REDUCED
318318
depends on !GCC_PLUGIN_RANDSTRUCT || COMPILE_TEST
319+
depends on BPF_SYSCALL
319320
help
320321
Generate deduplicated BTF type information from DWARF debug info.
321322
Turning this on expects presence of pahole tool, which will convert

0 commit comments

Comments
 (0)