Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2672481rdb; Mon, 12 Feb 2024 12:22:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVVqPSI+rsICGqUcjbaauWMzqxMjRubhAVLUJHOu+0fjHB97+F+OYkCqS5ZYfKeXvSgslgnyGd5fKhS6SptJa/A+8aJIfISvTBFj5N8/w== X-Google-Smtp-Source: AGHT+IHaQFJ3EplHc897aXS30qdjWtwU0VJ5KGbOm4TEXdOT5+3Z3OhP2nG9xUsrD8CMF6m08Z1P X-Received: by 2002:a17:902:c951:b0:1d9:8d17:87ac with SMTP id i17-20020a170902c95100b001d98d1787acmr7937966pla.58.1707769359813; Mon, 12 Feb 2024 12:22:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707769359; cv=pass; d=google.com; s=arc-20160816; b=VisL5WwsfLMbEBvWJnf2wdG7wdFYMwWI7Sarz5U5X2QH0q9Ei65YG2WCWSYlAggPbk AYUOcWHWlQxbVMiLwLhnranQ6Z9MI2/i/dFj5kiGS4gTcyDoqtEePMUjW8+eS7k53YG2 +gvl9yAUABbSBLM8vHB7W0pNgaRfXeSqeYXgFPhaHoHVns/wwTjBdenYJ42bOhy+E6bR ZqmmZW42bSuWwwJzaNreVMuV0sj9SU5XKL4tXdZmNPAQtph2sUe8dMeqo8zwOjqt5H32 6yU8A+4US/W/R789KHIeVTfrQFe/jAdnJZs+INKbprUzKWfJFGMhP4WYxyOyQ3cKqFI1 fMiw== 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:dkim-signature; bh=CSkTVHBMewwnu8yq5IPAUhgGr9Iydcb2u3j6O+zxJnQ=; fh=G/VN325OmezKYrg7S/7I0KhOuTmqK/is2g+DXKq+Hpg=; b=pXcpIS8TSbU7DY+Ap+pMW1DKjxK1IQuBA1pABiiU4mNSm/dJ/O5tsPKtNwTr8enfM8 jv7UOHeyAFkeqE4HJT8qVwOKtXA2FJZeS70pZ72qsd3HdgL5QsEEUncSKAZiOWIwnfG2 eyySnUlk3Pl6M4Pr2EOPctJbTqy29kKWxcATP4Jxnp1VimVCWPqGdNeMI2pnHVOvfuWZ LLOQfuX6RqDiAqdS0NYoIFqJfZIPtMqZk22lENRJdSzlqcky3rAvuZ2X4tqdOzt3FL1u RLRfs3lF8lolFj8ht9eWVmvqPIiTwiK16ACaz7H9LRHfyhk5gTvOaFnAOzy4zbVNPZ2+ WnIA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IA0NkTZj; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-62329-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62329-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCWItX/ur3doSAF8rjfoQI3bVxFfHPEQgpD/9Am84npMGAu3o2DJ8Ek5kaBl02+IkOGdzJx4dVSqlqClLgnDoSuhIM9NHC8AdK4DN19G6A== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id mf6-20020a170902fc8600b001da17808d86si747837plb.142.2024.02.12.12.22.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 12:22:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62329-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; dkim=pass header.i=@google.com header.s=20230601 header.b=IA0NkTZj; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-62329-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62329-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 72C92280E56 for ; Mon, 12 Feb 2024 20:22:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01727482EB; Mon, 12 Feb 2024 20:22:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IA0NkTZj" Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 6BE6A47A7A for ; Mon, 12 Feb 2024 20:22:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707769349; cv=none; b=hhGEuCkOnroUco8iLiF8D7hW/vACFHqZiNMKWDeMjgulyOh9CGXW+tyARHm0tr23gokrSi9wyErxI2ziaRddSiz+2c/DKRD5PeUtUtsg2IquiHEb1lign19ExLwuYmk9AHqHdx5wdm2idMB8N+8hD119hfl7xs2fFtsKBUaW+So= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707769349; c=relaxed/simple; bh=1jyb/LgyCJSFAs/iMDtWO35G1TCZMxoahITHRWxYqTM=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=K7YKe7y2yIiyGp1HBlXkjeL6lY4rjgJxTmgxQCJnxPG0U42A5OWrvQ2uAzR1a9WX5qnUJ4ZoWBfQc9fstrbq/kN/WZQC7As7QyZct2K0NzZYNgFlhhgf32gdnpUGEaqGaYTQi7L6zIz6jQfBdj8SjaVACPGkpVp67N1lyrS98Ec= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=IA0NkTZj; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1d89f0ab02bso22485ad.1 for ; Mon, 12 Feb 2024 12:22:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707769347; x=1708374147; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=CSkTVHBMewwnu8yq5IPAUhgGr9Iydcb2u3j6O+zxJnQ=; b=IA0NkTZjJMhGTstt/Tvf42VjN7kaIRSv+wWKUktiXc9GtE88Rvf1tWqWcxtb1n3+1X Wy2wIryxwznO4NRXMgQqRoBm3asizqsvcCaHUPq9mtq0W9MOrAgAn4mYKbr9qhaAlo5p zr9/Krv3x7p3FxkbZNHI2xEAma+l6SmxdkWPdxtB5JjaVD40v2EBW36wXUjais8rJDKd 5/6mkmDLdwowRVcF+WLHTI3VsR9ByV2fTajyLtLsbLKfJcNiTepImBx7/NIDghG48Pkv W8XTDFT5M1+WhMW5OskVsNqdtnHTNPH8qlOJcGkFuD6zC7jCFvHIzes19JuC81mJOBUK QHYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707769347; x=1708374147; 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=CSkTVHBMewwnu8yq5IPAUhgGr9Iydcb2u3j6O+zxJnQ=; b=mJMc6uf5YrRjE+X1ceWHwcXoQW8QCC6pLALSyVx8vB4Y1dZxJee2AZtiNVe+uMrGMM TYnSn8QMi39oVS1pytg2xVAaKcRltCshNbaaFh5dlns4rHOKupqooswgX9Q24KZJfxl7 +6QW+V9xLwhvFOyE4JxztT/VBlLNQXaLyxFjDooHE2yHGCjBiXX5JvCG5+G2NxgyM1P2 D8l4Kf4ewfW3xD8vRlavev7Zc7PmQmZSu6xiRq6lBYlEXFNyW/MIqBAnifEIt6jbpAvS aPdH+kj74D5qRdQPup7mm3hejXWJL8986excAfh0m7gd8OHlY9wHGc4+c34hv3JQNaV3 BARA== X-Forwarded-Encrypted: i=1; AJvYcCU8eyIWZd40Y++zFdcWcPZ3UEn+tJkxoe5krVbIxk6uzhWQVUogKXlA4Pdlt75+EzAkHOOn0jmdRSnonsgFjS/7+B61ZwU1bybptwwM X-Gm-Message-State: AOJu0YxAFjHrR71UcXc9UKGc6VH458ptu5ImhZrNU9NRZ/Sq13YtOZ8F CorCt5ELKFw2n9ic0Yn5IUAENh+ISWb1z4nItLbW1ocCN5Sd1VSoZukvxkY4C4zniZP3hWyI29f 2XEhF+5qzCaSf/Ri/HFk197gwHHAQaAd8Gjoh X-Received: by 2002:a17:902:cece:b0:1d8:d6bf:145b with SMTP id d14-20020a170902cece00b001d8d6bf145bmr341044plg.15.1707769346579; Mon, 12 Feb 2024 12:22:26 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240207223639.3139601-1-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Mon, 12 Feb 2024 12:22:15 -0800 Message-ID: Subject: Re: [PATCH v2 0/6] maps memory improvements and fixes To: Namhyung Kim Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Song Liu , Miguel Ojeda , Liam Howlett , Colin Ian King , K Prateek Nayak , Artem Savkov , Changbin Du , Masami Hiramatsu , Athira Rajeev , Yang Jihong , Tiezhu Yang , James Clark , Leo Yan , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Feb 12, 2024 at 12:10=E2=80=AFPM Namhyung Kim = wrote: > > On Sat, Feb 10, 2024 at 10:08=E2=80=AFAM Ian Rogers = wrote: > > > > On Fri, Feb 9, 2024 at 6:46=E2=80=AFPM Ian Rogers = wrote: > > > > > > On Thu, Feb 8, 2024 at 9:44=E2=80=AFAM Namhyung Kim wrote: > > > > > > > > Hi Ian, > > > > > > > > On Wed, Feb 7, 2024 at 2:37=E2=80=AFPM Ian Rogers wrote: > > > > > > > > > > First 6 patches from: > > > > > https://lore.kernel.org/lkml/20240202061532.1939474-1-irogers@goo= gle.com/ > > > > > > > > > > v2. Fix NO_LIBUNWIND=3D1 build issue. > > > > > > > > > > Ian Rogers (6): > > > > > perf maps: Switch from rbtree to lazily sorted array for addres= ses > > > > > perf maps: Get map before returning in maps__find > > > > > perf maps: Get map before returning in maps__find_by_name > > > > > perf maps: Get map before returning in maps__find_next_entry > > > > > perf maps: Hide maps internals > > > > > perf maps: Locking tidy up of nr_maps > > > > > > > > Now I see a perf test failure on the vmlinux test: > > > > > > > > $ sudo ./perf test -v vmlinux > > > > 1: vmlinux symtab matches kallsyms = : > > > > --- start --- > > > > test child forked, pid 4164115 > > > > /proc/{kallsyms,modules} inconsistency while looking for > > > > "[__builtin__kprobes]" module! > > > > /proc/{kallsyms,modules} inconsistency while looking for > > > > "[__builtin__kprobes]" module! > > > > /proc/{kallsyms,modules} inconsistency while looking for > > > > "[__builtin__ftrace]" module! > > > > Looking at the vmlinux_path (8 entries long) > > > > Using /usr/lib/debug/boot/vmlinux-6.5.13-1rodete2-amd64 for symbols > > > > perf: Segmentation fault > > > > Obtained 16 stack frames. > > > > ./perf(+0x1b7dcd) [0x55c40be97dcd] > > > > ./perf(+0x1b7eb7) [0x55c40be97eb7] > > > > /lib/x86_64-linux-gnu/libc.so.6(+0x3c510) [0x7f33d7a5a510] > > > > ./perf(+0x1c2e9c) [0x55c40bea2e9c] > > > > ./perf(+0x1c43f6) [0x55c40bea43f6] > > > > ./perf(+0x1c4649) [0x55c40bea4649] > > > > ./perf(+0x1c46d3) [0x55c40bea46d3] > > > > ./perf(+0x1c7303) [0x55c40bea7303] > > > > ./perf(+0x1c70b5) [0x55c40bea70b5] > > > > ./perf(+0x1c73e6) [0x55c40bea73e6] > > > > ./perf(+0x11833e) [0x55c40bdf833e] > > > > ./perf(+0x118f78) [0x55c40bdf8f78] > > > > ./perf(+0x103d49) [0x55c40bde3d49] > > > > ./perf(+0x103e75) [0x55c40bde3e75] > > > > ./perf(+0x1044c0) [0x55c40bde44c0] > > > > ./perf(+0x104de0) [0x55c40bde4de0] > > > > test child interrupted > > > > ---- end ---- > > > > vmlinux symtab matches kallsyms: FAILED! > > > > > > Ah, tripped over a latent bug summarized in this part of an asan stac= k trace: > > > ``` > > > freed by thread T0 here: > > > #0 0x7fa13bcd74b5 in __interceptor_realloc > > > ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:85 > > > #1 0x561d66377713 in __maps__insert util/maps.c:353 > > > #2 0x561d66377b89 in maps__insert util/maps.c:413 > > > #3 0x561d6652911d in dso__process_kernel_symbol util/symbol-elf.c:= 1460 > > > #4 0x561d6652aaae in dso__load_sym_internal util/symbol-elf.c:1675 > > > #5 0x561d6652b6dc in dso__load_sym util/symbol-elf.c:1771 > > > #6 0x561d66321a4e in dso__load util/symbol.c:1914 > > > #7 0x561d66372cd9 in map__load util/map.c:353 > > > #8 0x561d663730e7 in map__find_symbol_by_name_idx util/map.c:397 > > > #9 0x561d663731e7 in map__find_symbol_by_name util/map.c:410 > > > #10 0x561d66378208 in maps__find_symbol_by_name_cb util/maps.c:524 > > > #11 0x561d66377f49 in maps__for_each_map util/maps.c:471 > > > #12 0x561d663784a0 in maps__find_symbol_by_name util/maps.c:546 > > > #13 0x561d662093e8 in machine__find_kernel_symbol_by_name util/mac= hine.h:243 > > > #14 0x561d6620abbd in test__vmlinux_matches_kallsyms > > > tests/vmlinux-kallsyms.c:330 > > > ... > > > ``` > > > dso__process_kernel_symbol rewrites the kernel maps here: > > > https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.= git/tree/tools/perf/util/symbol-elf.c#n1378 > > > which resizes the maps_by_address array causing the maps__for_each_ma= p > > > iteration in frame 11 to be iterating over a stale/freed value. > > > > > > The most correct solutions would be to clone the maps_by_address arra= y > > > prior to iteration, or reference count maps_by_address and its size. > > > Neither of these solutions particularly appeal, so just reloading the > > > maps_by_address and size on each iteration also fixes the problem, bu= t > > > possibly causes some maps to be skipped/repeated. I think this is > > > acceptable correctness for the performance. > > Can we move map__load() out of maps__for_each_map() ? > I think the callback should just return the map and break the loop. > And it can call the map__load() out of the read lock. It would need a rewrite of map__find_symbol_by_name which is being called by a callback from maps__find_symbol_by_name. Perhaps an initial pass to ensure everything is loaded and a safe version of the loop that copies the maps_by_address ahead of copying it. It'd be of a scope that'd be worth its own patch set. > > > > An aside, shouldn't taking a write lock to modify the maps deadlock > > with holding the read lock for iteration? Well no because > > perf_singlethreaded is true for the test: > > https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.gi= t/tree/tools/perf/util/rwsem.c#n17 > > Another perf_singlethreaded considered evil :-) Note, just getting rid > > of perf_singlethreaded means latent bugs like this will pop up and > > will need resolution. > > Yeah, maybe. How about turning it on in the test code? Agreed, but I think it should be a follow up. Thanks, Ian > Thanks, > Namhyung