aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2021-11-12 12:57:13 +0100
committerJiri Olsa <jolsa@kernel.org>2021-11-18 11:17:41 +0100
commit12ea728e52b0432131a800281f2015a7358b3d81 (patch)
treec6ae2f66d31b767a2092e527215ff6ee372452d3
parent378851fb026c8aeef2c2f622957a91a1f0fae87f (diff)
downloadperf-12ea728e52b0432131a800281f2015a7358b3d81.tar.gz
bpf: Resolve id in bpf_tramp_id_single
Moving the id resolving in the bpf_tramp_id_single function so it's centralized together with the trampoline's allocation and init. Signed-off-by: Jiri Olsa <jolsa@kernel.org>
-rw-r--r--include/linux/bpf.h3
-rw-r--r--kernel/bpf/syscall.c21
-rw-r--r--kernel/bpf/trampoline.c18
-rw-r--r--kernel/bpf/verifier.c4
4 files changed, 24 insertions, 22 deletions
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 894ee812e2138..dda24339e4b19 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -756,7 +756,8 @@ 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);
struct bpf_tramp_id *bpf_tramp_id_single(const struct bpf_prog *tgt_prog,
- struct btf *btf, u32 btf_id);
+ struct bpf_prog *prog, u32 btf_id,
+ struct bpf_attach_target_info *tgt_info);
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 8109b0fc7d2fd..0acf6cb0fdc7c 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -2773,9 +2773,9 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,
goto out_put_prog;
}
- id = bpf_tramp_id_single(tgt_prog, NULL, btf_id);
- if (!id) {
- err = -ENOMEM;
+ id = bpf_tramp_id_single(tgt_prog, prog, btf_id, NULL);
+ if (IS_ERR(id)) {
+ err = PTR_ERR(id);
goto out_put_prog;
}
}
@@ -2828,9 +2828,9 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,
}
btf_id = prog->aux->attach_btf_id;
- id = bpf_tramp_id_single(NULL, prog->aux->attach_btf, btf_id);
- if (!id) {
- err = -ENOMEM;
+ id = bpf_tramp_id_single(NULL, prog, btf_id, NULL);
+ if (IS_ERR(id)) {
+ err = PTR_ERR(id);
goto out_unlock;
}
}
@@ -2842,15 +2842,6 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,
* different from the destination specified at load time, we
* need a new trampoline and a check for compatibility
*/
- struct bpf_attach_target_info tgt_info = {};
-
- err = bpf_check_attach_target(NULL, prog, tgt_prog, btf_id,
- &tgt_info);
- if (err)
- goto out_unlock;
-
- id->addr[0] = (void *) tgt_info.tgt_addr;
-
attach = bpf_tramp_attach(id, tgt_prog, prog);
if (IS_ERR(attach)) {
err = PTR_ERR(attach);
diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
index 4a4ef9396b7ea..e6a73088eceed 100644
--- a/kernel/bpf/trampoline.c
+++ b/kernel/bpf/trampoline.c
@@ -105,18 +105,30 @@ struct bpf_tramp_id *bpf_tramp_id_alloc(u32 max)
}
struct bpf_tramp_id *bpf_tramp_id_single(const struct bpf_prog *tgt_prog,
- struct btf *btf, u32 btf_id)
+ struct bpf_prog *prog, u32 btf_id,
+ struct bpf_attach_target_info *tgt_info)
{
struct bpf_tramp_id *id;
+ if (!tgt_info) {
+ struct bpf_attach_target_info __tgt_info = {};
+ int err;
+
+ tgt_info = &__tgt_info;
+ err = bpf_check_attach_target(NULL, prog, tgt_prog, btf_id,
+ tgt_info);
+ if (err)
+ return ERR_PTR(err);
+ }
id = bpf_tramp_id_alloc(1);
if (!id)
- return NULL;
+ return ERR_PTR(-ENOMEM);
if (tgt_prog)
id->obj_id = tgt_prog->aux->id;
else
- id->obj_id = btf_obj_id(btf);
+ id->obj_id = btf_obj_id(prog->aux->attach_btf);
id->id[0] = btf_id;
+ id->addr[0] = (void *) tgt_info->tgt_addr;
id->cnt = 1;
return id;
}
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 9914487f22811..8d56d43489aa5 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -13995,12 +13995,10 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
return -EINVAL;
}
- id = bpf_tramp_id_single(NULL, prog->aux->attach_btf, btf_id);
+ id = bpf_tramp_id_single(tgt_prog, prog, btf_id, &tgt_info);
if (!id)
return -ENOMEM;
- id->addr[0] = (void *) tgt_info.tgt_addr;
-
attach = bpf_tramp_attach(id, tgt_prog, prog);
if (IS_ERR(attach)) {
bpf_tramp_id_free(id);