Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4479849ybx; Mon, 4 Nov 2019 14:07:25 -0800 (PST) X-Google-Smtp-Source: APXvYqw/PfeJOr9yx1keF/Xc9ez5rDvFEGYsGKoVXqIl4wMDgS4nVMl3A6dJiEj68rggvbcSlfGv X-Received: by 2002:aa7:d709:: with SMTP id t9mr30610978edq.266.1572905244863; Mon, 04 Nov 2019 14:07:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905244; cv=none; d=google.com; s=arc-20160816; b=lqLOZS0Y9eCecu5atpPkNjTmoCgRcWd7T2C8lvKsw44sJy66LuVFfHf7MKqS7yUPul OAnpLSTj+F4YiLK2/pjDJXTv+1YX+Uh1jlD6prt0LAmHSbNlNCQ/O/scZY0UrF7HdVbF 4Rmh0jyehwKGZa5QbqUb3e7E+dGFazHX1qabinVLizzKaHdX7SlTo30joTb2VXtI8llQ Zx7DorsitowIdxZiMB0Xa6Ez6wOPc0IEl+lOe9qSo0XJ+3ROCi4MlP7AhQn0rfsp+hFE 3B8wFOC/GcfHTv6ssjWon2gWCUe9Lcn6wINWmpznGOLmTL3Gy1VcMH9n8heTjzKis8lV hN0g== 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=F4ijh3sfPvH/B3JshofgdcwWA5m9JljUel4Wo/RtYNo=; b=JxH6Od3o6PSvLrIq8egO7OZrCcyTA/2nZOFPX47uw6bQC4eDJ8CBtfrLjolo/AkVpl e/1EJ52EdaVdxrHBO1soxk9na96myTqYYjztx93fapngvchfdx0ArfyvOeL6QvAkKtmh a2tbFfHYXWhBqTlhDH5d7Z/l7WbMX8dsoNf0X6/LT7mfMNw3x7habnq0AgxowPqDRjIS ghb7s8z2yD1mDjxQVhdBIhyq0XxYkJmmtKo41ySwi1a23o+N/zIKeMVXEMq2kaXMpKGy hPMXTaIfrQc9m91NW63icKDBDKfpcXpog1VghtSOIRv9hvZdzcrtLbST8eeOCwL/hQiD dvMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0aDuTa01; 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 me8si2131736ejb.382.2019.11.04.14.07.01; Mon, 04 Nov 2019 14:07:24 -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=0aDuTa01; 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 S2388933AbfKDWGH (ORCPT + 99 others); Mon, 4 Nov 2019 17:06:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:37544 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389888AbfKDWF6 (ORCPT ); Mon, 4 Nov 2019 17:05:58 -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 1A20C2084D; Mon, 4 Nov 2019 22:05:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572905157; bh=qvZy1e6ZELCo1IUUHbk2bgjAD4hfRU/4u/aLXq5lOzM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0aDuTa01wy/2abMtm6M1H9AhvfbYUVOyUkRq3iLUz69GHaJOP7vteW25RXaHkf4es fgqi9/CWGPMSTSJCaADV2z/n8waEDCE5gOLlZEFJa9cTNhO52b5rtAUhWhu/kycyD5 jppKtw1hMtifm0R/crjAmUtWGMvM3CraPodXoaE0= 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 5.3 010/163] perf map: Fix overlapped map handling Date: Mon, 4 Nov 2019 22:43:20 +0100 Message-Id: <20191104212141.249329773@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212140.046021995@linuxfoundation.org> References: <20191104212140.046021995@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 7666206d06fa7..f18113581cf03 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 @@ -847,6 +848,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