Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link: always include requested symbol in kprobe creation errors #959

Merged
merged 1 commit into from
Mar 6, 2023

Conversation

ti-mo
Copy link
Collaborator

@ti-mo ti-mo commented Mar 6, 2023

Before, when a caller would try to set a kprobe on e.g. __x64_sys_listen, the error message would look something like 'creating perf_kprobe PMU: token __arm64___x64_sys_listen: not found: no such file or directory'. This doesn't mention that the requested symbol has been attempted in addition to the prefixed symbol mentioned in the error message.

If a symbol doesn't exist, which is going to be the vast majority of cases, the caller will only see the prefixed symbol echoed in the error message, which can make them wonder if the original symbol has been attempted at all.

This patch makes PMU and tracefs errors more uniform and always mentions the requested symbol in the error string, which only used to happen for tracefs.

Fixes #956

@ti-mo ti-mo requested review from lmb, mmat11 and mtardy March 6, 2023 11:02
Copy link
Member

@mtardy mtardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that would be lovely! 😸

So now it will look like this:

creating perf_kprobe PMU (tried '_x64_sys_listen'): token __arm64___x64_sys_listen: not found: no such file or directory

It still requires knowing that the lib is retrying on fail with an arch-specific prefix but at least the original symbol appears in the error which is excellent!

link/kprobe.go Outdated
@@ -199,7 +199,7 @@ 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)
return nil, fmt.Errorf("creating perf_kprobe PMU (tried '%s'): %w", symbol, err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to just return the original error?

origErr := pmuKprobe(...)

fallbackErr := pmuKprobe(...)
if fallbackErr != nil { return origErr }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The best would be both, being explicit about the fact that symbol1 and adaptedSymbol1 failed. Losing the fallbackErr could make the behavior not very clear I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay if we stick with my proposal? It's a simple change and conveys that both symbols were attempted in a familiar format. Omitting the fallback error will obscure the prefixing behaviour, so the caller will probably conclude they need to add the prefix explicitly and retry, which I'd like to avoid.

Go 1.20 introduces errors.Join(), but that uses newlines, which I'd also like to avoid. 🙂

link/kprobe.go Outdated Show resolved Hide resolved
Before, when a caller would try to set a kprobe on e.g. __x64_sys_listen,
the error message would look something like 'creating perf_kprobe PMU:
token __arm64___x64_sys_listen: not found: no such file or directory'.
This doesn't mention that the requested symbol has been attempted in addition
to the prefixed symbol mentioned in the error message.

If a symbol doesn't exist, which is going to be the vast majority of cases,
the caller will only see the prefixed symbol echoed in the error message,
which can make them wonder if the original symbol has been attempted at all.

This patch makes PMU and tracefs errors more uniform and always mentions the
requested symbol in the error string, which only used to happen for tracefs.
Also documents the behaviour on K(ret)probe().

Fixes cilium#956

Signed-off-by: Timo Beckers <timo@isovalent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error logs when retrying to attach a kprobe with an arch specific prefix
4 participants