Skip to content

Commit 4930b7f

Browse files
olsajirianakryiko
authored andcommitted
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: Jiri Olsa <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Acked-by: Song Liu <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 48f0dfd commit 4930b7f

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

kernel/trace/bpf_trace.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,6 +3033,7 @@ struct bpf_uprobe_multi_link;
30333033
struct bpf_uprobe {
30343034
struct bpf_uprobe_multi_link *link;
30353035
loff_t offset;
3036+
unsigned long ref_ctr_offset;
30363037
u64 cookie;
30373038
struct uprobe_consumer consumer;
30383039
};
@@ -3172,7 +3173,6 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
31723173
{
31733174
struct bpf_uprobe_multi_link *link = NULL;
31743175
unsigned long __user *uref_ctr_offsets;
3175-
unsigned long *ref_ctr_offsets = NULL;
31763176
struct bpf_link_primer link_primer;
31773177
struct bpf_uprobe *uprobes = NULL;
31783178
struct task_struct *task = NULL;
@@ -3245,18 +3245,12 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
32453245
if (!uprobes || !link)
32463246
goto error_free;
32473247

3248-
if (uref_ctr_offsets) {
3249-
ref_ctr_offsets = kvcalloc(cnt, sizeof(*ref_ctr_offsets), GFP_KERNEL);
3250-
if (!ref_ctr_offsets)
3251-
goto error_free;
3252-
}
3253-
32543248
for (i = 0; i < cnt; i++) {
32553249
if (ucookies && __get_user(uprobes[i].cookie, ucookies + i)) {
32563250
err = -EFAULT;
32573251
goto error_free;
32583252
}
3259-
if (uref_ctr_offsets && __get_user(ref_ctr_offsets[i], uref_ctr_offsets + i)) {
3253+
if (uref_ctr_offsets && __get_user(uprobes[i].ref_ctr_offset, uref_ctr_offsets + i)) {
32603254
err = -EFAULT;
32613255
goto error_free;
32623256
}
@@ -3287,7 +3281,7 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
32873281
for (i = 0; i < cnt; i++) {
32883282
err = uprobe_register_refctr(d_real_inode(link->path.dentry),
32893283
uprobes[i].offset,
3290-
ref_ctr_offsets ? ref_ctr_offsets[i] : 0,
3284+
uprobes[i].ref_ctr_offset,
32913285
&uprobes[i].consumer);
32923286
if (err) {
32933287
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
32993293
if (err)
33003294
goto error_free;
33013295

3302-
kvfree(ref_ctr_offsets);
33033296
return bpf_link_settle(&link_primer);
33043297

33053298
error_free:
3306-
kvfree(ref_ctr_offsets);
33073299
kvfree(uprobes);
33083300
kfree(link);
33093301
if (task)

0 commit comments

Comments
 (0)