]> www.infradead.org Git - users/hch/configfs.git/commitdiff
selftests: net: declare section names for bpf_offload
authorJakub Kicinski <kuba@kernel.org>
Tue, 9 Apr 2024 03:15:48 +0000 (20:15 -0700)
committerJakub Kicinski <kuba@kernel.org>
Wed, 10 Apr 2024 21:03:12 +0000 (14:03 -0700)
Non-ancient ip (iproute2-5.15.0, libbpf 0.7.0) refuses to load
the sample with maps because we don't generate BTF:

   libbpf: BTF is required, but is missing or corrupted.
   ERROR: opening BPF object file failed

Enable BTF by adding -g to clang flags. With that done
neither of the programs load:

  libbpf: prog 'func': error relocating .BTF.ext function info: -22
  libbpf: prog 'func': failed to relocate calls: -22
  libbpf: failed to load object 'ksft-net-drv/net/sample_ret0.bpf.o'

Andrii explains that this is because we don't specify
section names for the code. Add the section names, too.

Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Stanislav Fomichev <sdf@google.com>
Acked-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20240409031549.3531084-4-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/Makefile
tools/testing/selftests/net/bpf_offload.py
tools/testing/selftests/net/sample_map_ret0.bpf.c
tools/testing/selftests/net/sample_ret0.bpf.c

index e8bfa715aa4959f184642efade3b6b4fab26c023..a3c781cb8367b101f879ea1b20107a3aa51e2f97 100644 (file)
@@ -149,7 +149,8 @@ BPF_PROG_OBJS := $(OUTPUT)/nat6to4.o $(OUTPUT)/xdp_dummy.o \
        $(OUTPUT)/sample_map_ret0.bpf.o $(OUTPUT)/sample_ret0.bpf.o
 
 $(BPF_PROG_OBJS): $(OUTPUT)/%.o : %.c $(BPFOBJ) | $(MAKE_DIRS)
-       $(CLANG) -O2 --target=bpf -c $< $(CCINCLUDE) $(CLANG_SYS_INCLUDES) -o $@
+       $(CLANG) -O2 -g --target=bpf $(CCINCLUDE) $(CLANG_SYS_INCLUDES) \
+       -c $< -o $@
 
 $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile)                    \
           $(APIDIR)/linux/bpf.h                                               \
index 174dba1a48d3e753f3762acdda98cc04f14f2069..76b53ac2c8c645e539570f1d41e40986aac2f62e 100755 (executable)
@@ -237,7 +237,7 @@ def tc(args, JSON=True, ns="", fail=True, include_stderr=False):
 def ethtool(dev, opt, args, fail=True):
     return cmd("ethtool %s %s %s" % (opt, dev["ifname"], args), fail=fail)
 
-def bpf_obj(name, sec=".text", path=bpf_test_dir,):
+def bpf_obj(name, sec="xdp", path=bpf_test_dir,):
     return "obj %s sec %s" % (os.path.join(path, name), sec)
 
 def bpf_pinned(name):
index 495990d355ef366e40b224002b0878f84aa389d2..43ca92594926b5cd781f5c6f4cdf5ab952d0ee6f 100644 (file)
@@ -17,7 +17,7 @@ struct {
 } array SEC(".maps");
 
 /* Sample program which should always load for testing control paths. */
-SEC(".text") int func()
+SEC("xdp") int func()
 {
        __u64 key64 = 0;
        __u32 key = 0;
index fec99750d6ea22a2b4751457a24ecdd95a750138..1df5ca98bb6507dbdcb180e08fb93687eadbcb2c 100644 (file)
@@ -1,6 +1,9 @@
 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */
 
+#define SEC(name) __attribute__((section(name), used))
+
 /* Sample program which should always load for testing control paths. */
+SEC("xdp")
 int func()
 {
        return 0;