Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Add ARM support #82

Merged
merged 56 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
4419cc8
Add ARM64 Support
edeNFed Feb 11, 2023
7c076e8
update net/http probe to get args from ctx instead of goroutine
MikeGoldsmith Apr 19, 2023
90b1f32
Merge branch 'main' into mike/arm
MikeGoldsmith Apr 19, 2023
7ba89cd
fix c file formatting
MikeGoldsmith Apr 19, 2023
0e83fa5
more c file formatting tidy
MikeGoldsmith Apr 19, 2023
ace3233
get http header ctx pointer for net/http instrumentation
MikeGoldsmith Apr 19, 2023
3786f5c
switch back to goroutine
MikeGoldsmith Apr 19, 2023
aac8000
set bpf2go target as bpfel
MikeGoldsmith Apr 24, 2023
e5f3d10
revert bpf2go target to $TARGET
MikeGoldsmith Apr 24, 2023
e383822
remove generated probe go files
MikeGoldsmith Apr 24, 2023
eae59eb
Merge branch 'main' of github.com:open-telemetry/opentelemetry-go-ins…
MikeGoldsmith Apr 24, 2023
318de9f
set TARGET in build workflow to amd64
MikeGoldsmith Apr 24, 2023
1c4180a
add default docker image name to makefile
MikeGoldsmith Apr 24, 2023
2e7b9a9
remove TARGET and IMG env vars in build workflow
MikeGoldsmith Apr 24, 2023
1d2c117
set TARGETARCH in build workflow
MikeGoldsmith Apr 24, 2023
ad676be
tidy up build workflow
MikeGoldsmith Apr 24, 2023
6777738
update go generate to use set targets directly
MikeGoldsmith Apr 24, 2023
3f90100
add qemu
pkanal Apr 24, 2023
37ecf3c
lets see what happens with buildarch
pkanal Apr 24, 2023
3f7f1b1
try buildx
pkanal Apr 24, 2023
fd741f1
try buildx
pkanal Apr 24, 2023
a538ef0
testing if we need buildx setup step
pkanal Apr 24, 2023
068af9b
remove --no-cache option
pkanal Apr 24, 2023
c0df55d
Merge pull request #4 from honeycombio/purvi-robb/debug-ci-targetarch
robbkidd Apr 24, 2023
58df81b
switch back to specific eBPF arch targets
MikeGoldsmith Apr 25, 2023
926fdb7
tidy up docker/make files
MikeGoldsmith Apr 25, 2023
63bba9e
set default target as amd64
MikeGoldsmith Apr 25, 2023
a5956d2
readd buildx
MikeGoldsmith Apr 25, 2023
e22a0a5
fix buildx arg
MikeGoldsmith Apr 25, 2023
0d83da2
fix image name
MikeGoldsmith Apr 25, 2023
2ef3b6e
wait for longer for e2e pods
MikeGoldsmith Apr 25, 2023
121b6df
Revert "wait for longer for e2e pods"
MikeGoldsmith Apr 25, 2023
5d58216
apply fix for instrumenting stripped binaries
MikeGoldsmith Apr 25, 2023
11af7d2
Revert "apply fix for instrumenting stripped binaries"
MikeGoldsmith Apr 25, 2023
c3bce84
Merge branch 'main' of github.com:open-telemetry/opentelemetry-go-ins…
MikeGoldsmith Apr 27, 2023
9b358df
use $TARGET for gin bpf2cmd
MikeGoldsmith Apr 28, 2023
1dda4ca
Merge branch 'main' of github.com:open-telemetry/opentelemetry-go-ins…
MikeGoldsmith Apr 28, 2023
ef84926
update ptrace_linux_arm
MikeGoldsmith Apr 28, 2023
cf07836
add changelog entry
MikeGoldsmith Apr 28, 2023
2e4948d
extend get_goroutine to work with go <1.17
MikeGoldsmith Apr 28, 2023
d3748a5
Merge branch 'main' of github.com:open-telemetry/opentelemetry-go-ins…
MikeGoldsmith Apr 28, 2023
d4451a1
add missing licese files
MikeGoldsmith Apr 28, 2023
f54f447
fix bad merge in Makefile
MikeGoldsmith Apr 28, 2023
c507a1e
remove unnessary additional funcname for net/http instrumentor
MikeGoldsmith Apr 28, 2023
b6ede1b
Merge branch 'main' of github.com:open-telemetry/opentelemetry-go-ins…
MikeGoldsmith Apr 29, 2023
1248b3c
Merge branch 'main' of github.com:open-telemetry/opentelemetry-go-ins…
MikeGoldsmith May 2, 2023
8a00211
update bpf2go generate commands to use both arm and amd
MikeGoldsmith May 2, 2023
7d7392a
Update changelog entry
MikeGoldsmith May 2, 2023
eed05ee
re-add comments to pt_regs struct
MikeGoldsmith May 2, 2023
7663e44
add build guards to findReturnInstructions arch files
MikeGoldsmith May 2, 2023
36f80a6
Merge branch 'mike/arm' of github.com:honeycombio/opentelemetry-go-in…
MikeGoldsmith May 2, 2023
9afe789
unexport error const
MikeGoldsmith May 2, 2023
12a4b75
separate imports
MikeGoldsmith May 2, 2023
6e89433
update mapSize description
MikeGoldsmith May 2, 2023
c395a5c
Fix changelog entry
MikeGoldsmith May 2, 2023
ece179f
Merge branch 'main' into mike/arm
MikeGoldsmith May 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: actions/checkout@v3
- name: Build auto-instrumentation
run: |
IMG=otel-go-instrumentation make docker-build
make docker-build
offsets:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
platforms: linux/amd64,linux/arm64
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM fedora:38 as builder
ARG TARGETARCH
RUN echo "arch: $TARGETARCH"
RUN dnf install clang llvm make libbpf-devel -y
RUN curl -LO https://go.dev/dl/go1.20.linux-amd64.tar.gz && tar -C /usr/local -xzf go*.linux-amd64.tar.gz
RUN curl -LO https://go.dev/dl/go1.20.linux-${TARGETARCH}.tar.gz && tar -C /usr/local -xzf go*.linux-${TARGETARCH}.tar.gz
ENV PATH="/usr/local/go/bin:${PATH}"
WORKDIR /app
COPY . .
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ REPODIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

# Build the list of include directories to compile the bpf program
BPF_INCLUDE += -I${REPODIR}/include/libbpf
BPF_INCLUDE+= -I${REPODIR}/include
BPF_INCLUDE += -I${REPODIR}/include

# Tools
TOOLS_MOD_DIR := ./internal/tools
Expand All @@ -19,6 +19,8 @@ $(TOOLS)/%: | $(TOOLS)
GOLICENSES = $(TOOLS)/go-licenses
$(TOOLS)/go-licenses: PACKAGE=github.com/google/go-licenses

IMG?=otel-go-instrumentation

.PHONY: tools
tools: $(GOLICENSES)

Expand All @@ -30,11 +32,11 @@ generate:

.PHONY: build
build: generate
GOOS=linux GOARCH=amd64 go build -o otel-go-instrumentation cli/main.go
GOOS=linux go build -o otel-go-instrumentation cli/main.go

.PHONY: docker-build
docker-build:
docker build -t $(IMG) .
docker buildx build -t $(IMG) .

.PHONY: offsets
offsets:
Expand Down
6 changes: 6 additions & 0 deletions include/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ static __always_inline void *write_target_data(void *data, s32 size)
{
s32 start_index = 0;
u64 updated_start = start + size;

// align updated_start to 8 bytes
if (updated_start % 8 != 0) {
updated_start += 8 - (updated_start % 8);
}

bpf_map_update_elem(&alloc_map, &start_index, &updated_start, BPF_ANY);
return target;
}
Expand Down
30 changes: 15 additions & 15 deletions include/arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "common.h"
#include "bpf_tracing.h"
#include "bpf_helpers.h"
#include <stdbool.h>

Expand All @@ -24,23 +25,23 @@ void *get_argument_by_reg(struct pt_regs *ctx, int index)
switch (index)
{
case 1:
return (void *)(ctx->rax);
return (void *)GO_PARAM1(ctx);
case 2:
return (void *)(ctx->rbx);
return (void *)GO_PARAM2(ctx);
case 3:
return (void *)(ctx->rcx);
return (void *)GO_PARAM3(ctx);
case 4:
return (void *)(ctx->rdi);
return (void *)GO_PARAM4(ctx);
case 5:
return (void *)(ctx->rsi);
return (void *)GO_PARAM5(ctx);
case 6:
return (void *)(ctx->r8);
return (void *)GO_PARAM6(ctx);
case 7:
return (void *)(ctx->r9);
return (void *)GO_PARAM7(ctx);
case 8:
return (void *)(ctx->r10);
return (void *)GO_PARAM8(ctx);
case 9:
return (void *)(ctx->r11);
return (void *)GO_PARAM9(ctx);
default:
return NULL;
}
Expand All @@ -49,7 +50,7 @@ void *get_argument_by_reg(struct pt_regs *ctx, int index)
void *get_argument_by_stack(struct pt_regs *ctx, int index)
{
void *ptr = 0;
bpf_probe_read(&ptr, sizeof(ptr), (void *)(ctx->rsp + (index * 8)));
bpf_probe_read(&ptr, sizeof(ptr), (void *)(PT_REGS_SP(ctx) + (index * 8)));
return ptr;
}

Expand All @@ -63,8 +64,7 @@ void *get_argument(struct pt_regs *ctx, int index)
return get_argument_by_stack(ctx, index);
}

// In x86, current goroutine is pointed by r14, according to
// https://go.googlesource.com/go/+/refs/heads/dev.regabi/src/cmd/compile/internal-abi.md#amd64-architecture
inline void *get_goroutine_address(struct pt_regs *ctx) {
return (void *)(ctx->r14);
}
inline void *get_goroutine_address(struct pt_regs *ctx)
{
return (void *)GOROUTINE(ctx);
}
86 changes: 51 additions & 35 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,41 +84,57 @@ enum
#define BPF_F_INDEX_MASK 0xffffffffULL
#define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK

#define PT_REGS_RC(x) ((x)->rax)
struct pt_regs
{
/*
* C ABI says these regs are callee-preserved. They aren't saved on kernel entry
* unless syscall needs a complete, fully filled "struct pt_regs".
*/
unsigned long r15;
unsigned long r14;
unsigned long r13;
unsigned long r12;
unsigned long rbp;
unsigned long rbx;
/* These regs are callee-clobbered. Always saved on kernel entry. */
unsigned long r11;
unsigned long r10;
unsigned long r9;
unsigned long r8;
unsigned long rax;
unsigned long rcx;
unsigned long rdx;
unsigned long rsi;
unsigned long rdi;
/*
* On syscall entry, this is syscall#. On CPU exception, this is error code.
* On hw interrupt, it's IRQ number:
*/
unsigned long orig_rax;
/* Return frame for iretq */
MikeGoldsmith marked this conversation as resolved.
Show resolved Hide resolved
unsigned long rip;
unsigned long cs;
unsigned long eflags;
unsigned long rsp;
unsigned long ss;
/* top of stack page */
#if defined(__TARGET_ARCH_x86)
struct pt_regs {
long unsigned int r15;
long unsigned int r14;
long unsigned int r13;
long unsigned int r12;
long unsigned int bp;
long unsigned int bx;
long unsigned int r11;
long unsigned int r10;
long unsigned int r9;
long unsigned int r8;
long unsigned int ax;
long unsigned int cx;
long unsigned int dx;
long unsigned int si;
long unsigned int di;
long unsigned int orig_ax;
long unsigned int ip;
long unsigned int cs;
long unsigned int flags;
long unsigned int sp;
long unsigned int ss;
};
#elif defined(__TARGET_ARCH_arm64)
struct user_pt_regs {
__u64 regs[31];
__u64 sp;
__u64 pc;
__u64 pstate;
};

struct pt_regs {
union {
struct user_pt_regs user_regs;
struct {
u64 regs[31];
u64 sp;
u64 pc;
u64 pstate;
};
};
u64 orig_x0;
s32 syscallno;
u32 unused2;
u64 orig_addr_limit;
u64 pmr_save;
u64 stackframe[2];
u64 lockdep_hardirqs;
u64 exit_rcu;
};
#endif

#endif /* __VMLINUX_H__ */
6 changes: 5 additions & 1 deletion include/go_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ static __always_inline struct go_string write_user_go_string(char *str, u32 len)
new_string.len = len;

// Copy new string struct to userspace
write_target_data((void *)&new_string, sizeof(new_string));
void *res = write_target_data((void *)&new_string, sizeof(new_string));
if (res == NULL) {
new_string.len = 0;
}

return new_string;
}

Expand Down
55 changes: 55 additions & 0 deletions include/libbpf/bpf_tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#elif defined(__TARGET_ARCH_sparc)
#define bpf_target_sparc
#define bpf_target_defined
#elif defined(__TARGET_ARCH_riscv)
#define bpf_target_riscv
#define bpf_target_defined
#else

/* Fall back to what the compiler says */
Expand All @@ -48,6 +51,9 @@
#elif defined(__sparc__)
#define bpf_target_sparc
#define bpf_target_defined
#elif defined(__riscv) && __riscv_xlen == 64
#define bpf_target_riscv
#define bpf_target_defined
#endif /* no compiler target */

#endif
Expand All @@ -60,6 +66,17 @@

#if defined(__KERNEL__) || defined(__VMLINUX_H__)

#define GO_PARAM1(x) ((x)->ax)
#define GO_PARAM2(x) ((x)->bx)
#define GO_PARAM3(x) ((x)->cx)
#define GO_PARAM4(x) ((x)->di)
#define GO_PARAM5(x) ((x)->si)
#define GO_PARAM6(x) ((x)->r8)
#define GO_PARAM7(x) ((x)->r9)
#define GO_PARAM8(x) ((x)->r10)
#define GO_PARAM9(x) ((x)->r11)
#define GOROUTINE(x) ((x)->r14)

#define PT_REGS_PARM1(x) ((x)->di)
#define PT_REGS_PARM2(x) ((x)->si)
#define PT_REGS_PARM3(x) ((x)->dx)
Expand Down Expand Up @@ -192,6 +209,18 @@ struct pt_regs;
/* arm64 provides struct user_pt_regs instead of struct pt_regs to userspace */
struct pt_regs;
#define PT_REGS_ARM64 const volatile struct user_pt_regs

#define GO_PARAM1(x) (((PT_REGS_ARM64 *)(x))->regs[0])
#define GO_PARAM2(x) (((PT_REGS_ARM64 *)(x))->regs[1])
#define GO_PARAM3(x) (((PT_REGS_ARM64 *)(x))->regs[2])
#define GO_PARAM4(x) (((PT_REGS_ARM64 *)(x))->regs[3])
#define GO_PARAM5(x) (((PT_REGS_ARM64 *)(x))->regs[4])
#define GO_PARAM6(x) (((PT_REGS_ARM64 *)(x))->regs[5])
#define GO_PARAM7(x) (((PT_REGS_ARM64 *)(x))->regs[6])
#define GO_PARAM8(x) (((PT_REGS_ARM64 *)(x))->regs[7])
#define GO_PARAM9(x) (((PT_REGS_ARM64 *)(x))->regs[8])
#define GOROUTINE(x) (((PT_REGS_ARM64 *)(x))->regs[28])

#define PT_REGS_PARM1(x) (((PT_REGS_ARM64 *)(x))->regs[0])
#define PT_REGS_PARM2(x) (((PT_REGS_ARM64 *)(x))->regs[1])
#define PT_REGS_PARM3(x) (((PT_REGS_ARM64 *)(x))->regs[2])
Expand Down Expand Up @@ -288,6 +317,32 @@ struct pt_regs;
#define PT_REGS_IP_CORE(x) BPF_CORE_READ((x), pc)
#endif

#elif defined(bpf_target_riscv)

struct pt_regs;
#define PT_REGS_RV const volatile struct user_regs_struct
#define PT_REGS_PARM1(x) (((PT_REGS_RV *)(x))->a0)
#define PT_REGS_PARM2(x) (((PT_REGS_RV *)(x))->a1)
#define PT_REGS_PARM3(x) (((PT_REGS_RV *)(x))->a2)
#define PT_REGS_PARM4(x) (((PT_REGS_RV *)(x))->a3)
#define PT_REGS_PARM5(x) (((PT_REGS_RV *)(x))->a4)
#define PT_REGS_RET(x) (((PT_REGS_RV *)(x))->ra)
#define PT_REGS_FP(x) (((PT_REGS_RV *)(x))->s5)
#define PT_REGS_RC(x) (((PT_REGS_RV *)(x))->a5)
#define PT_REGS_SP(x) (((PT_REGS_RV *)(x))->sp)
#define PT_REGS_IP(x) (((PT_REGS_RV *)(x))->epc)

#define PT_REGS_PARM1_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), a0)
#define PT_REGS_PARM2_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), a1)
#define PT_REGS_PARM3_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), a2)
#define PT_REGS_PARM4_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), a3)
#define PT_REGS_PARM5_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), a4)
#define PT_REGS_RET_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), ra)
#define PT_REGS_FP_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), fp)
#define PT_REGS_RC_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), a5)
#define PT_REGS_SP_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), sp)
#define PT_REGS_IP_CORE(x) BPF_CORE_READ((PT_REGS_RV *)(x), epc)

#endif

#if defined(bpf_target_powerpc)
Expand Down
Loading