@cryptotaxi247 / netdata-1 / commits / bd1845f2a

Fetch libbpf from netdata fork (#9637)

Vladimir Kobal committed Aug 3, 2020 at 09:37 UTC bd1845f2a7565eaaa64ebc5d946cecb6db92f50b
6 files changed +4 -239
Makefile.am
-1
@@ -59,7 +59,6 @@ dist_noinst_DATA = \
59 netdata.spec \
60 package.json \
61 docs \
62 - libnetdata/ebpf/libbpf.c.diff \
62 packaging/version \
63 packaging/dashboard.version \
64 packaging/dashboard.checksums \
libnetdata/ebpf/libbpf.c.diff deleted
-229
@@ -1,229 +0,0 @@
1 ---- a/src/libbpf.c
2 -+++ b/src/libbpf.c
3 -@@ -620,6 +620,93 @@ bpf_object__init_prog_names(struct bpf_object *obj)
4 - return 0;
5 - }
6 -
7 -+static __u32 choose_specific_version0(int fd, __u32 current)
8 -+{
9 -+ char ver[256];
10 -+ __u32 v_major, v_minor, v_patch;
11 -+ ssize_t len = read(fd, ver, sizeof(ver));
12 -+ if (len < 0) {
13 -+ return 0;
14 -+ }
15 -+ ver[len] = '\0';
16 -+
17 -+ char *first = strchr(ver, ' ');
18 -+ if (!first) {
19 -+ return 0;
20 -+ }
21 -+
22 -+ first++;
23 -+ char *version = strchr(first, ' ');
24 -+ if (!version) {
25 -+ return 0;
26 -+ }
27 -+
28 -+ version++;
29 -+ if (sscanf(version, "%u.%u.%u", &v_major, &v_minor, &v_patch) != 3)
30 -+ return current;
31 -+
32 -+ return KERNEL_VERSION(v_major, v_minor, v_patch);
33 -+}
34 -+
35 -+static __u32 choose_kernel_version(__u32 current)
36 -+{
37 -+ FILE *fp_d = fopen("/etc/debian_version","r");
38 -+ int fp_u = open("/proc/version_signature", O_RDONLY);
39 -+ FILE *fp_rh = fopen("/etc/redhat-release","r");
40 -+ char tmp[32];
41 -+ int de = 0;
42 -+ __u32 ret;
43 -+
44 -+ if (!fp_d && !fp_rh && fp_u == -1)
45 -+ return current;
46 -+
47 -+ struct utsname u;
48 -+ uname(&u);
49 -+
50 -+ if (fp_d) {
51 -+ fclose(fp_d);
52 -+ de = 1;
53 -+ }
54 -+
55 -+ if (fp_rh) {
56 -+ fclose(fp_rh);
57 -+ de = 0;
58 -+ }
59 -+
60 -+ if ( fp_u > 0 ) {
61 -+ ret = choose_specific_version0(fp_u, current);
62 -+ close(fp_u);
63 -+ return (!ret)?current:ret;
64 -+ }
65 -+
66 -+ __u32 v_kernel,v_major, v_minor, v_patch;
67 -+ __u32 r_kernel,r_major, r_minor, r_patch;
68 -+
69 -+ if (sscanf(u.release, "%u.%u.%u-%u", &v_kernel, &v_major, &v_minor, &v_patch) != 4)
70 -+ return current;
71 -+
72 -+ int length = snprintf(tmp, 31, "%u.%u", v_kernel, v_major);
73 -+ tmp[length] = '\0';
74 -+
75 -+ char *parse = strstr(u.version, tmp);
76 -+ if (!parse) {
77 -+ return current;
78 -+ }
79 -+
80 -+ char *space = strchr(parse, ' ');
81 -+ if(space) {
82 -+ length = (int)(space - parse);
83 -+ strncpy(tmp, parse, (size_t)length);
84 -+ tmp[length] = '\0';
85 -+ }
86 -+
87 -+ if (sscanf(tmp, "%u.%u.%u-%u", &r_kernel, &r_major, &r_minor, &r_patch) != 4)
88 -+ return current;
89 -+
90 -+ ret = (de)?KERNEL_VERSION(r_kernel, r_major, r_minor):KERNEL_VERSION(r_kernel, r_major, r_minor) + r_patch;
91 -+ return (ret > current)?ret:current;
92 -+}
93 -+
94 - static __u32 get_kernel_version(void)
95 - {
96 - __u32 major, minor, patch;
97 -@@ -628,7 +715,11 @@ static __u32 get_kernel_version(void)
98 - uname(&info);
99 - if (sscanf(info.release, "%u.%u.%u", &major, &minor, &patch) != 3)
100 - return 0;
101 -- return KERNEL_VERSION(major, minor, patch);
102 -+
103 -+ if (major < 5)
104 -+ return choose_kernel_version(KERNEL_VERSION(major, minor, patch));
105 -+ else
106 -+ return KERNEL_VERSION(major, minor, patch);
107 - }
108 -
109 - static const struct btf_member *
110 -@@ -3239,6 +3330,10 @@ int bpf_map__resize(struct bpf_map *map, __u32 max_entries)
111 - static int
112 - bpf_object__probe_loading(struct bpf_object *obj)
113 - {
114 -+ // Don't probe loading for very old kernels. CentOS 7 can't load this probe.
115 -+ if (obj->kern_version <= KERNEL_VERSION(3, 10, 0))
116 -+ return 0;
117 -+
118 - struct bpf_load_program_attr attr;
119 - char *cp, errmsg[STRERR_BUFSIZE];
120 - struct bpf_insn insns[] = {
121 -@@ -7612,6 +7707,88 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,
122 - return pfd;
123 - }
124 -
125 -+static int perf_event_open_old_kprobe(bool retprobe, const char *name)
126 -+{
127 -+#define DEBUG_FS "/sys/kernel/debug/tracing/"
128 -+ struct perf_event_attr attr = {};
129 -+ char errmsg[STRERR_BUFSIZE];
130 -+ int kfd = -1, ret = -1, err;
131 -+ char event_alias[256], buf[PATH_MAX];
132 -+ const char *event_prefix = "";
133 -+ bool event_was_written = false;
134 -+
135 -+ kfd = open(DEBUG_FS "kprobe_events", O_WRONLY | O_APPEND, 0);
136 -+ if (kfd < 0) {
137 -+ pr_warn("failed to open '%s%s': %s\n",
138 -+ DEBUG_FS,
139 -+ "kprobe_events",
140 -+ libbpf_strerror_r(kfd, errmsg, sizeof(errmsg)));
141 -+ return kfd;
142 -+ }
143 -+
144 -+ char type = retprobe ? 'r' : 'p';
145 -+ snprintf(event_alias, sizeof(event_alias), "%c_netdata_%s_%d", type, name, getpid());
146 -+
147 -+#ifdef __x86_64__
148 -+ if (strncmp(name, "sys_", 4) == 0) {
149 -+ snprintf(buf, sizeof(buf), "%c:__x64_%s __x64_%s",
150 -+ type, event_alias, name);
151 -+ ret = write(kfd, buf, strlen(buf));
152 -+
153 -+ if (ret >= 0) {
154 -+ event_was_written = true;
155 -+ event_prefix = "__x64_";
156 -+ }
157 -+ }
158 -+#endif
159 -+
160 -+ if (!event_was_written) {
161 -+ snprintf(buf, sizeof(buf), "%c:%s %s",
162 -+ type, event_alias, name);
163 -+ ret = write(kfd, buf, strlen(buf));
164 -+ if (ret < 0) {
165 -+ pr_warn("failed to create kprobe '%s': %s\n",
166 -+ name,
167 -+ libbpf_strerror_r(ret, errmsg, sizeof(errmsg)));
168 -+ close(kfd);
169 -+ return ret;
170 -+ }
171 -+ }
172 -+
173 -+ close(kfd);
174 -+
175 -+ snprintf(buf, sizeof(buf), DEBUG_FS "events/kprobes/%s%s/id",
176 -+ event_prefix,
177 -+ event_alias);
178 -+
179 -+ ret = parse_uint_from_file(buf, "%d\n");
180 -+ if (ret < 0) {
181 -+ pr_warn("failed to determine event id: %s\n",
182 -+ libbpf_strerror_r(ret, errmsg, sizeof(errmsg)));
183 -+ return ret;
184 -+ }
185 -+ attr.config = ret;
186 -+
187 -+ attr.size = sizeof(attr);
188 -+ attr.type = PERF_TYPE_TRACEPOINT;
189 -+ attr.config1 = ptr_to_u64(name); /* kprobe_func */
190 -+ attr.config2 = 0; /* kprobe_addr */
191 -+
192 -+ /* pid filter is meaningful only for uprobes */
193 -+ kfd = syscall(__NR_perf_event_open, &attr,
194 -+ -1 /* pid */,
195 -+ 0 /* cpu */,
196 -+ -1 /* group_fd */, PERF_FLAG_FD_CLOEXEC);
197 -+ if (kfd < 0) {
198 -+ err = -errno;
199 -+ pr_warn("%s perf_event_open_old_kprobe() failed: %s\n",
200 -+ "kprobe",
201 -+ libbpf_strerror_r(err, errmsg, sizeof(errmsg)));
202 -+ return err;
203 -+ }
204 -+ return kfd;
205 -+}
206 -+
207 - struct bpf_link *bpf_program__attach_kprobe(struct bpf_program *prog,
208 - bool retprobe,
209 - const char *func_name)
210 -@@ -7623,11 +7800,14 @@ struct bpf_link *bpf_program__attach_kprobe(struct bpf_program *prog,
211 - pfd = perf_event_open_probe(false /* uprobe */, retprobe, func_name,
212 - 0 /* offset */, -1 /* pid */);
213 - if (pfd < 0) {
214 -- pr_warn("program '%s': failed to create %s '%s' perf event: %s\n",
215 -- bpf_program__title(prog, false),
216 -- retprobe ? "kretprobe" : "kprobe", func_name,
217 -- libbpf_strerror_r(pfd, errmsg, sizeof(errmsg)));
218 -- return ERR_PTR(pfd);
219 -+ pfd = perf_event_open_old_kprobe(retprobe, func_name);
220 -+ if (pfd < 0) {
221 -+ pr_warn("program '%s': failed to create %s '%s' perf event: %s\n",
222 -+ bpf_program__title(prog, false),
223 -+ retprobe ? "kretprobe" : "kprobe", func_name,
224 -+ libbpf_strerror_r(pfd, errmsg, sizeof(errmsg)));
225 -+ return ERR_PTR(pfd);
226 -+ }
227 - }
228 - link = bpf_program__attach_perf_event(prog, pfd);
229 - if (IS_ERR(link)) {
netdata-installer.sh
+1 -2
@@ -715,12 +715,11 @@ bundle_libbpf() {
715 LIBBPF_PACKAGE_BASENAME="v${LIBBPF_PACKAGE_VERSION}.tar.gz"
716
717 if fetch_and_verify "libbpf" \
718 - "https://github.com/libbpf/libbpf/archive/${LIBBPF_PACKAGE_BASENAME}" \
718 + "https://github.com/netdata/libbpf/archive/${LIBBPF_PACKAGE_BASENAME}" \
719 "${LIBBPF_PACKAGE_BASENAME}" \
720 "${tmp}" \
721 "${NETDATA_LOCAL_TARBALL_OVERRIDE_LIBBPF}"; then
722 if run tar -xf "${tmp}/${LIBBPF_PACKAGE_BASENAME}" -C "${tmp}" &&
723 - run git apply --directory="${tmp}/libbpf-${LIBBPF_PACKAGE_VERSION}" --unsafe-paths libnetdata/ebpf/libbpf.c.diff &&
723 build_libbpf "${tmp}/libbpf-${LIBBPF_PACKAGE_VERSION}" &&
724 copy_libbpf "${tmp}/libbpf-${LIBBPF_PACKAGE_VERSION}" &&
725 rm -rf "${tmp}"; then
packaging/bundle-libbpf.sh
+1 -5
@@ -10,13 +10,9 @@ else
10 fi
11
12 mkdir -p "${1}/externaldeps/libbpf" || exit 1
13 -curl -sSL --connect-timeout 10 --retry 3 "https://github.com/libbpf/libbpf/archive/${LIBBPF_TARBALL}" > "${LIBBPF_TARBALL}" || exit 1
13 +curl -sSL --connect-timeout 10 --retry 3 "https://github.com/netdata/libbpf/archive/${LIBBPF_TARBALL}" > "${LIBBPF_TARBALL}" || exit 1
14 sha256sum -c "${1}/packaging/libbpf.checksums" || exit 1
15 tar -xzf "${LIBBPF_TARBALL}" -C "${1}/externaldeps/libbpf" || exit 1
16 -LPWD="${PWD}"
17 -cd "${LIBBPF_BUILD_PATH}" || exit 1
18 -patch -p1 < "${1}/libnetdata/ebpf/libbpf.c.diff" || exit 1
19 -cd "${LPWD}" || exit 1
16 make -C "${LIBBPF_BUILD_PATH}/src" BUILD_STATIC_ONLY=1 OBJDIR=build/ DESTDIR=../ install || exit 1
17 cp -a "${LIBBPF_BUILD_PATH}/usr/${lib_subdir}/libbpf.a" "${1}/externaldeps/libbpf" || exit 1
18 cp -a "${LIBBPF_BUILD_PATH}/usr/include" "${1}/externaldeps/libbpf" || exit 1
packaging/libbpf.checksums
+1 -1
@@ -1 +1 @@
1 -c216c13b48f5fbd870a9b10a9cb747e0e6063f547e327c4d5a0688713e26a1a4 v0.0.9.tar.gz
1 +fc33402ba33c8f8c5aa18afbb86a9932965886f2906c50e8f2110a1a2126e3ee v0.0.9_netdata-1.tar.gz
packaging/libbpf.version
+1 -1
@@ -1 +1 @@
1 -0.0.9
1 +0.0.9_netdata-1