From nobody Sat Feb 7 11:12:43 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 E849123F38A; Fri, 28 Feb 2025 21:17:45 +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=1740777466; cv=none; b=Z1L7ZfnWw2MTzeegL4US80CXfo0XllOfZvOxBTLaVl3fGwY8FOniICOPlkgD96FNvJtup4GKY3+2wJYdvCC2gc+7KIaW+8fTsa8WOmyKGj3MyvaraFHo5H+bdsuoR6V/cUJPk2kFxwhu2aKoLAkLXoSmjeYqwCw8lOz3+pklEG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740777466; c=relaxed/simple; bh=Y8qIbnUvkhvjP32pb7XNv5MY+kYkOJtBc6Hdz6sbIgs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eMkRKVBsjNA6R/JmKckoLpvJds6a6CG803vd/STyKnRyhSXb26GmM8ROYghtpm9HC3mpEaF1qo1sXgIoyvdkqXlAiDP2DmleWp0I9wsc6hSiL1r2GD0Fyhr4+r+2gns34JeIO16GmVU7IYHW5m9/sfoboDXbCoCdCJ0VtTH+vPE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l/GH3PqN; 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="l/GH3PqN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A51FC4CED6; Fri, 28 Feb 2025 21:17:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740777465; bh=Y8qIbnUvkhvjP32pb7XNv5MY+kYkOJtBc6Hdz6sbIgs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l/GH3PqNYAIrokmI8p96m29QHuq/O60LL2Vb5HPQAAkZo+yTDleQYr7ml+733IipM Bp6ASQRtKNHU7BWBOOytL+evVCIQp7SNjA7ESn37jla4cHXCQIuJt3T3rw7UamjUpE opWQq3pEQNOlkc0xhU6kCtGLUEKyCqS/IrWCS9ioSLpa7E8vnesHcZq9Sy8M6b7Dik 54hONRqIbMAmYdj2lCKH4ojvYmeWdtlINxUGa+6r3JSg1e4lQqOQG7VhDHuM1E7kH0 f4e8HPpeQqwpZeD9hmRXuWWTm8KYGTYS4/marNJdYY2YEC6dfVBPi3wz0msQS1UmQN 0ec+OtQStB7QA== 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_maps() for kernel maps Date: Fri, 28 Feb 2025 18:17:29 -0300 Message-ID: <20250228211734.33781-2-acme@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228211734.33781-1-acme@kernel.org> References: <20250228211734.33781-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 maps' 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. Use the map__set_kmap_maps() name as per a review comment from Ian Rogers, later there are further suggestions from him on getting rid of the kmaps variable, see the thread referenced in the Link below. 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 Reviewed-by: Ian Rogers --- 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..51b507233269d8b4 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_maps(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_maps(new, maps); + return 0; } =20 --=20 2.48.1 From nobody Sat Feb 7 11:12:43 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 3C45A1D90D9; Fri, 28 Feb 2025 21:17:49 +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=1740777470; cv=none; b=sMIlbRQe8SS0shl26RNQOVvu4KHONnPZ+EKWJ6Oz5y1IWW207Nu63EEp82xv1ftWL80CnAWzaHsUA6a/K73GUDKCD3bHMXEJlzNGMuNwsYLzE5CfbJMmbZi2l18hW67mPWLkSQRZAQsnM3YeklOc6YqfkFeX0tPf9Y3E/A+o0hY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740777470; c=relaxed/simple; bh=nYvMSWvore7t4zds8hMyNDRRuPH29EvqkcyYPeWwVNw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HAzSKKQZnamftCmkSbr8oThpi6Eon5YP3Z3fzG9yfjSqQhWhpfjjF2DSokCEb+BGBF0dQnxk0Y24i5LMbgLxcZrNGIH6tkWu55dMgC9BI9BQk96AEjAbx3/isVf4zT1j3t7kki2wUkUXaVAOqjvelTUAxeK2d+YLcmyAXjLHFik= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d5p4w/6I; 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="d5p4w/6I" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A29CC4CEE5; Fri, 28 Feb 2025 21:17:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740777469; bh=nYvMSWvore7t4zds8hMyNDRRuPH29EvqkcyYPeWwVNw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d5p4w/6ITSxnYqVf3ySi7ph1aqF2rraZEy7egLfi6xPwxnje9uxo6bnJ/xbRtI8pP 3nWLQUD2GE4zswiLDx4EdCyqUmRoUnbhWwxr8XEpTF8DcMZDm4cYOCjPepSSCOn7CT KufsoUzezG4INIogD6Ws0SxHJ6aIQst4i6t/QiTSyWLM7YhGBDstP6ejPi71ryBSR9 jI8u66yDdz3lrRpX4cLIiKkChHXK6jrYHRxhguew55f5Rt0uLlXSmZn8W3xjeWFx5l 1a/zjVxTAh+jmzdH/+jMfpOuSyQGHA2XTqjwSyRYuo/O2d/TJ3DpmTPYuDuOOxujzJ bQkUKk91/9PEA== 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: Fri, 28 Feb 2025 18:17:30 -0300 Message-ID: <20250228211734.33781-3-acme@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228211734.33781-1-acme@kernel.org> References: <20250228211734.33781-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 Reviewed-by: Ian Rogers --- 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 51b507233269d8b4..8c5f5d79cd24a6bc 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_maps(new1, maps); + map__set_kmap_maps(new2, maps); + check_invariants(maps); return 0; } --=20 2.48.1 From nobody Sat Feb 7 11:12:43 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 B71C11D6DBF; Fri, 28 Feb 2025 21:17:53 +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=1740777473; cv=none; b=kS2dXFJBrdTTq5NXOShBh8FN51ZZDA/GMoQmUhGF/OMcAxFzTsA2kGuAI1ArOI3ie79ejnbSFCs/1aS5Xl1/72WG5xNjPk3phVmnC7h5qpyZPwU+N7t//cNpiGnHe2KT0tofKQFXJsX5AShNyOXuKuxUW5mt2bWVAdGVnGPEeWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740777473; c=relaxed/simple; bh=sjrduZrtANGdpUj5EgXRrIFwwsm8xjCE4Ylu0tFwt/Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QiCZdUNT8fuS2mxFhRdrmgVfo20+aMxxEjGTzOoiea7ci+HEFunc1T92F85ma3s2H7sUIEsrJQIAhvLQGr9k1ey5RILJwDTSZcBGh1EDMevERx1R49zk3tQ6b1Jc6oFj7zGlfzENzgXDnz+kQQdutGzA82qcWBld3qMvfFbUVD4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fqBLf742; 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="fqBLf742" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BBB5C4CED6; Fri, 28 Feb 2025 21:17:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740777473; bh=sjrduZrtANGdpUj5EgXRrIFwwsm8xjCE4Ylu0tFwt/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fqBLf742W/aj9XlZRqXBGO0LSS3C+4U9HKR1FQC3YE7BeTIYziPpojiNolYZMHi7U eBvaFFFrK7aJfrf+S3RXT8S34yTaFI5ErJMwrnz3W8zytehWBQoLcs9RpjdhkAmbTw IIXGBm9sZaPLo/DDmGW4ptg7JWfdBSsTBi0I5cOXFvZJXGmj/SjarehW9qXxA2K3Jr Yj5X6EnBPdY8HyX/c4UT8Bfl2Sr880E5rbYhvKpT3lCRHIZC2ZUsUthF6a0np+Vh5u +qmDWXDKJJfMeQHi9W75DVGCAJsodb+AIsdOSYOxz8vJS9cyIRSOf4Oe1WvpTRYAcj SjhCop4l7Si/A== 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: Fri, 28 Feb 2025 18:17:31 -0300 Message-ID: <20250228211734.33781-4-acme@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228211734.33781-1-acme@kernel.org> References: <20250228211734.33781-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 Reviewed-by: Ian Rogers --- 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.48.1 From nobody Sat Feb 7 11:12:43 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 9B2DD1D61B9; Fri, 28 Feb 2025 21:17:57 +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=1740777477; cv=none; b=Usnsot4Ri7kZkqj1j2y8H+wm7/VI/KZMwRaWhBIxwFzpa9bCYS72YW7CHeXXbw6/1XrCxm37N51MlZ4G/ynjujo/pCeORGwUyiEaiRcS0EEhUENSZcQVpALdJeTYXAR+szFaXQtoXtACYix74qq6DjR59wEteDbp+idSVjV4Yds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740777477; c=relaxed/simple; bh=R4l8L1c/nV72ALGwDhWP+iUKUkvQXfkGKJnJpjuBik8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MlKwifiappWzsErgz4Uqc+bk/8LVq0aYrnnuKEfQE8XJxGNBE2r8aDrdo/jrWwt5dgpF0rktKpU6IcPPXbeSonl0oncbq1ay0yfEE6CPggVlH/PrEvqxCtEwePegb4dVumetJNJJyFsbeN/PPnAHEk1DLvo+nCLkqQxJ0KMpzm0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hwRNgQtz; 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="hwRNgQtz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 119C3C4CEE2; Fri, 28 Feb 2025 21:17:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740777477; bh=R4l8L1c/nV72ALGwDhWP+iUKUkvQXfkGKJnJpjuBik8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hwRNgQtz/WF23o3J+mxNqeUjMnDYZX8Quv8DjnMEZumhfq+TMYx3WlGmc2yVTkL4a AblLI0RIROQxxK7JEkjo69FL116sog4Uv0jdJzMK4qEXpmp+qxmFPljep0BOpQxhRc i5iT/WiEoc8SV3QmGgrxIyt3roMzOPxN0g7J+vKeN76v155TFCRs0N6gnoD7iJKtmW uGJmp9bO3jg0tkUSv4w0lhLiyGq94jwBfZtciLWMXuayBrzIsjtpTNwYD/2hudHfE0 FJCzGiPgU1l/kqicC1BS5J8MS/KwShY70M32S9I1uwrStTMcvN/gwRqhF8WZ2Ihuyo GmOtxxfQYqWaw== 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: Fri, 28 Feb 2025 18:17:32 -0300 Message-ID: <20250228211734.33781-5-acme@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228211734.33781-1-acme@kernel.org> References: <20250228211734.33781-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 Reviewed-by: Ian Rogers --- 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 8c5f5d79cd24a6bc..77df9701d5ad7de3 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.48.1 From nobody Sat Feb 7 11:12:43 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 D48581D9A49; Fri, 28 Feb 2025 21:18:01 +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=1740777481; cv=none; b=FfXhHQEnDk27jaT80gD19452HkUkypt3WjkBfTuoFnYNmEIfJQ/pTVDVCfPf1OyIlezlktZfPDyNNn1YDVWLwURJ2a6G/dPJ1gXzr8Pk9oQvvYxsALkoIhu7kCZjNYb07zzY+fMbXFpke2aSjF91JsonjLUGht5KFiVqvbpKqqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740777481; c=relaxed/simple; bh=HOIWHA0hBCScYVAjbCgc402cQQuBHczuC2JXsLLUbNg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DPpxFQc8pq2y9gx8MUXy4xd4wEXNCB2K1mhMJlPdDUDwRHLLhqrgXa5EIAnXiP3pWo6XM2ctiZ8Z0f4hqff4L5TYx8Lt8Q/ZxX+XvkASK3BbOSD823/5Nkcpusg0vP5d0m3rCpaqQpjKKUQ7wf4mT7Q5QLiAsCWgNoEH7xrjXFc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hMgIn46B; 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="hMgIn46B" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9540C4AF0B; Fri, 28 Feb 2025 21:17:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740777481; bh=HOIWHA0hBCScYVAjbCgc402cQQuBHczuC2JXsLLUbNg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hMgIn46BPxIOPc1+Y6mdqJyWqZbzHaNkdzlJ7mE4vEPxczjpB5Te0FhE3F+Ub/BQg lea8AWhxAd0QXDvhlFi1SOaxuRKpbcsXdfkm18oC/4FdIwJumTfhAAGLRCBQQIcnlM IcEvLwbIIhCx3yPFctqSSJZ4cxKNY2MvQ/Xgv0vNmHkZpGXIDW4EQ2SkiUZZ35Qifp jo+ApE6qSO4J1G4VMrl4YHTreCFbeWoP/+TvYU1NcV034ByFoUJTioGnOmm8wwT2eC cyE/g1q2KGz+lM4nnBEoSq9GXMZojyYE672FEltnZv8HFBDKeOnol4tDfRTNu62zqR XIXrvH8wxfNLg== 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_maps() when replacing a kernel map Date: Fri, 28 Feb 2025 18:17:33 -0300 Message-ID: <20250228211734.33781-6-acme@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228211734.33781-1-acme@kernel.org> References: <20250228211734.33781-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_maps() 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 Reviewed-by: Ian Rogers --- 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 77df9701d5ad7de3..0b40d901675ed57e 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_maps(new, maps); + check_invariants(maps); return err; } --=20 2.48.1 From nobody Sat Feb 7 11:12:43 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 5D78B1DE894; Fri, 28 Feb 2025 21:18:05 +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=1740777485; cv=none; b=vC3rjgcXpH13noSn2Q/oiwDL3lQU27gVW68A45fLaRSVvboRClFIOBNXis+g0VGulCWZmshEyV7vWj3UFGklvE/Oe09kySpUXB9/fWqmN+u3RDLYsmKQbMrMYVPsA4FcAP6FzNRR5TGGTHD+l9as2gvAFCOTNJyk7EY6Qj9Jvjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740777485; c=relaxed/simple; bh=7QuwcONiFjBvgd7KcWu7hsE6a/J1QdNgA0OLlDjYQgs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aqk5gJEOKR2Fn9qBjutWNPgAxWGF22Ip9IZ7kwLE4ZiTBZ6LeV/yd9AezNCwZuLXSa0mFqb0v2p37RRp38TZCO5ZRgGW7XRMVA/CWU2PfHOeel7ehF0xQGQ3Cv0Kdxu8V7pIVfasxfgspheSXUu0qG9WzEIwhbwihr2CoV3cUGg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sXm1aFVy; 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="sXm1aFVy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB8CDC4CED6; Fri, 28 Feb 2025 21:18:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740777485; bh=7QuwcONiFjBvgd7KcWu7hsE6a/J1QdNgA0OLlDjYQgs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sXm1aFVyjcpZtzGCtgQznnxl36xZJNYmbLYKlTSOWL9/hVG+8J8CIGdC68fK/nTjk IWr6pneS4rI3VBsA9iI+MEs8rO9fWvjoD8CuQTfC+mBu+in0aTxNVrmOBTgrTVx3PB geB3OAG/Gf4jywmJATdCr7qGJKJHkAFiXfD3b8cb5k/pIAJkJUrhWecZUQiLrq/yQU y82iIsdYIxfI2oRKLe/uyWqjvgUNG9qD76CDSbpoaqI3RGYnWSO3SzqWSjWEFoUsPR cBa/teRB6kYkWEaJmXYKjhpT+HYqi6b1sI+0YTJfl8/sMsNTJXKSorrEIx5UjwsZ0H t5wVfNqwnPqGQ== 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: Fri, 28 Feb 2025 18:17:34 -0300 Message-ID: <20250228211734.33781-7-acme@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250228211734.33781-1-acme@kernel.org> References: <20250228211734.33781-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 Reviewed-by: Ian Rogers --- 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.48.1