Skip to content

Commit

Permalink
Skip trace BTF-not-annotated bpf progs
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Asphaltt committed Apr 25, 2024
1 parent 133b041 commit ad27ad5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/pwru/bpf_prog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions internal/pwru/tc_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func (t *tcTracer) trace(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)
}

Expand Down

0 comments on commit ad27ad5

Please sign in to comment.