From nobody Sat Feb 7 15:38:14 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 934A6271837; Thu, 27 Feb 2025 21:55:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740693308; cv=none; b=UNWqTY6BwXxj9VPfdjbZG8fb4fgf3OiqyLsSQDqsi+cSWR56z26TgBZ85GO/Q6MRTaPQDmhN8pDOQKM6c9nykS/fYcpNR1AvyCNA5HmnjYI5h1O4f288hrpW9wd1unAGDVwc9iKIrMwCIz9IO6C1RhAaVouHu07zwBzEjSG1ThM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740693308; c=relaxed/simple; bh=LpbilOsWLoNnJGzgX003R1u3AjO7Z8GyjuWN92uWcOw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DRkDbQffqvoF2MKWdvuufyPDmCT5pVvRmP2WWMiejIyZXlHabz1CyrlUgjU4W2++c841O8qV+ano8IfOcPpiUtzT/0Kn837X2THXard+OBFWNFgw9WWyvWZ84meXiupF5td26l2A5VtRlDsr5ufa5rn8aCZx+hV1jrEf3gQZzvo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FAmNIT7D; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FAmNIT7D" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1B83C4CEE5; Thu, 27 Feb 2025 21:55:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740693308; bh=LpbilOsWLoNnJGzgX003R1u3AjO7Z8GyjuWN92uWcOw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FAmNIT7DKxuc80lGD13aJcVJYbvFOxaD56SZBuaXjLwzSmDB0G5ThdlBxI07xxD80 n8e4XP/iqzHjxRv6o8sMEZOBhVwjFE3p1C05gWj3JbCrTGauNyiW0vZNzggkwsDBgT W+Yc9CprZHGggUJRWO/+LSw3DHIEcZERDXQ6L9uh+GkKibqPOWTKLRsIvaW6CNcaLj fX8nnkeWKVgnTIwC0RodkfP6RQXqqcoKEJVj/xmD5iJmgItBngpuxRQAcPhFZW4eIG X3cG1NXfgjzduohfQ4OBGVXXtn4FzC+aS9SsORfdGoy8BIzB4ApOIEklo7YCr9v5V5 MTRoLFUhFhJaw== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Peter Zijlstra , Stephane Eranian Subject: [PATCH 1/6] perf maps: Introduce map__set_kmap() for kernel maps Date: Thu, 27 Feb 2025 18:54:50 -0300 Message-ID: <20250227215455.30514-2-acme@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227215455.30514-1-acme@kernel.org> References: <20250227215455.30514-1-acme@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo We need to set it in other places than __maps__insert(), so that we can have access to the 'struct kmap' from a kernel 'struct map'. When building perf with 'DEBUG=3D1' we can notice it failing a consistency check done in the check_invariants() function: root@number:~# perf record -- perf test -w offcpu [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.040 MB perf.data (23 samples) ] perf: util/maps.c:95: check_invariants: Assertion `map__end(prev) <=3D ma= p__end(map)' failed. Aborted (core dumped) root@number:~# The investigation on that was happening bisected to 876e80cf83d10585 ("perf tools: Fixup end address of modules"), and the following patches will plug the problems found, this patch is just legwork on that direction. Acked-by: Namhyung Kim Cc: Adrian Hunter Cc: Ian Rogers Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Peter Zijlstra Cc: Stephane Eranian Link: https://lore.kernel.org/lkml/Z74V0hZXrTLM6VIJ@x1 Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/maps.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index 09c9cc326c08d435..e21d29f5df01c6f7 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -428,11 +428,29 @@ static unsigned int maps__by_name_index(const struct = maps *maps, const struct ma return -1; } =20 +static void map__set_kmap(struct map *map, struct maps *maps) +{ + struct dso *dso; + + if (map =3D=3D NULL) + return; + + dso =3D map__dso(map); + + if (dso && dso__kernel(dso)) { + struct kmap *kmap =3D map__kmap(map); + + if (kmap) + kmap->kmaps =3D maps; + else + pr_err("Internal error: kernel dso with non kernel= map\n"); + } +} + static int __maps__insert(struct maps *maps, struct map *new) { struct map **maps_by_address =3D maps__maps_by_address(maps); struct map **maps_by_name =3D maps__maps_by_name(maps); - const struct dso *dso =3D map__dso(new); unsigned int nr_maps =3D maps__nr_maps(maps); unsigned int nr_allocate =3D RC_CHK_ACCESS(maps)->nr_maps_allocated; =20 @@ -483,14 +501,9 @@ static int __maps__insert(struct maps *maps, struct ma= p *new) } if (map__end(new) < map__start(new)) RC_CHK_ACCESS(maps)->ends_broken =3D true; - if (dso && dso__kernel(dso)) { - struct kmap *kmap =3D map__kmap(new); =20 - if (kmap) - kmap->kmaps =3D maps; - else - pr_err("Internal error: kernel dso with non kernel map\n"); - } + map__set_kmap(new, maps); + return 0; } =20 --=20 2.47.0 From nobody Sat Feb 7 15:38:14 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 472AC272914; Thu, 27 Feb 2025 21:55:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740693312; cv=none; b=mlZe0L0JZE5ezd6B8rweaSAQN9xIxeFwC7zPc2BT4asJWIZ7JIiwfuz2rkwuuoEkL/JT76svWuKMgseY4o43pDgWxwwdBC4TGKb4P3wkVXYLPaJpHf+KBH3cryYG7eQqV3wC/7yqRrz0P13110qqLWWaHinXrcxOQdGrmEKK1Ow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740693312; c=relaxed/simple; bh=WoTiUX407mXfbtufK5LL7Tb0E3rMG/9ekMipJlBPJJM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZFG8hISeGaMQPkeerDB5lhplY7WfqjOOu+vfXRLtWKaD3NXg+MD1ba0ZIavgfAhd4P6hhrcX2/mrh4wa/Xa9M9FiO4FJOLt+d0q6AsCpGITARXbW9rdvw+WQMt6GZgwziZ61joJZ4KP25H9UOCEasD+HfbpTjm7Hh/mRTmxG1fg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n8FZgglB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="n8FZgglB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71033C4CEDD; Thu, 27 Feb 2025 21:55:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740693311; bh=WoTiUX407mXfbtufK5LL7Tb0E3rMG/9ekMipJlBPJJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n8FZgglB4MnsHJQtoBI1+zVu+oarKwpKVrVtQViGvNLLFax7Tcspv7wUHSmDLbkoN qtgqvVaLzrWE7yJlepAPGearSGuizTxjYJfrJ131yDUWVLZm5O9Gux1S+V+407ovSl RGn+wC4uENRwx+syL46ebKOZ2LmjF4fJrMLexZj9B9bnsZCZcDkzkuv8USOxYF/Q2N sZHM2srTf+9JzCMcMltFmJVKAE9mzZIVKSEFIJhsmWWi1PqrhwPBxd8rx5AUoPiOxJ E/ru4L6V9ypMdNVceifr2ZdqsofwYgJlAfR1gic9RhG68C7oNDPpbHv06fYkPrYeGr gtiA+V2PNjDHw== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Peter Zijlstra , Stephane Eranian Subject: [PATCH 2/6] perf maps: Set the kmaps for newly created/added kernel maps Date: Thu, 27 Feb 2025 18:54:51 -0300 Message-ID: <20250227215455.30514-3-acme@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227215455.30514-1-acme@kernel.org> References: <20250227215455.30514-1-acme@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo When using __maps__insert_sorted() the map kmaps field needs to be initialized, as we need kernel maps to work with map__kmap(). Fix it by using the newly introduced map__set_kmap() method. Acked-by: Namhyung Kim Cc: Adrian Hunter Cc: Ian Rogers Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Peter Zijlstra Cc: Stephane Eranian Link: https://lore.kernel.org/lkml/Z74V0hZXrTLM6VIJ@x1 Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/maps.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index e21d29f5df01c6f7..dec2e04696c9097e 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -798,6 +798,9 @@ static int __maps__insert_sorted(struct maps *maps, uns= igned int first_after_ind } RC_CHK_ACCESS(maps)->nr_maps =3D nr_maps + to_add; maps__set_maps_by_name_sorted(maps, false); + map__set_kmap(new1, maps); + map__set_kmap(new2, maps); + check_invariants(maps); return 0; } --=20 2.47.0 From nobody Sat Feb 7 15:38:14 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1AA2C274241; Thu, 27 Feb 2025 21:55:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740693316; cv=none; b=l0PoVnOvZOO/tRkeb8C4K//kRVgIvoE/CEqTNpdn3kK2LHE6Hd4byIexAi5mF9vsYzZvr2+p2rUVBCcxly8Zag/SD2BwyAcGJ7hmt+o5lhRhaYkSEcfj2fA/LIiArBI3Aop3LqbBsNQNbWw7Z925k2RzA3YjtIH44kvFfqCof6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740693316; c=relaxed/simple; bh=ueGo8XkhznNg4CshYONjwSCM1Qeqz26OnW+FSkMB/ZU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rtcoBYBgGWIcgA+0squPaJYAV17IztdTy7iX03gAY/jSW0lFbtduefjm7tO2AenyXvdKFSr/8GmbzPUK22ONkqoYLtTYzy6YJkxmXOGN29xDRn8yx9p3sQFj8t//RCqUg3A98WSqvBv9N+9en5vugVfsDksoTdFXEGRExJ3JlJw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vFAFTc1Z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="vFAFTc1Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F5C5C4CEE4; Thu, 27 Feb 2025 21:55:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740693315; bh=ueGo8XkhznNg4CshYONjwSCM1Qeqz26OnW+FSkMB/ZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vFAFTc1ZZi0Mgw9Vf+nZOR/YFSINbee+O5lugR60mhMGRTGgTOoD02HA5U2CeIp37 lul1D4dWxLuJwgqBBbhkyzK3kiqQudtKeLuBNgfsDVRWnvhPWqFwOroiPkPJ01bJAP gPSXl0dcWpytPsKXHbDIUwIIkwx3c35oLT9/agayN+veEQOerUi1rBOrzI1cB586fA MSACm39//ewCH7WVkq3/6QdPKLTeOmbOG7xuygAoa8Vdfj/4Mugaua4EKlfS01o1kx +LWyjl6Q8l76Acn/L8Ehej6ALVjnQaL6SkMwyBX85bWFkdfsVm0zKOiJcpuzXyeIWB TUaD3iQTemIJA== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Peter Zijlstra , Stephane Eranian Subject: [PATCH 3/6] perf machine: Fixup kernel maps ends after adding extra maps Date: Thu, 27 Feb 2025 18:54:52 -0300 Message-ID: <20250227215455.30514-4-acme@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227215455.30514-1-acme@kernel.org> References: <20250227215455.30514-1-acme@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Namhyung Kim I just noticed it would add extra kernel maps after modules. I think it should fixup end address of the kernel maps after adding all maps first. Fixes: 876e80cf83d10585 ("perf tools: Fixup end address of modules") Reported-by: Arnaldo Carvalho de Melo Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo Cc: Adrian Hunter Cc: Ian Rogers Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Peter Zijlstra Cc: Stephane Eranian Link: https://lore.kernel.org/lkml/Z7TvZGjVix2asYWI@x1 Link: https://lore.kernel.org/lkml/Z712hzvv22Ni63f1@google.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/machine.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 3f1faf94198dbe56..f7df01adad61ceea 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -1462,8 +1462,6 @@ static int machine__create_modules(struct machine *ma= chine) if (modules__parse(modules, machine, machine__create_module)) return -1; =20 - maps__fixup_end(machine__kernel_maps(machine)); - if (!machine__set_modules_path(machine)) return 0; =20 @@ -1557,6 +1555,8 @@ int machine__create_kernel_maps(struct machine *machi= ne) } } =20 + maps__fixup_end(machine__kernel_maps(machine)); + out_put: dso__put(kernel); return ret; --=20 2.47.0 From nobody Sat Feb 7 15:38:14 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 DC268271822; Thu, 27 Feb 2025 21:55:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740693320; cv=none; b=Vwu6GxdC/cGGW7VbPs0r/SuBQ6eo9hDbNAuuGH+bX0FM8ApJKAcgFLfPHa9aKfXmhSzwGieqN9H6KpJwUtw6T0OS7NFRyLUdHwT3GbXAZ7GO7dkdNH71LaQ3EqqaY9tKIP0s907eokCh+YVeu9fQoLIC42a5qbKogGuBmGQ/D20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740693320; c=relaxed/simple; bh=EW+8SC3MCIrg61lmqTxa4tS5pq7iQsw1/LDMacoSSIk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DyPq7QCFhyEsxNoa1ndZsZ+W7UZmDb8/dNRj2X7iOL8uB/14H16ZDzOxF7vaOLTmV5pUjFVJCnS4YLjAkDbDggGOU//CWbSoOCyc8PIughd3fg/ZBpEWKmNRsW5cJ7NHHs2u+UODpZYb+eH5HspXtV0sWyTH6O44Fj6CVvj14fc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s+caaAWu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="s+caaAWu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C51AC4CEDD; Thu, 27 Feb 2025 21:55:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740693319; bh=EW+8SC3MCIrg61lmqTxa4tS5pq7iQsw1/LDMacoSSIk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s+caaAWultGfJOASmznIZv2lG2r0Li3PQVoSyNs76F25eGOTTXfY4cLDaw4gi9qX3 4CG0ZJA80iKOLFltvhKLUj9QCO9HCoD2ob0a+PJ0R3VHuIrs3hyFQgpMBRPom0B9TA cNNUiXjhgw2X+NBF+RxqO4ulAB7QDh65kT7f2PZxzf3EEFTVAo6BBaz1kVvQqC9sXP h0UpYI9NQMkVa+OHpEzKsgr3b6aZ8of6Cdww6H4MpN6tlAFnv7aun0ooXey+6V2MtI VuPvcG/xAXqJUrAnqi4b9gSdr3nPJxjxDxZIlKu5wRXJkRo0qCH+NhkpLjX1hyp85s m78VERre/Oepg== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Peter Zijlstra , Stephane Eranian Subject: [PATCH 4/6] perf maps: Fixup maps_by_name when modifying maps_by_address Date: Thu, 27 Feb 2025 18:54:53 -0300 Message-ID: <20250227215455.30514-5-acme@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227215455.30514-1-acme@kernel.org> References: <20250227215455.30514-1-acme@kernel.org> 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="utf-8" Content-Transfer-Encoding: quoted-printable From: Namhyung Kim We can't just replacing the map in the maps_by_address and not touching on the maps_by_name, that would leave the refcount as 1 and thus trip another consistency check, this one: perf: util/maps.c:110: check_invariants: Assertion `refcount_read(map__refcnt(map)) > 1' failed. 106 /* 107 * Maps by name maps should be in maps_by_address, so 108 * the reference count should be higher. 109 */ 110 assert(refcount_read(map__refcnt(map)) > 1); Committer notice: Initialize the newly added 'ni' variable, that really can't be accessed unitialized trips some gcc versions, like: 12 20.00 archlinux:base : FAIL gcc version 13.2.1 20230= 801 (GCC) util/maps.c: In function =E2=80=98__maps__fixup_overlap_and_insert=E2= =80=99: util/maps.c:896:54: error: =E2=80=98ni=E2=80=99 may be used uninitializ= ed [-Werror=3Dmaybe-uninitialized] 896 | map__put(maps_by_name[ni]); | ^ util/maps.c:816:25: note: =E2=80=98ni=E2=80=99 was declared here 816 | unsigned int i, ni; | ^~ cc1: all warnings being treated as errors make[3]: *** [/git/perf-6.14.0-rc1/tools/build/Makefile.build:138: util= ] Error 2 Reported-by: Arnaldo Carvalho de Melo Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo Cc: Adrian Hunter Cc: Ian Rogers Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Peter Zijlstra Cc: Stephane Eranian Link: https://lore.kernel.org/lkml/Z79std66tPq-nqsD@google.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/maps.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index dec2e04696c9097e..dffc54a8a29bf3b0 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -813,7 +813,7 @@ static int __maps__fixup_overlap_and_insert(struct maps= *maps, struct map *new) { int err =3D 0; FILE *fp =3D debug_file(); - unsigned int i; + unsigned int i, ni =3D INT_MAX; // Some gcc complain, but depends on maps= _by_name... =20 if (!maps__maps_by_address_sorted(maps)) __maps__sort_by_address(maps); @@ -824,6 +824,7 @@ static int __maps__fixup_overlap_and_insert(struct maps= *maps, struct map *new) */ for (i =3D first_ending_after(maps, new); i < maps__nr_maps(maps); ) { struct map **maps_by_address =3D maps__maps_by_address(maps); + struct map **maps_by_name =3D maps__maps_by_name(maps); struct map *pos =3D maps_by_address[i]; struct map *before =3D NULL, *after =3D NULL; =20 @@ -843,6 +844,9 @@ static int __maps__fixup_overlap_and_insert(struct maps= *maps, struct map *new) map__fprintf(pos, fp); } =20 + if (maps_by_name) + ni =3D maps__by_name_index(maps, pos); + /* * Now check if we need to create new maps for areas not * overlapped by the new map: @@ -887,6 +891,12 @@ static int __maps__fixup_overlap_and_insert(struct map= s *maps, struct map *new) if (before) { map__put(maps_by_address[i]); maps_by_address[i] =3D before; + + if (maps_by_name) { + map__put(maps_by_name[ni]); + maps_by_name[ni] =3D map__get(before); + } + /* Maps are still ordered, go to next one. */ i++; if (after) { @@ -908,6 +918,12 @@ static int __maps__fixup_overlap_and_insert(struct map= s *maps, struct map *new) */ map__put(maps_by_address[i]); maps_by_address[i] =3D map__get(new); + + if (maps_by_name) { + map__put(maps_by_name[ni]); + maps_by_name[ni] =3D map__get(new); + } + err =3D __maps__insert_sorted(maps, i + 1, after, NULL); map__put(after); check_invariants(maps); @@ -926,6 +942,12 @@ static int __maps__fixup_overlap_and_insert(struct map= s *maps, struct map *new) */ map__put(maps_by_address[i]); maps_by_address[i] =3D map__get(new); + + if (maps_by_name) { + map__put(maps_by_name[ni]); + maps_by_name[ni] =3D map__get(new); + } + check_invariants(maps); return err; } --=20 2.47.0 From nobody Sat Feb 7 15:38:14 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9B626271835; Thu, 27 Feb 2025 21:55:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740693324; cv=none; b=LMR8ZkGc1o5Man+yB5RdfXsH1bOB1MSFbJ0EjByXoym5QpC9orcW21FJ/u/p8D5mPUc9xzhb2WUOYaPvnWukP48KGY5q4UbmupBEaDzouZs2jcaHSoux9HRx1Hnb/qfWJ+v6ymsmlCSkHeRsJjyoJdevgV0YEQRLiQoCizTjTtY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740693324; c=relaxed/simple; bh=h7BhvuSO4LxIjLp4A1ne8AL/fHsgrqjcSVvxLGZlXdY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CSXL0xnj5rRtSw6m5+g/3SZHWvXJbwxz/AqhtSDy1ifHqW5WOJLY5bn3gnOP/Vh9YQP604JRzlzkVdtzQNbufGVccEW2Zm+GDNzZO+axa6osSObweM8OkjqADBy5AzRELio3PPriUsyhvsVQ5cxorq+hgk6zRLSsmgEsYi+LMhQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gg29myMa; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gg29myMa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE007C4CEE5; Thu, 27 Feb 2025 21:55:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740693323; bh=h7BhvuSO4LxIjLp4A1ne8AL/fHsgrqjcSVvxLGZlXdY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gg29myMapylP1vu4NCyMla2QbyrTLEo7qJmu2WEaqZJymxLqEssUqUdx8+6Hcnqs9 7l8PCZ3Z9caEVIXaaNIPu32qiQ51XBP/fy6rl30+sTjSQ9n+s8bp+1E8qcRVYYk3PU q3BVwubjn7NlRVDtFMOzYUVddg5T9RvK1GSwVHZNMIkkFZEWbV69mrEaBxdCooyvmn 1n609JEFfkLJ7TVAEuticJ742K/rfZCyMS6vGzxRF15Ro+fTuYB9+LG8XzNimenCWx gw297zd1BzHUn1UZU7BtuSAGYjjTnWX3KSs1kzW2nS+ucIRkOU1/QJ/nj55LlElj8S WqVsfHCOCQhEg== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Peter Zijlstra , Stephane Eranian Subject: [PATCH 5/6] perf maps: Add missing map__set_kmap() when replacing a kernel map Date: Thu, 27 Feb 2025 18:54:54 -0300 Message-ID: <20250227215455.30514-6-acme@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227215455.30514-1-acme@kernel.org> References: <20250227215455.30514-1-acme@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo Since in this case __maps__insert_sorted() is not called and thus doesn't have the opportunity to do the needed map__set_kmap() calls on the new map. Acked-by: Namhyung Kim Cc: Adrian Hunter Cc: Ian Rogers Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Peter Zijlstra Cc: Stephane Eranian Link: https://lore.kernel.org/lkml/Z7-May5w9VQd5QD0@x1 Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/maps.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index dffc54a8a29bf3b0..081466b3b4676044 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -948,6 +948,8 @@ static int __maps__fixup_overlap_and_insert(struct maps= *maps, struct map *new) maps_by_name[ni] =3D map__get(new); } =20 + map__set_kmap(new, maps); + check_invariants(maps); return err; } --=20 2.47.0 From nobody Sat Feb 7 15:38:14 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 74A7327129B; Thu, 27 Feb 2025 21:55:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740693327; cv=none; b=aNluhgLkKByQsmPcJCwK7DqvpvfGfp8iA4VB7cjF9F59xdPQ8mpxHEz4rn9wfqZ5yn/GF70FFhFbPqOHEnN6oKHDL0/COmE+cL+PS+WrhU35yCuiZbuJfoLkBS2RuZU9hhGgZE3hZMryciZ0PuvapSaDcRjBbZ9oy0otKW6+fwg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740693327; c=relaxed/simple; bh=dVkSwrO9bTxiAns+EuNEGFekp4a/+02PboKlbwgKvcQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RZzkuvLDlWrkEITjzCSE3MAF7280g4MjFso6CzBHpRgluTHIQxXoNr89dTX3WhTMp8I0yz9ZidnUkZ89pePyWMZ74KQVWmfZxQB2VpyzAwvaP08BvGOBilY0vOIVd8F8PEcg1WRA4VM/yq9k0PLJ9/mfE76cek4bfT+0uEbSvnI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IqqnoNdl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IqqnoNdl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D267C4CEDD; Thu, 27 Feb 2025 21:55:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740693327; bh=dVkSwrO9bTxiAns+EuNEGFekp4a/+02PboKlbwgKvcQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IqqnoNdl7vz79QlA3ijr77jounrRbCrdbVegaxnINXDNfv7VCJOZdaGlECquMJ0Rj Jjlfd5kO/83T8GbLpTG+mAAgsopOEfKGTdQ2UFAim4wWeOOUG2kU9mcoR/T4fLVjUl iItiDFwpGPJgJbWo9twLgyRu+MEQOgnEz+a+m6juoeYa/jMCvA/OqVAUfqMyvCnNhm COHDbHc8IE6crgRsJbWwNoxnZJl8ZGTAmDYOBgg7dXWgTLaNEhzDBiKDT+U5Jr2s0c 2p+sQXfyk1Ketf6A3cnFUaeuiM8OEhOB/2vNGv7MT3EjvXNMGqsm9IzdSCmToo+cXX jzsENbyDozD2g== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Peter Zijlstra , Stephane Eranian Subject: [PATCH 6/6] perf machine: Fix insertion of PERF_RECORD_KSYMBOL related kernel maps Date: Thu, 27 Feb 2025 18:54:55 -0300 Message-ID: <20250227215455.30514-7-acme@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227215455.30514-1-acme@kernel.org> References: <20250227215455.30514-1-acme@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Namhyung Kim This was detected at the end of a 'perf record' session when build-id collection was enabled and thus the BPF programs put in place while the session was running, some even put in place by perf itself were processed and inserted, with some overlaps related to BPF trampolines and programs took place. Using maps__fixup_overlap_and_insert() instead of maps__insert() "fixes" the problem, in the sense that overlaps will be dealt with and then the consistency will be kept, but it would be interesting to fully understand why such overlaps take place and how to deal with them when doing symbol resolution. Reported-by: Arnaldo Carvalho de Melo Suggested-by: Ian Rogers Tested-by: Arnaldo Carvalho de Melo Cc: Adrian Hunter Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Peter Zijlstra Cc: Stephane Eranian Link: https://lore.kernel.org/lkml/CAP-5=3DfXEEMFgPF2aZhKsfrY_En+qoqX20dWfu= E_ad73Uxf0ZHQ@mail.gmail.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/machine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index f7df01adad61ceea..a81ffd2d1a054d60 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -718,7 +718,7 @@ static int machine__process_ksymbol_register(struct mac= hine *machine, =20 map__set_start(map, event->ksymbol.addr); map__set_end(map, map__start(map) + event->ksymbol.len); - err =3D maps__insert(machine__kernel_maps(machine), map); + err =3D maps__fixup_overlap_and_insert(machine__kernel_maps(machine), ma= p); if (err) { err =3D -ENOMEM; goto out; --=20 2.47.0