在 2023/5/26 17:53, Jiri Olsa 写道:
On Fri, May 26, 2023 at 10:10:47AM +0800, Jackie Liu wrote:
SNIP
-resolve_kprobe_multi_cb(unsigned long long sym_addr, char sym_type,
- const char *sym_name, void *ctx)
+kallsyms_resolve_kprobe_multi_cb(unsigned long long sym_addr, char sym_type,
+ const char *sym_name, void *ctx)
{
struct kprobe_multi_resolve *res = ctx;
int err;
@@ -10431,8 +10438,8 @@ resolve_kprobe_multi_cb(unsigned long long sym_addr, char sym_type,
if (!glob_match(sym_name, res->pattern))
return 0;
- err = libbpf_ensure_mem((void **) &res->addrs, &res->cap, sizeof(unsigned long),
- res->cnt + 1);
+ err = libbpf_ensure_mem((void **) &res->addrs, &res->cap,
+ sizeof(unsigned long), res->cnt + 1);
hum, looks like this is just formatting change, AFAICS we don't need that
if (err)
return err;
@@ -10440,6 +10447,75 @@ resolve_kprobe_multi_cb(unsigned long long sym_addr, char sym_type,
return 0;
}
SNIP
+
+static void kprobe_multi_resolve_free(struct kprobe_multi_resolve *res)
+{
+ while (res->syms && res->cnt)
+ free((char *)res->syms[--res->cnt]);
+
+ free(res->syms);
+ free(res->addrs);
we should set cnt and cap to zero for the fallback sake
It is necessary to set cap to 0, cnt is already 0, if syms exists.
+}
+
struct bpf_link *
bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog,
const char *pattern,
@@ -10476,13 +10552,20 @@ bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog,
return libbpf_err_ptr(-EINVAL);
if (pattern) {
- err = libbpf_kallsyms_parse(resolve_kprobe_multi_cb, &res);
- if (err)
- goto error;
+ err = libbpf_available_kprobes_parse(ftrace_resolve_kprobe_multi_cb,
+ &res);
+ if (err) {
+ /* fallback to kallsyms */
we need to call kprobe_multi_resolve_free in here and set
cnt/cap to zero in kprobe_multi_resolve_free
Yes.
jirka
+ err = libbpf_kallsyms_parse(kallsyms_resolve_kprobe_multi_cb,
+ &res);
+ if (err)
+ goto error;
+ }
if (!res.cnt) {
err = -ENOENT;
goto error;
}
+ syms = res.syms;
addrs = res.addrs;
cnt = res.cnt;
}
@@ -10511,12 +10594,12 @@ bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog,
goto error;
}
link->fd = link_fd;
- free(res.addrs);
+ kprobe_multi_resolve_free(&res);
return link;
error:
free(link);
- free(res.addrs);
+ kprobe_multi_resolve_free(&res);
return libbpf_err_ptr(err);
}
--
2.25.1