Skip to content

Commit

Permalink
link/kprobe: Allow fallback to tracefs on old kernels
Browse files Browse the repository at this point in the history
Centos 8 (with kernel 4.18) has kprobe PMU support, but
don't allow `.` in symbol name. Detect such cases and
fallback to tracefs interface.

Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
  • Loading branch information
chenhengqi committed Mar 28, 2022
1 parent f02f144 commit 570d306
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions link/kprobe.go
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"strings"
"sync"
"unsafe"

Expand Down Expand Up @@ -263,6 +264,13 @@ func pmuProbe(typ probeType, args probeArgs) (*perfEvent, error) {

rawFd, err := unix.PerfEventOpen(&attr, args.pid, 0, -1, unix.PERF_FLAG_FD_CLOEXEC)

// On some old kernels, kprobe PMU don't allow `.` in symbol name and return -EINVAL
// in such cases. Returns ErrNotSupported to fallback to tracefs interface.
// https://github.com/torvalds/linux/blob/94710cac0ef4/kernel/trace/trace_kprobe.c#L340-L343
if errors.Is(err, unix.EINVAL) && strings.Contains(args.symbol, ".") {
return nil, fmt.Errorf("symbol '%s' not supported: %w", args.symbol, ErrNotSupported)
}

// 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.
Expand Down

0 comments on commit 570d306

Please sign in to comment.