diff mbox series

[bpf-next,15/29] bpf: Add support to store multiple addrs in bpf_tramp_id object

Message ID 20211118112455.475349-16-jolsa@kernel.org (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series bpf: Add batch support for attaching trampolines | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next fail VM_Test
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count fail Series longer than 15 patches (and no cover letter)
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 12431 this patch: 12431
netdev/cc_maintainers warning 1 maintainers not CCed: kpsingh@kernel.org
netdev/build_clang success Errors and warnings before: 2105 this patch: 2105
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 11594 this patch: 11594
netdev/checkpatch warning CHECK: No space is necessary after a cast WARNING: From:/Signed-off-by: email address mismatch: 'From: Jiri Olsa <jolsa@redhat.com>' != 'Signed-off-by: Jiri Olsa <jolsa@kernel.org>' WARNING: Prefer kcalloc over kzalloc with multiply
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jiri Olsa Nov. 18, 2021, 11:24 a.m. UTC
Adding support to store multiple addrs in bpf_tramp_id object,
to provide address values for id values stored in the object.

The id->addr[idx] returns address value for id->id[idx] id.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 include/linux/bpf.h     |  2 +-
 kernel/bpf/syscall.c    |  2 +-
 kernel/bpf/trampoline.c | 20 ++++++++++++--------
 kernel/bpf/verifier.c   |  2 +-
 4 files changed, 15 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 47e25d8be600..13e9dcfd47e7 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -676,7 +676,7 @@  struct bpf_tramp_id {
 	u32 cnt;
 	u32 obj_id;
 	u32 *id;
-	void *addr;
+	void **addr;
 };
 
 struct bpf_tramp_node {
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 216fcce07326..0ae3b5b7419a 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -2853,7 +2853,7 @@  static int bpf_tracing_prog_attach(struct bpf_prog *prog,
 		if (err)
 			goto out_unlock;
 
-		id->addr = (void *) tgt_info.tgt_addr;
+		id->addr[0] = (void *) tgt_info.tgt_addr;
 
 		attach = bpf_tramp_attach(id, tgt_prog, prog);
 		if (IS_ERR(attach)) {
diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
index d65f463c532d..d9675d619963 100644
--- a/kernel/bpf/trampoline.c
+++ b/kernel/bpf/trampoline.c
@@ -92,7 +92,10 @@  struct bpf_tramp_id *bpf_tramp_id_alloc(u32 max)
 	id = kzalloc(sizeof(*id), GFP_KERNEL);
 	if (id) {
 		id->id = kzalloc(sizeof(u32) * max, GFP_KERNEL);
-		if (!id->id) {
+		id->addr = kzalloc(sizeof(*id->addr) * max, GFP_KERNEL);
+		if (!id->id || !id->addr) {
+			kfree(id->id);
+			kfree(id->addr);
 			kfree(id);
 			return NULL;
 		}
@@ -117,6 +120,7 @@  void bpf_tramp_id_free(struct bpf_tramp_id *id)
 {
 	if (!id)
 		return;
+	kfree(id->addr);
 	kfree(id->id);
 	kfree(id);
 }
@@ -159,7 +163,7 @@  static int bpf_trampoline_module_get(struct bpf_trampoline *tr)
 	int err = 0;
 
 	preempt_disable();
-	mod = __module_text_address((unsigned long) tr->id->addr);
+	mod = __module_text_address((unsigned long) tr->id->addr[0]);
 	if (mod && !try_module_get(mod))
 		err = -ENOENT;
 	preempt_enable();
@@ -187,7 +191,7 @@  static int is_ftrace_location(void *ip)
 
 static int unregister_fentry(struct bpf_trampoline *tr, void *old_addr)
 {
-	void *ip = tr->id->addr;
+	void *ip = tr->id->addr[0];
 	int ret;
 
 	if (tr->func.ftrace_managed)
@@ -202,7 +206,7 @@  static int unregister_fentry(struct bpf_trampoline *tr, void *old_addr)
 
 static int modify_fentry(struct bpf_trampoline *tr, void *old_addr, void *new_addr)
 {
-	void *ip = tr->id->addr;
+	void *ip = tr->id->addr[0];
 	int ret;
 
 	if (tr->func.ftrace_managed)
@@ -215,7 +219,7 @@  static int modify_fentry(struct bpf_trampoline *tr, void *old_addr, void *new_ad
 /* first time registering */
 static int register_fentry(struct bpf_trampoline *tr, void *new_addr)
 {
-	void *ip = tr->id->addr;
+	void *ip = tr->id->addr[0];
 	int ret;
 
 	ret = is_ftrace_location(ip);
@@ -434,7 +438,7 @@  static int bpf_trampoline_update(struct bpf_trampoline *tr)
 
 	err = arch_prepare_bpf_trampoline(im, im->image, im->image + PAGE_SIZE,
 					  &tr->func.model, flags, tprogs,
-					  tr->id->addr);
+					  tr->id->addr[0]);
 	if (err < 0)
 		goto out;
 
@@ -503,7 +507,7 @@  int bpf_trampoline_link_prog(struct bpf_tramp_node *node, struct bpf_trampoline
 			goto out;
 		}
 		tr->extension_prog = prog;
-		err = bpf_arch_text_poke(tr->id->addr, BPF_MOD_JUMP, NULL,
+		err = bpf_arch_text_poke(tr->id->addr[0], BPF_MOD_JUMP, NULL,
 					 prog->bpf_func);
 		goto out;
 	}
@@ -539,7 +543,7 @@  int bpf_trampoline_unlink_prog(struct bpf_tramp_node *node, struct bpf_trampolin
 	mutex_lock(&tr->mutex);
 	if (kind == BPF_TRAMP_REPLACE) {
 		WARN_ON_ONCE(!tr->extension_prog);
-		err = bpf_arch_text_poke(tr->id->addr, BPF_MOD_JUMP,
+		err = bpf_arch_text_poke(tr->id->addr[0], BPF_MOD_JUMP,
 					 tr->extension_prog->bpf_func, NULL);
 		tr->extension_prog = NULL;
 		goto out;
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 1903d5d256b6..56c518efa2d2 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -14000,7 +14000,7 @@  static int check_attach_btf_id(struct bpf_verifier_env *env)
 		return -ENOMEM;
 
 	bpf_tramp_id_init(id, tgt_prog, prog->aux->attach_btf, btf_id);
-	id->addr = (void *) tgt_info.tgt_addr;
+	id->addr[0] = (void *) tgt_info.tgt_addr;
 
 	attach = bpf_tramp_attach(id, tgt_prog, prog);
 	if (IS_ERR(attach)) {