Skip to content

Commit

Permalink
feat: Add ebpf support for mips,ppc and risc archs
Browse files Browse the repository at this point in the history
* Test if the bpf assets can be compiled for different archs in CI.

* We are only ensuring the bpf assets are able to compile. No guarantee that these work in prod as we are not doing any functional testing.

Signed-off-by: Mahendra Paipuri <[email protected]>
  • Loading branch information
mahendrapaipuri committed Sep 29, 2024
1 parent 1b009cd commit 5964d3d
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/step_tests-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
- name: Setup clang 18
run: ./scripts/install_clang.sh

- name: Run checkmetrics and checkrules
run: make checkmetrics checkrules
- name: Run checkmetrics, checkrules and checkbpf
run: make checkmetrics checkrules checkbpf

- name: Run unit tests for Go packages
run: make test
Expand Down
12 changes: 6 additions & 6 deletions .promu-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ crossbuild:
- linux/386
- linux/amd64
- linux/arm64
# - linux/mips
# - linux/mips64
# - linux/mips64le
# - linux/mipsle
- linux/mips
- linux/mips64
- linux/mips64le
- linux/mipsle
# - linux/ppc64
# - linux/ppc64le
# - linux/riscv64
- linux/ppc64le
- linux/riscv64
# - linux/s390x
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ ifeq ($(CGO_BUILD), 1)
./cmd/ceems_lb
checkmetrics := skip-checkmetrics
checkrules := skip-checkrules
checkbpf := skip-checkbpf

# go test flags
coverage-file := coverage-cgo.out
Expand All @@ -67,6 +68,7 @@ else
./internal/security ./cmd/ceems_exporter
checkmetrics := checkmetrics
checkrules := checkrules
checkbpf := checkbpf

# go test flags
coverage-file := coverage-go.out
Expand Down Expand Up @@ -107,7 +109,7 @@ $(eval $(call goarch_pair,amd64,386))
$(eval $(call goarch_pair,mips64,mips))
$(eval $(call goarch_pair,mips64el,mipsel))

all:: vet common-all $(cross-test) $(test-docker) $(checkmetrics) $(checkrules) $(test-e2e)
all:: vet common-all $(cross-test) $(test-docker) $(checkmetrics) $(checkrules) $(checkbpf) $(test-e2e)

.PHONY: coverage
coverage:
Expand Down Expand Up @@ -262,6 +264,15 @@ checkrules: $(PROMTOOL)
skip-checkrules: $(PROMTOOL)
@echo ">> SKIP checking rules for correctness"

.PHONY: checkbpf
checkbpf: $(PROMTOOL)
@echo ">> checking bpf assets compilation"
./scripts/checkbpf.sh

.PHONY: skip-checkbpf
skip-checkbpf: $(PROMTOOL)
@echo ">> SKIP checking bpf assets compilation"

.PHONY: test-docker
test-docker:
@echo ">> testing docker image"
Expand Down
32 changes: 23 additions & 9 deletions pkg/collector/bpf/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ else ifeq ($(GOARCH),arm64)
else ifeq ($(GOARCH),mips)
BPF_TARGET_ARCH = mips
BPF_TARGET_MARCH = bpfeb
else ifeq ($(GOARCH),mipsle)
BPF_TARGET_ARCH = mips
BPF_TARGET_MARCH = bpfel
else ifeq ($(GOARCH),mips64)
BPF_TARGET_ARCH = mips
BPF_TARGET_MARCH = bpfeb
else ifeq ($(GOARCH),mips64le)
BPF_TARGET_ARCH = mips
BPF_TARGET_MARCH = bpfel
else ifeq ($(GOARCH),ppc64)
BPF_TARGET_ARCH = powerpc
BPF_TARGET_MARCH = bpfeb
Expand All @@ -45,15 +54,20 @@ else ifeq ($(GOARCH),s390x)
endif

# Do not compile BPF assets for mipsle, mips64 and mips64le architectures
ifeq ($(GOARCH),mipsle)
BPF_TARGET_COMPILE = 0
endif
ifeq ($(GOARCH),mips64)
BPF_TARGET_COMPILE = 0
endif
ifeq ($(GOARCH),mips64le)
BPF_TARGET_COMPILE = 0
endif
# Update 20240929: We are compiling all mips now as we added type defs in
# vmlinux.h.
# Atleast clang compiles them but not sure if it works in prod as we dont
# test them in CI.
#
# ifeq ($(GOARCH),mipsle)
# BPF_TARGET_COMPILE = 0
# endif
# ifeq ($(GOARCH),mips64)
# BPF_TARGET_COMPILE = 0
# endif
# ifeq ($(GOARCH),mips64le)
# BPF_TARGET_COMPILE = 0
# endif

ROOT_DIR := $(dir $(lastword $(MAKEFILE_LIST)))

Expand Down
161 changes: 161 additions & 0 deletions pkg/collector/bpf/include/vmlinux.h
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,126 @@ struct pt_regs {
u64 exit_rcu;
};

#elif defined(__TARGET_ARCH_mips)
/*
* Definitions for the following architectures are nicked from
* https://github.com/eunomia-bpf/vmlinux/tree/main
*/

struct user_pt_regs {
__u64 regs[32];
__u64 lo;
__u64 hi;
__u64 cp0_epc;
__u64 cp0_badvaddr;
__u64 cp0_status;
__u64 cp0_cause;
};

struct pt_regs {
long unsigned int pad0[8];
long unsigned int regs[32];
long unsigned int cp0_status;
long unsigned int hi;
long unsigned int lo;
long unsigned int cp0_badvaddr;
long unsigned int cp0_cause;
long unsigned int cp0_epc;
long unsigned int __last[0];
};

#elif defined(__TARGET_ARCH_powerpc)

struct user_pt_regs {
long unsigned int gpr[32];
long unsigned int nip;
long unsigned int msr;
long unsigned int orig_gpr3;
long unsigned int ctr;
long unsigned int link;
long unsigned int xer;
long unsigned int ccr;
long unsigned int softe;
long unsigned int trap;
long unsigned int dar;
long unsigned int dsisr;
long unsigned int result;
};

struct pt_regs {
union {
struct user_pt_regs user_regs;
struct {
long unsigned int gpr[32];
long unsigned int nip;
long unsigned int msr;
long unsigned int orig_gpr3;
long unsigned int ctr;
long unsigned int link;
long unsigned int xer;
long unsigned int ccr;
long unsigned int softe;
long unsigned int trap;
long unsigned int dar;
long unsigned int dsisr;
long unsigned int result;
};
};
union {
struct {
long unsigned int ppr;
long unsigned int exit_result;
union {
long unsigned int kuap;
long unsigned int amr;
};
long unsigned int iamr;
};
long unsigned int __pad[4];
};
};

#elif defined(__TARGET_ARCH_riscv)

struct pt_regs {
long unsigned int epc;
long unsigned int ra;
long unsigned int sp;
long unsigned int gp;
long unsigned int tp;
long unsigned int t0;
long unsigned int t1;
long unsigned int t2;
long unsigned int s0;
long unsigned int s1;
long unsigned int a0;
long unsigned int a1;
long unsigned int a2;
long unsigned int a3;
long unsigned int a4;
long unsigned int a5;
long unsigned int a6;
long unsigned int a7;
long unsigned int s2;
long unsigned int s3;
long unsigned int s4;
long unsigned int s5;
long unsigned int s6;
long unsigned int s7;
long unsigned int s8;
long unsigned int s9;
long unsigned int s10;
long unsigned int s11;
long unsigned int t3;
long unsigned int t4;
long unsigned int t5;
long unsigned int t6;
long unsigned int status;
long unsigned int badaddr;
long unsigned int cause;
long unsigned int orig_a0;
};

#endif

struct desc_ptr {
Expand Down Expand Up @@ -21518,6 +21638,45 @@ struct user_i387_struct {
__u32 padding[24];
};

#if defined(__TARGET_ARCH_riscv)

struct user_regs_struct {
long unsigned int pc;
long unsigned int ra;
long unsigned int sp;
long unsigned int gp;
long unsigned int tp;
long unsigned int t0;
long unsigned int t1;
long unsigned int t2;
long unsigned int s0;
long unsigned int s1;
long unsigned int a0;
long unsigned int a1;
long unsigned int a2;
long unsigned int a3;
long unsigned int a4;
long unsigned int a5;
long unsigned int a6;
long unsigned int a7;
long unsigned int s2;
long unsigned int s3;
long unsigned int s4;
long unsigned int s5;
long unsigned int s6;
long unsigned int s7;
long unsigned int s8;
long unsigned int s9;
long unsigned int s10;
long unsigned int s11;
long unsigned int t3;
long unsigned int t4;
long unsigned int t5;
long unsigned int t6;
};

#else

struct user_regs_struct {
long unsigned int r15;
long unsigned int r14;
Expand Down Expand Up @@ -21548,6 +21707,8 @@ struct user_regs_struct {
long unsigned int gs;
};

#endif

struct user {
struct user_regs_struct regs;
int u_fpvalid;
Expand Down
19 changes: 19 additions & 0 deletions scripts/checkbpf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -exo pipefail

# Change directory
cd pkg/collector/bpf

# List of archs to test
declare -a archs=("386" "amd64" "arm64" "mips" "mipsle" "mips64" "mips64le" "ppc64le" "riscv64")

# Test if we can compile bpf assets for all these archs
for arch in "${archs[@]}"
do
echo "Compiling bpf assets for $arch"
make clean
GOARCH="$arch" make
done

# Clean up all the assets
make clean

0 comments on commit 5964d3d

Please sign in to comment.