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

Disable failing kfunc #1432

Merged
merged 2 commits into from
Jul 31, 2020
Merged

Conversation

viktormalik
Copy link
Contributor

@viktormalik viktormalik commented Jul 22, 2020

There is a number of functions that are listed as traceable in kfunc, but their tracing crashes bpftrace. This PR disables tracing of 2 kinds of such functions:

  1. Functions not listed in /sys/kernel/debug/tracing/available_filter_functions (e.g. inlined functions or functions marked as "notrace"). These should not be traceable even though there is BTF info for them (which makes them appear on the kfunc list). This fixes Inline functions are listed as traceable in kfunc #1366.
  2. Functions having more than 6 parameters. Kernel currently doesn't support BPF trampolines for functions with more than 6 parameters.
Checklist
  • Language changes are updated in docs/reference_guide.md
  • User-visible and non-trivial changes updated in CHANGELOG.md

@mmisono
Copy link
Collaborator

mmisono commented Jul 23, 2020

Thanks for fixing this. Looks good to me.

Copy link
Member

@danobi danobi left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Just some small comments. Also, can you apply the clang-format diff the CI is complaining about?

src/btf.h Outdated
@@ -44,9 +44,11 @@ class BTF
std::unique_ptr<std::istream> get_funcs(std::regex* re,
bool params,
std::string prefix) const;
bool is_traceable_func(std::string& func_name) const;
Copy link
Member

Choose a reason for hiding this comment

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

Nit

Suggested change
bool is_traceable_func(std::string& func_name) const;
bool is_traceable_func(const std::string& func_name) const;

Comment on lines +753 to +758
if (available_funs.fail())
{
if (bt_debug != DebugLevel::kNone)
{
std::cerr << "Error while reading traceable functions from "
<< kprobe_path << ": " << strerror(errno);
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this seems unlikely to fail. But when it does fail, kfuncs are disabled. I think this message would help user figure out what went wrong in that case. Not sure if it should be hidden behind -d flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true, although I don't think that the message should be shown every time the user lists probes and the file is not available. I'd suggest leaving it behind -d flag and displaying a similar message when user tries to attach a kfunc and it fails due to this error. I'd implement that as a separate PR that will improve error messages for kfuncs in general.

Copy link
Member

Choose a reason for hiding this comment

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

Why not raise an exception? That way the caller can figure out what to do with it which makes more sense for a "library" function like this imo.

If kfuncs depend on this we should probably hook it into --info too, would be confusing if bpftrace reports that kfuncs should work when it doesn.t

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why not raise an exception? That way the caller can figure out what to do with it which makes more sense for a "library" function like this imo.

I agree that raising an exception is cleaner, however, the caller is always the same - the constructor of BTF, called from the constructor of BPFtrace, so we would end up with the same problem again. A solution could be to postpone reading of the file to the phase when the function list is actually queried, but the function doing it (BTF::get_funcs) is marked as const and I didn't want to break that.

If kfuncs depend on this we should probably hook it into --info too, would be confusing if bpftrace reports that kfuncs should work when it doesn.t

I agree, will do.

The list of available kfunc symbols is taken from the BTF data, however,
it should not include non-traceable functions (those that are not listed
in /sys/kernel/debug/tracing/available_filter_functions) as tracing of
these may fail or be unstable. These are usually inlined functions or
functions marked as "notrace".

Resolves iovisor#1366.
Currently, when creating a BPF trampoline (in function
arch_prepare_bpf_trampoline), kernel only supports saving arguments of
the probed function that are passed in registers (at least for x86,
which is now the only architecture that has BPF trampolines). If the
function has more arguments, it is not attached, causing bpftrace to
fail.

This patch disables tracing of functions that have more arguments than
the number passed in registers for the current architecture.
Copy link
Member

@danobi danobi left a comment

Choose a reason for hiding this comment

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

LGTM

Also, as @fbs mentioned, hooking this into --info would be nice

@danobi danobi merged commit 9fb5bc2 into bpftrace:master Jul 31, 2020
@viktormalik viktormalik deleted the disable-failing-kfunc branch July 31, 2020 06:39
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.

Inline functions are listed as traceable in kfunc
4 participants