Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1567528
| From | tip-bot for Joe Stringer <tipbot@zytor.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [tip:perf/core] tools lib bpf: Fix map offsets in relocation |
| Date | 2017-01-26 16:40 +0100 |
| Message-ID | <t3Ujv-Eh-11@gated-at.bofh.it> (permalink) |
| References | <t2BsB-8iC-19@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Commit-ID: 94e5adece8b37a23d99fb1f8a5de94b23194f387
Gitweb: http://git.kernel.org/tip/94e5adece8b37a23d99fb1f8a5de94b23194f387
Author: Joe Stringer <joe@ovn.org>
AuthorDate: Sun, 22 Jan 2017 17:11:22 -0800
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 26 Jan 2017 11:42:56 -0300
tools lib bpf: Fix map offsets in relocation
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>
---
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 84e6b35..671d5ad 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;
}
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCHv2 perf/core 0/7] Libbpf improvements Joe Stringer <joe@ovn.org> - 2017-01-23 02:20 +0100
[PATCHv2 perf/core 6/7] tools lib bpf: Add bpf_map__pin() Joe Stringer <joe@ovn.org> - 2017-01-23 02:20 +0100
[PATCHv2 perf/core 4/7] tools lib bpf: Add libbpf_get_error() Joe Stringer <joe@ovn.org> - 2017-01-23 02:20 +0100
[tip:perf/core] tools lib bpf: Add libbpf_get_error() tip-bot for Joe Stringer <tipbot@zytor.com> - 2017-01-26 16:40 +0100
[PATCHv2 perf/core 7/7] tools lib bpf: Add bpf_object__pin() Joe Stringer <joe@ovn.org> - 2017-01-23 02:20 +0100
[PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin() Joe Stringer <joe@ovn.org> - 2017-01-23 02:20 +0100
Re: [PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin() "Wangnan (F)" <wangnan0@huawei.com> - 2017-01-25 02:10 +0100
Re: [PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin() Joe Stringer <joe@ovn.org> - 2017-01-25 02:20 +0100
Re: [PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin() "Wangnan (F)" <wangnan0@huawei.com> - 2017-01-25 03:20 +0100
Re: [PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin() Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-26 20:40 +0100
Re: [PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin() Joe Stringer <joe@ovn.org> - 2017-01-26 20:50 +0100
Re: [PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin() "Wangnan (F)" <wangnan0@huawei.com> - 2017-01-25 02:10 +0100
[PATCHv2 perf/core 1/7] tools lib bpf: Fix map offsets in relocation Joe Stringer <joe@ovn.org> - 2017-01-23 02:20 +0100
[tip:perf/core] tools lib bpf: Fix map offsets in relocation tip-bot for Joe Stringer <tipbot@zytor.com> - 2017-01-26 16:40 +0100
[PATCHv2 perf/core 3/7] tools lib bpf: Add set/is helpers for all prog types Joe Stringer <joe@ovn.org> - 2017-01-23 02:20 +0100
[tip:perf/core] tools lib bpf: Add set/is helpers for all prog types tip-bot for Joe Stringer <tipbot@zytor.com> - 2017-01-26 16:40 +0100
[PATCHv2 perf/core 2/7] tools lib bpf: Define prog_type fns with macro Joe Stringer <joe@ovn.org> - 2017-01-23 02:20 +0100
[tip:perf/core] tools lib bpf: Define prog_type fns with macro tip-bot for Joe Stringer <tipbot@zytor.com> - 2017-01-26 16:40 +0100
Re: [PATCHv2 perf/core 0/7] Libbpf improvements Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-01-24 17:20 +0100
Re: [PATCHv2 perf/core 0/7] Libbpf improvements Joe Stringer <joe@ovn.org> - 2017-01-25 02:00 +0100
csiph-web