Skip to content

Commit

Permalink
bpf: iterators: Split iterators.lskel.h into little- and big- endian …
Browse files Browse the repository at this point in the history
…versions

iterators.lskel.h is little-endian, therefore bpf iterator is currently
broken on big-endian systems. Introduce a big-endian version and add
instructions regarding its generation. Unfortunately bpftool's
cross-endianness capabilities are limited to BTF right now, so the
procedure requires access to a big-endian machine or a configured
emulator.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20230128000650.1516334-25-iii@linux.ibm.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Ilya Leoshkevich authored and Alexei Starovoitov committed Jan 28, 2023
1 parent 42fae97 commit 0f0e5f5
Show file tree
Hide file tree
Showing 5 changed files with 435 additions and 7 deletions.
6 changes: 5 additions & 1 deletion kernel/bpf/preload/bpf_preload_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
#include <linux/init.h>
#include <linux/module.h>
#include "bpf_preload.h"
#include "iterators/iterators.lskel.h"
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#include "iterators/iterators.lskel-little-endian.h"
#else
#include "iterators/iterators.lskel-big-endian.h"
#endif

static struct bpf_link *maps_link, *progs_link;
static struct iterators_bpf *skel;
Expand Down
12 changes: 7 additions & 5 deletions kernel/bpf/preload/iterators/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,22 @@ endif

.PHONY: all clean

all: iterators.lskel.h
all: iterators.lskel-little-endian.h

big: iterators.lskel-big-endian.h

clean:
$(call msg,CLEAN)
$(Q)rm -rf $(OUTPUT) iterators

iterators.lskel.h: $(OUTPUT)/iterators.bpf.o | $(BPFTOOL)
iterators.lskel-%.h: $(OUTPUT)/%/iterators.bpf.o | $(BPFTOOL)
$(call msg,GEN-SKEL,$@)
$(Q)$(BPFTOOL) gen skeleton -L $< > $@


$(OUTPUT)/iterators.bpf.o: iterators.bpf.c $(BPFOBJ) | $(OUTPUT)
$(OUTPUT)/%/iterators.bpf.o: iterators.bpf.c $(BPFOBJ) | $(OUTPUT)
$(call msg,BPF,$@)
$(Q)$(CLANG) -g -O2 -target bpf $(INCLUDES) \
$(Q)mkdir -p $(@D)
$(Q)$(CLANG) -g -O2 -target bpf -m$* $(INCLUDES) \
-c $(filter %.c,$^) -o $@ && \
$(LLVM_STRIP) -g $@

Expand Down
5 changes: 4 additions & 1 deletion kernel/bpf/preload/iterators/README
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
WARNING:
If you change "iterators.bpf.c" do "make -j" in this directory to rebuild "iterators.skel.h".
If you change "iterators.bpf.c" do "make -j" in this directory to
rebuild "iterators.lskel-little-endian.h". Then, on a big-endian
machine, do "make -j big" in this directory to rebuild
"iterators.lskel-big-endian.h". Commit both resulting headers.
Make sure to have clang 10 installed.
See Documentation/bpf/bpf_devel_QA.rst
Loading

0 comments on commit 0f0e5f5

Please sign in to comment.