Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp5768160ybn; Sun, 29 Sep 2019 05:25:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZOCcrkEclOL4v9+DP3nmuN3xAQR0gCXfS+shUHmVZyUa2s0HUOoKScYmkk4TRh++mKMJ3 X-Received: by 2002:a05:6402:3066:: with SMTP id bs6mr14187890edb.127.1569759948545; Sun, 29 Sep 2019 05:25:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569759948; cv=none; d=google.com; s=arc-20160816; b=wgYWU2wzjOkuRrO24Fp/U/1LE6hA3arzszSJiPd9QsvbfsoCjYVvRvMV52ZvNYnxeo 8kEzgxRkXLeqyo9bqq5apWMsVFBdIk4dT5mlkvjJRqloNs7z6FuHpqLd91VEyhozenh8 r0zNW3VaxufwJxZItESq0NMcXCjXhyPx2jMVHauQVdl2IZxk2cVx4iJkaJtA6PbOqrmZ TMzVsXP5ztshaz3dVZrgBh+XaLzGzynSRQAMisY1KKAnuin5Y9lHIXSNF3CGHriUQ8if yeTjWrQpyivaJVza/hfha6crdnuca/9S+WxgsDHf33CB/TPwHYdSG5TlmmxtS8+5Xic5 QUcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=OApSb6pyDOVJ11rwqEKcRkl3p6EMZ7tQjgxOLv7bRJY=; b=u3J9XM71fAX3xmHQoM9TX6c0FAy9zhBAR0aOGuYKc4sGbnHJf28uTktDyUtgu5aIul d6Uqmxn9+OAWENsY3H8Q2Jm8vj7fMfJCJyf4hHIRAZA4mPnrAWDCbGsK9hUfz+Pb3pqD ckBNnwvX618rKn+7QhAP+bXoZ1tdTkcbvQ4pdKzgJo/me+AvJZeiuWriDoKxZE7vBbTG n6lMtdvC8jqJ3KVfgepButRwQstvFVxwAZ9tO8CqqPxDfiMjWtT6t3MnvSky38BINlj+ qmr49dRkDXGx0oSLPV62QekvGZZMKs1lkJyrlsEKjhofONInekegqAc9ClgoUV7vmNLk dtQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x45si5077944edd.388.2019.09.29.05.25.12; Sun, 29 Sep 2019 05:25:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728576AbfI2MYv (ORCPT + 99 others); Sun, 29 Sep 2019 08:24:51 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:3232 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725924AbfI2MYv (ORCPT ); Sun, 29 Sep 2019 08:24:51 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id AF436ADB89A0F8BA623A; Sun, 29 Sep 2019 20:24:48 +0800 (CST) Received: from euler.huawei.com (10.175.104.193) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.439.0; Sun, 29 Sep 2019 20:24:42 +0800 From: Wei Li To: , , , CC: , , , , , , , Subject: [PATCH] perf symbols: Don't split kernel symbols when using kallsyms Date: Sun, 29 Sep 2019 20:34:25 +0800 Message-ID: <20190929123425.22589-1-liwei391@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.104.193] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If there is ovelapping of vmlinux addresses with modules on a system, the kernel symbols will be split to unique DSOs([kernel].N) when using /proc/kallsyms, introduced by commit 2e538c4a1847 ("perf tools: Improve kernel/modules symbol lookup"). When doing perf probe/report on such a system, it will fail in finding symbol, as the symbol split process is after the map searching, and the created maps can't be matched with name in kernel_get_module_map(). I think the split is confusing and not so useful when using [kernel].N instead of the original ELF section names here. So remove the split process when using /proc/kallsyms only. On my arm32 system: V2R7C00_HI1212-OSN9800 ~/liwei # ./perf probe -v -a printk probe-definition(0): printk symbol:printk file:(null) line:0 offset:0 return:0 lazy:(null) 0 arguments map_groups__set_modules_path_dir: cannot open /lib/modules/5.3.0-rc5+ dir Problems setting modules path maps, continuing anyway... No kprobe blacklist support, ignored Failed to open cache(-1): /root/.debug/[kernel.kallsyms]/8eb36727183e955c790f0c7feb22d8306be7ce99/probes Cache open error: -1 Looking at the vmlinux_path (8 entries long) symsrc__init: cannot get elf header. Could not open debuginfo. Try to use symbols. Looking at the vmlinux_path (8 entries long) symsrc__init: cannot get elf header. Failed to open /proc/kcore. Note /proc/kcore requires CAP_SYS_RAWIO capability to access. Using /proc/kallsyms for symbols Failed to find symbol printk in kernel Error: Failed to add events. Reason: No such file or directory (Code: -2) V2R7C00_HI1212-OSN9800 ~/liwei # ./perf probe -F vector_addrexcptn vector_dabt vector_fiq vector_irq vector_pabt vector_rst vector_und V2R7C00_HI1212-OSN9800 ~/liwei # sort -u /proc/kallsyms | head -n 10 01df0000 t __vectors_start 01df1000 t __stubs_start 01df1004 t vector_rst 01df1020 t vector_irq 01df10a0 t vector_dabt 01df1120 t vector_pabt 01df11a0 t vector_und 01df1220 t vector_addrexcptn 01df1240 T vector_fiq bf000000 t $a [eth] V2R7C00_HI1212-OSN9800 ~/liwei # sort -u /proc/kallsyms | grep _stext -B 10 c1e04000 t swapper_pg_dir c1e08000 T stext c1e08000 t _text c1e080b8 t __create_page_tables c1e081bc t __fixup_smp c1e08224 t __fixup_smp_on_up c1e08240 t __fixup_pv_table c1e082b0 t __vet_atags c1e08300 T __turn_mmu_on c1e08300 t __idmap_text_start c1e08300 t _stext V2R7C00_HI1212-OSN9800 ~/liwei # ./perf record -a sleep 2 Couldn't synthesize bpf events. [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.024 MB perf.data (140 samples) ] V2R7C00_HI1212-OSN9800 ~/liwei # ./perf report # To display the perf.data header info, please use --header/--header-only options. # # # Total Lost Samples: 0 # # Samples: 140 of event 'cycles' # Event count (approx.): 9286809 # # Overhead Command Shared Object Symbol # ........ ....... ................. ................. # 15.89% swapper [unknown] [k] 0xc1e10b2c 7.83% swapper [unknown] [k] 0xc1e303f4 6.66% swapper [unknown] [k] 0xc1e84d58 6.28% sleep ld-2.27.so [.] do_lookup_x 6.07% swapper [unknown] [k] 0xc23f59dc 3.19% swapper [unknown] [k] 0xc23f0bfc 3.18% swapper [unknown] [k] 0xc2194d18 3.18% sleep libc-2.27.so [.] _dl_addr 3.17% sleep [unknown] [k] 0xc1e23454 3.16% sleep ld-2.27.so [.] check_match 3.12% sleep ld-2.27.so [.] strcmp 3.12% swapper [unknown] [k] 0xc1e52ce8 3.10% sleep [unknown] [k] 0xc1f738a4 3.08% sleep [unknown] [k] 0xc21a1ef8 3.05% sleep [unknown] [k] 0xc1f7109c 3.02% sleep [unknown] [k] 0xc1f59520 2.99% sleep [unknown] [k] 0xc23f54d4 ... Signed-off-by: Wei Li --- tools/perf/util/symbol.c | 54 ++++++---------------------------------- 1 file changed, 7 insertions(+), 47 deletions(-) diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 4efde7879474..1c0d6d0e4ed1 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -743,9 +743,7 @@ static int map_groups__split_kallsyms_for_kcore(struct map_groups *kmaps, struct } /* - * Split the symbols into maps, making sure there are no overlaps, i.e. the - * kernel range is broken in several maps, named [kernel].N, as we don't have - * the original ELF section names vmlinux have. + * Remove module and useless symbols from the map derived from /proc/kallsyms. */ static int map_groups__split_kallsyms(struct map_groups *kmaps, struct dso *dso, u64 delta, struct map *initial_map) @@ -753,10 +751,9 @@ static int map_groups__split_kallsyms(struct map_groups *kmaps, struct dso *dso, struct machine *machine; struct map *curr_map = initial_map; struct symbol *pos; - int count = 0, moved = 0; + int moved = 0; struct rb_root_cached *root = &dso->symbols; struct rb_node *next = rb_first_cached(root); - int kernel_range = 0; bool x86_64; if (!kmaps) @@ -823,57 +820,20 @@ static int map_groups__split_kallsyms(struct map_groups *kmaps, struct dso *dso, * symbols at this point. */ goto discard_symbol; - } else if (curr_map != initial_map) { - char dso_name[PATH_MAX]; - struct dso *ndso; - + } else { + curr_map = initial_map; if (delta) { /* Kernel was relocated at boot time */ pos->start -= delta; pos->end -= delta; } - - if (count == 0) { - curr_map = initial_map; - goto add_symbol; - } - - if (dso->kernel == DSO_TYPE_GUEST_KERNEL) - snprintf(dso_name, sizeof(dso_name), - "[guest.kernel].%d", - kernel_range++); - else - snprintf(dso_name, sizeof(dso_name), - "[kernel].%d", - kernel_range++); - - ndso = dso__new(dso_name); - if (ndso == NULL) - return -1; - - ndso->kernel = dso->kernel; - - curr_map = map__new2(pos->start, ndso); - if (curr_map == NULL) { - dso__put(ndso); - return -1; - } - - curr_map->map_ip = curr_map->unmap_ip = identity__map_ip; - map_groups__insert(kmaps, curr_map); - ++kernel_range; - } else if (delta) { - /* Kernel was relocated at boot time */ - pos->start -= delta; - pos->end -= delta; } -add_symbol: + if (curr_map != initial_map) { rb_erase_cached(&pos->rb_node, root); symbols__insert(&curr_map->dso->symbols, pos); ++moved; - } else - ++count; + } continue; discard_symbol: @@ -887,7 +847,7 @@ static int map_groups__split_kallsyms(struct map_groups *kmaps, struct dso *dso, dso__set_loaded(curr_map->dso); } - return count + moved; + return moved; } bool symbol__restricted_filename(const char *filename, -- 2.17.1