aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2021-11-12 12:52:18 +0100
committerJiri Olsa <jolsa@kernel.org>2021-11-18 11:17:41 +0100
commit378851fb026c8aeef2c2f622957a91a1f0fae87f (patch)
tree6e8dc6e1d233bf97679da71a9087768339e1f85e
parentf5a40d5d53c2fce8f51178370a072bc405d48c77 (diff)
downloadperf-378851fb026c8aeef2c2f622957a91a1f0fae87f.tar.gz
bpf: Add bpf_tramp_id_single function
Adding bpf_tramp_id_single function as interface to create trampoline with single ID and grouping together the trampoline allocation with init that is used on several places and save us few lines. Signed-off-by: Jiri Olsa <jolsa@kernel.org>
-rw-r--r--include/linux/bpf.h5
-rw-r--r--kernel/bpf/syscall.c18
-rw-r--r--kernel/bpf/trampoline.c11
-rw-r--r--kernel/bpf/verifier.c3
4 files changed, 18 insertions, 19 deletions
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 13e9dcfd47e7a..894ee812e2138 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -755,9 +755,8 @@ struct bpf_tramp_id *bpf_tramp_id_alloc(u32 cnt);
void bpf_tramp_id_free(struct bpf_tramp_id *id);
bool bpf_tramp_id_is_empty(struct bpf_tramp_id *id);
int bpf_tramp_id_is_equal(struct bpf_tramp_id *a, struct bpf_tramp_id *b);
-void bpf_tramp_id_init(struct bpf_tramp_id *id,
- const struct bpf_prog *tgt_prog,
- struct btf *btf, u32 btf_id);
+struct bpf_tramp_id *bpf_tramp_id_single(const struct bpf_prog *tgt_prog,
+ struct btf *btf, u32 btf_id);
int bpf_trampoline_link_prog(struct bpf_tramp_node *node, struct bpf_trampoline *tr);
int bpf_trampoline_unlink_prog(struct bpf_tramp_node *node, struct bpf_trampoline *tr);
void bpf_trampoline_put(struct bpf_trampoline *tr);
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 0ae3b5b7419a2..8109b0fc7d2fd 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -2766,12 +2766,6 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,
goto out_put_prog;
}
- id = bpf_tramp_id_alloc(1);
- if (!id) {
- err = -ENOMEM;
- goto out_put_prog;
- }
-
tgt_prog = bpf_prog_get(tgt_prog_fd);
if (IS_ERR(tgt_prog)) {
err = PTR_ERR(tgt_prog);
@@ -2779,7 +2773,11 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,
goto out_put_prog;
}
- bpf_tramp_id_init(id, tgt_prog, NULL, btf_id);
+ id = bpf_tramp_id_single(tgt_prog, NULL, btf_id);
+ if (!id) {
+ err = -ENOMEM;
+ goto out_put_prog;
+ }
}
link = kzalloc(sizeof(*link), GFP_USER);
@@ -2829,14 +2827,12 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,
goto out_unlock;
}
- id = bpf_tramp_id_alloc(1);
+ btf_id = prog->aux->attach_btf_id;
+ id = bpf_tramp_id_single(NULL, prog->aux->attach_btf, btf_id);
if (!id) {
err = -ENOMEM;
goto out_unlock;
}
-
- btf_id = prog->aux->attach_btf_id;
- bpf_tramp_id_init(id, NULL, prog->aux->attach_btf, btf_id);
}
if (!prog->aux->dst_attach ||
diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
index d9675d6199634..4a4ef9396b7ea 100644
--- a/kernel/bpf/trampoline.c
+++ b/kernel/bpf/trampoline.c
@@ -104,16 +104,21 @@ struct bpf_tramp_id *bpf_tramp_id_alloc(u32 max)
return id;
}
-void bpf_tramp_id_init(struct bpf_tramp_id *id,
- const struct bpf_prog *tgt_prog,
- struct btf *btf, u32 btf_id)
+struct bpf_tramp_id *bpf_tramp_id_single(const struct bpf_prog *tgt_prog,
+ struct btf *btf, u32 btf_id)
{
+ struct bpf_tramp_id *id;
+
+ id = bpf_tramp_id_alloc(1);
+ if (!id)
+ return NULL;
if (tgt_prog)
id->obj_id = tgt_prog->aux->id;
else
id->obj_id = btf_obj_id(btf);
id->id[0] = btf_id;
id->cnt = 1;
+ return id;
}
void bpf_tramp_id_free(struct bpf_tramp_id *id)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 56c518efa2d20..9914487f22811 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -13995,11 +13995,10 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
return -EINVAL;
}
- id = bpf_tramp_id_alloc(1);
+ id = bpf_tramp_id_single(NULL, prog->aux->attach_btf, btf_id);
if (!id)
return -ENOMEM;
- bpf_tramp_id_init(id, tgt_prog, prog->aux->attach_btf, btf_id);
id->addr[0] = (void *) tgt_info.tgt_addr;
attach = bpf_tramp_attach(id, tgt_prog, prog);