* [PATCH net v2] bpf: Fix build when CONFIG_BPF_SYSCALL is disabled
@ 2021-11-10 20:54 Vinicius Costa Gomes
2021-11-10 21:25 ` Kumar Kartikeya Dwivedi
0 siblings, 1 reply; 8+ messages in thread
From: Vinicius Costa Gomes @ 2021-11-10 20:54 UTC (permalink / raw)
To: bpf
Cc: Vinicius Costa Gomes, netdev, ast, daniel, memxor, kafai, andrii,
songliubraving, yhs
When CONFIG_DEBUG_INFO_BTF is enabled and CONFIG_BPF_SYSCALL is
disabled, the following compilation error can be seen:
GEN .version
CHK include/generated/compile.h
UPD include/generated/compile.h
CC init/version.o
AR init/built-in.a
LD vmlinux.o
MODPOST vmlinux.symvers
MODINFO modules.builtin.modinfo
GEN modules.builtin
LD .tmp_vmlinux.btf
ld: net/ipv4/tcp_cubic.o: in function `cubictcp_unregister':
net/ipv4/tcp_cubic.c:545: undefined reference to `bpf_tcp_ca_kfunc_list'
ld: net/ipv4/tcp_cubic.c:545: undefined reference to `unregister_kfunc_btf_id_set'
ld: net/ipv4/tcp_cubic.o: in function `cubictcp_register':
net/ipv4/tcp_cubic.c:539: undefined reference to `bpf_tcp_ca_kfunc_list'
ld: net/ipv4/tcp_cubic.c:539: undefined reference to `register_kfunc_btf_id_set'
BTF .btf.vmlinux.bin.o
pahole: .tmp_vmlinux.btf: No such file or directory
LD .tmp_vmlinux.kallsyms1
.btf.vmlinux.bin.o: file not recognized: file format not recognized
make: *** [Makefile:1187: vmlinux] Error 1
'bpf_tcp_ca_kfunc_list', 'register_kfunc_btf_id_set()' and
'unregister_kfunc_btf_id_set()' are only defined when
CONFIG_BPF_SYSCALL is enabled.
Fix that by moving those definitions somewhere that doesn't depend on
the bpf() syscall.
Fixes: 14f267d95fe4 ("bpf: btf: Introduce helpers for dynamic BTF set registration")
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
kernel/bpf/btf.c | 33 ---------------------------------
kernel/bpf/core.c | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 33 deletions(-)
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index dbc3ad07e21b..cc9868376345 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -6344,33 +6344,8 @@ const struct bpf_func_proto bpf_btf_find_by_name_kind_proto = {
BTF_ID_LIST_GLOBAL_SINGLE(btf_task_struct_ids, struct, task_struct)
-/* BTF ID set registration API for modules */
-
-struct kfunc_btf_id_list {
- struct list_head list;
- struct mutex mutex;
-};
-
#ifdef CONFIG_DEBUG_INFO_BTF_MODULES
-void register_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
- struct kfunc_btf_id_set *s)
-{
- mutex_lock(&l->mutex);
- list_add(&s->list, &l->list);
- mutex_unlock(&l->mutex);
-}
-EXPORT_SYMBOL_GPL(register_kfunc_btf_id_set);
-
-void unregister_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
- struct kfunc_btf_id_set *s)
-{
- mutex_lock(&l->mutex);
- list_del_init(&s->list);
- mutex_unlock(&l->mutex);
-}
-EXPORT_SYMBOL_GPL(unregister_kfunc_btf_id_set);
-
bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist, u32 kfunc_id,
struct module *owner)
{
@@ -6390,11 +6365,3 @@ bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist, u32 kfunc_id,
}
#endif
-
-#define DEFINE_KFUNC_BTF_ID_LIST(name) \
- struct kfunc_btf_id_list name = { LIST_HEAD_INIT(name.list), \
- __MUTEX_INITIALIZER(name.mutex) }; \
- EXPORT_SYMBOL_GPL(name)
-
-DEFINE_KFUNC_BTF_ID_LIST(bpf_tcp_ca_kfunc_list);
-DEFINE_KFUNC_BTF_ID_LIST(prog_test_kfunc_list);
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 2405e39d800f..f2939a6d8199 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -2456,6 +2456,43 @@ int __weak bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
DEFINE_STATIC_KEY_FALSE(bpf_stats_enabled_key);
EXPORT_SYMBOL(bpf_stats_enabled_key);
+/* BTF ID set registration API for modules */
+
+struct kfunc_btf_id_list {
+ struct list_head list;
+ struct mutex mutex;
+};
+
+#ifdef CONFIG_DEBUG_INFO_BTF_MODULES
+
+void register_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
+ struct kfunc_btf_id_set *s)
+{
+ mutex_lock(&l->mutex);
+ list_add(&s->list, &l->list);
+ mutex_unlock(&l->mutex);
+}
+EXPORT_SYMBOL_GPL(register_kfunc_btf_id_set);
+
+void unregister_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
+ struct kfunc_btf_id_set *s)
+{
+ mutex_lock(&l->mutex);
+ list_del_init(&s->list);
+ mutex_unlock(&l->mutex);
+}
+EXPORT_SYMBOL_GPL(unregister_kfunc_btf_id_set);
+
+#endif
+
+#define DEFINE_KFUNC_BTF_ID_LIST(name) \
+ struct kfunc_btf_id_list name = { LIST_HEAD_INIT(name.list), \
+ __MUTEX_INITIALIZER(name.mutex) }; \
+ EXPORT_SYMBOL_GPL(name)
+
+DEFINE_KFUNC_BTF_ID_LIST(bpf_tcp_ca_kfunc_list);
+DEFINE_KFUNC_BTF_ID_LIST(prog_test_kfunc_list);
+
/* All definitions of tracepoints related to BPF. */
#define CREATE_TRACE_POINTS
#include <linux/bpf_trace.h>
--
2.32.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net v2] bpf: Fix build when CONFIG_BPF_SYSCALL is disabled
2021-11-10 20:54 [PATCH net v2] bpf: Fix build when CONFIG_BPF_SYSCALL is disabled Vinicius Costa Gomes
@ 2021-11-10 21:25 ` Kumar Kartikeya Dwivedi
2021-11-10 21:59 ` Alexei Starovoitov
2021-11-10 23:10 ` Vinicius Costa Gomes
0 siblings, 2 replies; 8+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2021-11-10 21:25 UTC (permalink / raw)
To: Vinicius Costa Gomes
Cc: bpf, netdev, ast, daniel, kafai, andrii, songliubraving, yhs
On Thu, Nov 11, 2021 at 02:24:18AM IST, Vinicius Costa Gomes wrote:
> When CONFIG_DEBUG_INFO_BTF is enabled and CONFIG_BPF_SYSCALL is
> disabled, the following compilation error can be seen:
>
> GEN .version
> CHK include/generated/compile.h
> UPD include/generated/compile.h
> CC init/version.o
> AR init/built-in.a
> LD vmlinux.o
> MODPOST vmlinux.symvers
> MODINFO modules.builtin.modinfo
> GEN modules.builtin
> LD .tmp_vmlinux.btf
> ld: net/ipv4/tcp_cubic.o: in function `cubictcp_unregister':
> net/ipv4/tcp_cubic.c:545: undefined reference to `bpf_tcp_ca_kfunc_list'
> ld: net/ipv4/tcp_cubic.c:545: undefined reference to `unregister_kfunc_btf_id_set'
> ld: net/ipv4/tcp_cubic.o: in function `cubictcp_register':
> net/ipv4/tcp_cubic.c:539: undefined reference to `bpf_tcp_ca_kfunc_list'
> ld: net/ipv4/tcp_cubic.c:539: undefined reference to `register_kfunc_btf_id_set'
> BTF .btf.vmlinux.bin.o
> pahole: .tmp_vmlinux.btf: No such file or directory
> LD .tmp_vmlinux.kallsyms1
> .btf.vmlinux.bin.o: file not recognized: file format not recognized
> make: *** [Makefile:1187: vmlinux] Error 1
>
> 'bpf_tcp_ca_kfunc_list', 'register_kfunc_btf_id_set()' and
> 'unregister_kfunc_btf_id_set()' are only defined when
> CONFIG_BPF_SYSCALL is enabled.
>
> Fix that by moving those definitions somewhere that doesn't depend on
> the bpf() syscall.
>
> Fixes: 14f267d95fe4 ("bpf: btf: Introduce helpers for dynamic BTF set registration")
> Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Thanks for the fix.
But instead of moving this to core.c, you can probably make the btf.h
declaration conditional on CONFIG_BPF_SYSCALL, since this is not useful in
isolation (only used by verifier for module kfunc support). For the case of
kfunc_btf_id_list variables, just define it as an empty struct and static
variables, since the definition is still inside btf.c. So it becomes a noop for
!CONFIG_BPF_SYSCALL.
I am also not sure whether BTF is useful without BPF support, but maybe I'm
missing some usecase.
That's just my opinion however, I'll defer to BPF maintainers.
--
Kartikeya
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net v2] bpf: Fix build when CONFIG_BPF_SYSCALL is disabled
2021-11-10 21:25 ` Kumar Kartikeya Dwivedi
@ 2021-11-10 21:59 ` Alexei Starovoitov
2021-11-10 23:51 ` Vinicius Costa Gomes
2021-11-10 23:10 ` Vinicius Costa Gomes
1 sibling, 1 reply; 8+ messages in thread
From: Alexei Starovoitov @ 2021-11-10 21:59 UTC (permalink / raw)
To: Kumar Kartikeya Dwivedi
Cc: Vinicius Costa Gomes, bpf, Network Development,
Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau,
Andrii Nakryiko, Song Liu, Yonghong Song
On Wed, Nov 10, 2021 at 1:25 PM Kumar Kartikeya Dwivedi
<memxor@gmail.com> wrote:
>
> On Thu, Nov 11, 2021 at 02:24:18AM IST, Vinicius Costa Gomes wrote:
> > When CONFIG_DEBUG_INFO_BTF is enabled and CONFIG_BPF_SYSCALL is
> > disabled, the following compilation error can be seen:
> >
> > GEN .version
> > CHK include/generated/compile.h
> > UPD include/generated/compile.h
> > CC init/version.o
> > AR init/built-in.a
> > LD vmlinux.o
> > MODPOST vmlinux.symvers
> > MODINFO modules.builtin.modinfo
> > GEN modules.builtin
> > LD .tmp_vmlinux.btf
> > ld: net/ipv4/tcp_cubic.o: in function `cubictcp_unregister':
> > net/ipv4/tcp_cubic.c:545: undefined reference to `bpf_tcp_ca_kfunc_list'
> > ld: net/ipv4/tcp_cubic.c:545: undefined reference to `unregister_kfunc_btf_id_set'
> > ld: net/ipv4/tcp_cubic.o: in function `cubictcp_register':
> > net/ipv4/tcp_cubic.c:539: undefined reference to `bpf_tcp_ca_kfunc_list'
> > ld: net/ipv4/tcp_cubic.c:539: undefined reference to `register_kfunc_btf_id_set'
> > BTF .btf.vmlinux.bin.o
> > pahole: .tmp_vmlinux.btf: No such file or directory
> > LD .tmp_vmlinux.kallsyms1
> > .btf.vmlinux.bin.o: file not recognized: file format not recognized
> > make: *** [Makefile:1187: vmlinux] Error 1
> >
> > 'bpf_tcp_ca_kfunc_list', 'register_kfunc_btf_id_set()' and
> > 'unregister_kfunc_btf_id_set()' are only defined when
> > CONFIG_BPF_SYSCALL is enabled.
> >
> > Fix that by moving those definitions somewhere that doesn't depend on
> > the bpf() syscall.
> >
> > Fixes: 14f267d95fe4 ("bpf: btf: Introduce helpers for dynamic BTF set registration")
> > Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
>
> Thanks for the fix.
>
> But instead of moving this to core.c, you can probably make the btf.h
> declaration conditional on CONFIG_BPF_SYSCALL, since this is not useful in
> isolation (only used by verifier for module kfunc support). For the case of
> kfunc_btf_id_list variables, just define it as an empty struct and static
> variables, since the definition is still inside btf.c. So it becomes a noop for
> !CONFIG_BPF_SYSCALL.
>
> I am also not sure whether BTF is useful without BPF support, but maybe I'm
> missing some usecase.
Unlikely. I would just disallow such config instead of sprinkling
the code with ifdefs.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net v2] bpf: Fix build when CONFIG_BPF_SYSCALL is disabled
2021-11-10 21:25 ` Kumar Kartikeya Dwivedi
2021-11-10 21:59 ` Alexei Starovoitov
@ 2021-11-10 23:10 ` Vinicius Costa Gomes
1 sibling, 0 replies; 8+ messages in thread
From: Vinicius Costa Gomes @ 2021-11-10 23:10 UTC (permalink / raw)
To: Kumar Kartikeya Dwivedi
Cc: bpf, netdev, ast, daniel, kafai, andrii, songliubraving, yhs
Hi,
Kumar Kartikeya Dwivedi <memxor@gmail.com> writes:
> On Thu, Nov 11, 2021 at 02:24:18AM IST, Vinicius Costa Gomes wrote:
>> When CONFIG_DEBUG_INFO_BTF is enabled and CONFIG_BPF_SYSCALL is
>> disabled, the following compilation error can be seen:
>>
>> GEN .version
>> CHK include/generated/compile.h
>> UPD include/generated/compile.h
>> CC init/version.o
>> AR init/built-in.a
>> LD vmlinux.o
>> MODPOST vmlinux.symvers
>> MODINFO modules.builtin.modinfo
>> GEN modules.builtin
>> LD .tmp_vmlinux.btf
>> ld: net/ipv4/tcp_cubic.o: in function `cubictcp_unregister':
>> net/ipv4/tcp_cubic.c:545: undefined reference to `bpf_tcp_ca_kfunc_list'
>> ld: net/ipv4/tcp_cubic.c:545: undefined reference to `unregister_kfunc_btf_id_set'
>> ld: net/ipv4/tcp_cubic.o: in function `cubictcp_register':
>> net/ipv4/tcp_cubic.c:539: undefined reference to `bpf_tcp_ca_kfunc_list'
>> ld: net/ipv4/tcp_cubic.c:539: undefined reference to `register_kfunc_btf_id_set'
>> BTF .btf.vmlinux.bin.o
>> pahole: .tmp_vmlinux.btf: No such file or directory
>> LD .tmp_vmlinux.kallsyms1
>> .btf.vmlinux.bin.o: file not recognized: file format not recognized
>> make: *** [Makefile:1187: vmlinux] Error 1
>>
>> 'bpf_tcp_ca_kfunc_list', 'register_kfunc_btf_id_set()' and
>> 'unregister_kfunc_btf_id_set()' are only defined when
>> CONFIG_BPF_SYSCALL is enabled.
>>
>> Fix that by moving those definitions somewhere that doesn't depend on
>> the bpf() syscall.
>>
>> Fixes: 14f267d95fe4 ("bpf: btf: Introduce helpers for dynamic BTF set registration")
>> Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
>
> Thanks for the fix.
>
> But instead of moving this to core.c, you can probably make the btf.h
> declaration conditional on CONFIG_BPF_SYSCALL, since this is not useful in
> isolation (only used by verifier for module kfunc support). For the case of
> kfunc_btf_id_list variables, just define it as an empty struct and static
> variables, since the definition is still inside btf.c. So it becomes a noop for
> !CONFIG_BPF_SYSCALL.
>
> I am also not sure whether BTF is useful without BPF support, but maybe I'm
> missing some usecase.
From my side, you are not missing anything, it was just random chance
that I had a 'x86_64_defconfig + debug + BTF' .config laying around and
the build broke with it. I don't have any real usecases for this
combination.
Cheers,
--
Vinicius
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net v2] bpf: Fix build when CONFIG_BPF_SYSCALL is disabled
2021-11-10 21:59 ` Alexei Starovoitov
@ 2021-11-10 23:51 ` Vinicius Costa Gomes
2021-11-11 0:13 ` Kumar Kartikeya Dwivedi
0 siblings, 1 reply; 8+ messages in thread
From: Vinicius Costa Gomes @ 2021-11-10 23:51 UTC (permalink / raw)
To: Alexei Starovoitov, Kumar Kartikeya Dwivedi
Cc: bpf, Network Development, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau, Andrii Nakryiko, Song Liu, Yonghong Song
Alexei Starovoitov <alexei.starovoitov@gmail.com> writes:
>> Thanks for the fix.
>>
>> But instead of moving this to core.c, you can probably make the btf.h
>> declaration conditional on CONFIG_BPF_SYSCALL, since this is not useful in
>> isolation (only used by verifier for module kfunc support). For the case of
>> kfunc_btf_id_list variables, just define it as an empty struct and static
>> variables, since the definition is still inside btf.c. So it becomes a noop for
>> !CONFIG_BPF_SYSCALL.
>>
>> I am also not sure whether BTF is useful without BPF support, but maybe I'm
>> missing some usecase.
>
> Unlikely. I would just disallow such config instead of sprinkling
> the code with ifdefs.
Is something like this what you have in mind?
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 6fdbf9613aec..eae860c86e26 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -316,6 +316,7 @@ config DEBUG_INFO_BTF
bool "Generate BTF typeinfo"
depends on !DEBUG_INFO_SPLIT && !DEBUG_INFO_REDUCED
depends on !GCC_PLUGIN_RANDSTRUCT || COMPILE_TEST
+ depends on BPF_SYSCALL
help
Generate deduplicated BTF type information from DWARF debug info.
Turning this on expects presence of pahole tool, which will convert
Cheers,
--
Vinicius
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net v2] bpf: Fix build when CONFIG_BPF_SYSCALL is disabled
2021-11-10 23:51 ` Vinicius Costa Gomes
@ 2021-11-11 0:13 ` Kumar Kartikeya Dwivedi
2021-11-11 2:04 ` Vinicius Costa Gomes
0 siblings, 1 reply; 8+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2021-11-11 0:13 UTC (permalink / raw)
To: Vinicius Costa Gomes
Cc: Alexei Starovoitov, bpf, Network Development, Alexei Starovoitov,
Daniel Borkmann, Martin KaFai Lau, Andrii Nakryiko, Song Liu,
Yonghong Song
On Thu, Nov 11, 2021 at 05:21:53AM IST, Vinicius Costa Gomes wrote:
> Alexei Starovoitov <alexei.starovoitov@gmail.com> writes:
>
> >> Thanks for the fix.
> >>
> >> But instead of moving this to core.c, you can probably make the btf.h
> >> declaration conditional on CONFIG_BPF_SYSCALL, since this is not useful in
> >> isolation (only used by verifier for module kfunc support). For the case of
> >> kfunc_btf_id_list variables, just define it as an empty struct and static
> >> variables, since the definition is still inside btf.c. So it becomes a noop for
> >> !CONFIG_BPF_SYSCALL.
> >>
> >> I am also not sure whether BTF is useful without BPF support, but maybe I'm
> >> missing some usecase.
> >
> > Unlikely. I would just disallow such config instead of sprinkling
> > the code with ifdefs.
>
> Is something like this what you have in mind?
>
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index 6fdbf9613aec..eae860c86e26 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -316,6 +316,7 @@ config DEBUG_INFO_BTF
> bool "Generate BTF typeinfo"
> depends on !DEBUG_INFO_SPLIT && !DEBUG_INFO_REDUCED
> depends on !GCC_PLUGIN_RANDSTRUCT || COMPILE_TEST
> + depends on BPF_SYSCALL
> help
> Generate deduplicated BTF type information from DWARF debug info.
> Turning this on expects presence of pahole tool, which will convert
>
>
BTW, you will need a little more than that, I suspect the compiler optimizes out
the register/unregister call so we don't see a build failure, but adding a side
effect gives me errors, so something like this should resolve the problem (since
kfunc_btf_id_list variable definition is behind CONFIG_BPF_SYSCALL).
diff --git a/include/linux/btf.h b/include/linux/btf.h
index 203eef993d76..e9881ef9e9aa 100644
--- a/include/linux/btf.h
+++ b/include/linux/btf.h
@@ -254,6 +254,8 @@ void unregister_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
struct kfunc_btf_id_set *s);
bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist, u32 kfunc_id,
struct module *owner);
+extern struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list;
+extern struct kfunc_btf_id_list prog_test_kfunc_list;
#else
static inline void register_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
struct kfunc_btf_id_set *s)
@@ -268,13 +270,13 @@ static inline bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist,
{
return false;
}
+struct kfunc_btf_id_list {};
+static struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list __maybe_unused;
+static struct kfunc_btf_id_list prog_test_kfunc_list __maybe_unused;
+
#endif
#define DEFINE_KFUNC_BTF_ID_SET(set, name) \
struct kfunc_btf_id_set name = { LIST_HEAD_INIT(name.list), (set), \
THIS_MODULE }
-
-extern struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list;
-extern struct kfunc_btf_id_list prog_test_kfunc_list;
-
#endif
--
Kartikeya
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net v2] bpf: Fix build when CONFIG_BPF_SYSCALL is disabled
2021-11-11 0:13 ` Kumar Kartikeya Dwivedi
@ 2021-11-11 2:04 ` Vinicius Costa Gomes
2021-11-11 2:11 ` Kumar Kartikeya Dwivedi
0 siblings, 1 reply; 8+ messages in thread
From: Vinicius Costa Gomes @ 2021-11-11 2:04 UTC (permalink / raw)
To: Kumar Kartikeya Dwivedi
Cc: Alexei Starovoitov, bpf, Network Development, Alexei Starovoitov,
Daniel Borkmann, Martin KaFai Lau, Andrii Nakryiko, Song Liu,
Yonghong Song
Hi Kartikeya,
Kumar Kartikeya Dwivedi <memxor@gmail.com> writes:
> On Thu, Nov 11, 2021 at 05:21:53AM IST, Vinicius Costa Gomes wrote:
>> Alexei Starovoitov <alexei.starovoitov@gmail.com> writes:
>>
>> >> Thanks for the fix.
>> >>
>> >> But instead of moving this to core.c, you can probably make the btf.h
>> >> declaration conditional on CONFIG_BPF_SYSCALL, since this is not useful in
>> >> isolation (only used by verifier for module kfunc support). For the case of
>> >> kfunc_btf_id_list variables, just define it as an empty struct and static
>> >> variables, since the definition is still inside btf.c. So it becomes a noop for
>> >> !CONFIG_BPF_SYSCALL.
>> >>
>> >> I am also not sure whether BTF is useful without BPF support, but maybe I'm
>> >> missing some usecase.
>> >
>> > Unlikely. I would just disallow such config instead of sprinkling
>> > the code with ifdefs.
>>
>> Is something like this what you have in mind?
>>
>> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
>> index 6fdbf9613aec..eae860c86e26 100644
>> --- a/lib/Kconfig.debug
>> +++ b/lib/Kconfig.debug
>> @@ -316,6 +316,7 @@ config DEBUG_INFO_BTF
>> bool "Generate BTF typeinfo"
>> depends on !DEBUG_INFO_SPLIT && !DEBUG_INFO_REDUCED
>> depends on !GCC_PLUGIN_RANDSTRUCT || COMPILE_TEST
>> + depends on BPF_SYSCALL
>> help
>> Generate deduplicated BTF type information from DWARF debug info.
>> Turning this on expects presence of pahole tool, which will convert
>>
>>
>
> BTW, you will need a little more than that, I suspect the compiler optimizes out
> the register/unregister call so we don't see a build failure, but adding a side
> effect gives me errors, so something like this should resolve the problem (since
> kfunc_btf_id_list variable definition is behind CONFIG_BPF_SYSCALL).
>
> diff --git a/include/linux/btf.h b/include/linux/btf.h
> index 203eef993d76..e9881ef9e9aa 100644
> --- a/include/linux/btf.h
> +++ b/include/linux/btf.h
> @@ -254,6 +254,8 @@ void unregister_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
> struct kfunc_btf_id_set *s);
> bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist, u32 kfunc_id,
> struct module *owner);
> +extern struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list;
> +extern struct kfunc_btf_id_list prog_test_kfunc_list;
> #else
> static inline void register_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
> struct kfunc_btf_id_set *s)
> @@ -268,13 +270,13 @@ static inline bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist,
> {
> return false;
> }
> +struct kfunc_btf_id_list {};
> +static struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list __maybe_unused;
> +static struct kfunc_btf_id_list prog_test_kfunc_list __maybe_unused;
> +
> #endif
>
> #define DEFINE_KFUNC_BTF_ID_SET(set, name) \
> struct kfunc_btf_id_set name = { LIST_HEAD_INIT(name.list), (set), \
> THIS_MODULE }
> -
> -extern struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list;
> -extern struct kfunc_btf_id_list prog_test_kfunc_list;
> -
> #endif
>
I could not reproduce the build failure here even when adding some side
effects, but I didn't try very hard.
As you are more familiar with the code, I would be glad if you could
take it from here and propose a patch.
Cheers,
--
Vinicius
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net v2] bpf: Fix build when CONFIG_BPF_SYSCALL is disabled
2021-11-11 2:04 ` Vinicius Costa Gomes
@ 2021-11-11 2:11 ` Kumar Kartikeya Dwivedi
0 siblings, 0 replies; 8+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2021-11-11 2:11 UTC (permalink / raw)
To: Vinicius Costa Gomes
Cc: Alexei Starovoitov, bpf, Network Development, Alexei Starovoitov,
Daniel Borkmann, Martin KaFai Lau, Andrii Nakryiko, Song Liu,
Yonghong Song
On Thu, Nov 11, 2021 at 07:34:38AM IST, Vinicius Costa Gomes wrote:
> Hi Kartikeya,
>
> Kumar Kartikeya Dwivedi <memxor@gmail.com> writes:
>
> > On Thu, Nov 11, 2021 at 05:21:53AM IST, Vinicius Costa Gomes wrote:
> >> Alexei Starovoitov <alexei.starovoitov@gmail.com> writes:
> >>
> >> >> Thanks for the fix.
> >> >>
> >> >> But instead of moving this to core.c, you can probably make the btf.h
> >> >> declaration conditional on CONFIG_BPF_SYSCALL, since this is not useful in
> >> >> isolation (only used by verifier for module kfunc support). For the case of
> >> >> kfunc_btf_id_list variables, just define it as an empty struct and static
> >> >> variables, since the definition is still inside btf.c. So it becomes a noop for
> >> >> !CONFIG_BPF_SYSCALL.
> >> >>
> >> >> I am also not sure whether BTF is useful without BPF support, but maybe I'm
> >> >> missing some usecase.
> >> >
> >> > Unlikely. I would just disallow such config instead of sprinkling
> >> > the code with ifdefs.
> >>
> >> Is something like this what you have in mind?
> >>
> >> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> >> index 6fdbf9613aec..eae860c86e26 100644
> >> --- a/lib/Kconfig.debug
> >> +++ b/lib/Kconfig.debug
> >> @@ -316,6 +316,7 @@ config DEBUG_INFO_BTF
> >> bool "Generate BTF typeinfo"
> >> depends on !DEBUG_INFO_SPLIT && !DEBUG_INFO_REDUCED
> >> depends on !GCC_PLUGIN_RANDSTRUCT || COMPILE_TEST
> >> + depends on BPF_SYSCALL
> >> help
> >> Generate deduplicated BTF type information from DWARF debug info.
> >> Turning this on expects presence of pahole tool, which will convert
> >>
> >>
> >
> > BTW, you will need a little more than that, I suspect the compiler optimizes out
> > the register/unregister call so we don't see a build failure, but adding a side
> > effect gives me errors, so something like this should resolve the problem (since
> > kfunc_btf_id_list variable definition is behind CONFIG_BPF_SYSCALL).
> >
> > diff --git a/include/linux/btf.h b/include/linux/btf.h
> > index 203eef993d76..e9881ef9e9aa 100644
> > --- a/include/linux/btf.h
> > +++ b/include/linux/btf.h
> > @@ -254,6 +254,8 @@ void unregister_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
> > struct kfunc_btf_id_set *s);
> > bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist, u32 kfunc_id,
> > struct module *owner);
> > +extern struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list;
> > +extern struct kfunc_btf_id_list prog_test_kfunc_list;
> > #else
> > static inline void register_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
> > struct kfunc_btf_id_set *s)
> > @@ -268,13 +270,13 @@ static inline bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist,
> > {
> > return false;
> > }
> > +struct kfunc_btf_id_list {};
> > +static struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list __maybe_unused;
> > +static struct kfunc_btf_id_list prog_test_kfunc_list __maybe_unused;
> > +
> > #endif
> >
> > #define DEFINE_KFUNC_BTF_ID_SET(set, name) \
> > struct kfunc_btf_id_set name = { LIST_HEAD_INIT(name.list), (set), \
> > THIS_MODULE }
> > -
> > -extern struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list;
> > -extern struct kfunc_btf_id_list prog_test_kfunc_list;
> > -
> > #endif
> >
>
> I could not reproduce the build failure here even when adding some side
> effects, but I didn't try very hard.
>
> As you are more familiar with the code, I would be glad if you could
> take it from here and propose a patch.
>
Sure, no worries!
>
> Cheers,
> --
> Vinicius
--
Kartikeya
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-11-11 2:11 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-10 20:54 [PATCH net v2] bpf: Fix build when CONFIG_BPF_SYSCALL is disabled Vinicius Costa Gomes
2021-11-10 21:25 ` Kumar Kartikeya Dwivedi
2021-11-10 21:59 ` Alexei Starovoitov
2021-11-10 23:51 ` Vinicius Costa Gomes
2021-11-11 0:13 ` Kumar Kartikeya Dwivedi
2021-11-11 2:04 ` Vinicius Costa Gomes
2021-11-11 2:11 ` Kumar Kartikeya Dwivedi
2021-11-10 23:10 ` Vinicius Costa Gomes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).