-
Notifications
You must be signed in to change notification settings - Fork 26
Preflight checks for BTF support #1120
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
Changes from all commits
e00a408
798f9a6
f04c729
3630696
29a7691
e6e5de4
c26fbde
f0d8766
ab9a5bd
f701f16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,9 @@ You should have received a copy of the GNU General Public License along with thi | |
|
||
#include <fstream> | ||
|
||
#include <bpf/libbpf.h> | ||
#include <linux/bpf.h> | ||
|
||
#include "Logging.h" | ||
|
||
namespace collector { | ||
|
@@ -179,6 +182,72 @@ bool HostInfo::HasEBPFSupport() { | |
return collector::hasEBPFSupport(kernel, GetOSID()); | ||
} | ||
|
||
bool HostInfo::HasBTFSymbols() { | ||
// This list is taken from libbpf | ||
const char* locations[] = { | ||
/* try canonical vmlinux BTF through sysfs first */ | ||
"/sys/kernel/btf/vmlinux", | ||
/* fall back to trying to find vmlinux on disk otherwise */ | ||
"/boot/vmlinux-%1$s", | ||
"/lib/modules/%1$s/vmlinux-%1$s", | ||
"/lib/modules/%1$s/build/vmlinux", | ||
"/usr/lib/modules/%1$s/kernel/vmlinux", | ||
"/usr/lib/debug/boot/vmlinux-%1$s", | ||
"/usr/lib/debug/boot/vmlinux-%1$s.debug", | ||
"/usr/lib/debug/lib/modules/%1$s/vmlinux", | ||
0}; | ||
|
||
char path[PATH_MAX + 1]; | ||
const char* const* location; | ||
|
||
for (location = locations; *location; location++) { | ||
snprintf(path, PATH_MAX, *location, kernel_version_.release.c_str()); | ||
std::string host_path = GetHostPath(path); | ||
|
||
if (faccessat(AT_FDCWD, host_path.c_str(), R_OK, AT_EACCESS) == 0) { | ||
CLOG(DEBUG) << "BTF symbols found in " << host_path; | ||
return true; | ||
|
||
} else { | ||
if (errno == ENOTDIR || errno == ENOENT) { | ||
CLOG(DEBUG) << host_path << " does not exist"; | ||
} else { | ||
CLOG(WARNING) << "Unable to access " << host_path << ": " << StrError(); | ||
} | ||
} | ||
} | ||
|
||
CLOG(DEBUG) << "Unable to find BTF symbols in any of the usual locations."; | ||
|
||
return false; | ||
} | ||
|
||
bool HostInfo::HasBPFRingBufferSupport() { | ||
int res; | ||
|
||
res = libbpf_probe_bpf_map_type(BPF_MAP_TYPE_RINGBUF, NULL); | ||
|
||
if (res < 0) { | ||
CLOG(WARNING) << "Unable to check for the BPF RingBuffer availability. " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't find a reference to the errno availability in the docs for that case. And the code suggests that it does not reflect the actual error reason. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one [1]? It seems this function does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. errno is tested underneath, but when the error if reported at the API level, I am afraid this information is lost. |
||
<< "Assuming it is available."; | ||
} | ||
|
||
return res != 0; | ||
} | ||
|
||
bool HostInfo::HasBPFTracingSupport() { | ||
int res; | ||
|
||
res = libbpf_probe_bpf_prog_type(BPF_PROG_TYPE_TRACING, NULL); | ||
|
||
if (res < 0) { | ||
CLOG(WARNING) << "Unable to check for the BPF tracepoint program type support. " | ||
<< "Assuming it is available."; | ||
} | ||
|
||
return res != 0; | ||
} | ||
|
||
bool HostInfo::IsUEFI() { | ||
struct stat sb; | ||
std::string efi_path = GetHostPath("/sys/firmware/efi"); | ||
|
Uh oh!
There was an error while loading. Please reload this page.