Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4467962ybx; Mon, 4 Nov 2019 13:56:17 -0800 (PST) X-Google-Smtp-Source: APXvYqwIQqNX6cAd/Jyom4/+7k4OPdhu/nOp62j4W/C+/MrulQy/lCmVa3R6XCdDa7q8Zd7qkf0q X-Received: by 2002:aa7:df87:: with SMTP id b7mr11302288edy.296.1572904576924; Mon, 04 Nov 2019 13:56:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572904576; cv=none; d=google.com; s=arc-20160816; b=KlpIEwgWCKXJpsrVmLI8XOFJU+ydyWfr47sWGNiY4g/f3070/C92TSBU3k1AmvzgCT o93Ivh2Yd+36TUJVjQiNuswb4+vQpJZwkDtCeB7AG1jzjp2S4y750z+HXUBjEgJbBnB2 QsnIejbVuxKXNpAs+mNbrlfguTj9K9CUvScVHqe3Ci9qq4uK/H7UjIbn+cIgw8wgxqA/ lb9z23RSK7/Rn72xH8ouCS7jPUlyXKIiBU0aQ6mgRJF2BL3AIrgJIzkMS93aSJlnvIj2 Ykn4/K+lvmeXbrc9uzHEgSgtKaTautXRX6udecwBIm/+fAdEJT4iWpnJklFESc6aQvtC H/Fg== 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=dhGMLJxCOVj/TzpnV/7sQyQM7f+U055MysDPfnEFfrU=; b=sUqq6Iw0BVgIJmiAOj83yWzlIqoSbgVOHwttavItyerG2wP9TBsNa+knWWVpF72uXK rFLHWHXUbE/xWI3wQ9I1q1lmPv6II5smOKGumelk5u/PiqRZ1eyZeZF6myfXGGN8NtQR fib6Uz99rf7cbqF1NwZ0oSuE792Xh+eF74Y6PV01Jh4hjBtXD5mQ+JDviCuQ/apYP6YU MMqjWDDb4kN7H6tMpi9nDNJIDESXx9MTIjj7DIr2tRXhQzN/XPSs7FyXXOSTn7PRDqLP lW0MbPPRKUkvRmeqAzNEKp1tNkbVdg5I+YmNfD2oK/l0QS16rAwkxNd0+rSYxEHPQKGQ Hz9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ReUHcutN; 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 b15si8250263eda.174.2019.11.04.13.55.53; Mon, 04 Nov 2019 13:56:16 -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=ReUHcutN; 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 S1730928AbfKDVxL (ORCPT + 99 others); Mon, 4 Nov 2019 16:53:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:46886 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730894AbfKDVxF (ORCPT ); Mon, 4 Nov 2019 16:53:05 -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 84EBD21D71; Mon, 4 Nov 2019 21:53:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572904384; bh=fjQiodUtUnL7E1QsrnGW+Yr+9a3iGa0tjDl/Uey1G/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ReUHcutN+PmOC2S222YjGU6Qntk6URMFJlrRS/4h+I5C+K7jmS8X/N+/WUQdEs4iq Tj+lvAnV7skHog+L+jFJFCE8vTrjJt0yrCa2+UT2J3bLO0eXGUGx6BA+uGGC26s/mp /rqFbQuUY+taciv9P3XzjUuLjZRh5y/lUxUuupAM= 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.14 28/95] perf map: Fix overlapped map handling Date: Mon, 4 Nov 2019 22:44:26 +0100 Message-Id: <20191104212056.591490118@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212038.056365853@linuxfoundation.org> References: <20191104212038.056365853@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 4e7bd27501224..63db9872c8808 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 @@ -737,6 +738,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