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. Add a new option to
workaround this problem.

Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
  • Loading branch information
chenhengqi committed Mar 25, 2022
1 parent f02f144 commit 9570ff3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion link/kprobe.go
Expand Up @@ -49,6 +49,13 @@ type KprobeOptions struct {
//
// Needs kernel 5.15+.
Cookie uint64

// Fallback to legacy tracefs kprobe interface
// event if kernel has kprobe PMU
//
// This allows old kernels which has kprobe PMU
// but don't support `.` in symbol names to work properly
Legacy bool
}

const (
Expand Down Expand Up @@ -174,7 +181,9 @@ func kprobe(symbol string, prog *ebpf.Program, opts *KprobeOptions, ret bool) (*
return tp, nil
}
if err != nil && !errors.Is(err, ErrNotSupported) {
return nil, fmt.Errorf("creating perf_kprobe PMU: %w", err)
if opts == nil || !opts.Legacy {
return nil, fmt.Errorf("creating perf_kprobe PMU: %w", err)
}
}

// Use tracefs if kprobe PMU is missing.
Expand Down

0 comments on commit 9570ff3

Please sign in to comment.