linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	 Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	 Adrian Hunter <adrian.hunter@intel.com>,
	Song Liu <song@kernel.org>,  Miguel Ojeda <ojeda@kernel.org>,
	Liam Howlett <liam.howlett@oracle.com>,
	 Colin Ian King <colin.i.king@gmail.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	 Artem Savkov <asavkov@redhat.com>,
	Changbin Du <changbin.du@huawei.com>,
	 Masami Hiramatsu <mhiramat@kernel.org>,
	Athira Rajeev <atrajeev@linux.vnet.ibm.com>,
	 Yang Jihong <yangjihong1@huawei.com>,
	Tiezhu Yang <yangtiezhu@loongson.cn>,
	 James Clark <james.clark@arm.com>, Leo Yan <leo.yan@linaro.org>,
	 linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	 bpf@vger.kernel.org
Subject: Re: [PATCH v2 0/6] maps memory improvements and fixes
Date: Mon, 12 Feb 2024 12:10:16 -0800	[thread overview]
Message-ID: <CAM9d7choe-CruqcdkLMPC1Eu4Oca0CBaaq-uiCd=csiLY60NBw@mail.gmail.com> (raw)
In-Reply-To: <CAP-5=fXs8=HvjGpkLwuZBi0Hh8jtmz7=0Tp7HRgU8FOFN0GZvg@mail.gmail.com>

On Sat, Feb 10, 2024 at 10:08 AM Ian Rogers <irogers@google.com> wrote:
>
> On Fri, Feb 9, 2024 at 6:46 PM Ian Rogers <irogers@google.com> wrote:
> >
> > On Thu, Feb 8, 2024 at 9:44 AM Namhyung Kim <namhyung@kernel.org> wrote:
> > >
> > > Hi Ian,
> > >
> > > On Wed, Feb 7, 2024 at 2:37 PM Ian Rogers <irogers@google.com> wrote:
> > > >
> > > > First 6 patches from:
> > > > https://lore.kernel.org/lkml/20240202061532.1939474-1-irogers@google.com/
> > > >
> > > > v2. Fix NO_LIBUNWIND=1 build issue.
> > > >
> > > > Ian Rogers (6):
> > > >   perf maps: Switch from rbtree to lazily sorted array for addresses
> > > >   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: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/machine.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_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

  reply	other threads:[~2024-02-12 20:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-07 22:36 [PATCH v2 0/6] maps memory improvements and fixes Ian Rogers
2024-02-07 22:36 ` [PATCH v2 1/6] perf maps: Switch from rbtree to lazily sorted array for addresses Ian Rogers
2024-02-07 22:36 ` [PATCH v2 2/6] perf maps: Get map before returning in maps__find Ian Rogers
2024-02-07 22:36 ` [PATCH v2 3/6] perf maps: Get map before returning in maps__find_by_name Ian Rogers
2024-02-07 22:36 ` [PATCH v2 4/6] perf maps: Get map before returning in maps__find_next_entry Ian Rogers
2024-02-07 22:36 ` [PATCH v2 5/6] perf maps: Hide maps internals Ian Rogers
2024-02-07 22:36 ` [PATCH v2 6/6] perf maps: Locking tidy up of nr_maps Ian Rogers
2024-02-08 17:44 ` [PATCH v2 0/6] maps memory improvements and fixes Namhyung Kim
2024-02-10  2:46   ` Ian Rogers
2024-02-10 18:08     ` Ian Rogers
2024-02-12 20:10       ` Namhyung Kim [this message]
2024-02-12 20:22         ` Ian Rogers
2024-02-13 17:53           ` Namhyung Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAM9d7choe-CruqcdkLMPC1Eu4Oca0CBaaq-uiCd=csiLY60NBw@mail.gmail.com' \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=asavkov@redhat.com \
    --cc=atrajeev@linux.vnet.ibm.com \
    --cc=bpf@vger.kernel.org \
    --cc=changbin.du@huawei.com \
    --cc=colin.i.king@gmail.com \
    --cc=irogers@google.com \
    --cc=james.clark@arm.com \
    --cc=jolsa@kernel.org \
    --cc=kprateek.nayak@amd.com \
    --cc=leo.yan@linaro.org \
    --cc=liam.howlett@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=song@kernel.org \
    --cc=yangjihong1@huawei.com \
    --cc=yangtiezhu@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).