Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp261944lqo; Tue, 7 May 2024 21:11:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWnRDOHKi5+/z2kvVkDp0njLXGk7S5ZBTFrxu8dmkCheoXz8HWQWbPqo/GsGHg8D08hdXuzugzCxqzeKIrROCU+y3W5MsIFPilc97Lg8g== X-Google-Smtp-Source: AGHT+IEEK3v3UQVFQXSsM8L4w5rfOTIFZfmj8d6CYcqlbc3u13sLUDSo7vqkAyNuKfYOEkE2YAhW X-Received: by 2002:a05:6830:164f:b0:6f0:444c:d534 with SMTP id 46e09a7af769-6f0b7827445mr1545671a34.5.1715141477420; Tue, 07 May 2024 21:11:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715141477; cv=pass; d=google.com; s=arc-20160816; b=hc8MkNOsIPFkthC1rJjTDS75Epabi41slLBgOZaVWdbpJukIsLGfDrVqVi5qLUgp1c nrTB6DFO/VEb1TwX4k3MV5MhkFFZbA/YaSbhnSFTnShMvmhPQLw/M7S8I9vDyYhWKk5Q lO5jQ8kPR3trUGQjm767/gp65YCWu2t+AYhorVW4CI3C3RPdtSDtGD9j8GFFHPQFdR7Y ZOqrdd3a0mG2SREKzM5+BpYwRZFObmdZpXUwUjnvx7pIHOam6e34tlk9Iqnf4mcFu/R2 WFK2sBGjl9OSUGaySD8eOzuxJpRTDBNe7Nkvl+SMxaNc/zY11TGJnKa/nwTrj4pfTP/j 5f2A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence; bh=t6Tgq5sUgs5xCTDmSUyawjsdeW0mmRIbMV6Rvd2uVAY=; fh=tAbiolDjpXRVzxYmYLwoLfWeGBr0ikNAWzF8/dHvJEs=; b=yaqnuLFPNkBtqhCiJsfvuC73B537FZYQ7S+6FKIHMPLuIXDqlqT7SxwlQXBjD2FolS Rqv/HVQRYF2qmAEXLb3K/2OfkzNZJYV8t5yFS6EKAxLwjGl2ZvzWJ2Kf9RgiWsJ4is8X YaN1xXdhXeN8f7yyHEOpysxP3M8WpkAvDVU6xINqwloYr6YKeCvTtGVLnhI9oDftU4Qg nNK2w96sPVYwXHYgO+cH9lDSM0YuHW7L3oBVs5KspM+SA3pj2awSTKD9QuNNZTgzIHf/ x8Tuy80fPQvVv6/A33LPCvAGwEt5mld9h8+Y8XbCN4g6+waTTbpevzs6vSz/T0Q+IuiF MzZQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-172674-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172674-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id o3-20020a656143000000b0061dc9000e73si9435733pgv.632.2024.05.07.21.11.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 21:11:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172674-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-172674-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172674-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 0A692282C3E for ; Wed, 8 May 2024 04:11:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 925BD15E8C; Wed, 8 May 2024 04:11:08 +0000 (UTC) Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A55208F5D; Wed, 8 May 2024 04:11:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715141468; cv=none; b=Zx01pFUxcPgloCf3MeE+XmVgW5OZeDOsDqWLdpzjltvi//9jcuwCmIf/kAvsOau744i0jApImKz7xuc/Ba6Ax8MnSmeUYo4UvZ6bZvIDekCsilnBTXUQ68HvLZH9Ma2TsKFSV2jz/ti3hh99wz5KNztGav8QwidHhDKgAHC056E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715141468; c=relaxed/simple; bh=JhAVlxDI8/QA3/FC66i0btB5Emz0CXwud/+uVLzEY6k=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=i7uBkCx0QAU236v+HuWlzSu5JP28acRxOC8WMK7/FwVCa5ipJlXYC7IXHSO0dGL1k41A0NdfdzKFMG+VqYCQoItTWRc6dVIZlpOcoQIRQniuOgSYrPk7BY5Jb+M91wQfsM93rX9VaM3IOXBALcp/Tm5MBoTh99eu6OBJwTXwV/c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2b273cbbdfdso2804096a91.1; Tue, 07 May 2024 21:11:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715141466; x=1715746266; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t6Tgq5sUgs5xCTDmSUyawjsdeW0mmRIbMV6Rvd2uVAY=; b=Lz4Ux7a0Sk7IHnRf9HEYttxaiEu9lIMHmkRw09XA2cjwYEb6x/JxWIJfcmlrOBfYaS xH4a9CjIxnl//TSuOS3WpfTOc2ROw21CQoc78D1Xm64xYzP0D/0JE5yQoPY1wOWTDbYo rfq+AIAePrVni9FURI2bu60wXVrV1aimUyvAZErg6ENYxEnmc6lm/lCTbm4OxJ/RG3aA Mg9miLrMzbmocuaoxceLGCj4FAXH5irlsBU8nE/hmlhCaCRlXkIDRFOJw2Gy29uMys0e Vh/HswzIhL1/L4v3vhyXKR6gtPup516Et6UKLuMsJ+PlK9YRKuSYTfjTQ0oaROU+B1Qp gv4w== X-Forwarded-Encrypted: i=1; AJvYcCXQJexxRrPZzfdqHPYDCi/TKq/Ao/K90pxJdWd/RauFfs4wCQBa5aTL1TKvXQaUpde2rpxDSS3X+O4I8E7uWmu9IvXmH24gmvygg0IZ X-Gm-Message-State: AOJu0Yz9SGLX9mURQN5xt+Bb8ZYMuVbRSgNO8XVowkOUDq8rEBE7qxwf SpFt1//LqrnVaL+w7KFMPij+LY4NxRgUyM2ZJ2azLzD2HqFs7XhV+02xaz690c9UrMUSvaX5D7Z kHvdPDAqlbP1uZzvfoJzIG1RfySw= X-Received: by 2002:a17:90a:c901:b0:2b6:29d3:30b with SMTP id 98e67ed59e1d1-2b629d30502mr552653a91.7.1715141465782; Tue, 07 May 2024 21:11:05 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240507141210.195939-1-james.clark@arm.com> <20240507141210.195939-4-james.clark@arm.com> In-Reply-To: <20240507141210.195939-4-james.clark@arm.com> From: Namhyung Kim Date: Tue, 7 May 2024 21:10:54 -0700 Message-ID: Subject: Re: [PATCH 3/4] perf symbols: Update kcore map before merging in remaining symbols To: James Clark Cc: linux-perf-users@vger.kernel.org, atrajeev@linux.vnet.ibm.com, irogers@google.com, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, May 7, 2024 at 7:13=E2=80=AFAM James Clark wr= ote: > > When loading kcore, the main vmlinux map is updated in the same loop > that merges the remaining maps. If a map that overlaps is merged in > before kcore, the list can become unsortable when the main map addresses > are updated. This will later trigger the check_invariants() assert: > > $ perf record > $ perf report > > util/maps.c:96: check_invariants: Assertion `map__end(prev) <=3D > map__start(map) || map__start(prev) =3D=3D map__start(map)' failed. > Aborted > > Fix it by moving the main map update prior to the loop so that > maps__merge_in() can split it if necessary. Looks like you and Leo are working on the same problem. https://lore.kernel.org/r/20240505202805.583253-1-leo.yan@arm.com/ > > Fixes: 659ad3492b91 ("perf maps: Switch from rbtree to lazily sorted arra= y for addresses") > Signed-off-by: James Clark > --- > tools/perf/util/symbol.c | 40 +++++++++++++++++++++------------------- > 1 file changed, 21 insertions(+), 19 deletions(-) > > diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c > index 2d95f22d713d..e98dfe766da3 100644 > --- a/tools/perf/util/symbol.c > +++ b/tools/perf/util/symbol.c > @@ -1289,7 +1289,7 @@ static int dso__load_kcore(struct dso *dso, struct = map *map, > { > struct maps *kmaps =3D map__kmaps(map); > struct kcore_mapfn_data md; > - struct map *replacement_map =3D NULL; > + struct map *map_ref, *replacement_map =3D NULL; > struct machine *machine; > bool is_64_bit; > int err, fd; > @@ -1367,6 +1367,24 @@ static int dso__load_kcore(struct dso *dso, struct= map *map, > if (!replacement_map) > replacement_map =3D list_entry(md.maps.next, struct map_l= ist_node, node)->map; > > + /* > + * Update addresses of vmlinux map. Re-insert it to ensure maps a= re > + * correctly ordered. Do this before using maps__merge_in() for t= he > + * remaining maps so vmlinux gets split if necessary. > + */ > + map_ref =3D map__get(map); > + maps__remove(kmaps, map_ref); A nitpick. It'd be natural to use 'map' instead of 'map_ref' (even if they are the same) since IIUC we want to remove the old 'map' and update 'map_ref' then add it back. > + > + map__set_start(map_ref, map__start(replacement_map)); > + map__set_end(map_ref, map__end(replacement_map)); > + map__set_pgoff(map_ref, map__pgoff(replacement_map)); > + map__set_mapping_type(map_ref, map__mapping_type(replacement_map)= ); So here, replacement_map should not be NULL right? Thanks, Namhyung > + > + err =3D maps__insert(kmaps, map_ref); > + map__put(map_ref); > + if (err) > + goto out_err; > + > /* Add new maps */ > while (!list_empty(&md.maps)) { > struct map_list_node *new_node =3D list_entry(md.maps.nex= t, struct map_list_node, node); > @@ -1374,24 +1392,8 @@ static int dso__load_kcore(struct dso *dso, struct= map *map, > > list_del_init(&new_node->node); > > - if (RC_CHK_EQUAL(new_map, replacement_map)) { > - struct map *map_ref; > - > - /* Ensure maps are correctly ordered */ > - map_ref =3D map__get(map); > - maps__remove(kmaps, map_ref); > - > - map__set_start(map_ref, map__start(new_map)); > - map__set_end(map_ref, map__end(new_map)); > - map__set_pgoff(map_ref, map__pgoff(new_map)); > - map__set_mapping_type(map_ref, map__mapping_type(= new_map)); > - > - err =3D maps__insert(kmaps, map_ref); > - map__put(map_ref); > - map__put(new_map); > - if (err) > - goto out_err; > - } else { > + /* skip if replacement_map, already inserted above */ > + if (!RC_CHK_EQUAL(new_map, replacement_map)) { > /* > * Merge kcore map into existing maps, > * and ensure that current maps (eBPF) > -- > 2.34.1 >