Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp114142lqo; Tue, 7 May 2024 14:03:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXPJEb4+GgDx72n4vj0oVTgqu1HlykDX/tPjXdmVkxdGW2CtPom2ClMKbSvi1CXyyX5wBABQe5YuDssDHFaDpqM9gWnFzXCmKB1V4jWkg== X-Google-Smtp-Source: AGHT+IHTJsAuu6A/y//fE+KTOgLiv6Jwc3vW/SRphbDwLDAb8u/rtx2ruGukKFGwlczAMU/xAZ2b X-Received: by 2002:a62:ee08:0:b0:6ed:cc76:3f9f with SMTP id d2e1a72fcca58-6f49c20f2a1mr891190b3a.13.1715115829741; Tue, 07 May 2024 14:03:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715115829; cv=pass; d=google.com; s=arc-20160816; b=TEET+t/WHEC4BTtYDnEjT4peTKzmVXonOo+R7gJq8Ij0GV5uo69Lp/ljJtf9e4iEl8 5AJ7E1K+ThksrRYXJ/zY/37dWLTLA/rcSLgg2TfVFYmFv6tym3wzfvbloXLrlfq8Q4OZ jumR017on2874z7Jb/qQ5jWbyu1Z5nDBYZB2d5UdHLVVSNYf+fQktvl83q5KDlgSwYdh 3xAWa5kE4LTlIj9rij91Nt9Se0Hcx28C8iBzGW8nhnp9J7vkid7TTw7XDDMPamOXMi2k ofOQGLKblI3eKGBuGdect4ga+Njp3y8P3HMwE/MWpJ44ht7hKS2kJm8odFe+D25xArbF g+HA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=zZNs4tA7go3R/DMVxte1WF4G+JtqmyTgtWCsoCAO8/U=; fh=TwnF7hP/CQVb1d3lFDRer0ALPG5ibw3iIO5Z4yeuyQA=; b=z6u5TJkiWyv/a5GJ6IQXiLhrUTqs9NFq7Y7hRjTmCVWZMNb9mvWBoyDRQ4BbfKB4Sl zIpZFo7Vo93H4bIWKiBickvIQ5IN8B10yWtawkjyaVBpSCxHwgbBCCLmMOpPWzQleV4n crQGtOZXgosivBC0BOjajeBxuciIUYGmFaztBXPMTwCuIV8EdMxytpu4G95vItA3H6NO MunfittwAZ0TLlFY/O1Es8hhkUzWl2fPaxfyDcTNCW/eKjq2G1Hq62kg5ZiyEOck30Hj p2Hb7oeVId7EvokeCyg1wkkPaEkQLdCUk2NBTTqUM4/ice4m9x79q+PnfMzoyoBBJsgs rpqA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=LQxPkjUH; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-172180-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172180-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id lm10-20020a056a003c8a00b006f45d41a3fesi7384492pfb.138.2024.05.07.14.03.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 14:03:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172180-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=LQxPkjUH; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-172180-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172180-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C5654B21493 for ; Tue, 7 May 2024 21:02:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A642871B3B; Tue, 7 May 2024 21:01:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="LQxPkjUH" Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E330618733E for ; Tue, 7 May 2024 21:01:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715115718; cv=none; b=kd4qgSBvSgLUkQDYVsSOPim3KZHtRwCmJsxfkwR/bZTDiv/hOGrDAmoNOcqHyw3/kgezMoUSsPSiiCWIOeDg5R0qJx1X8lpUlJCnaq2gSo7ndYUShFZtDRGE5ybJ6lk/vJHfSzavbLf5l0NH08or+e6XQcZk+I7EOv1mm9yvex4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715115718; c=relaxed/simple; bh=JiWno9R6/bTX27Lyw4lnPCe5j/IzJx7mLRUg0SFwwzA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PybLTAY2J0t5HwhtngS33/MNiAoMrxJ2ype/gwg39LElzQbF21K8yGRhNSc6BegJ1iMeGWWjvmenZ4ahka1sAP9yVfhJAta0jWLHg/i8SOscPdiW+3Pqo+k5BktkgbQfmG/X+Oppox3e21YIie9BZA1HrOyhqvk5YWNM9M92O6I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=LQxPkjUH; arc=none smtp.client-ip=95.215.58.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Wed, 8 May 2024 05:01:51 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1715115714; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zZNs4tA7go3R/DMVxte1WF4G+JtqmyTgtWCsoCAO8/U=; b=LQxPkjUHpSk5OiqLAHPQlApMHIdCDDWwHwWi5rhrQDv8xB+Zra1Sex3T5nBDL+Jlo5OC2f UKTBXWUxiNGEY7cWSa+q1Uw1ZVV4yMiuXfMCUKT+E7eoJcRkl6AS+Rhe37TPYH/fbTdq6U BDBhov3gOiz0f6H3vaLu2x9nDJyuWm8= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Leo Yan To: Adrian Hunter Cc: Leo Yan , Arnaldo Carvalho de Melo , Ian Rogers , Namhyung Kim , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Athira Rajeev , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf maps: Process kcore maps in order Message-ID: <20240507210151.GB1384@debian-dev> References: <20240505202805.583253-1-leo.yan@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT Hi Adrian, On Mon, May 06, 2024 at 08:43:01AM +0300, Adrian Hunter wrote: [...] > > diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c > > index 9ebdb8e13c0b..e15d70845488 100644 > > --- a/tools/perf/util/symbol.c > > +++ b/tools/perf/util/symbol.c > > @@ -1266,7 +1266,24 @@ static int kcore_mapfn(u64 start, u64 len, u64 pgoff, void *data) > > map__set_end(list_node->map, map__start(list_node->map) + len); > > map__set_pgoff(list_node->map, pgoff); > > > > - list_add(&list_node->node, &md->maps); > > + /* > > + * Kcore maps are ordered with: > > + * [_text.._end): Kernel text section > > + * [VMALLOC_START..VMALLOC_END): vmalloc > > + * ... > > + * > > + * On Arm64, the '_text' and 'VMALLOC_START' are the same values > > + * but VMALLOC_END (~124TiB) is much bigger then the text end > > + * address. So '_text' region is the subset of the vmalloc region. > > + * > > + * Afterwards, when dso__load_kcore() adjusts kernel maps, we must > > + * process the kernel text size prior to handling vmalloc region. > > + * This can avoid to using any inaccurate kernel text size when > > + * extending maps with vmalloc region. For this reason, here it > > + * always adds kcore maps to the tail of list to make sure the > > + * sequential handling is in order. > > + */ > > + list_add_tail(&list_node->node, &md->maps); > > This seems reasonable, but I wonder if it might be robust > and future proof to also process the main map first > e.g. totally untested: Makes sense for me, I verified your proposal with a minor improvment, please see the comment below. > diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c > index 9ebdb8e13c0b..63bce45a5abb 100644 > --- a/tools/perf/util/symbol.c > +++ b/tools/perf/util/symbol.c > @@ -1365,16 +1365,15 @@ static int dso__load_kcore(struct dso *dso, struct map *map, > if (!replacement_map) > replacement_map = list_entry(md.maps.next, struct map_list_node, node)->map; > > - /* Add new maps */ > + /* Add replacement_map */ > while (!list_empty(&md.maps)) { For the replacement map, as we have located it in the list, here we don't need to iterate the whole kcore map list anymore. We can directly use the replacement map to update the passed map: /* Update replacement_map */ if (replacement_map) { struct map *map_ref; list_del_init(&replacement_node->node); map__set_start(map, map__start(replacement_map)); map__set_end(map, map__end(replacement_map)); map__set_pgoff(map, map__pgoff(replacement_map)); map__set_mapping_type(map, map__mapping_type(replacement_map)); /* Ensure maps are correctly ordered */ map_ref = map__get(map); maps__remove(kmaps, map_ref); err = maps__insert(kmaps, map_ref); map__put(map_ref); map__put(replacement_map); if (err) goto out_err; free(replacement_node); } I also uploaded the verified change to https://termbin.com/rrfo. Please let me know if you would like to send a patch for this, or you want me to spin a new version. Either is fine for me. Thanks for review and suggestion! Leo > struct map_list_node *new_node = list_entry(md.maps.next, struct map_list_node, node); > struct map *new_map = new_node->map; > > - list_del_init(&new_node->node); > - > if (RC_CHK_EQUAL(new_map, replacement_map)) { > struct map *map_ref; > > + list_del_init(&new_node->node); > map__set_start(map, map__start(new_map)); > map__set_end(map, map__end(new_map)); > map__set_pgoff(map, map__pgoff(new_map)); > @@ -1385,20 +1384,29 @@ static int dso__load_kcore(struct dso *dso, struct map *map, > err = maps__insert(kmaps, map_ref); > map__put(map_ref); > map__put(new_map); > + free(new_node); > if (err) > goto out_err; > - } else { > - /* > - * Merge kcore map into existing maps, > - * and ensure that current maps (eBPF) > - * stay intact. > - */ > - if (maps__merge_in(kmaps, new_map)) { > - err = -EINVAL; > - goto out_err; > - } > } > + } > + > + /* Add new maps */ > + while (!list_empty(&md.maps)) { > + struct map_list_node *new_node = list_entry(md.maps.next, struct map_list_node, node); > + struct map *new_map = new_node->map; > + > + list_del_init(&new_node->node); > + > + /* > + * Merge kcore map into existing maps, > + * and ensure that current maps (eBPF) > + * stay intact. > + */ > + if (maps__merge_in(kmaps, new_map)) > + err = -EINVAL; > free(new_node); > + if (err) > + goto out_err; > } > > if (machine__is(machine, "x86_64")) { > > >