From 616e3afc11c1bb48c21ae1230d9060b5b5e96d56 Mon Sep 17 00:00:00 2001 From: Connor O'Brien Date: Tue, 1 Feb 2022 18:11:31 -0800 Subject: libbpf: support building bpftool Make changes necessary for bpftool to successfully build against libbpf - Grant visibility - Include hashmap.h and nlattr.h in libbpf_headers - Remove #if 0 block around references to __NR_bpf in skel_internal.h. This is no longer necessary now that we've added __NR_bpf to our glibc headers, and the affected functions are needed for building bpftool. Test: m bpftool Test: m libbpf pahole libbpf_bcc Bug: 203823368 Signed-off-by: Connor O'Brien Change-Id: If39f0989e162e0a7eac65e339b40ebda25211e2d --- Android.bp | 3 +++ src/skel_internal.h | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Android.bp b/Android.bp index 75ca2ba..8ef21c7 100644 --- a/Android.bp +++ b/Android.bp @@ -45,10 +45,12 @@ genrule { "bpf/bpf_helpers.h", "bpf/bpf_tracing.h", "bpf/btf.h", + "bpf/hashmap.h", "bpf/libbpf_common.h", "bpf/libbpf.h", "bpf/libbpf_legacy.h", "bpf/libbpf_version.h", + "bpf/nlattr.h", "bpf/skel_internal.h", "bpf/xsk.h", ], @@ -82,6 +84,7 @@ cc_library_static { "libz", ], visibility: [ + "//external/bpftool", "//external/dwarves", "//external/stg", ], diff --git a/src/skel_internal.h b/src/skel_internal.h index 2761970..dcd3336 100644 --- a/src/skel_internal.h +++ b/src/skel_internal.h @@ -57,9 +57,6 @@ struct bpf_load_and_run_opts { const char *errstr; }; -// ANDROID: Since the glibc stub we have does not know about __NR_bpf, this -// fails to compile. For now, just do not provide this functionality. -#if 0 static inline int skel_sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr, unsigned int size) { @@ -199,6 +196,5 @@ out: close(prog_fd); return err; } -#endif #endif -- cgit v1.2.3 From c6828c8d89c42717dabe3da54b1326af6e3aea3d Mon Sep 17 00:00:00 2001 From: Connor O'Brien Date: Tue, 1 Feb 2022 13:07:16 -0800 Subject: Make full libbpf visible to libbpf-tools libbpf-tools are eBPF-based tracing tools that combine a compiled BPF program & userspace code for loading, map creation, data processing etc. into a single standalone binary. Since they use libbpf functionality outside the subset provided by libbpf_minimal, they can only be built against the full libbpf. Grant visibility only to external/bcc/libbpf-tools, which contains only these tools. Other code in BCC (such as libbpf_bcc) can still only be built against libbpf_minimal Bug: 203823368 Test: m ksnoop Signed-off-by: Connor O'Brien Change-Id: Ie69e15a26ab158504b5deed57527784d9753737c --- Android.bp | 1 + 1 file changed, 1 insertion(+) diff --git a/Android.bp b/Android.bp index 8ef21c7..7b368a1 100644 --- a/Android.bp +++ b/Android.bp @@ -85,6 +85,7 @@ cc_library_static { ], visibility: [ "//external/bpftool", + "//external/bcc/libbpf-tools", "//external/dwarves", "//external/stg", ], -- cgit v1.2.3 From 57c0335cea7cbea301ae60e1b705c07512edf735 Mon Sep 17 00:00:00 2001 From: Connor O'Brien Date: Wed, 16 Feb 2022 12:24:18 -0800 Subject: btfloader: don't retry BTF loading after success We should only call btf__load_into_kernel() a second time if the first call fails. Bug: 219857711 Test: libbpf_load_test on 5.4 & 5.10 cuttlefish Signed-off-by: Connor O'Brien Change-Id: I7e25d4725992893ec88a6f7bcdf1ba3b1ca26968 --- android/btfloader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/btfloader.cpp b/android/btfloader.cpp index 24df4d6..cd82262 100644 --- a/android/btfloader.cpp +++ b/android/btfloader.cpp @@ -72,8 +72,8 @@ int main(int argc, char **argv) { bt->info = (BTF_INFO_KIND(bt->info)) << 24; } } + if (btf__load_into_kernel(btf)) return kERROR_LOAD_BTF; } - if (btf__load_into_kernel(btf)) return kERROR_LOAD_BTF; btfFd = btf__fd(btf); if (sendBtfFd(socketFd, btf__fd(btf))) return kERROR_SEND_BTF_FD; -- cgit v1.2.3 From ff0dd64de11aa532066b554b7c57d7191bd8edc1 Mon Sep 17 00:00:00 2001 From: Connor O'Brien Date: Wed, 16 Feb 2022 12:36:12 -0800 Subject: libbpf: run libbpf_load_test in presubmit Changes to btfloader or to libbpf proper can break program loading. Add TEST_MAPPING file to run libbpf_load_test in order to prevent this. Bug: 219857711 Test: atest --test-mapping external/libbpf Signed-off-by: Connor O'Brien Change-Id: I4d00407fefa8ac77031dc89bb888bb425527fa0d --- TEST_MAPPING | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 TEST_MAPPING diff --git a/TEST_MAPPING b/TEST_MAPPING new file mode 100644 index 0000000..90892fe --- /dev/null +++ b/TEST_MAPPING @@ -0,0 +1,7 @@ +{ + "presubmit": [ + { + "name": "libbpf_load_test" + } + ] +} -- cgit v1.2.3 From ae6cd3345b78a75652e83afb072e99e70e5887d8 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Fri, 18 Mar 2022 16:02:39 -0700 Subject: Add libbpf to hwasan-postsubmit Test: Run tests under HWASan. Bug: 193568145 Change-Id: I59d4616967817e0a9855e86eebf3230247f1383b --- TEST_MAPPING | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/TEST_MAPPING b/TEST_MAPPING index 90892fe..b6a940b 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -3,5 +3,10 @@ { "name": "libbpf_load_test" } + ], + "hwasan-postsubmit": [ + { + "name": "libbpf_load_test" + } ] } -- cgit v1.2.3