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
Signed-off-by: Sun Jian <[email protected]>
---
.../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(+)
diff --git a/tools/testing/selftests/bpf/progs/bpf_qdisc_common.h
b/tools/testing/selftests/bpf/progs/bpf_qdisc_common.h
index 3754f581b328..bed2294c35f9 100644
--- a/tools/testing/selftests/bpf/progs/bpf_qdisc_common.h
+++ b/tools/testing/selftests/bpf/progs/bpf_qdisc_common.h
@@ -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;
diff --git a/tools/testing/selftests/bpf/progs/bpf_qdisc_fail__incompl_ops.c
b/tools/testing/selftests/bpf/progs/bpf_qdisc_fail__incompl_ops.c
index f188062ed730..8f9b2d2cb9a1 100644
--- a/tools/testing/selftests/bpf/progs/bpf_qdisc_fail__incompl_ops.c
+++ b/tools/testing/selftests/bpf/progs/bpf_qdisc_fail__incompl_ops.c
@@ -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"
diff --git a/tools/testing/selftests/bpf/progs/bpf_qdisc_fifo.c
b/tools/testing/selftests/bpf/progs/bpf_qdisc_fifo.c
index 1de2be3e370b..524d3ae2c9a1 100644
--- a/tools/testing/selftests/bpf/progs/bpf_qdisc_fifo.c
+++ b/tools/testing/selftests/bpf/progs/bpf_qdisc_fifo.c
@@ -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"
diff --git a/tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c
b/tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c
index 1a3233a275c7..dd47820fa230 100644
--- a/tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c
+++ b/tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c
@@ -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"
--
2.43.0