Commit 4930b7f5 authored by Jiri Olsa's avatar Jiri Olsa Committed by Andrii Nakryiko

bpf: Store ref_ctr_offsets values in bpf_uprobe array

We will need to return ref_ctr_offsets values through link_info
interface in following change, so we need to keep them around.

Storing ref_ctr_offsets values directly into bpf_uprobe array.
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Acked-by: default avatarSong Liu <song@kernel.org>
Link: https://lore.kernel.org/bpf/20231125193130.834322-3-jolsa@kernel.org
parent 48f0dfd8
...@@ -3033,6 +3033,7 @@ struct bpf_uprobe_multi_link; ...@@ -3033,6 +3033,7 @@ struct bpf_uprobe_multi_link;
struct bpf_uprobe { struct bpf_uprobe {
struct bpf_uprobe_multi_link *link; struct bpf_uprobe_multi_link *link;
loff_t offset; loff_t offset;
unsigned long ref_ctr_offset;
u64 cookie; u64 cookie;
struct uprobe_consumer consumer; struct uprobe_consumer consumer;
}; };
...@@ -3172,7 +3173,6 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr ...@@ -3172,7 +3173,6 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
{ {
struct bpf_uprobe_multi_link *link = NULL; struct bpf_uprobe_multi_link *link = NULL;
unsigned long __user *uref_ctr_offsets; unsigned long __user *uref_ctr_offsets;
unsigned long *ref_ctr_offsets = NULL;
struct bpf_link_primer link_primer; struct bpf_link_primer link_primer;
struct bpf_uprobe *uprobes = NULL; struct bpf_uprobe *uprobes = NULL;
struct task_struct *task = NULL; struct task_struct *task = NULL;
...@@ -3245,18 +3245,12 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr ...@@ -3245,18 +3245,12 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
if (!uprobes || !link) if (!uprobes || !link)
goto error_free; goto error_free;
if (uref_ctr_offsets) {
ref_ctr_offsets = kvcalloc(cnt, sizeof(*ref_ctr_offsets), GFP_KERNEL);
if (!ref_ctr_offsets)
goto error_free;
}
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
if (ucookies && __get_user(uprobes[i].cookie, ucookies + i)) { if (ucookies && __get_user(uprobes[i].cookie, ucookies + i)) {
err = -EFAULT; err = -EFAULT;
goto error_free; goto error_free;
} }
if (uref_ctr_offsets && __get_user(ref_ctr_offsets[i], uref_ctr_offsets + i)) { if (uref_ctr_offsets && __get_user(uprobes[i].ref_ctr_offset, uref_ctr_offsets + i)) {
err = -EFAULT; err = -EFAULT;
goto error_free; goto error_free;
} }
...@@ -3287,7 +3281,7 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr ...@@ -3287,7 +3281,7 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
err = uprobe_register_refctr(d_real_inode(link->path.dentry), err = uprobe_register_refctr(d_real_inode(link->path.dentry),
uprobes[i].offset, uprobes[i].offset,
ref_ctr_offsets ? ref_ctr_offsets[i] : 0, uprobes[i].ref_ctr_offset,
&uprobes[i].consumer); &uprobes[i].consumer);
if (err) { if (err) {
bpf_uprobe_unregister(&path, uprobes, i); bpf_uprobe_unregister(&path, uprobes, i);
...@@ -3299,11 +3293,9 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr ...@@ -3299,11 +3293,9 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
if (err) if (err)
goto error_free; goto error_free;
kvfree(ref_ctr_offsets);
return bpf_link_settle(&link_primer); return bpf_link_settle(&link_primer);
error_free: error_free:
kvfree(ref_ctr_offsets);
kvfree(uprobes); kvfree(uprobes);
kfree(link); kfree(link);
if (task) if (task)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment