From 9aca74399ebbce07f1783f7bc261f11fb81ce6443fd8fdad7cf0adc4942acffc Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Tue, 1 Jun 2021 10:55:47 +0000 Subject: [PATCH] Accepting request 896646 from home:michals - Handle zero sized per-cpu veriables in Linux BTF. + btf_encoder-fix-and-complete-filtering-out-zero-sized-per-CPU-variables.patch OBS-URL: https://build.opensuse.org/request/show/896646 OBS-URL: https://build.opensuse.org/package/show/devel:tools/dwarves?expand=0&rev=65 --- ...ing-out-zero-sized-per-CPU-variables.patch | 84 +++++++++++++++++++ dwarves.changes | 6 ++ dwarves.spec | 1 + 3 files changed, 91 insertions(+) create mode 100644 btf_encoder-fix-and-complete-filtering-out-zero-sized-per-CPU-variables.patch diff --git a/btf_encoder-fix-and-complete-filtering-out-zero-sized-per-CPU-variables.patch b/btf_encoder-fix-and-complete-filtering-out-zero-sized-per-CPU-variables.patch new file mode 100644 index 0000000..92b3003 --- /dev/null +++ b/btf_encoder-fix-and-complete-filtering-out-zero-sized-per-CPU-variables.patch @@ -0,0 +1,84 @@ +From 0d17503db0580a6635d103fed030724b38ba1364 Mon Sep 17 00:00:00 2001 +From: Andrii Nakryiko +Date: Mon, 24 May 2021 16:42:22 -0700 +Subject: [PATCH] btf_encoder: fix and complete filtering out zero-sized + per-CPU variables +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Upstram: accepted - expected version 1.22 +Git-commit: 0d17503db0580a6635d103fed030724b38ba1364 + +btf_encoder is ignoring zero-sized per-CPU ELF symbols, but the same has to be +done for DWARF variables when matching them with ELF symbols. This is due to +zero-sized DWARF variables matching unrelated (non-zero-sized) variable that +happens to be allocated at the exact same address, leading to a lot of +confusion in BTF. + +See [0] for when this causes big problems. + + [0] https://lore.kernel.org/bpf/CAEf4BzZ0-sihSL-UAm21JcaCCY92CqfNxycHRZYXcoj8OYb=wA@mail.gmail.com/ + +Committer notes: + +Kept the {} around the if block with more than one line, which +simplifies the original patch by just removing that assignment +to the 'dwarf_name' variable. + +Reported-by: Michal Suchánek +Signed-off-by: Andrii Nakryiko +Cc: Jiri Olsa +Cc: bpf@vger.kernel.org +Cc: dwarves@vger.kernel.org +Cc: kernel-team@fb.com +Signed-off-by: Arnaldo Carvalho de Melo +--- + btf_encoder.c | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +diff --git a/btf_encoder.c b/btf_encoder.c +index c711f12..033c927 100644 +--- a/btf_encoder.c ++++ b/btf_encoder.c +@@ -538,6 +538,7 @@ int cu__encode_btf(struct cu *cu, int verbose, bool force, + cu__for_each_variable(cu, core_id, pos) { + uint32_t size, type, linkage; + const char *name, *dwarf_name; ++ const struct tag *tag; + uint64_t addr; + int id; + +@@ -550,6 +551,7 @@ int cu__encode_btf(struct cu *cu, int verbose, bool force, + + /* addr has to be recorded before we follow spec */ + addr = var->ip.addr; ++ dwarf_name = variable__name(var, cu); + + /* DWARF takes into account .data..percpu section offset + * within its segment, which for vmlinux is 0, but for kernel +@@ -583,7 +585,6 @@ int cu__encode_btf(struct cu *cu, int verbose, bool force, + * per-CPU symbols have non-zero values. + */ + if (var->ip.addr == 0) { +- dwarf_name = variable__name(var, cu); + if (!dwarf_name || strcmp(dwarf_name, name)) + continue; + } +@@ -600,6 +601,13 @@ int cu__encode_btf(struct cu *cu, int verbose, bool force, + break; + } + ++ tag = cu__type(cu, var->ip.tag.type); ++ if (tag__size(tag, cu) == 0) { ++ if (btf_elf__verbose) ++ fprintf(stderr, "Ignoring zero-sized per-CPU variable '%s'...\n", dwarf_name ?: ""); ++ continue; ++ } ++ + type = var->ip.tag.type + type_id_off; + linkage = var->external ? BTF_VAR_GLOBAL_ALLOCATED : BTF_VAR_STATIC; + +-- +2.31.1 + diff --git a/dwarves.changes b/dwarves.changes index de938c5..c9d67b0 100644 --- a/dwarves.changes +++ b/dwarves.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Tue Jun 1 10:28:25 UTC 2021 - Michal Suchanek + +- Handle zero sized per-cpu veriables in Linux BTF. + + btf_encoder-fix-and-complete-filtering-out-zero-sized-per-CPU-variables.patch + ------------------------------------------------------------------- Mon May 3 08:45:43 UTC 2021 - Jiri Slaby diff --git a/dwarves.spec b/dwarves.spec index 0fb245d..3b82e80 100644 --- a/dwarves.spec +++ b/dwarves.spec @@ -29,6 +29,7 @@ Source: https://fedorapeople.org/~acme/dwarves/dwarves-%version.tar.xz Source2: https://fedorapeople.org/~acme/dwarves/dwarves-%version.tar.sign Source9: baselibs.conf Patch0: remove-ftrace-filter.patch +Patch1: btf_encoder-fix-and-complete-filtering-out-zero-sized-per-CPU-variables.patch BuildRequires: cmake BuildRequires: libdw-devel >= 0.171 %if 0%{?suse_version} < 1550