From a710121a072a5b4fff974043ab82f168953cde67 Mon Sep 17 00:00:00 2001 From: "chengshuyi.csy" Date: Thu, 23 Dec 2021 13:35:24 +0800 Subject: [PATCH 1/3] libbpf: Support SYSAK_WORK_PATH env var where to find vmlinux bpf file. Signed-off-by: chengshuyi.csy --- source/lib/internal/ebpf/libbpf/src/btf.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/lib/internal/ebpf/libbpf/src/btf.c b/source/lib/internal/ebpf/libbpf/src/btf.c index d9c10830..f7e46e10 100644 --- a/source/lib/internal/ebpf/libbpf/src/btf.c +++ b/source/lib/internal/ebpf/libbpf/src/btf.c @@ -4598,11 +4598,24 @@ struct btf *libbpf_find_kernel_btf(void) { "/usr/lib/debug/lib/modules/%1$s/vmlinux" }, }; char path[PATH_MAX + 1]; + char *sysak_env_path; struct utsname buf; struct btf *btf; int i; uname(&buf); + sysak_env_path = getenv("SYSAK_WORK_PATH"); + if (sysak_env_path) { + snprintf(path, PATH_MAX, "%s/tools/vmlinux-%s", sysak_env_path, buf.release); + + btf = btf__parse(path, NULL); + pr_debug("loading kernel BTF '%s': %ld\n", + path, IS_ERR(btf) ? PTR_ERR(btf) : 0); + if (IS_ERR(btf)) + goto out; + + return btf; + } for (i = 0; i < ARRAY_SIZE(locations); i++) { snprintf(path, PATH_MAX, locations[i].path_fmt, buf.release); @@ -4623,6 +4636,7 @@ struct btf *libbpf_find_kernel_btf(void) return btf; } +out: pr_warn("failed to find valid kernel BTF\n"); return ERR_PTR(-ESRCH); } -- Gitee From 204867b8c5545abc3fde84d7041e82ac086e5b3d Mon Sep 17 00:00:00 2001 From: "chengshuyi.csy" Date: Thu, 23 Dec 2021 13:37:03 +0800 Subject: [PATCH 2/3] btf: Unzip the btf file to the SYSAK_WORK_PATH/tools path by default. Signed-off-by: chengshuyi.csy --- source/tools/combine/btf/btf.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/tools/combine/btf/btf.sh b/source/tools/combine/btf/btf.sh index 8b8a0b96..bc1e7cda 100644 --- a/source/tools/combine/btf/btf.sh +++ b/source/tools/combine/btf/btf.sh @@ -2,9 +2,8 @@ # author: Shuyi Cheng # email: chengshuyi@linux.alibaba.com -TOOLS_ROOT=$(dirname "$0") -zip_path=${TOOLS_ROOT}/BTF/btf.7z -btf_dir=${TOOLS_ROOT}/BTF +zip_path=${SYSAK_WORK_PATH}/tools/BTF/btf.7z +btf_dir=${SYSAK_WORK_PATH}/tools btf_path=${btf_dir}/vmlinux-$(uname -r) usage() { @@ -14,7 +13,7 @@ usage() { } extract_btf() { - ${TOOLS_ROOT}/BTF/7za e ${zip_path} -o${btf_dir} vmlinux-btf/vmlinux-$(uname -r) + ${SYSAK_WORK_PATH}/tools/BTF/7za e ${zip_path} -o${btf_dir} vmlinux-btf/vmlinux-$(uname -r) } while getopts 'd:h' OPT; do -- Gitee From 67529404db34c0dea9616b43ff8c5447acafb79a Mon Sep 17 00:00:00 2001 From: "chengshuyi.csy" Date: Thu, 23 Dec 2021 13:38:09 +0800 Subject: [PATCH 3/3] bpf: Update bpf test to verify whether libbpf supports SYSAK_WORK_PATH. Signed-off-by: chengshuyi.csy --- source/tools/test/bpf_test/bpf/bpftest1.bpf.c | 7 +++---- source/tools/test/bpf_test/bpf/bpftest2.bpf.c | 2 ++ source/tools/test/bpf_test/bpftest.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/source/tools/test/bpf_test/bpf/bpftest1.bpf.c b/source/tools/test/bpf_test/bpf/bpftest1.bpf.c index 4186d909..09e41de5 100644 --- a/source/tools/test/bpf_test/bpf/bpftest1.bpf.c +++ b/source/tools/test/bpf_test/bpf/bpftest1.bpf.c @@ -4,14 +4,13 @@ #include #include "../bpftest.h" - - SEC("kprobe/tcp_v4_connect") -int BPF_KPROBE(kprobe_tcp_v4_connect,struct sock *sk, struct sockaddr *uaddr, int addr_len) +int BPF_KPROBE(kprobe_tcp_v4_connect, struct sock *sk, struct sockaddr *uaddr, int addr_len) { u64 tgid = bpf_get_current_pid_tgid(); + int tmp; + BPF_CORE_READ_INTO(&tmp, sk, sk_rcvbuf); return 0; } - char LICENSE[] SEC("license") = "GPL"; \ No newline at end of file diff --git a/source/tools/test/bpf_test/bpf/bpftest2.bpf.c b/source/tools/test/bpf_test/bpf/bpftest2.bpf.c index 4186d909..d5561764 100644 --- a/source/tools/test/bpf_test/bpf/bpftest2.bpf.c +++ b/source/tools/test/bpf_test/bpf/bpftest2.bpf.c @@ -10,6 +10,8 @@ SEC("kprobe/tcp_v4_connect") int BPF_KPROBE(kprobe_tcp_v4_connect,struct sock *sk, struct sockaddr *uaddr, int addr_len) { u64 tgid = bpf_get_current_pid_tgid(); + int tmp; + BPF_CORE_READ_INTO(&tmp, sk, sk_rcvbuf); return 0; } diff --git a/source/tools/test/bpf_test/bpftest.c b/source/tools/test/bpf_test/bpftest.c index 6d3420e7..f50d8d4c 100644 --- a/source/tools/test/bpf_test/bpftest.c +++ b/source/tools/test/bpf_test/bpftest.c @@ -57,7 +57,7 @@ int main(int argc, char **argv) goto cleanup; printf("bpftest2 program load done, test finished. exit.\n"); - while(1){} + // while(1){} cleanup: // destory the bpf program bpftest1_bpf__destroy(bpftest1); -- Gitee