Received: by 2002:ab2:7a09:0:b0:1f8:46dc:890e with SMTP id k9csp274496lqo; Wed, 15 May 2024 14:11:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU8XFiPqbzen++5VAmgp5+w90Fz0Wgb7JjzRhvy5n7ie+9KKNnbGO8OWVDvk+V7fkvxzrNccLAYfjrWa0r5YaPRjiRa9kK0zl/Krd/dfA== X-Google-Smtp-Source: AGHT+IGVkIhIqFdMKFAWDq0xPJuEoAqm/pk/pNPf81XjsJWLoHLt4SYnvl1taLQ+GTgCpLxTUxq+ X-Received: by 2002:a81:a18d:0:b0:61d:fcdd:2d6a with SMTP id 00721157ae682-622aff5fb0emr154963497b3.19.1715807489309; Wed, 15 May 2024 14:11:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715807489; cv=pass; d=google.com; s=arc-20160816; b=cscS3DQRabpX1ZgG3niOoqyD1y+DIqmU4IBnPKVpBc9wLguVT6VK6crjqgj+nBIEy4 q/cVnI1pdf3mvBlXTkgahsjGwteRBRpQH4gPCSL/5WhpbAt5lAZzUpYA6E7nJDHzBioj SN5mscQaFAaQte3yfMkiRGtZPNJ805YegD59J/Z9ZrnwfSryMx8kQ2lu4XdkJBI/sG1Y g+S1gR2Pd+YrQxwMYsOCJ/8P52NXXPVtbtIwKIgdTIxkKkr74cyLAZr3H+c9vamukMJU R9vSQI0U4o+o2aAlioe3TlXj1DST35LAY1C65YMM5sIHmxZGfig9YpT6bzbI8DToxGbr lj8A== 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:references:in-reply-to:message-id :date:subject:cc:to:from; bh=QNPNJE1VPOR7OXdxlXZ1zxPGT63bf3l9P2wbrSLCjfc=; fh=5BksDJxA/SfhQk3QQHTEZ4fXEO+DxcBDG1/AZim0b5U=; b=ZlvcMBmsX1vh6Qyt90o1No8+UYN60ZFO97a1QV/Q7DJwQ3YJUzaUoIVvPF/1+pKGcu 7HhbPnYw9KBM809j4wDz4D3KyzH/Ikrnrv6z7Epps3waB7czl7O4kiEZxwW0uHxJt2aG rG/0FlMwGTPzVH20B3GTGrhyBze362cC+p6mKhCb+oAGcHw3930slOFwmLxbA0V702tR lZZ6m8q8UZcTISEQ7atHON6G34y2Mxtb3mxN/zG4R70T8zGSbRpnOOAGJ8MBQyJUuPxE 7svlKxTZlxVqKZ2TD38HijvOcoXxRB1YQwIPVcq5Ai6eDIoFQFLbWGyy8D9istlyti8U vRkQ==; 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-180369-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180369-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43df549d48fsi138993491cf.18.2024.05.15.14.11.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 14:11:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180369-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; 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-180369-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180369-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D87DC1C220FB for ; Wed, 15 May 2024 21:11:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DCE9915B553; Wed, 15 May 2024 21:11:10 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 42D1915B11D; Wed, 15 May 2024 21:11:08 +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=1715807470; cv=none; b=qpJ8y9ZBNkhUqy/Js7dDnM9F2CJ44FM7dpiKv7FpyRGd7SN3S/53VRp47NmD6DrAxp8DI2Wz8pDYHEyrMzQ6rHGr0VK1Pa/RJnd+PqqXeQeCL1wkD3K+RZHk4QB4hT7Hu4GQ6x2JPmN2BzfySsP1V57nJvLTfLuZvkBD64r1JNQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715807470; c=relaxed/simple; bh=WyFMRDi/bs5IDpAIMfC56d+PwBTs80Y/L12c4A53rFA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Jh+X+a0ywGgvxZreBgBsVl//9OOeYkzCOeU4Kvx0stT+qz5dNl8Si/LoG4SExJRNhQDsqoTAv3OAQF7QmSp/xSCDDunjwoz8pbGcaaJtlvIiPtTN1n/PDUNDHUNwGTN2K+etWsPYarapRgESeI8mtSazePVZ3lAYJTdMsjJqwRs= 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 ACD151007; Wed, 15 May 2024 14:11:31 -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 6BDE23F7A6; Wed, 15 May 2024 14:11:04 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Adrian Hunter , James Clark , Peter Zijlstra , Ingo Molnar , Namhyung Kim , Ian Rogers , Mark Rutland , Alexander Shishkin , Jiri Olsa , Athira Rajeev , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v2 1/2] perf maps: Sort kcore maps Date: Wed, 15 May 2024 22:10:44 +0100 Message-Id: <20240515211045.377080-2-leo.yan@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240515211045.377080-1-leo.yan@arm.com> References: <20240515211045.377080-1-leo.yan@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When merging kcore maps into the kernel maps, it has an implicit requirement for the kcore maps ordering, otherwise, some sections delivered by the kcore maps will be ignored. Let's see below example: Ordering 1: Kcore maps | Start address | End address -----------------+--------------------+-------------------- kcore_text | 0xffff800080000000 | 0xffff8000822f0000 vmalloc | 0xffff800080000000 | 0xfffffdffbf800000 Ordering 2: Kcore maps | Start address | End address -----------------+--------------------+-------------------- vmalloc | 0xffff800080000000 | 0xfffffdffbf800000 kcore_text | 0xffff800080000000 | 0xffff8000822f0000 The 'kcore_text' map is a subset of the 'vmalloc' map. When merging these two maps into the kernal maps with the maps__merge_in() function, the ordering 1 inserts the 'kcore_text' map prior to the 'vmalloc' map, thus the 'kcore_text' map will be respected. On the other hand, if maps are inserted with the ordering 2, the 'vmalloc' is inserted ahead, as a result, its subset map will be ignored afterwards. To merge the maps in a reliable way, this commit sorts the kcore maps before merging them. Besides sorting the maps based on the end address, it also gives the priority to a subset map to insert it before its superset map in the list. Signed-off-by: Leo Yan --- tools/perf/util/symbol.c | 50 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 9e5940b5bc59..c1513976ab6e 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -1256,6 +1256,7 @@ static int kcore_mapfn(u64 start, u64 len, u64 pgoff, void *data) { struct kcore_mapfn_data *md = data; struct map_list_node *list_node = map_list_node__new(); + struct map_list_node *node; if (!list_node) return -ENOMEM; @@ -1269,8 +1270,55 @@ 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); + list_for_each_entry(node, &md->maps, node) { + /* + * When the new map (list_node)'s end address is less than + * current node, it can be divided into three cases. + * + * Case 1: the new map does not overlap with the current node, + * as the new map's end address is less than the current node's + * start address. + * [*******node********] + * [***list_node***] `start `end + * `start `end + * + * Case 2: the new map overlaps with the current node. + * + * ,start ,end + * [*******node********] + * [***list_node***] + * `start `end + * + * Case 3: the new map is subset of the current node. + * + * ,start ,end + * [*******node********] + * [***list_node***] + * `start `end + * + * For above three cases, insert the new map node before the + * current node. + */ + if (map__end(node->map) > map__end(list_node->map)) + break; + + /* + * When the new map is subset of the current node and both nodes + * have the same end address, insert the new map node before the + * current node. + * + * ,start ,end + * [*******node********] + * [***list_node***] + * `start `end + */ + if ((map__end(node->map) == map__end(list_node->map)) && + (map__start(node->map) <= map__start(list_node->map))) + break; + } + /* Insert the new node (list_node) ahead */ + list_add_tail(&list_node->node, &node->node); return 0; } -- 2.34.1