Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp552941lqh; Tue, 7 May 2024 07:17:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVlB6HB77cwR1cvaZoq0MuJQt6bh5KYpEdEDA97OVnlxfne3nwh4PqgCWCmxaFi1DTfOJxXFx0LHD26iYNKGEcx21/RMPgEyOU8qV85Bg== X-Google-Smtp-Source: AGHT+IGq2NGjC9OJ4vkvFCxggZB/YAac8x1vwxBTPVhx6iQKsDSGTDHNdh8p9o8XL7v6hiR7TIVU X-Received: by 2002:a17:906:4c42:b0:a59:cc26:ceaf with SMTP id d2-20020a1709064c4200b00a59cc26ceafmr4274825ejw.26.1715091471681; Tue, 07 May 2024 07:17:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715091471; cv=pass; d=google.com; s=arc-20160816; b=QbbPk3NdrojoVEymaAeVflb1cljdTNtS0g9W7zYRvIN37Cs+DtfqKbTOpF7Qm0Hh8A Nm6n5jzDB9X6tR7piCI/nTQGsd7qeRPzpKjY2RH0CZaZp8+AF8+rF6t3M8tbbs+YnFu1 pADqHI0rxMISwtIpex8daoBJDxaa5D8xi7KHEjOeFLT1CSZcupNOddrkXS0au56UrgOC Xtwh2EeM6zWdCtOWbJmW5QTj9tfzYXnjqLb0972wId3Ic6pgayX8AUqZkzlPSAzS1SVl MlrhDAeIBnv3yopLAvwkRJ2x852wlA9s4mIbMCnRMEl9pG2T+GtbEJsC0DbBJ7wG23oe hfxg== 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=mr00tkzBjO/BsX4EQaYONHYzz/yzFG0dV6Wf3Q5MHUk=; fh=z3/YlGhmWVGbDDVRrPyvN7QnpotMsOuIPt85/Od1vi8=; b=0CBpIQiXTO0omVD+nkYNXLNVUVTLjSLEi6zBkEwZ4C/ycpye7KfXuQxtvxoXkmOtke o6pQcvxRJ1MOe7yZw+uOQNBfdXVN0g4Mzu3eNrs1ZJEcbteyj9DtE/esLiwPgQLtQsBM tq+k0UhT6SzkGJ8Q4igzEJ2sEgdNeE81qtxlw3SF/SroaEhFeEO2xyXnpDf8Q8tBFGD8 g8XWZoNKDja8Q7CuOUq2SZF8RwDnvgWzbzUe/ZLeMzjn7NYOiH3tteU+hWPxZyDdNLyB sfYzCi7jFlPWYE3SRPAvIrsXjVqCnz0LYtWe4Y9n9sE5dpi2NeTZ06GJcLdbBb8nWv9u noFA==; 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-171538-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171538-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id kw18-20020a170907771200b00a55afd8f5e8si6341954ejc.870.2024.05.07.07.17.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 07:17:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171538-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-171538-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171538-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 5C3141F21BB8 for ; Tue, 7 May 2024 14:17:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1326D16DEDF; Tue, 7 May 2024 14:13:35 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6EE0616D32E; Tue, 7 May 2024 14:13: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=1715091213; cv=none; b=JLzbQVTh4g7WQ3NKCxqwxdaDs065pWALb3NcrpHnn46TL8f7zW1hEMaC7m7gjr6JU8MaQd30TR6TPAiYyD8iwz0XXinPoGx87xb8nXbMaeCoNZYNiVQDvOADKn7APmlna/rRj0hJ4mpgy/69UR/Zu3PvdX4UxJzD01CcSFoOw0k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715091213; c=relaxed/simple; bh=j60Lp76p4GCMge0RHYRlaMeijthkr1haXgYWLgtV6oU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IO6emxOByH9u6Q5Bv/0eVVneLeR4EvvE5zZhrGZjEQjwvBrQWX5lKm+K1NiJnZ1lzm7tgIPvC/W8JqbfmDYFmG+cpIePwm5T79L9sxKIz4g7HmFnF/RnNRRW941uNh54lfBHvrogx2HeOKft7rlosPJinhC4kD7u3/TNvLn2S+w= 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 498F51516; Tue, 7 May 2024 07:13:33 -0700 (PDT) Received: from e127643.broadband (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 687C93F6A8; Tue, 7 May 2024 07:13:05 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org, atrajeev@linux.vnet.ibm.com, irogers@google.com Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org Subject: [PATCH 3/4] perf symbols: Update kcore map before merging in remaining symbols Date: Tue, 7 May 2024 15:12:07 +0100 Message-Id: <20240507141210.195939-4-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240507141210.195939-1-james.clark@arm.com> References: <20240507141210.195939-1-james.clark@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 loading kcore, the main vmlinux map is updated in the same loop that merges the remaining maps. If a map that overlaps is merged in before kcore, the list can become unsortable when the main map addresses are updated. This will later trigger the check_invariants() assert: $ perf record $ perf report util/maps.c:96: check_invariants: Assertion `map__end(prev) <= map__start(map) || map__start(prev) == map__start(map)' failed. Aborted Fix it by moving the main map update prior to the loop so that maps__merge_in() can split it if necessary. Fixes: 659ad3492b91 ("perf maps: Switch from rbtree to lazily sorted array for addresses") Signed-off-by: James Clark --- tools/perf/util/symbol.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 2d95f22d713d..e98dfe766da3 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -1289,7 +1289,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map, { struct maps *kmaps = map__kmaps(map); struct kcore_mapfn_data md; - struct map *replacement_map = NULL; + struct map *map_ref, *replacement_map = NULL; struct machine *machine; bool is_64_bit; int err, fd; @@ -1367,6 +1367,24 @@ static int dso__load_kcore(struct dso *dso, struct map *map, if (!replacement_map) replacement_map = list_entry(md.maps.next, struct map_list_node, node)->map; + /* + * Update addresses of vmlinux map. Re-insert it to ensure maps are + * correctly ordered. Do this before using maps__merge_in() for the + * remaining maps so vmlinux gets split if necessary. + */ + map_ref = map__get(map); + maps__remove(kmaps, map_ref); + + map__set_start(map_ref, map__start(replacement_map)); + map__set_end(map_ref, map__end(replacement_map)); + map__set_pgoff(map_ref, map__pgoff(replacement_map)); + map__set_mapping_type(map_ref, map__mapping_type(replacement_map)); + + err = maps__insert(kmaps, map_ref); + map__put(map_ref); + if (err) + goto out_err; + /* Add new maps */ while (!list_empty(&md.maps)) { struct map_list_node *new_node = list_entry(md.maps.next, struct map_list_node, node); @@ -1374,24 +1392,8 @@ static int dso__load_kcore(struct dso *dso, struct map *map, list_del_init(&new_node->node); - if (RC_CHK_EQUAL(new_map, replacement_map)) { - struct map *map_ref; - - /* Ensure maps are correctly ordered */ - map_ref = map__get(map); - maps__remove(kmaps, map_ref); - - map__set_start(map_ref, map__start(new_map)); - map__set_end(map_ref, map__end(new_map)); - map__set_pgoff(map_ref, map__pgoff(new_map)); - map__set_mapping_type(map_ref, map__mapping_type(new_map)); - - err = maps__insert(kmaps, map_ref); - map__put(map_ref); - map__put(new_map); - if (err) - goto out_err; - } else { + /* skip if replacement_map, already inserted above */ + if (!RC_CHK_EQUAL(new_map, replacement_map)) { /* * Merge kcore map into existing maps, * and ensure that current maps (eBPF) -- 2.34.1