From: sashiko-bot@kernel.org
To: "Arnaldo Carvalho de Melo" <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v7 5/9] perf config: Serialize config file access with a mutex
Date: Fri, 02 Oct 2026 09:13:13 +0000 [thread overview]
Message-ID: <20261002091313.6A6401F0089A@smtp.kernel.org> (raw)
In-Reply-To: <20261001185400.2754753-6-acme@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] perf: DO_ONCE lacks memory barriers causing double-checked locking race
--
commit 0b6c61f1a2ea254be797a11efae079eb0c53f03d
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
perf config: Serialize config file access with a mutex
This commit serializes perf config file access using mutexes to support
concurrent reads and writes from background features. It also replaces the
lazy initialization of system_path() and home_perfconfig() with DO_ONCE() to
prevent string leaks when accessed by multiple threads.
> diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
> index 6e0ff8a9140cc..287401f159e66 100644
> --- a/tools/perf/util/config.c
> +++ b/tools/perf/util/config.c
[ ... ]
> @@ -565,21 +571,24 @@ static int perf_config_from_file(config_fn_t fn, const char *filename, void *dat
> fclose(f);
> config_file_name = NULL;
> }
> + mutex_unlock(&config_mutex);
> return ret;
> }
>
> -const char *perf_etc_perfconfig(void)
> -{
> - static const char *system_wide;
> +/* system_path() allocates, so it is computed once. */
> +static const char *etc_perfconfig;
>
> - if (!system_wide)
> - /*
> - * ETC_PERFCONFIG is absolute, so its unresolved path is
> - * the same string, better than the callers crashing.
> - */
> - system_wide = system_path(ETC_PERFCONFIG) ?: ETC_PERFCONFIG;
> +static void perf_etc_perfconfig__init(void)
> +{
> + etc_perfconfig = system_path(ETC_PERFCONFIG);
> + if (!etc_perfconfig)
> + etc_perfconfig = ETC_PERFCONFIG;
> +}
>
> - return system_wide;
> +const char *perf_etc_perfconfig(void)
> +{
> + DO_ONCE(perf_etc_perfconfig__init);
[Severity: High]
Does this use of DO_ONCE() introduce a double-checked locking race?
The DO_ONCE() macro in tools/perf/util/mutex.h implements a lockless check
of the ___done flag without memory barriers:
if (!___done) { \
mutex_lock(&___once_lock); \
if (!___done) { \
fn(__VA_ARGS__); \
___done = true;
Because of the missing barriers (such as smp_load_acquire and
smp_store_release), a second thread can observe ___done == true out of
order, before the stores initializing etc_perfconfig become globally
visible.
Can this result in returning an uninitialized NULL value to callers relying
on a valid string?
> + return etc_perfconfig;
> +}
>
> static int perf_env_bool(const char *k, int def)
[ ... ]
> @@ -637,19 +646,18 @@ static char *home_perfconfig(void)
> return NULL;
> }
>
> -const char *perf_home_perfconfig(void)
> -{
> - static const char *config;
> - static bool failed;
> -
> - if (failed || config)
> - return config;
> +/* home_perfconfig() allocates and warns, so it is computed once. */
> +static const char *home_config;
>
> - config = home_perfconfig();
> - if (!config)
> - failed = true;
> +static void perf_home_perfconfig__init(void)
> +{
> + home_config = home_perfconfig();
> +}
>
> - return config;
> +const char *perf_home_perfconfig(void)
> +{
> + DO_ONCE(perf_home_perfconfig__init);
[Severity: High]
Could this similarly risk returning a NULL pointer due to the non-atomic
DO_ONCE() implementation described above?
> + return home_config;
> +}
>
> static struct perf_config_section *find_section(struct list_head *sections,
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261001185400.2754753-1-acme@kernel.org?part=5
next prev parent reply other threads:[~2026-10-02 9:13 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 18:53 [PATCH v7 0/9] perf tools: Add progress diagnostics and a false-sharing workload Arnaldo Carvalho de Melo
2026-10-01 18:53 ` [PATCH v7 1/9] perf config: Move perf_config__set_variable() to util/config.c Arnaldo Carvalho de Melo
2026-10-02 9:13 ` sashiko-bot
2026-10-01 18:53 ` [PATCH v7 2/9] perf config: Make perf_etc_perfconfig() never return NULL Arnaldo Carvalho de Melo
2026-10-02 9:13 ` sashiko-bot
2026-10-01 18:53 ` [PATCH v7 3/9] perf mutex: Add DEFINE_MUTEX() static initializer Arnaldo Carvalho de Melo
2026-10-02 9:13 ` sashiko-bot
2026-10-01 18:53 ` [PATCH v7 4/9] perf mutex: Add DO_ONCE() for one-time initialization Arnaldo Carvalho de Melo
2026-10-02 9:13 ` sashiko-bot
2026-10-01 18:53 ` [PATCH v7 5/9] perf config: Serialize config file access with a mutex Arnaldo Carvalho de Melo
2026-10-02 9:13 ` sashiko-bot [this message]
2026-10-01 18:53 ` [PATCH v7 6/9] perf report: Add --progress option Arnaldo Carvalho de Melo
2026-10-02 9:13 ` sashiko-bot
2026-10-01 18:53 ` [PATCH v7 7/9] perf report: Add --no-progress option Arnaldo Carvalho de Melo
2026-10-02 9:13 ` sashiko-bot
2026-10-01 18:53 ` [PATCH v7 8/9] perf scripts: Add perf-stuck, to tell where a running perf is stuck Arnaldo Carvalho de Melo
2026-10-02 9:13 ` sashiko-bot
2026-10-01 18:54 ` [PATCH v7 9/9] perf test: Add false_sharing workload exhibiting cross-CPU false sharing Arnaldo Carvalho de Melo
2026-10-02 9:13 ` sashiko-bot
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=20261002091313.6A6401F0089A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=acme@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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