Skip to content

Commit

Permalink
Fix fentry probes wrt. missing_probes config
Browse files Browse the repository at this point in the history
Currently, fentry/fexit probes do not correctly respect the
missing_probes config, especially for the "ignore" and "warn" settings.
The reason is that while a warning is correctly displayed (or not for
"ignore"), the probe is still attempted to be loaded which causes the
loading of the entire BPF object fail as libbpf fails on not finding the
symbol in BTF.

Fix this issue by disabling auto-load for missing probes. Note that this
means that the code for the missing probes is still generated into the
BPF object. This is a bit inefficient but will be necessary for AOT as
we will not know which symbols exist on the target machine in advance.

Also fix the error/warning message a bit to show "symbol" instead of
":symbol" in case when module name is not given.
  • Loading branch information
viktormalik authored and jordalgo committed Dec 12, 2024
1 parent a1568e6 commit c11adab
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/include/aot_skip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,13 @@ aot.other.symbolize enum in tuple map value
aot.probe.fentry
aot.probe.fentry args
aot.probe.fentry args as a pointer
aot.probe.fentry_error_missing_probes
aot.probe.fentry func builtin
aot.probe.fentry_ignore_missing_probes
aot.probe.fentry_module
aot.probe.fentry_module_wildcard
aot.probe.fentry_multiple_attach_point_multiple_functions
aot.probe.fentry_warn_missing_probes
aot.probe.fentry_wildcard
aot.probe.fexit
aot.probe.kfunc
Expand Down
3 changes: 3 additions & 0 deletions src/attached_probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ std::string progtypeName(libbpf::bpf_prog_type t)

void AttachedProbe::attach_fentry()
{
if (progfd_ < 0)
return;

tracing_fd_ = bpf_raw_tracepoint_open(nullptr, progfd_);
if (tracing_fd_ < 0) {
throw FatalUserException("Error attaching probe: " + probe_.name);
Expand Down
9 changes: 7 additions & 2 deletions src/bpfprogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,29 @@ void BpfProgram::set_attach_target(const Probe &probe,

const std::string &mod = probe.path;
const std::string &fun = probe.attach_point;
const std::string attach_target = !mod.empty() ? mod + ":" + fun : fun;

const std::string &btf_fun = probe.type == ProbeType::iter ? "bpf_iter_" + fun
: fun;
if (btf.get_btf_id(btf_fun, mod) < 0) {
std::string msg = "No BTF found for " + mod + ":" + fun;
const std::string msg = "No BTF found for " + attach_target;
if (probe.orig_name != probe.name &&
config.get(ConfigKeyMissingProbes::default_) !=
ConfigMissingProbes::error) {
// One attach point in a multi-attachpoint probe failed and the user
// requested not to error out. Show a warning (if requested) and continue
// but disable auto-loading of the program as it would make the entire BPF
// object loading fail.
if (config.get(ConfigKeyMissingProbes::default_) ==
ConfigMissingProbes::warn)
LOG(WARNING) << msg << ", skipping.";
bpf_program__set_autoload(bpf_prog_, false);
} else {
// explicit match failed, fail hard
throw FatalUserException(msg);
}
}

const std::string &attach_target = !mod.empty() ? mod + ":" + fun : fun;
bpf_program__set_attach_target(bpf_prog_, 0, attach_target.c_str());
}

Expand Down
13 changes: 13 additions & 0 deletions tests/runtime/probe
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ REQUIRES_FEATURE fentry
REQUIRES_FEATURE btf
AFTER ./testprogs/fentry_args 1111 2222

NAME fentry_warn_missing_probes
PROG fentry:vfs_read,fentry:nonsense { exit(); }
EXPECT WARNING: No BTF found for nonsense, skipping.

NAME fentry_ignore_missing_probes
PROG config = { missing_probes = "ignore" } fentry:vfs_read,fentry:nonsense { exit(); }
EXPECT_NONE WARNING: No BTF found for nonsense, skipping.

NAME fentry_error_missing_probes
PROG config = { missing_probes = "error" } fentry:vfs_read,fentry:nonsense { exit(); }
EXPECT ERROR: No BTF found for nonsense
WILL_FAIL

# Sanity check for kfunc/kretfunc alias
NAME kfunc
PROG kfunc:vfs_read { printf("SUCCESS %d\n", pid); exit(); }
Expand Down

0 comments on commit c11adab

Please sign in to comment.