linux-stable/tools/lib/api
Ian Rogers 97d5f2e9ee tools api fs: More thread safety for global filesystem variables
Multiple threads, such as with "perf top", may race to initialize a
file system path like hugetlbfs. The racy initialization of the path
leads to at least memory leaks. To avoid this initialize each fs for
reading the mount point path with pthread_once.

Mounting the file system may also be racy, so introduce a mutex over
the function. This does mean that the path is being accessed with and
without a mutex, which is inherently racy but hopefully benign,
especially as there are fewer callers to fs__mount.

Remove the fs__entries by directly using global variables, this was
done as no argument like the index can be passed to the init once
routine.

Issue found and tested with "perf top" and address sanitizer.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20230609224004.180988-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-06-13 23:40:32 -03:00
..
fd perf record: Fix way of handling non-perf-event pollfds 2022-10-04 08:55:19 -03:00
fs tools api fs: More thread safety for global filesystem variables 2023-06-13 23:40:32 -03:00
Build tools lib api: Add str_error_c to libapi 2016-07-27 17:16:43 -03:00
cpu.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
cpu.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
debug-internal.h tools lib api: Renaming pr_warning to pr_warn 2019-10-18 15:02:57 +02:00
debug.c tools lib api: Renaming pr_warning to pr_warn 2019-10-18 15:02:57 +02:00
debug.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
io.h tools api: Add io__getline 2023-04-04 13:23:59 -03:00
Makefile tools lib api: Add dependency test to install_headers 2022-12-14 11:16:12 -03:00