Skip to contentSkip to conversation

selftests/bpf: fix qdisc kfunc declarations

PATCH In review Sun Jian 2 participants 3 messages Dec 31, 2025 – Jan 6

Subsystems (3)
lore
Share & tools
lore

Sun Jian

author
#0 lore raw

PATCH 1/1 selftests/bpf: fix qdisc kfunc declarations

The qdisc BPF selftests fail to build because qdisc-related kfuncs are used without proper declarations, and struct bpf_sk_buff_ptr is only introduced in a function prototype scope, triggering -Wvisibility and type mismatch errors under -Werror.

Fix the build by:
- adding a file-scope forward declaration for struct bpf_sk_buff_ptr
- declaring qdisc kfuncs (bpf_qdisc_* and bpf_skb_get_hash/bpf_kfree_skb) as __ksym in the shared header
- including required BPF headers in qdisc test progs

Tested: make -C tools/testing/selftests/bpf OUTPUT=/tmp/selftests-bpf \
/tmp/selftests-bpf/bpf_qdisc_fifo.bpf.o \
/tmp/selftests-bpf/bpf_qdisc_fq.bpf.o \
/tmp/selftests-bpf/bpf_qdisc_fail__incompl_ops.bpf.o

---
 .../selftests/bpf/progs/bpf_qdisc_common.h      | 17 +++++++++++++++++
 .../bpf/progs/bpf_qdisc_fail__incompl_ops.c     |  4 ++++
 .../selftests/bpf/progs/bpf_qdisc_fifo.c        |  4 ++++
 .../testing/selftests/bpf/progs/bpf_qdisc_fq.c  |  1 +
 4 files changed, 26 insertions(+)
tools/testing/selftests/bpf/progs/bpf_qdisc_common.h +17 -0
index 3754f581b328..bed2294c35f9 100644
@@ -3,6 +3,9 @@
 #ifndef _BPF_QDISC_COMMON_H
 #define _BPF_QDISC_COMMON_H
 
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+
 #define NET_XMIT_SUCCESS        0x00
 #define NET_XMIT_DROP           0x01    /* skb dropped                  */
 #define NET_XMIT_CN             0x02    /* congestion notification      */
@@ -14,6 +17,20 @@
 
 struct bpf_sk_buff_ptr;
 
+/* kfunc declarations provided via vmlinux BTF */
+extern void bpf_qdisc_skb_drop(struct sk_buff *skb,
+			       struct bpf_sk_buff_ptr *to_free) __ksym;
+
+extern void bpf_qdisc_bstats_update(struct Qdisc *sch,
+				    const struct sk_buff *skb) __ksym;
+
+extern void bpf_qdisc_watchdog_schedule(struct Qdisc *sch,
+					u64 expire, u64 delta_ns) __ksym;
+
+extern __u32 bpf_skb_get_hash(struct sk_buff *skb) __ksym;
+
+extern void bpf_kfree_skb(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;
tools/testing/selftests/bpf/progs/bpf_qdisc_fail__incompl_ops.c +4 -0
index f188062ed730..8f9b2d2cb9a1 100644
@@ -1,6 +1,10 @@
 // SPDX-License-Identifier: GPL-2.0
 
 #include <vmlinux.h>
+
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
 #include "bpf_experimental.h"
 #include "bpf_qdisc_common.h"
 
tools/testing/selftests/bpf/progs/bpf_qdisc_fifo.c +4 -0
index 1de2be3e370b..524d3ae2c9a1 100644
@@ -1,6 +1,10 @@
 // SPDX-License-Identifier: GPL-2.0
 
 #include <vmlinux.h>
+
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
 #include "bpf_experimental.h"
 #include "bpf_qdisc_common.h"
 
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +1 -0
index 1a3233a275c7..dd47820fa230 100644
@@ -35,6 +35,7 @@
 #include <vmlinux.h>
 #include <errno.h>
 #include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
 #include "bpf_experimental.h"
 #include "bpf_qdisc_common.h"
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 46 lines · Sun Jian

The qdisc BPF selftests fail to build because qdisc-related kfuncs are used without proper declarations, and struct bpf_sk_buff_ptr is only introduced in a function prototype scope, triggering -Wvisibility and type mismatch errors under -Werror.

Fix the build by:
- adding a file-scope forward declaration for struct bpf_sk_buff_ptr
- declaring qdisc kfuncs (bpf_qdisc_* and bpf_skb_get_hash/bpf_kfree_skb) as __ksym in the shared header
- including required BPF headers in qdisc test progs

Tested: make -C tools/testing/selftests/bpf OUTPUT=/tmp/selftests-bpf \
/tmp/selftests-bpf/bpf_qdisc_fifo.bpf.o \
/tmp/selftests-bpf/bpf_qdisc_fq.bpf.o \
/tmp/selftests-bpf/bpf_qdisc_fail__incompl_ops.bpf.o

---
 .../selftests/bpf/progs/bpf_qdisc_common.h      | 17 +++++++++++++++++
 .../bpf/progs/bpf_qdisc_fail__incompl_ops.c     |  4 ++++
 .../selftests/bpf/progs/bpf_qdisc_fifo.c        |  4 ++++
 .../testing/selftests/bpf/progs/bpf_qdisc_fq.c  |  1 +
 4 files changed, 26 insertions(+)
tools/testing/selftests/bpf/progs/bpf_qdisc_common.h +6 -0
index 3754f581b328..bed2294c35f9 100644
@@ -3,6 +3,9 @@
 #ifndef _BPF_QDISC_COMMON_H
 #define _BPF_QDISC_COMMON_H
 
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+
 #define NET_XMIT_SUCCESS        0x00
 #define NET_XMIT_DROP           0x01    /* skb dropped                  */
 #define NET_XMIT_CN             0x02    /* congestion notification      */
@@ -14,6 +17,20 @@
 
 struct bpf_sk_buff_ptr;
 
+/* kfunc declarations provided via vmlinux BTF */
+extern void bpf_qdisc_skb_drop(struct sk_buff *skb,
+                              struct bpf_sk_buff_ptr *to_free) __ksym;

tools/testing/selftests/bpf/progs/bpf_qdisc_common.h line 32

Quoted 10 lines
tools/testing/selftests/bpf/progs/bpf_qdisc_common.h +10 -0
+
+extern void bpf_qdisc_bstats_update(struct Qdisc *sch,
+                                   const struct sk_buff *skb) __ksym;
+
+extern void bpf_qdisc_watchdog_schedule(struct Qdisc *sch,
+                                       u64 expire, u64 delta_ns) __ksym;
+
+extern __u32 bpf_skb_get_hash(struct sk_buff *skb) __ksym;
+
+extern void bpf_kfree_skb(struct sk_buff *skb) __ksym;

Stop this spam.
You keep ignoring earlier feedback.

pw-bot: cr

author
#2 lore raw
Quoted 2 lines · Alexei Starovoitov

Stop this spam.
You keep ignoring earlier feedback.

Sorry. I misdiagnosed a local build/setup issue as a kernel bug. I’ll stop sending patches and fix my setup first.

Thanks,
Sun