selftests/bpf: Re-add kfunc declarations to qdisc tests
Subsystems (3)
PATCH 1/1 selftests/bpf: Re-add kfunc declarations to qdisc tests
BPF selftests compilation fails on systems with CONFIG_NET_SCH_BPF=n. The reason is that qdisc-related kfuncs are included via vmlinux.h but when qdisc is disabled, they are not defined and do not appear in vmlinux.h.
Fix the issue by defining the kfunc prototypes explicitly in bpf_qdisc_common.h. They were originally there but were removed by the fixed commit mentioned below.
--- tools/testing/selftests/bpf/progs/bpf_qdisc_common.h | 6 ++++++ 1 file changed, 6 insertions(+)
tools/testing/selftests/bpf/progs/bpf_qdisc_common.h +6 -0
@@ -14,6 +14,12 @@struct bpf_sk_buff_ptr ; +u32 bpf_skb_get_hash(struct sk_buff *p) __ksym; +void bpf_kfree_skb(struct sk_buff *p) __ksym; +void bpf_qdisc_skb_drop(struct sk_buff *p, struct bpf_sk_buff_ptr *to_free) __ksym; +void bpf_qdisc_watchdog_schedule(struct Qdisc *sch, u64 expire, u64 delta_ns) __ksym; +void bpf_qdisc_bstats_update(struct Qdisc *sch, const struct sk_buff *skb) __ksym; +static struct qdisc_skb_cb *qdisc_skb_cb (const struct sk_buff *skb) {return (struct qdisc_skb_cb *)skb->cb;
Signature · 1 line
2.50.0
Quoted 5 lines · Viktor Malik
BPF selftests compilation fails on systems with
CONFIG_NET_SCH_BPF=n. The reason is that qdisc-related kfuncs are included viavmlinux.hbut when qdisc is disabled, they are not defined and do not appear invmlinux.h.
Quoted 7 lines
Fix the issue by defining the kfunc prototypes explicitly in
bpf_qdisc_common.h. They were originally there but were removed by the fixed commit mentioned below.Fixes 2f9838e25790 ("selftests/bpf: Cleanup bpf qdisc selftests")Signed-off-by Viktor Malik <[email protected]>---
Quoted 5 lines · Viktor Malik
BPF selftests compilation fails on systems with
CONFIG_NET_SCH_BPF=n. The reason is that qdisc-related kfuncs are included viavmlinux.hbut when qdisc is disabled, they are not defined and do not appear invmlinux.h.
Yes and that's expected behavior. It's not a bug. That's why we have CONFIG_NET_SCH_BPF=y in selftests/bpf/config
and CI picks it up automatically.
If we add these kfuncs to bpf_qdisc_common.h where would we draw the line when the kfuncs should be added or not ?
Currently we don't add any new kfuncs, since they all should be in vmlinux.h
--
pw-bot: cr
Quoted 7 lines · Alexei Starovoitov
Quoted 5 lines · Viktor Malik
BPF selftests compilation fails on systems with
CONFIG_NET_SCH_BPF=n. The reason is that qdisc-related kfuncs are included viavmlinux.hbut when qdisc is disabled, they are not defined and do not appear invmlinux.h.
Quoted 7 lines
Yes and that's expected behavior. It's not a bug. That's why we have
CONFIG_NET_SCH_BPF=yin selftests/bpf/config
and CI picks it up automatically.If we add these kfuncs to
bpf_qdisc_common.hwhere would we draw the line when the kfuncs should be added or not ?
I'd say that we should add kfuncs which are only included in vmlinux.h under certain configurations. Obviously stuff like CONFIG_BPF=y can be presumed but there're tons of configs options which may be disabled on a system and it still makes sense to compile and run at least a part of test_progs on them.
Quoted 2 lines
Currently we don't add any new kfuncs, since they all should be in
vmlinux.h
This way, we're preventing people to build and therefore run *any* test_progs on systems which do not have all the configs required in selftests/bpf/config. Running selftests on such systems may reveal bugs not captured by the CI so I think that it may be eventually beneficial for everyone.
WDYT?
Quoted 4 lines
--
pw-bot: cr
Quoted 23 lines · Viktor Malik
Quoted 7 lines · Alexei Starovoitov
Quoted 5 lines · Viktor Malik
BPF selftests compilation fails on systems with
CONFIG_NET_SCH_BPF=n. The reason is that qdisc-related kfuncs are included viavmlinux.hbut when qdisc is disabled, they are not defined and do not appear invmlinux.h.Quoted 7 lines
Yes and that's expected behavior. It's not a bug. That's why we have
CONFIG_NET_SCH_BPF=yin selftests/bpf/config
and CI picks it up automatically.If we add these kfuncs to
bpf_qdisc_common.hwhere would we draw the line when the kfuncs should be added or not ?I'd say that we should add kfuncs which are only included in
vmlinux.hunder certain configurations. Obviously stuff likeCONFIG_BPF=ycan be presumed but there're tons of configs options which may be disabled on a system and it still makes sense to compile and run at least a part oftest_progson them.
Quoted 8 lines
Quoted 2 lines
Currently we don't add any new kfuncs, since they all should be in
vmlinux.hThis way, we're preventing people to build and therefore run *any*
test_progson systems which do not have all the configs required in selftests/bpf/config. Running selftests on such systems may reveal bugs not captured by the CI so I think that it may be eventually beneficial for everyone.
Not quite. What's stopping people to build selftests
with 'make -k' ?
Some bpf progs will not compile, but test_progs binary will be built and it will run the rest of the tests.
We can take this patch, but let's define the rules for adding kfuncs explicitly.
What are you proposing exactly ?
Anything that is gated by some CONFIG_FOO _must_ be added explicitly ? Assuming we won't be going back and retroactively adding them ?
Quoted 34 lines · Alexei Starovoitov
Quoted 23 lines · Viktor Malik
Quoted 7 lines · Alexei Starovoitov
Quoted 5 lines · Viktor Malik
BPF selftests compilation fails on systems with
CONFIG_NET_SCH_BPF=n. The reason is that qdisc-related kfuncs are included viavmlinux.hbut when qdisc is disabled, they are not defined and do not appear invmlinux.h.Quoted 7 lines
Yes and that's expected behavior. It's not a bug. That's why we have
CONFIG_NET_SCH_BPF=yin selftests/bpf/config
and CI picks it up automatically.If we add these kfuncs to
bpf_qdisc_common.hwhere would we draw the line when the kfuncs should be added or not ?I'd say that we should add kfuncs which are only included in
vmlinux.hunder certain configurations. Obviously stuff likeCONFIG_BPF=ycan be presumed but there're tons of configs options which may be disabled on a system and it still makes sense to compile and run at least a part oftest_progson them.Quoted 8 lines
Quoted 2 lines
Currently we don't add any new kfuncs, since they all should be in
vmlinux.hThis way, we're preventing people to build and therefore run *any*
test_progson systems which do not have all the configs required in selftests/bpf/config. Running selftests on such systems may reveal bugs not captured by the CI so I think that it may be eventually beneficial for everyone.
Quoted 7 lines
Not quite. What's stopping people to build selftests
with 'make -k' ?
Some bpf progs will not compile, buttest_progsbinary will be built and it will run the rest of the tests.We can take this patch, but let's define the rules for adding kfuncs explicitly.
Note, we have a VMLINUX_H argument that can be passed into BPF selftests' makefile. We used to use this for libbpf CI to build latest selftests against (very) old kernels, and it worked well.
I don't think we need to make exceptions for a few kfuncs, all it takes is to have vmlinux.h generated from kernel image built from proper configuration.
Also note, that "proper configuration" only applies to *built* kernel, not the actually running host kernel. See how VMLINUX_BTF_PATHS is defined and handled: host kernel is the last thing we use for vmlinux.h generation, only if all other options are unavailable.
Quoted 3 lines
What are you proposing exactly ?
Anything that is gated by someCONFIG_FOO_must_ be added explicitly ? Assuming we won't be going back and retroactively adding them ?
Quoted 36 lines · Andrii Nakryiko
Quoted 34 lines · Alexei Starovoitov
Quoted 31 lines · Viktor Malik
Quoted 7 lines · Alexei Starovoitov
Quoted 5 lines · Viktor Malik
BPF selftests compilation fails on systems with
CONFIG_NET_SCH_BPF=n. The reason is that qdisc-related kfuncs are included viavmlinux.hbut when qdisc is disabled, they are not defined and do not appear invmlinux.h.Quoted 7 lines
Yes and that's expected behavior. It's not a bug. That's why we have
CONFIG_NET_SCH_BPF=yin selftests/bpf/config
and CI picks it up automatically.If we add these kfuncs to
bpf_qdisc_common.hwhere would we draw the line when the kfuncs should be added or not ?I'd say that we should add kfuncs which are only included in
vmlinux.hunder certain configurations. Obviously stuff likeCONFIG_BPF=ycan be presumed but there're tons of configs options which may be disabled on a system and it still makes sense to compile and run at least a part oftest_progson them.Quoted 2 lines
Currently we don't add any new kfuncs, since they all should be in
vmlinux.hThis way, we're preventing people to build and therefore run *any*
test_progson systems which do not have all the configs required in selftests/bpf/config. Running selftests on such systems may reveal bugs not captured by the CI so I think that it may be eventually beneficial for everyone.
Quoted 4 lines
Quoted 4 lines
Not quite. What's stopping people to build selftests
with 'make -k' ?
Some bpf progs will not compile, buttest_progsbinary will be built and it will run the rest of the tests.
I don't think test_progs will be built if some of the objects from progs/ do not build. I just tried to run make -k on a kernel with CONFIG_NET_SCH_BPF=n. The compilation finished, some test binaries exist, but not test_progs.
In addition, we generally don't want to ignore all the errors as some of them may be important.
Quoted 8 lines
Quoted 3 lines
We can take this patch, but let's define the rules for adding kfuncs explicitly.
Note, we have a
VMLINUX_Hargument that can be passed into BPF selftests' makefile. We used to use this for libbpf CI to build latest selftests against (very) old kernels, and it worked well.
Quoted 8 lines
I don't think we need to make exceptions for a few kfuncs, all it takes is to have
vmlinux.hgenerated from kernel image built from proper configuration.Also note, that "proper configuration" only applies to *built* kernel, not the actually running host kernel. See how
VMLINUX_BTF_PATHSis defined and handled: host kernel is the last thing we use forvmlinux.hgeneration, only if all other options are unavailable.
This is a good point but the problem here is the extra kernel build. If you want to check that BPF in your kernel is working properly, you don't want to do another kernel build with a different config just for the sake of being able to build selftests.
Quoted 3 lines
Quoted 3 lines
What are you proposing exactly ?
Anything that is gated by someCONFIG_FOO_must_ be added explicitly ? Assuming we won't be going back and retroactively adding them ?
Yes, exactly like that. Except for this qdisc one, we haven't run into any issues for a long time, so I don't think that it's necessary to retroactively add the kfuncs.
But if you prefer to have it unified, I can take some time to clean it up - add config-gated kfuncs where they are missing and replace universally-available kfuncs by vmlinux.h.
Quoted 68 lines · Viktor Malik
Quoted 36 lines · Andrii Nakryiko
Quoted 34 lines · Alexei Starovoitov
Quoted 31 lines · Viktor Malik
Quoted 7 lines · Alexei Starovoitov
Quoted 5 lines · Viktor Malik
BPF selftests compilation fails on systems with
CONFIG_NET_SCH_BPF=n. The reason is that qdisc-related kfuncs are included viavmlinux.hbut when qdisc is disabled, they are not defined and do not appear invmlinux.h.Quoted 7 lines
Yes and that's expected behavior. It's not a bug. That's why we have
CONFIG_NET_SCH_BPF=yin selftests/bpf/config
and CI picks it up automatically.If we add these kfuncs to
bpf_qdisc_common.hwhere would we draw the line when the kfuncs should be added or not ?I'd say that we should add kfuncs which are only included in
vmlinux.hunder certain configurations. Obviously stuff likeCONFIG_BPF=ycan be presumed but there're tons of configs options which may be disabled on a system and it still makes sense to compile and run at least a part oftest_progson them.Quoted 2 lines
Currently we don't add any new kfuncs, since they all should be in
vmlinux.hThis way, we're preventing people to build and therefore run *any*
test_progson systems which do not have all the configs required in selftests/bpf/config. Running selftests on such systems may reveal bugs not captured by the CI so I think that it may be eventually beneficial for everyone.Quoted 4 lines
Quoted 4 lines
Not quite. What's stopping people to build selftests
with 'make -k' ?
Some bpf progs will not compile, buttest_progsbinary will be built and it will run the rest of the tests.I don't think
test_progswill be built if some of the objects from progs/ do not build. I just tried to runmake -kon a kernel withCONFIG_NET_SCH_BPF=n. The compilation finished, some test binaries exist, but nottest_progs.In addition, we generally don't want to ignore all the errors as some of them may be important.
Quoted 8 lines
Quoted 3 lines
We can take this patch, but let's define the rules for adding kfuncs explicitly.
Note, we have a
VMLINUX_Hargument that can be passed into BPF selftests' makefile. We used to use this for libbpf CI to build latest selftests against (very) old kernels, and it worked well.Quoted 8 lines
I don't think we need to make exceptions for a few kfuncs, all it takes is to have
vmlinux.hgenerated from kernel image built from proper configuration.Also note, that "proper configuration" only applies to *built* kernel, not the actually running host kernel. See how
VMLINUX_BTF_PATHSis defined and handled: host kernel is the last thing we use forvmlinux.hgeneration, only if all other options are unavailable.
Quoted 4 lines
This is a good point but the problem here is the extra kernel build. If you want to check that BPF in your kernel is working properly, you don't want to do another kernel build with a different config just for the sake of being able to build selftests.
What exactly is problematic? That's what I and others do all the time. If kernel build time is a concern, then pre-generate/pre-package vmlinux.h separately and use it to avoid building the kernel. (but BPF selftest *expects* kernel to be built first, we also build bpf_testmod against that kernel). Or just build/package test_progs itself, if that's what works better.
Basically, we have that selftest/bpf/config file for a reason: so that we don't guard every single thing that might not build or work properly if some of the Kconfig value is not set.
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
What are you proposing exactly ?
Anything that is gated by someCONFIG_FOO_must_ be added explicitly ? Assuming we won't be going back and retroactively adding them ?Yes, exactly like that. Except for this qdisc one, we haven't run into
we should be getting rid of all those __ksym __weak kfunc redefinitions because they now should come from vmlinux.h, not add more of that, IMO.
Quoted 7 lines
any issues for a long time, so I don't think that it's necessary to retroactively add the kfuncs.
But if you prefer to have it unified, I can take some time to clean it up - add config-gated kfuncs where they are missing and replace universally-available kfuncs by
vmlinux.h.
Quoted 3 lines · Andrii Nakryiko
Quoted 2 lines · Viktor Malik
On 7/1/25 22:28, Andrii Nakryiko wrote:
[...]
Quoted 18 lines
Quoted 13 lines
Quoted 4 lines
Note, we have a
VMLINUX_Hargument that can be passed into BPF selftests' makefile. We used to use this for libbpf CI to build latest selftests against (very) old kernels, and it worked well.Quoted 8 lines
I don't think we need to make exceptions for a few kfuncs, all it takes is to have
vmlinux.hgenerated from kernel image built from proper configuration.Also note, that "proper configuration" only applies to *built* kernel, not the actually running host kernel. See how
VMLINUX_BTF_PATHSis defined and handled: host kernel is the last thing we use forvmlinux.hgeneration, only if all other options are unavailable.Quoted 4 lines
This is a good point but the problem here is the extra kernel build. If you want to check that BPF in your kernel is working properly, you don't want to do another kernel build with a different config just for the sake of being able to build selftests.
Quoted 6 lines
What exactly is problematic? That's what I and others do all the time. If kernel build time is a concern, then pre-generate/pre-package
vmlinux.hseparately and use it to avoid building the kernel. (but BPF selftest *expects* kernel to be built first, we also buildbpf_testmodagainst that kernel). Or just build/packagetest_progsitself, if that's what works better.
Yes, we need to have a kernel built before building selftests but your solution would require to build it twice - once with the desired configuration and once with added selftests/bpf/config to generate vmlinux.h that can be used for selftests build.
Pre-building vmlinux.h is not really an option for automated builds as every kernel change may introduce some new kfuncs which will be needed for selftests build. So, we'd need to build vmlinux.h every time.
Quoted 3 lines
Basically, we have that selftest/bpf/config file for a reason: so that we don't guard every single thing that might not build or work properly if some of the
Kconfigvalue is not set.
[...]
Quoted 3 lines
we should be getting rid of all those
__ksym__weakkfunc redefinitions because they now should come fromvmlinux.h, not add more of that, IMO.
I understand that having those kfunc definitions in selftests is cumbersome and has maintenence cost. While vmlinux.h works for upstream use-cases, it has its problems for distro packagers, so I'll try to think about some solution that would be acceptable for both sides.
Eduard Zingerman
maintainerOn Tue, 2025-07-01 at 14:07 -0700, Andrii Nakryiko wrote:
[...]
Quoted 3 lines
we should be getting rid of all those
__ksym__weakkfunc redefinitions because they now should come fromvmlinux.h, not add more of that, IMO.
Tbh, I'm not sure this matters much. Kfunc signatures don't change often (don't remember it ever happen), so having prototypes here and there in selftests shouldn't be a maintenance burden.
Quoted 5 lines · Eduard Zingerman
On Tue, 2025-07-01 at 14:07 -0700, Andrii Nakryiko wrote:
[...]
Quoted 7 lines
Quoted 3 lines
we should be getting rid of all those
__ksym__weakkfunc redefinitions because they now should come fromvmlinux.h, not add more of that, IMO.Tbh, I'm not sure this matters much. Kfunc signatures don't change often (don't remember it ever happen), so having prototypes here and there in selftests shouldn't be a maintenance burden.
Ok, if I'm the only one who thinks we shouldn't duplicate kfunc definitions because we have an established approach that works, so be it, not such a big deal.
I'm curious to see if the next step would be someone asking to do something about enum or struct that is defined only with some kernel configuration that selftest relies on. Are we going to add extra #defines just to be able to do #ifndef-#define-#endif guarding in selftest source code just to accommodate someone wanting to build BPF selftests, but not wanting to follow prescribed build setup? Or start adding feature detection in Makefile and exclude some tests from being built? Will that start to be a maintenance burden?
I guess I just don't understand the direction here.
Eduard Zingerman
maintainerOn Wed, 2025-07-02 at 10:28 -0700, Andrii Nakryiko wrote:
[...]
Quoted 4 lines
Ok, if I'm the only one who thinks we shouldn't duplicate kfunc definitions because we have an established approach that works, so be it, not such a big deal.
Quoted 8 lines
I'm curious to see if the next step would be someone asking to do something about enum or struct that is defined only with some kernel configuration that selftest relies on. Are we going to add extra #defines just to be able to do #ifndef-#define-#endif guarding in selftest source code just to accommodate someone wanting to build BPF selftests, but not wanting to follow prescribed build setup? Or start adding feature detection in
Makefileand exclude some tests from being built? Will that start to be a maintenance burden?
In my personal opinion adding #ifndef-#define-#endif and feature detection in the makefile would constitute maintenance burden, yes.
Quoted 1 line
I guess I just don't understand the direction here.