Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2667300rdb; Mon, 12 Feb 2024 12:11:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUoHYJBS3nuRwwWXfeENtkbbULgFgPG2ZzfHdXTJ0PQkLdy5ADZQ0u1T0/CiOfUuSm9yreOIRMIUEo8QgLJlBeM7UblYBRRuAHEIDEJrQ== X-Google-Smtp-Source: AGHT+IF/xRa4BPrAEaEGGs0iiAP3s4lEa99xXyB3MU6znYhKHRRuRiAbx6r8AOBGyFih1sPc3RQt X-Received: by 2002:a17:90a:3ec3:b0:297:803:924a with SMTP id k61-20020a17090a3ec300b002970803924amr5455965pjc.23.1707768665399; Mon, 12 Feb 2024 12:11:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707768665; cv=pass; d=google.com; s=arc-20160816; b=whopT4gYA0uk2GVtpgLqNFSfheFgDRBSvU7i2fGjO+LLKyeZzvJcIY828H6HHuh5Gh dDz+M9dtPOUroOT1ouFNrW8dci0Epr+x1xV40+KXAX7VxNsneWiNKfZQeOmfel9X0pMD mzwKITsRZWeK49xsgQaPzLY2eRr8Zoqf93TC4M3V7YPaMDEJr1e9IQu8Xs+iAOhy4r6u TWQpUNhs+g8amxO2R7mVJpYfbunYywhkELlUJqnj3BH3fR3G5TnQFbTz7S02GUspDy6f kih+x2CPvgp4fb8dxahvzTCxElTQwOyINDMc9P1y+d7tchOBRrF1hgkgplP7389dkc+h AsHg== 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=ilCu2b5Ljq7Q+kjgZF6WcxqcCWOVeMmlalciWaHgshQ=; fh=atINHsSFR+amQUQMi9mEMwlQWKLCj+0tjII0EqZBO1Q=; b=0zBPwNBEZwlY0c2S3+MBi6T4o+hPrD7sfCiSD5XtxupcgLKzhkM/DcBHcjFpZBvxxg JiSK1EMY5BHiJ4ELsbLdUKnMoFg42cka9iJuYGI1XgL4krZzOHNz99dHSoKyJkCilnlO Xk08aWXYWUWEMW6DEvELvwM2rpMG5A7Wt3Nd/O/cU8UpRbTvo8TqnTHeacSBjz/Cp1DV JoKw3uyu5e17/oViie+JixDlR5J7y6ths14DjfpD6Tjh5jZ6vT6EZvzCRktpsR0fg2Z2 TFPDWasPu/7FCLfqp3/Af5hYJDc1hgv+mudI8BfKRlxR80F5DT0CArk0C8pr9R21XqNY stPw==; 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-62317-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62317-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCX7tdQuzja50F8a/xorTBb2l138cJmfo0pl6PqfrnQj85hqVW63kKq1qRaCzj5V4f3c7riRN8ynAaz4dt/qe0trghUYNVk4K6XB0oRa0w== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id mq6-20020a17090b380600b002949bbe7302si740071pjb.50.2024.02.12.12.11.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 12:11:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62317-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-62317-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62317-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 0F5BA28694E for ; Mon, 12 Feb 2024 20:11:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C6FA481BE; Mon, 12 Feb 2024 20:10:55 +0000 (UTC) Received: from mail-vk1-f171.google.com (mail-vk1-f171.google.com [209.85.221.171]) (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 68B4345C12; Mon, 12 Feb 2024 20:10:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707768655; cv=none; b=iqdAmT3OtkHLlXl3hfW/uZkfArOVWELlsPBByYxGMjQ3s8ORAK/6u6SUIifkjwYHIipHAzzsDJstT3EQEc4tRDZ4Z7jd4D+C7lv/En7GA43LiAkeuZzx+OB9u5Ybuz72ej2Yaj91VlPUNefmEQLhw6bS9jGMdRNee5OkiBYkvq0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707768655; c=relaxed/simple; bh=ErAi3yiO2NiNGUJ00p6OoRPUZbYyjNagusL7Wg6tQAU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=JtL2SkQQPYxg7phNSMhO+IPyM4cAXze2eyEPr0Me9BxbKMQTrJ5W5wRwKVaUZ+h8M0KhH1o2lyp3eRDIitNK0erZcP4vS1e06Kylt6iS3cXpTEOa4W3grn3pYzXCNUO2IGp5qfkF58jc+8un7eEiY/Y5NSNaro/7QSgGlLdM57k= 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.221.171 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-vk1-f171.google.com with SMTP id 71dfb90a1353d-4c022adaa88so509882e0c.0; Mon, 12 Feb 2024 12:10:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707768652; x=1708373452; 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=ilCu2b5Ljq7Q+kjgZF6WcxqcCWOVeMmlalciWaHgshQ=; b=CDcBhTgkjmNhJTTSQS+pzDLnlZQjIpk32jYSxGQp48wMHzFGBT2Y22McQV+7TMTSv6 9B7OvmTitN2y3zSh0K+an5Jzvzo3/dSRohw1yA+nwJhjTfGVlVVHORsyHYvdBVLCMyPb rcqJeUdaX78idHBGy6DVkgTTRv8exr/gmh8rrB1WCE/SZnWEauw1KTyTAoPesnkS0GYW OPDdhH+tMdNgyTH8aZj2BX6+bGuzyIou75pS9qNmtdH1cVZQQxUom3dX5dKnjvz0sHEc POXMlkLR7E3+AYd8gxogqjqclYejxB6UHLs7DuwfsjY9f47l2qeeNRX7FvUIKWj1WEq6 N2kA== X-Forwarded-Encrypted: i=1; AJvYcCWNu7wTh9v+1/GvcyC0TZVHxwCIPWOTJjHny9uMNvSRQ2RAp9bx1L0GNNxru8dw++IrUj8dmSqcr93qWMyvVFYFXFsrxpiRNDC1OIu3eU6gdm72xcE5xEqWgXt62n9UnWjpUIdZ/HrqsHJRcVao95SGQYHktI68giqb+1C02BjZh2Xh7w== X-Gm-Message-State: AOJu0YzjoZOtIHG4hjTiJX3j0UpB6uLJ+gOwXHZxQeoCQjVOJZKWTn48 uaSWsyESKyJ/qNmrzJUOlNxkBfnO7Z3Viu0HNNccj479bDmutH1HzFQ2mqUrgqHHegPOqt8zeTJ o2MPsqVJMREMT0GCQ9Z73TFVHhEM= X-Received: by 2002:a05:6122:4a02:b0:4c0:774b:e7b0 with SMTP id ez2-20020a0561224a0200b004c0774be7b0mr3110373vkb.13.1707768652111; Mon, 12 Feb 2024 12:10:52 -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: Namhyung Kim Date: Mon, 12 Feb 2024 12:10:16 -0800 Message-ID: Subject: Re: [PATCH v2 0/6] maps memory improvements and fixes To: Ian Rogers 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 Sat, Feb 10, 2024 at 10:08=E2=80=AFAM Ian Rogers wr= ote: > > On Fri, Feb 9, 2024 at 6:46=E2=80=AFPM Ian Rogers wr= ote: > > > > 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@googl= e.com/ > > > > > > > > v2. Fix NO_LIBUNWIND=3D1 build issue. > > > > > > > > Ian Rogers (6): > > > > perf maps: Switch from rbtree to lazily sorted array for addresse= s > > > > 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 stack = 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:14= 60 > > #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/machi= ne.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.gi= t/tree/tools/perf/util/symbol-elf.c#n1378 > > which resizes the maps_by_address array causing the maps__for_each_map > > iteration in frame 11 to be iterating over a stale/freed value. > > > > The most correct solutions would be to clone the maps_by_address array > > 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, but > > 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. > > 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.git/= 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? Thanks, Namhyung