Skip to content

Commit

Permalink
link: don't treat EINVAL from perf_event_open as ENOENT
Browse files Browse the repository at this point in the history
Running TestUprobeExtWithOpts on arm64 currently gives a weird error:

    uprobe_test.go:101: creating perf_uprobe PMU: symbol 'open+0x1' not found: file does not exist

Investigating via strace shows that perf_event_open returns EINVAL:

    perf_event_open({type=0x7 /* PERF_TYPE_??? */, size=PERF_ATTR_SIZE_VER1, ...}, -1, 0, -1, PERF_FLAG_FD_CLOEXEC) = -1 EINVAL (Invalid argument)

We map this to ENOENT since older kernels don't return a useful error
when the target function doesn't exist. The example above shows that this is
too broad.

Stop mapping EINVAL to ENOENT.
  • Loading branch information
lmb committed Jul 21, 2022
1 parent e2d485b commit 90411de
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion link/kprobe.go
Expand Up @@ -304,7 +304,7 @@ func pmuProbe(typ probeType, args probeArgs) (*perfEvent, error) {
// Since commit 97c753e62e6c, ENOENT is correctly returned instead of EINVAL
// when trying to create a kretprobe for a missing symbol. Make sure ENOENT
// is returned to the caller.
if errors.Is(err, os.ErrNotExist) || errors.Is(err, unix.EINVAL) {
if errors.Is(err, os.ErrNotExist) {
return nil, fmt.Errorf("symbol '%s+%#x' not found: %w", args.symbol, args.offset, os.ErrNotExist)
}
// Since commit ab105a4fb894, -EILSEQ is returned when a kprobe sym+offset is resolved
Expand Down

0 comments on commit 90411de

Please sign in to comment.