On Thu, Jan 18, 2024 at 5:54 PM Jiri Olsa <jolsa@xxxxxxxxxx> wrote: > > Storing cookies in kprobe_multi bpf_link_info data. The cookies > field is optional and if provided it needs to be an array of > __u64 with kprobe_multi.count length. > > Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx> LGTM. Acked-by: Yafang Shao <laoar.shao@xxxxxxxxx> > --- > include/uapi/linux/bpf.h | 1 + > kernel/trace/bpf_trace.c | 15 +++++++++++++++ > tools/include/uapi/linux/bpf.h | 1 + > 3 files changed, 17 insertions(+) > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > index b823d367a83c..199cb93dca7f 100644 > --- a/include/uapi/linux/bpf.h > +++ b/include/uapi/linux/bpf.h > @@ -6563,6 +6563,7 @@ struct bpf_link_info { > __u32 count; /* in/out: kprobe_multi function count */ > __u32 flags; > __u64 missed; > + __aligned_u64 cookies; > } kprobe_multi; > struct { > __aligned_u64 path; > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c > index 7ac6c52b25eb..c98c20abaf99 100644 > --- a/kernel/trace/bpf_trace.c > +++ b/kernel/trace/bpf_trace.c > @@ -2679,6 +2679,7 @@ static void bpf_kprobe_multi_link_dealloc(struct bpf_link *link) > static int bpf_kprobe_multi_link_fill_link_info(const struct bpf_link *link, > struct bpf_link_info *info) > { > + u64 __user *ucookies = u64_to_user_ptr(info->kprobe_multi.cookies); > u64 __user *uaddrs = u64_to_user_ptr(info->kprobe_multi.addrs); > struct bpf_kprobe_multi_link *kmulti_link; > u32 ucount = info->kprobe_multi.count; > @@ -2686,6 +2687,8 @@ static int bpf_kprobe_multi_link_fill_link_info(const struct bpf_link *link, > > if (!uaddrs ^ !ucount) > return -EINVAL; > + if (ucookies && !ucount) > + return -EINVAL; > > kmulti_link = container_of(link, struct bpf_kprobe_multi_link, link); > info->kprobe_multi.count = kmulti_link->cnt; > @@ -2699,6 +2702,18 @@ static int bpf_kprobe_multi_link_fill_link_info(const struct bpf_link *link, > else > ucount = kmulti_link->cnt; > > + if (ucookies) { > + if (kmulti_link->cookies) { > + if (copy_to_user(ucookies, kmulti_link->cookies, ucount * sizeof(u64))) > + return -EFAULT; > + } else { > + for (i = 0; i < ucount; i++) { > + if (put_user(0, ucookies + i)) > + return -EFAULT; > + } > + } > + } > + > if (kallsyms_show_value(current_cred())) { > if (copy_to_user(uaddrs, kmulti_link->addrs, ucount * sizeof(u64))) > return -EFAULT; > diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h > index b823d367a83c..199cb93dca7f 100644 > --- a/tools/include/uapi/linux/bpf.h > +++ b/tools/include/uapi/linux/bpf.h > @@ -6563,6 +6563,7 @@ struct bpf_link_info { > __u32 count; /* in/out: kprobe_multi function count */ > __u32 flags; > __u64 missed; > + __aligned_u64 cookies; > } kprobe_multi; > struct { > __aligned_u64 path; > -- > 2.43.0 > -- Regards Yafang