Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2845470yba; Mon, 22 Apr 2019 14:08:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqyB3EAeegXnvGyysOSzCT/bKHoIOZOrZn/9isQ4L/ePI4HhynFbD75j+OBjZCdydfnT83pF X-Received: by 2002:a65:558a:: with SMTP id j10mr20822853pgs.85.1555967334985; Mon, 22 Apr 2019 14:08:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555967334; cv=none; d=google.com; s=arc-20160816; b=O2eBs9AU9xAjQo4CWPaM8YhKwzAtd7Dfbu/GarDXEgTX209RCdtZkOFLGQtDbX+srC 1ze0aSJYHUbvEs/sRB6QfPzmg6STLLwU+jjFcIB7siv5XccPvve0c1O8yJ32OSE5s3G9 u/l07cIQOemcYmmSPzdN4kTIhn3PoDOKdIOUDfAgT6PRO/c+ZFf6JnwlJ2W+FcgW2GEX BbqkDFZwG4pEli9n3J/5w9Mq61gZRvwgYaZJux2ZPvgZ0O0Ctc2Koj+V1XqzlKfBYUhf MvyXB9U9Bwm2ddb0+5s3MG6oiYFx5+CpQGCD3oP+3T/9c63T65D4DdKGdFla08MswCGW Nacg== 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=PJaaGp16934cF9IysHWYvBpT5Gl/50eX9mV1RxiADuE=; b=krvTElWcoZwNjCTe55Aj0cbG6bRNOfGvBYaLNHiFRzPPKdRwyPGBpeiBC6dRKBXA/o kuR3uqFXb7wJFdPcbwuE0dKAZ4k2WIXq7bTp97nKXEZg8fLITFt5eDSj4F7Vk66ypnA6 LMpkyuodBeVes4SaqC1tmaq1nwPGmo+pnaFE0bZYovpc0hnywGRdSDSMdoLIQ1OK8hz4 CX1yfjqMlBh8NCzH41cSnt37cnCIHU6uDx1STiaggCPKCvUMjDiEakv4HYZmAox4tG7M eCHmyG93N1plzyYIE8nEaJvZ5JmwNj0AqPLjOXSoyakMeDEqY4IzvBcpo+TdM/+8E/yR aCSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YIz4hhqk; 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 j1si503731pgs.311.2019.04.22.14.08.40; Mon, 22 Apr 2019 14:08:54 -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=YIz4hhqk; 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 S1730247AbfDVTrV (ORCPT + 99 others); Mon, 22 Apr 2019 15:47:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:50000 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730235AbfDVTrT (ORCPT ); Mon, 22 Apr 2019 15:47:19 -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 423A721904; Mon, 22 Apr 2019 19:47:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962437; bh=PCIVu1n1j+g6BGI70UthruE8q1IRMdJjK/wOID8PIng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YIz4hhqkTwKbjac9ZwXYQf0Nzc3A/mHeNYbcoeLDfze/qGrOAWUZV6+GBvCWPb2QW SD9D1RuqrgBgPhw9tD4rQy2GFbrmFgoIfi9SArllNUmsE9SkjJIi+yFlyV5w5tB1OH V+lvXINE3FGtqgQyed1BhznKbeFe96lynzdfEukM= 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 4.19 63/68] perf machine: Update kernel map address and re-order properly Date: Mon, 22 Apr 2019 15:45:11 -0400 Message-Id: <20190422194516.11634-63-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194516.11634-1-sashal@kernel.org> References: <20190422194516.11634-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 b1508ce3e412..076718a7b3ea 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