Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1566621
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 14/23] tools lib bpf: Fix map offsets in relocation |
| Date | 2017-01-25 15:00 +0100 |
| Message-ID | <t3whd-2sl-39@gated-at.bofh.it> (permalink) |
| References | <t3whb-2sl-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Joe Stringer <joe@ovn.org>
Commit 4708bbda5cb2 ("tools lib bpf: Fix maps resolution") attempted to
fix map resolution by identifying the number of symbols that point to
maps, and using this number to resolve each of the maps.
However, during relocation the original definition of the map size was
still in use. For up to two maps, the calculation was correct if there
was a small difference in size between the map definition in libbpf and
the one that the client library uses. However if the difference was
large, particularly if more than two maps were used in the BPF program,
the relocation would fail.
For example, when using a map definition with size 28, with three maps,
map relocation would count:
(sym_offset / sizeof(struct bpf_map_def) => map_idx)
(0 / 16 => 0), ie map_idx = 0
(28 / 16 => 1), ie map_idx = 1
(56 / 16 => 3), ie map_idx = 3
So, libbpf reports:
libbpf: bpf relocation: map_idx 3 large than 2
Fix map relocation by checking the exact offset of maps when doing
relocation.
Signed-off-by: Joe Stringer <joe@ovn.org>
[Allow different map size in an object]
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: netdev@vger.kernel.org
Fixes: 4708bbda5cb2 ("tools lib bpf: Fix maps resolution")
Link: http://lkml.kernel.org/r/20170123011128.26534-2-joe@ovn.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/bpf/libbpf.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 84e6b35da4bd..671d5ad07cf1 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -779,7 +779,7 @@ static int
bpf_program__collect_reloc(struct bpf_program *prog,
size_t nr_maps, GElf_Shdr *shdr,
Elf_Data *data, Elf_Data *symbols,
- int maps_shndx)
+ int maps_shndx, struct bpf_map *maps)
{
int i, nrels;
@@ -829,7 +829,15 @@ bpf_program__collect_reloc(struct bpf_program *prog,
return -LIBBPF_ERRNO__RELOC;
}
- map_idx = sym.st_value / sizeof(struct bpf_map_def);
+ /* TODO: 'maps' is sorted. We can use bsearch to make it faster. */
+ for (map_idx = 0; map_idx < nr_maps; map_idx++) {
+ if (maps[map_idx].offset == sym.st_value) {
+ pr_debug("relocation: find map %zd (%s) for insn %u\n",
+ map_idx, maps[map_idx].name, insn_idx);
+ break;
+ }
+ }
+
if (map_idx >= nr_maps) {
pr_warning("bpf relocation: map_idx %d large than %d\n",
(int)map_idx, (int)nr_maps - 1);
@@ -953,7 +961,8 @@ static int bpf_object__collect_reloc(struct bpf_object *obj)
err = bpf_program__collect_reloc(prog, nr_maps,
shdr, data,
obj->efile.symbols,
- obj->efile.maps_shndx);
+ obj->efile.maps_shndx,
+ obj->maps);
if (err)
return err;
}
--
2.9.3
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[GIT PULL 00/23] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-25 15:00 +0100 [PATCH 19/23] perf tools: Propagate perf_config() errors Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-25 15:00 +0100 [PATCH 15/23] tools lib bpf: Define prog_type fns with macro Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-25 15:00 +0100 [PATCH 10/23] perf script: Add "brstackasm" output for branch stacks Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-25 15:00 +0100 [PATCH 11/23] perf probe: Fix wrong register name for arm64 Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-25 15:00 +0100 [PATCH 09/23] perf script: Add support for printing assembler Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-25 15:00 +0100 [PATCH 18/23] perf scripting perl: Do not die() when not founding event for a type Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-25 15:00 +0100 [PATCH 21/23] perf util: Add more debug message on failure path Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-25 15:00 +0100 [PATCH 08/23] perf tools: Add disassembler for x86 using the XED library Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-25 15:00 +0100 [PATCH 14/23] tools lib bpf: Fix map offsets in relocation Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-25 15:00 +0100 [PATCH 02/23] perf hists browser: Put hist_entry folding logic into single function Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-25 15:00 +0100 [PATCH 22/23] perf ftrace: Introduce new 'ftrace' tool Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-25 15:00 +0100 [PATCH 01/23] perf unwind: Fix looking up dwarf unwind stack info Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-25 15:00 +0100 [PATCH 13/23] perf probe: Delete an unnecessary assignment in try_to_find_absolute_address() Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-25 15:00 +0100 [PATCH 23/23] perf ftrace: Make 'function_graph' be the default tracer Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-25 15:00 +0100 [PATCH 04/23] perf c2c report: Display Total records column in offset view Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-25 15:00 +0100 [PATCH 06/23] perf tools: Add probing for the XED disassembler library Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-25 15:00 +0100
csiph-web