Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2916363yba; Mon, 22 Apr 2019 15:39:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqzAsXJOKJ8qHsXd4EallXXozpAwZBLBMqSvpswW1eIR6bQlYX/C1g7sWLC7XHciRtf5o2HF X-Received: by 2002:a17:902:505:: with SMTP id 5mr9935944plf.323.1555972755736; Mon, 22 Apr 2019 15:39:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555972755; cv=none; d=google.com; s=arc-20160816; b=lnckjP+SlrIQyv8PBX36XIpCMa/SANT/D8VAZ5atXLq9nwtSeR0gMH0oyJssQSzugs 2v97CfHl+cMNQ7waPnB5vfSg7mjOcAFh3IRN/4U0zm8h2WQDD2uY82h9uvnv0q43LKSh X+N2jrN9iBS7hNiObaVqiZ79x6hnaCVr86vgS8Javk4/CSNzLelgsJpFQSS5KIas7O4x VNvlBAUM3szUV9P2wGOnom1bw3bPydGQ4G7kZ/NiuyJiVnwuCK2YxkhpAFcM9EUKNwk/ R1IowiiQoVLgxsyf+0LTczSgtL8HWtv5AjcaYbDY0wGZNmgoYdW/w+TvvhH60dkjQ8Od shrw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zLMVHeIFFE3MRLz42kUa7q51QAXjSuKnBJxe9uZ5dd0=; b=YFp0sBn/ivfIlmmzGIXV09mKviYWdNPOmnPYu3hBvp/IncSH9dn3SMIoITB6Bc/6Gb 92sIrZ5ftIzA5Pc744qblDMgZT0SkNUXf8UFGXwhazrg2osJkqmyaXyrhLr9tzchM9DG skaPaTOimxJt2uh7+ZMXTgwaJkAD9TUcZkcVTMwM7kqh9Z7feqY+9NZ2vb5uM/w+2+AO YxvKrQwQqxtuJ+DM9WCFEG8bIHUBqDZi7LMSgyfGClRAmCp5lFkYJlI1SAeW+NlSWj3N beU2ozkrJPxnPwTPNR2bbuw3+WFAW74jejlHTjAtuKSBwUKqJ7l40ZUGbH/x6Uhm0ykj EORg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="FxPQ/ekQ"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1si3827914pgk.39.2019.04.22.15.38.56; Mon, 22 Apr 2019 15:39:15 -0700 (PDT) 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="FxPQ/ekQ"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729144AbfDVTpH (ORCPT + 99 others); Mon, 22 Apr 2019 15:45:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:46506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729650AbfDVTpF (ORCPT ); Mon, 22 Apr 2019 15:45:05 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7E42321917; Mon, 22 Apr 2019 19:45:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962303; bh=QSSVqJcdKCNCBVMh8LvsH//+/JhBsseika3eMnLBAms=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FxPQ/ekQpuwsGShmmW3NtiPiViY+ig44s4ebJ1THO+mCNDVV5SfV1hKJPD5gligjY E08r/q6eDKcfGtiXOITiprcHf5V99VSoXrcBdiNrZ3suBeQ415DjDalXhQn2LKVtfw 9xnx9XjcK0ZuhUwMwbCrxP9tGsVyVyzC7EuQCKcM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Wei Li , Alexander Shishkin , David Ahern , Hanjun Guo , Kim Phillips , Li Bin , Peter Zijlstra , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH AUTOSEL 5.0 92/98] perf machine: Update kernel map address and re-order properly Date: Mon, 22 Apr 2019 15:41:59 -0400 Message-Id: <20190422194205.10404-92-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194205.10404-1-sashal@kernel.org> References: <20190422194205.10404-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wei Li [ Upstream commit 977c7a6d1e263ff1d755f28595b99e4bc0c48a9f ] Since commit 1fb87b8e9599 ("perf machine: Don't search for active kernel start in __machine__create_kernel_maps"), the __machine__create_kernel_maps() just create a map what start and end are both zero. Though the address will be updated later, the order of map in the rbtree may be incorrect. The commit ee05d21791db ("perf machine: Set main kernel end address properly") fixed the logic in machine__create_kernel_maps(), but it's still wrong in function machine__process_kernel_mmap_event(). To reproduce this issue, we need an environment which the module address is before the kernel text segment. I tested it on an aarch64 machine with kernel 4.19.25: [root@localhost hulk]# grep _stext /proc/kallsyms ffff000008081000 T _stext [root@localhost hulk]# grep _etext /proc/kallsyms ffff000009780000 R _etext [root@localhost hulk]# tail /proc/modules hisi_sas_v2_hw 77824 0 - Live 0xffff00000191d000 nvme_core 126976 7 nvme, Live 0xffff0000018b6000 mdio 20480 1 ixgbe, Live 0xffff0000018ab000 hisi_sas_main 106496 1 hisi_sas_v2_hw, Live 0xffff000001861000 hns_mdio 20480 2 - Live 0xffff000001822000 hnae 28672 3 hns_dsaf,hns_enet_drv, Live 0xffff000001815000 dm_mirror 40960 0 - Live 0xffff000001804000 dm_region_hash 32768 1 dm_mirror, Live 0xffff0000017f5000 dm_log 32768 2 dm_mirror,dm_region_hash, Live 0xffff0000017e7000 dm_mod 315392 17 dm_mirror,dm_log, Live 0xffff000001780000 [root@localhost hulk]# Before fix: [root@localhost bin]# perf record sleep 3 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.011 MB perf.data (9 samples) ] [root@localhost bin]# perf buildid-list -i perf.data 4c4e46c971ca935f781e603a09b52a92e8bdfee8 [vdso] [root@localhost bin]# perf buildid-list -i perf.data -H 0000000000000000000000000000000000000000 /proc/kcore [root@localhost bin]# After fix: [root@localhost tools]# ./perf/perf record sleep 3 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.011 MB perf.data (9 samples) ] [root@localhost tools]# ./perf/perf buildid-list -i perf.data 28a6c690262896dbd1b5e1011ed81623e6db0610 [kernel.kallsyms] 106c14ce6e4acea3453e484dc604d66666f08a2f [vdso] [root@localhost tools]# ./perf/perf buildid-list -i perf.data -H 28a6c690262896dbd1b5e1011ed81623e6db0610 /proc/kcore Signed-off-by: Wei Li Acked-by: Jiri Olsa Acked-by: Namhyung Kim Cc: Alexander Shishkin Cc: David Ahern Cc: Hanjun Guo Cc: Kim Phillips Cc: Li Bin Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20190228092003.34071-1-liwei391@huawei.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin (Microsoft) --- tools/perf/util/machine.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 143f7057d581..596db1daee35 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -1358,6 +1358,20 @@ static void machine__set_kernel_mmap(struct machine *machine, machine->vmlinux_map->end = ~0ULL; } +static void machine__update_kernel_mmap(struct machine *machine, + u64 start, u64 end) +{ + struct map *map = machine__kernel_map(machine); + + map__get(map); + map_groups__remove(&machine->kmaps, map); + + machine__set_kernel_mmap(machine, start, end); + + map_groups__insert(&machine->kmaps, map); + map__put(map); +} + int machine__create_kernel_maps(struct machine *machine) { struct dso *kernel = machine__get_kernel(machine); @@ -1390,17 +1404,11 @@ int machine__create_kernel_maps(struct machine *machine) goto out_put; } - /* we have a real start address now, so re-order the kmaps */ - map = machine__kernel_map(machine); - - map__get(map); - map_groups__remove(&machine->kmaps, map); - - /* assume it's the last in the kmaps */ - machine__set_kernel_mmap(machine, addr, ~0ULL); - - map_groups__insert(&machine->kmaps, map); - map__put(map); + /* + * we have a real start address now, so re-order the kmaps + * assume it's the last in the kmaps + */ + machine__update_kernel_mmap(machine, addr, ~0ULL); } if (machine__create_extra_kernel_maps(machine, kernel)) @@ -1536,7 +1544,7 @@ static int machine__process_kernel_mmap_event(struct machine *machine, if (strstr(kernel->long_name, "vmlinux")) dso__set_short_name(kernel, "[kernel.vmlinux]", false); - machine__set_kernel_mmap(machine, event->mmap.start, + machine__update_kernel_mmap(machine, event->mmap.start, event->mmap.start + event->mmap.len); /* -- 2.19.1