All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii@kernel.org>
To: <bpf@vger.kernel.org>, <ast@kernel.org>, <daniel@iogearbox.net>
Cc: <andrii@kernel.org>, <kernel-team@fb.com>
Subject: [PATCH bpf-next 06/10] libbpf: record subprog-resolved CO-RE relocations unconditionally
Date: Mon, 25 Apr 2022 17:45:07 -0700	[thread overview]
Message-ID: <20220426004511.2691730-7-andrii@kernel.org> (raw)
In-Reply-To: <20220426004511.2691730-1-andrii@kernel.org>

Previously, libbpf recorded CO-RE relocations with insns_idx resolved
according to finalized subprog locations (which are appended at the end
of entry BPF program) to simplify the job of light skeleton generator.

This is necessary because once subprogs' instructions are appended to
main entry BPF program all the subprog instruction indices are shifted
and that shift is different for each entry (main) BPF program, so it's
generally impossible to map final absolute insn_idx of the finalized BPF
program to their original locations inside subprograms.

This information is now going to be used not only during light skeleton
generation, but also to map absolute instruction index to subprog's
instruction and its corresponding CO-RE relocation. So start recording
these relocations always, not just when obj->gen_loader is set.

This information is going to be freed at the end of bpf_object__load()
step, as before (but this can change in the future if there will be
a need for this information post load step).

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/lib/bpf/libbpf.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index efc1ea91e12e..5ebbfe8b5e1c 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -5749,16 +5749,16 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)
 				return -EINVAL;
 			insn = &prog->insns[insn_idx];
 
-			if (prog->obj->gen_loader) {
-				err = record_relo_core(prog, rec, insn_idx);
-				if (err) {
-					pr_warn("prog '%s': relo #%d: failed to record relocation: %d\n",
-						prog->name, i, err);
-					goto out;
-				}
-				continue;
+			err = record_relo_core(prog, rec, insn_idx);
+			if (err) {
+				pr_warn("prog '%s': relo #%d: failed to record relocation: %d\n",
+					prog->name, i, err);
+				goto out;
 			}
 
+			if (prog->obj->gen_loader)
+				continue;
+
 			err = bpf_core_resolve_relo(prog, rec, i, obj->btf, cand_cache, &targ_res);
 			if (err) {
 				pr_warn("prog '%s': relo #%d: failed to relocate: %d\n",
@@ -6299,7 +6299,6 @@ bpf_object__relocate_calls(struct bpf_object *obj, struct bpf_program *prog)
 	if (err)
 		return err;
 
-
 	return 0;
 }
 
@@ -6360,8 +6359,7 @@ bpf_object__relocate(struct bpf_object *obj, const char *targ_btf_path)
 				err);
 			return err;
 		}
-		if (obj->gen_loader)
-			bpf_object__sort_relos(obj);
+		bpf_object__sort_relos(obj);
 	}
 
 	/* Before relocating calls pre-process relocations and mark
@@ -6421,8 +6419,7 @@ bpf_object__relocate(struct bpf_object *obj, const char *targ_btf_path)
 			return err;
 		}
 	}
-	if (!obj->gen_loader)
-		bpf_object__free_relocs(obj);
+
 	return 0;
 }
 
@@ -7014,8 +7011,8 @@ bpf_object__load_progs(struct bpf_object *obj, int log_level)
 		if (err)
 			return err;
 	}
-	if (obj->gen_loader)
-		bpf_object__free_relocs(obj);
+
+	bpf_object__free_relocs(obj);
 	return 0;
 }
 
-- 
2.30.2


  parent reply	other threads:[~2022-04-26  0:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-26  0:45 [PATCH bpf-next 00/10] Teach libbpf to "fix up" BPF verifier log Andrii Nakryiko
2022-04-26  0:45 ` [PATCH bpf-next 01/10] libbpf: fix anonymous type check in CO-RE logic Andrii Nakryiko
2022-04-26  0:45 ` [PATCH bpf-next 02/10] libbpf: drop unhelpful "program too large" guess Andrii Nakryiko
2022-04-26  0:45 ` [PATCH bpf-next 03/10] libbpf: fix logic for finding matching program for CO-RE relocation Andrii Nakryiko
2022-04-26  0:45 ` [PATCH bpf-next 04/10] libbpf: avoid joining .BTF.ext data with BPF programs by section name Andrii Nakryiko
2022-04-26  0:45 ` [PATCH bpf-next 05/10] selftests/bpf: add CO-RE relos and SEC("?...") to linked_funcs selftests Andrii Nakryiko
2022-04-26  0:45 ` Andrii Nakryiko [this message]
2022-04-26  0:45 ` [PATCH bpf-next 07/10] libbpf: refactor CO-RE relo human description formatting routine Andrii Nakryiko
2022-04-26 18:52   ` Alexei Starovoitov
2022-04-26 22:20     ` Andrii Nakryiko
2022-04-26  0:45 ` [PATCH bpf-next 08/10] libbpf: simplify bpf_core_parse_spec() signature Andrii Nakryiko
2022-04-26  0:45 ` [PATCH bpf-next 09/10] libbpf: fix up verifier log for unguarded failed CO-RE relos Andrii Nakryiko
2022-04-26 18:59   ` Alexei Starovoitov
2022-04-26 22:16     ` Andrii Nakryiko
2022-04-26  0:45 ` [PATCH bpf-next 10/10] selftests/bpf: add libbpf's log fixup logic selftests Andrii Nakryiko
2022-04-26 22:50 ` [PATCH bpf-next 00/10] Teach libbpf to "fix up" BPF verifier log patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220426004511.2691730-7-andrii@kernel.org \
    --to=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.