Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1044398lqh; Sun, 5 May 2024 13:29:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVXzGyjZNcSiKN7i6LdpBPFA26Y9LMfnJCwNABNgHzXIGB4Ifzv+EgydfQxDb1jEYYtC8ACLIIuQlzaA989rjA0KWp4izVk2gNXVNzLZQ== X-Google-Smtp-Source: AGHT+IHE8OmufldV+1jnMnQTgZztIPEBOXWqZCGBDZlVsfksanN5dmL10lOoCzeW/KyQX6LtWYC1 X-Received: by 2002:a05:6359:4594:b0:183:e337:8eb8 with SMTP id no20-20020a056359459400b00183e3378eb8mr10485497rwb.13.1714940941088; Sun, 05 May 2024 13:29:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714940941; cv=pass; d=google.com; s=arc-20160816; b=KSBc+5fMk9C20j9rDAT6K9Zj0259Z+jC4OUNYvbBaWCQkZj0CEGcugO+UuTRuO/sBO ZJU+jQ5OkhQfBmvh7ba1bAURea0HcXmiF/zfiKu46arHOu35mgnODeOjXDXCtGaC4MRw euiiV0ouk7VxWwzESR0Zv+aflU9ddGF1Tetg7sbV7QJO+w29sbjufxE6uMSWGJbA3QoC jMCEIj57Y5Gl0VkZFkH2RkLnXQmEfIgIaiObmoWPqL1zIdLe4ijwNiVEJzPdawV2j9Qy wlfFKW9iBvKcS7GQFVfWO+Sw6s0hifM+xKYkHRghVxcfvvPwcjnB2PK2lN9VCy9nOtb0 R10w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=f/xcc10kpquLduQ7eXaYW1saFYvWrd96uA36Po0PFRQ=; fh=Ql7aazfm+rGUmIisS7pi7Yea+a5pSMfSF6kuwWe0x1M=; b=sLNH1x3/wa69HbSF75sAIyo+T9n2/9cs2xa9p1p7WfZSKF1FgKyLvOV02bOwPsdQUF csEziFqCUV3YiFUY85UlKH5XDEaXP0BeGiYZwgU4p0HumDohtsW4QQbWfj6jf4RV97Hr JcoJwFruzD5wsq3RirbZNBe2mf55dVgw3hapoxkc8g366HkdywFV3VO3cu0jx0X87CtI xilLIgX7NobaSoEMzaL7u56q/idJrv/1isY7G16SWaEOGjq90hhnHJBUzxkz84b6zet8 ADpLwKoJooBGKhYlBTdwpmUFiU2dIyr7qGU7ioIQPMa/zTn6b9gB8M3s2OB/FncI/Htw 1etA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-169141-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169141-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n67-20020a632746000000b0061ad115d004si6813767pgn.721.2024.05.05.13.29.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 May 2024 13:29:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169141-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-169141-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169141-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AE2B128250B for ; Sun, 5 May 2024 20:29:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 44E1774BE4; Sun, 5 May 2024 20:28:54 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC9E56D1A8; Sun, 5 May 2024 20:28:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714940933; cv=none; b=I7KB4qm9mnS1/uZ6lrwj7MdydxENAzilmk8Ibi27LsR5Sz/KbvCWEw3nelFWqVcNhoiDzLDWvlk0mB2BKET9aJZN8Tyty8V3IAFsBh6b6eH44qB2HkfvdWWsHVRe8zwQF9OknKS09gK/Ps1ViF9nAfUEEwkJ34AsPK5mk8/zSFA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714940933; c=relaxed/simple; bh=uESbJ3gRnZBQpJ7WWb9YkLM+GSeZA1GW9OYoZk1ZIRY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=CGabTcdwGx3pL1LzBbP98dQN/qFefrtC14M1a0NxkWVZk1ScUzEgFMJIzF48p7cIFC1hen5jOFz5lSh54HIknsZrswl2f4hDuklgeMR+v49ahuiGwD0w6lws5+TtvDz4Ouax/YybhJT7w0SGZrhU8a4HCTBldSZei0MTrIPv0Jw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 698F51007; Sun, 5 May 2024 13:29:10 -0700 (PDT) Received: from PF4Q20KV.arm.com (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 305723F793; Sun, 5 May 2024 13:28:42 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Ian Rogers , Namhyung Kim , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Athira Rajeev , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH] perf maps: Process kcore maps in order Date: Sun, 5 May 2024 21:28:05 +0100 Message-Id: <20240505202805.583253-1-leo.yan@arm.com> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Arm64, after enabling the 'DEBUG=1' build option, the tool exits abnormally: # ./perf report --itrace=Zi10ibT # perf: util/maps.c:42: check_invariants: Assertion `map__end(prev) <= map__start(map) || map__start(prev) == map__start(map)' failed. Aborted The details for causing this error are described in below. Firstly, machine__get_running_kernel_start() calculates the delta between the '_stext' symbol and the '_edata' symbol for the kernel map, alongside with eBPF maps: DSO | Start address | End address -----------------+--------------------+-------------------- kernel.kallsyms 0xffff800080000000 0xffff800082229200 bpf_prog 0xffff800082545aac 0xffff800082545c94 ... Then, the perf tool retrieves kcore maps: Kcore maps | Start address | End address -----------------+--------------------+-------------------- kcore_text 0xffff800080000000 0xffff8000822f0000 vmalloc 0xffff800080000000 0xfffffdffbf800000 ... Finally, the function dso__load_kcore() extends the kernel maps based on the retrieved kcore info. Since it uses the inverted order for processing the kcore maps, it extends maps for the vmalloc region prior to the 'kcore_text' map: DSO | Start address | End address -----------------+--------------------+-------------------- kernel.kallsyms 0xffff800080000000 0xffff800082229200 kernel.kallsyms 0xffff800082229200 0xffff800082545aac -> Extended for vmalloc region bpf_prog 0xffff800082545aac 0xffff800082545c94 ... DSO | Start address | End address -----------------+--------------------+-------------------- kernel.kallsyms 0xffff800080000000 0xffff8000822f0000 -> Updated for kcore_text map kernel.kallsyms 0xffff800082229200 0xffff800082545aac bpf_prog 0xffff800082545aac 0xffff800082545c94 ... As result, the two maps [0xffff800080000000..0xffff8000822f0000) and [0xffff800082229200..0xffff800082545aac) are overlapping and triggers failure. The current code processes kcore maps in inverted order. To fix it, this patch adds kcore maps in the tail of list, afterwards these maps will be processed in the order. Therefore, the kernel text section can be processed prior to handling the vmalloc region, which avoids using the inaccurate kernel text size when extending maps with the vmalloc region. Signed-off-by: Leo Yan --- tools/perf/util/symbol.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 9ebdb8e13c0b..e15d70845488 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -1266,7 +1266,24 @@ static int kcore_mapfn(u64 start, u64 len, u64 pgoff, void *data) map__set_end(list_node->map, map__start(list_node->map) + len); map__set_pgoff(list_node->map, pgoff); - list_add(&list_node->node, &md->maps); + /* + * Kcore maps are ordered with: + * [_text.._end): Kernel text section + * [VMALLOC_START..VMALLOC_END): vmalloc + * ... + * + * On Arm64, the '_text' and 'VMALLOC_START' are the same values + * but VMALLOC_END (~124TiB) is much bigger then the text end + * address. So '_text' region is the subset of the vmalloc region. + * + * Afterwards, when dso__load_kcore() adjusts kernel maps, we must + * process the kernel text size prior to handling vmalloc region. + * This can avoid to using any inaccurate kernel text size when + * extending maps with vmalloc region. For this reason, here it + * always adds kcore maps to the tail of list to make sure the + * sequential handling is in order. + */ + list_add_tail(&list_node->node, &md->maps); return 0; } -- 2.43.0