Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp1544647ybb; Fri, 29 Mar 2019 06:40:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqyU7aXKz0mrdzJ3nfoAOFKmEn+ijvJX86VpnD99sJOdbpWOHUcmk1iE6BZSEyxyPfPoPNRQ X-Received: by 2002:a63:5a20:: with SMTP id o32mr43920757pgb.225.1553866804427; Fri, 29 Mar 2019 06:40:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553866804; cv=none; d=google.com; s=arc-20160816; b=q5YtSSUU/QPKKyf0dF+yLvBWpJ+VhuHD4OOdKCgbZWn6uHn6yACBg57wG1aEFdN2z3 DZhrVGR54igelNCoCeKJR18gbS58E/6lKHk8N8KVkVH5cW3N0JhMj1s/WgWIo09jUtJz 3Qouq1uZ394bMogPX0oHVLvWSDeNA7II3zxBDGJN0GTGTq4myy7SbdOLRyYl0MKieKPy 0+yyWTBcYN5nw3RBMCXkmyTz0w/JrUz1czNwBmM4PXbcR2HKGDH/8tvDm29bfcymedh9 VBcwSnoMa3JYWWdsbZcPsB79Pfe0GsAjNHxEnrKVaqkZ1aAhCA23eXnBr0TlfXnvsjAp bhXQ== 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=Nkr6+OI8Y/qxdwrITRzgu9GlkniWvqOXzi97sonzYEA=; b=jT+471M66S+Rpb4T80LBqRfPaVWFji0TO9qup1ejlIYGEIp6RB7I6aXENQmx/y/ETn 9wrYBbIHFidd1ChxUtGGxA3u0SkBHEJCzrQpOlYOJpjIK370ozdBwbTzVtZIQGz3q8D6 iNGdB8UmB81fhl51ekcFgA9DrBVSF3dd7kdnsdR3Tzrx1UQY4RG5bX1ylc3MaQVVOs4k tJhdY4MLCeDr5Z0dA+DNdvYRNDL0j7vlKZUk45H7j1jHPR1e0nihCTo9Yf+D6N8sQ3l/ PaWqkw6ZNOi67ejDfLe7VzT6UFQLsW6wsGn+1OKLfn6MuSotUEqoA94XaSJEUiMk6VRj B3ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=L6zwUDoc; 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 t26si1901233pgu.504.2019.03.29.06.39.48; Fri, 29 Mar 2019 06:40:04 -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=L6zwUDoc; 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 S1729857AbfC2Niu (ORCPT + 99 others); Fri, 29 Mar 2019 09:38:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:34080 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729834AbfC2Nis (ORCPT ); Fri, 29 Mar 2019 09:38:48 -0400 Received: from quaco.ghostprotocols.net (unknown [190.15.121.82]) (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 802362184E; Fri, 29 Mar 2019 13:38:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553866727; bh=kpX4c4XieS7ifnCt5ngHpLht6+pyVt2pTHDWOgb6Mfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L6zwUDocvNZ9Jl1jvo2ak/PaIZIeUtOLOSr8Cx4KSFsfz/nzgNUvWzahuqf/rVBoY YRjUd9j1qA5xDmMeuPX0qQzctoNr/l5C/zHMTN+up3swfRQOE7pcuCJMdQ0XZfGkGp DNzoHz4xzYwscpvm36O5yr71JCqR3ceClhuZe13c= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Wei Li , Alexander Shishkin , David Ahern , Hanjun Guo , Kim Phillips , Li Bin , Peter Zijlstra , Arnaldo Carvalho de Melo Subject: [PATCH 10/13] perf machine: Update kernel map address and re-order properly Date: Fri, 29 Mar 2019 10:37:58 -0300 Message-Id: <20190329133801.21004-11-acme@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190329133801.21004-1-acme@kernel.org> References: <20190329133801.21004-1-acme@kernel.org> MIME-Version: 1.0 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 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 --- 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 61959aba7e27..3c520baa198c 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -1421,6 +1421,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); @@ -1453,17 +1467,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)) @@ -1599,7 +1607,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.20.1