From f0fe6ed1ac808539d8437e13583875cb8d465947 Mon Sep 17 00:00:00 2001 From: Leon Hwang Date: Mon, 18 Mar 2024 00:28:10 +0800 Subject: [PATCH] Skip trace BTF-not-annotated bpf progs In bpf verifier, it denies that FENTRY/FEXIT cannot trace BTF-not-annotated bpf progs. Or, an error "FENTRY/FEXIT program can only be attached to another program annotated with BTF" occurs. Signed-off-by: Leon Hwang --- internal/pwru/bpf_prog.go | 7 ++++++- internal/pwru/tracing.go | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/pwru/bpf_prog.go b/internal/pwru/bpf_prog.go index 425d2e11..dfc4f2a4 100644 --- a/internal/pwru/bpf_prog.go +++ b/internal/pwru/bpf_prog.go @@ -12,6 +12,8 @@ import ( "golang.org/x/sys/unix" ) +var errNotFound = errors.New("not found") + type BpfProgName2Addr map[string]uint64 func listBpfProgs(typ ebpf.ProgramType) ([]*ebpf.Program, error) { @@ -49,7 +51,10 @@ func getEntryFuncName(prog *ebpf.Program) (string, string, error) { id, ok := info.BTFID() if !ok { - return "", "", fmt.Errorf("bpf program %s does not have BTF", info.Name) + // FENTRY/FEXIT program can only be attached to another program + // annotated with BTF. So if the BTF ID is not found, it means + // the program is not annotated with BTF. + return "", "", errNotFound } handle, err := btf.NewHandleFromID(id) diff --git a/internal/pwru/tracing.go b/internal/pwru/tracing.go index c3bda823..341a5681 100644 --- a/internal/pwru/tracing.go +++ b/internal/pwru/tracing.go @@ -66,6 +66,9 @@ func (t *tracing) traceProg(spec *ebpf.CollectionSpec, ) error { entryFn, name, err := getEntryFuncName(prog) if err != nil { + if errors.Is(err, errNotFound) { + return nil + } return fmt.Errorf("failed to get entry function name: %w", err) }