Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2174074ybb; Mon, 30 Mar 2020 00:42:00 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsk/fMMqhar1biTa2ahZqIQSdgP3ExJ2NqteXEreHUgCKeBDhwTagFmeQcr9EZ+9s+bPiRz X-Received: by 2002:aca:4fc7:: with SMTP id d190mr6847317oib.100.1585554120823; Mon, 30 Mar 2020 00:42:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585554120; cv=none; d=google.com; s=arc-20160816; b=j3n6IRnNo+kUdO1X753Mea6xxXHBEOxwccXzeXd2BR9qKU+mgu9/kWf2D9tp9FzHmB EeE1bDuKMlxztsc/2HIMK1MXpuojojKtTZqCi6fnLjj7490qCnFmlNFqz+v8XT2DSEyO 7EE4ZX/rgt7+LcnxT3G/1RDv8n90sbvqFAk2UxEdDKfqL+WCEvyPZ7bTV4U4DWgD9mfE QvUOBUz7mkiULEmLgtAUCfyRmvNdtuce4ZbWXP8zZixOAG2oCkty5lxte0G+8mDnaynR qIgD+xxJspZFp+ybrUUNp+E+7/8xfAMRK/GzgDLz+UjeOrD8HrdGMT9p8XiyDwVtBVyc U1ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:date:message-id:subject:from:cc:to; bh=m2XScPNtoy86iRnyJY/HBxWrD5JX4dENVID2vIve2kE=; b=LqIpQyraSbGoLmMDEHv/GFKYyc32oHPUNovQD8BpcffU7d4FDOm7ElHerTCht4pI/m vtdNwruThvDp3XUH5ETcIASMqNZj7GAz0QJ+oRNnpAJusCypM2KIRo33GtI6mq/0tGd7 WbHMLDlxHVnMGPP2zBuGUnAzHoDBLR2FE+J4juKDRrHLtv+iVT5Tf69O3/caRIAYyPtr kvyz76pPsyQelWyXAFHSE1PpMANvzXaGkpdpylCTdxfUnAsxRXnnhUcuf+rCi1hMZBIN aZdmKdoQS001cYFSWNIYwNSNZjMJaNwQIH98+XUwFu2enmNJqmWAp0msK4Rh0lslGdad w7qA== 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 p203si5684441oic.214.2020.03.30.00.41.47; Mon, 30 Mar 2020 00:42:00 -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 S1729486AbgC3Hlb (ORCPT + 99 others); Mon, 30 Mar 2020 03:41:31 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:56424 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728766AbgC3Hlb (ORCPT ); Mon, 30 Mar 2020 03:41:31 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 79CE774F8F34A2E3430B; Mon, 30 Mar 2020 15:41:23 +0800 (CST) Received: from [127.0.0.1] (10.173.221.117) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Mon, 30 Mar 2020 15:41:13 +0800 To: , CC: , , , , , , , , , , , From: Kemeng Shi Subject: [PATCH] perf report: Fix arm64 gap between kernel start and module end Message-ID: <33fd24c4-0d5a-9d93-9b62-dffa97c992ca@huawei.com> Date: Mon, 30 Mar 2020 15:41:11 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 Content-Type: text/plain; charset="gbk" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.173.221.117] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org During execution of command 'perf report' in my arm64 virtual machine, the error message is showed: failed to process sample __symbol__inc_addr_samples(860): ENOMEM! sym->name=__this_module, start=0x1477100, addr=0x147dbd8, end=0x80002000, func: 0 The error is caused with path: cmd_report __cmd_report perf_session__process_events __perf_session__process_events ordered_events__flush __ordered_events__flush oe->deliver (ordered_events__deliver_event) perf_session__deliver_event machines__deliver_event perf_evlist__deliver_sample tool->sample (process_sample_event) hist_entry_iter__add iter->add_entry_cb(hist_iter__report_callback) hist_entry__inc_addr_samples symbol__inc_addr_samples __symbol__inc_addr_samples h = annotated_source__histogram(src, evidx) (NULL) annotated_source__histogram failed is caused with path: ... hist_entry__inc_addr_samples symbol__inc_addr_samples symbol__hists annotated_source__alloc_histograms src->histograms = calloc(nr_hists, sizeof_sym_hist) (failed) Calloc failed as the symbol__size(sym) is too huge. As show in error message: start=0x1477100, end=0x80002000, size of symbol is about 2G. This is the same problem as 'perf annotate: Fix s390 gap between kernel end and module start (b9c0a64901d5bd)'. Perf gets symbol information from /proc/kallsyms in __dso__load_kallsyms. A part of symbol in /proc/kallsyms from my virtual machine is as follows: #cat /proc/kallsyms | sort ... ffff000001475080 d rpfilter_mt_reg [ip6t_rpfilter] ffff000001475100 d $d [ip6t_rpfilter] ffff000001475100 d __this_module [ip6t_rpfilter] ffff000080080000 t _head ffff000080080000 T _text ffff000080080040 t pe_header ... Take line 'ffff000001475100 d __this_module [ip6t_rpfilter]' as example. The start and end of symbol are both set to ffff000001475100 in dso__load_all_kallsyms. Then symbols__fixup_end will set the end of symbol to next big address to ffff000001475100 in /proc/kallsyms, ffff000080080000 in this example. Then sizeof of symbol will be about 2G and cause the problem. The start of module in my machine is ffff000000a62000 t $x [dm_mod] The start of kernel in my machine is ffff000080080000 t _head There is a big gap between end of module and begin of kernel if a samll amount of memory is used by module. And the last symbol in module will have a large address range as caotaining the big gap. Give that the module and kernel text segment sequence may change in the future, fix this by limiting range of last symbol in module and kernel to 4K in arch arm64. Signed-off-by: Kemeng Shi --- tools/perf/arch/arm64/util/Build | 1 + tools/perf/arch/arm64/util/machine.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tools/perf/arch/arm64/util/machine.c diff --git a/tools/perf/arch/arm64/util/Build b/tools/perf/arch/arm64/util/Build index 393b9895c..37cbfa5e9 100644 --- a/tools/perf/arch/arm64/util/Build +++ b/tools/perf/arch/arm64/util/Build @@ -2,6 +2,7 @@ libperf-y += header.o libperf-y += tsc.o libperf-y += sym-handling.o libperf-y += kvm-stat.o +libperf-y += machine.o libperf-$(CONFIG_DWARF) += dwarf-regs.o libperf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o diff --git a/tools/perf/arch/arm64/util/machine.c b/tools/perf/arch/arm64/util/machine.c new file mode 100644 index 000000000..a25be2431 --- /dev/null +++ b/tools/perf/arch/arm64/util/machine.c @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include "debug.h" +#include "symbol.h" + +/* On arm64, kernel text segment start at high memory address, + * for example 0xffff 0000 8xxx xxxx. Modules start at a low memory + * address, like 0xffff 0000 00ax xxxx. When only samll amount of + * memory is used by modules, gap between end of module's text segment + * and start of kernel text segment may be reach 2G. + * Therefore do not fill this gap and do not assign it to the kernel dso map. + */ + +#define SYMBOL_LIMIT (1 << 12) /* 4K */ + +void arch__symbols__fixup_end(struct symbol *p, struct symbol *c) +{ + if ((strchr(p->name, '[') && strchr(c->name, '[') == NULL) || + (strchr(p->name, '[') == NULL && strchr(c->name, '['))) + /* Limit range of last symbol in module and kernel */ + p->end += SYMBOL_LIMIT; + else + p->end = c->start; + pr_debug4("%s sym:%s end:%#lx\n", __func__, p->name, p->end); +} -- 2.19.1