Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4475345ybx; Mon, 4 Nov 2019 14:03:32 -0800 (PST) X-Google-Smtp-Source: APXvYqyd8oi1We32ldIRixQQYcr/+hTeYKg3VCiB7SUyxdREvGRx4HNoP9mWbXbknJl0QWM7SebL X-Received: by 2002:a50:d80c:: with SMTP id o12mr32245440edj.251.1572905012805; Mon, 04 Nov 2019 14:03:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905012; cv=none; d=google.com; s=arc-20160816; b=ZFEmVDtl/8YzLDnLhtUYqnvJVhWq/Y0nZkILswbcrpluBlljrqh72zsI6IIXa9JozM pzwBXNkdma8WJZnXXYtq6oFJ3w+VDS7RdMp9AzUfIA/d3DT7PyzfX9nWyDS26zFsmOZX uirO+mtFWyACdhVG7TrL1YnJGjwa9KA6+UIsWrMSimd+JKCiN+5+xgI1zjSqM/jphIs4 Kf93amxFyZGGHhuDU6Iqvd9qc/fYg3jlVTfh8zRxm6s4TBIM4F1B7niXRBMEy9ItHiKR 62OLAsOo8AJaW2ZwvSdr/FBHSlugVxMfxxf9BgeDs1595x8r2ZzkUOCqimou48uKwlBC LLKA== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PoR4vND2IFQK39RbzJDde4T/QiogvEKkeCSucOp1130=; b=p1YepNbCj2j/y31EN6V7kj9w5rZDOuiePXDxblXqglQBfTR6CIBUWJ3pHZGbvLOGzp FV7D4Fyh9AUH3Mb5O+2i/yCMWnvNnHu36FvTHfIudatzhXTJ3T5GBq4aTaqt4V6GZqrN z60B0UE7drx1UJMvY0W0QSreLq/O/1bC6GsGkfNHBgm2y/7fPieeUDkddtxyunJPM8/R QKvfXrvVYGMrXv987vViBJCLyIptanKOkzitOoEFLPf2CRWJMUOm5Kn0ucqbvRjv8qam 7NUGUcerB8uAiq0amkhOPCs+HvzlGnuRshomGWk8tkhLrf7JFEZ2H5CAgBr2wP+2ZbI6 +r7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EnwW2Odx; 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 h90si8963372edd.178.2019.11.04.14.03.09; Mon, 04 Nov 2019 14:03:32 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=EnwW2Odx; 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 S2388247AbfKDV7d (ORCPT + 99 others); Mon, 4 Nov 2019 16:59:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:56584 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388044AbfKDV7Z (ORCPT ); Mon, 4 Nov 2019 16:59:25 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E4492217F5; Mon, 4 Nov 2019 21:59:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572904764; bh=CijPseug8WjvqSM9u163BFI5BKbNbejSayzarGviZq0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EnwW2OdxQZP3bATwVc2JUnLuzgzZ1jFPjGqGK4hXOrH7gVtkdkTNpJZSacGlnAI+c mPwX711fBTDdQ4o/uTO41lhyIF5+OFZvrKnnOlvW2yByE4N4avgUKMmrcdIP8vowL1 3Iqm6ErmuYrmSbOknmeHP5ELJ79glUiFMPSeaJtA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Steve MacLean , Brian Robbins , Jiri Olsa , Alexander Shishkin , Andi Kleen , Davidlohr Bueso , Eric Saint-Etienne , John Keeping , John Salem , Leo Yan , Mark Rutland , Namhyung Kim , Peter Zijlstra , Song Liu , Stephane Eranian , Tom McDonald , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.19 062/149] perf map: Fix overlapped map handling Date: Mon, 4 Nov 2019 22:44:15 +0100 Message-Id: <20191104212141.108569610@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212126.090054740@linuxfoundation.org> References: <20191104212126.090054740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steve MacLean [ Upstream commit ee212d6ea20887c0ef352be8563ca13dbf965906 ] Whenever an mmap/mmap2 event occurs, the map tree must be updated to add a new entry. If a new map overlaps a previous map, the overlapped section of the previous map is effectively unmapped, but the non-overlapping sections are still valid. maps__fixup_overlappings() is responsible for creating any new map entries from the previously overlapped map. It optionally creates a before and an after map. When creating the after map the existing code failed to adjust the map.pgoff. This meant the new after map would incorrectly calculate the file offset for the ip. This results in incorrect symbol name resolution for any ip in the after region. Make maps__fixup_overlappings() correctly populate map.pgoff. Add an assert that new mapping matches old mapping at the beginning of the after map. Committer-testing: Validated correct parsing of libcoreclr.so symbols from .NET Core 3.0 preview9 (which didn't strip symbols). Preparation: ~/dotnet3.0-preview9/dotnet new webapi -o perfSymbol cd perfSymbol ~/dotnet3.0-preview9/dotnet publish perf record ~/dotnet3.0-preview9/dotnet \ bin/Debug/netcoreapp3.0/publish/perfSymbol.dll ^C Before: perf script --show-mmap-events 2>&1 | grep -e MMAP -e unknown |\ grep libcoreclr.so | head -n 4 dotnet 1907 373352.698780: PERF_RECORD_MMAP2 1907/1907: \ [0x7fe615726000(0x768000) @ 0 08:02 5510620 765057155]: \ r-xp .../3.0.0-preview9-19423-09/libcoreclr.so dotnet 1907 373352.701091: PERF_RECORD_MMAP2 1907/1907: \ [0x7fe615974000(0x1000) @ 0x24e000 08:02 5510620 765057155]: \ rwxp .../3.0.0-preview9-19423-09/libcoreclr.so dotnet 1907 373352.701241: PERF_RECORD_MMAP2 1907/1907: \ [0x7fe615c42000(0x1000) @ 0x51c000 08:02 5510620 765057155]: \ rwxp .../3.0.0-preview9-19423-09/libcoreclr.so dotnet 1907 373352.705249: 250000 cpu-clock: \ 7fe6159a1f99 [unknown] \ (.../3.0.0-preview9-19423-09/libcoreclr.so) After: perf script --show-mmap-events 2>&1 | grep -e MMAP -e unknown |\ grep libcoreclr.so | head -n 4 dotnet 1907 373352.698780: PERF_RECORD_MMAP2 1907/1907: \ [0x7fe615726000(0x768000) @ 0 08:02 5510620 765057155]: \ r-xp .../3.0.0-preview9-19423-09/libcoreclr.so dotnet 1907 373352.701091: PERF_RECORD_MMAP2 1907/1907: \ [0x7fe615974000(0x1000) @ 0x24e000 08:02 5510620 765057155]: \ rwxp .../3.0.0-preview9-19423-09/libcoreclr.so dotnet 1907 373352.701241: PERF_RECORD_MMAP2 1907/1907: \ [0x7fe615c42000(0x1000) @ 0x51c000 08:02 5510620 765057155]: \ rwxp .../3.0.0-preview9-19423-09/libcoreclr.so All the [unknown] symbols were resolved. Signed-off-by: Steve MacLean Tested-by: Brian Robbins Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: Davidlohr Bueso Cc: Eric Saint-Etienne Cc: John Keeping Cc: John Salem Cc: Leo Yan Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Song Liu Cc: Stephane Eranian Cc: Tom McDonald Link: http://lore.kernel.org/lkml/BN8PR21MB136270949F22A6A02335C238F7800@BN8PR21MB1362.namprd21.prod.outlook.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/map.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 6a6929f208b4d..1117ab86ebd34 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "symbol.h" +#include #include #include #include @@ -751,6 +752,8 @@ static int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp } after->start = map->end; + after->pgoff += map->end - pos->start; + assert(pos->map_ip(pos, map->end) == after->map_ip(after, map->end)); __map_groups__insert(pos->groups, after); if (verbose >= 2 && !use_browser) map__fprintf(after, fp); -- 2.20.1