From: sashiko-bot@kernel.org
To: "Swapnil Sapkal" <swapnil.sapkal@amd.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 3/3] perf lock contention: Fix SIGCHLD race in __cmd_contention()
Date: Thu, 09 Apr 2026 17:37:33 +0000 [thread overview]
Message-ID: <20260409173734.BC1E5C4CEF7@smtp.kernel.org> (raw)
In-Reply-To: <20260409162249.25581-4-swapnil.sapkal@amd.com>
Sashiko AI review found 1 potential issue(s):
- [High] Unconditional use of `sigsuspend()` without a state flag fails to fix the race condition and causes indefinite hangs.
--
commit bbcae9323bad3368550c5fd9165d487b92cd3bbd
Author: Swapnil Sapkal <swapnil.sapkal@amd.com>
perf lock contention: Fix SIGCHLD race in __cmd_contention()
This commit replaces pause() with sigsuspend() to prevent a race condition
where a short-lived workload exits and delivers SIGCHLD before the wait
begins.
> diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
> index e8962c985d34a..2da689de134a4 100644
> --- a/tools/perf/builtin-lock.c
> +++ b/tools/perf/builtin-lock.c
[ ... ]
> @@ -2123,12 +2124,25 @@ static int __cmd_contention(int argc, const char **argv)
> }
>
> if (use_bpf) {
> + /*
> + * Block all handled signals after evlist__prepare_workload()
> + * so the forked child does not inherit a modified signal
> + * mask, then use sigsuspend() to atomically unblock and
> + * wait. This prevents a race where a short-lived workload
> + * exits and delivers SIGCHLD before we are ready to wait.
> + */
> + sigemptyset(&sig_mask);
> + sigaddset(&sig_mask, SIGCHLD);
> + sigaddset(&sig_mask, SIGINT);
> + sigaddset(&sig_mask, SIGTERM);
> + sigprocmask(SIG_BLOCK, &sig_mask, &oldmask);
> +
> lock_contention_start();
> if (argc)
> evlist__start_workload(con.evlist);
>
> - /* wait for signal */
> - pause();
> + sigsuspend(&oldmask);
If SIGINT or SIGCHLD is delivered before sigprocmask() blocks them, won't it
be consumed by sighandler without setting any checked state, causing
sigsuspend() to hang indefinitely?
The signals are registered earlier in the function, leaving a window during
evlist__prepare_workload() and lock_contention_prepare() where they are
unblocked.
Should there be a volatile sig_atomic_t flag set by sighandler that is
checked in a loop, for example:
while (!done)
sigsuspend(&oldmask);
This would avoid missing signals that arrive before the block and ensure
sigsuspend() doesn't hang.
> + sigprocmask(SIG_SETMASK, &oldmask, NULL);
>
> lock_contention_stop();
> lock_contention_read(&con);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260409162249.25581-1-swapnil.sapkal@amd.com?part=3
prev parent reply other threads:[~2026-04-09 17:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-09 16:22 [PATCH v2 0/3] perf: Fix SIGCHLD vs pause() race with short-lived workloads Swapnil Sapkal
2026-04-09 16:22 ` [PATCH v2 1/3] perf sched stats: Fix SIGCHLD race in schedstat_record() Swapnil Sapkal
2026-04-09 16:51 ` sashiko-bot
2026-04-10 4:17 ` Namhyung Kim
2026-04-09 16:22 ` [PATCH v2 2/3] perf sched stats: Fix SIGCHLD race in schedstat_live() Swapnil Sapkal
2026-04-09 17:18 ` sashiko-bot
2026-04-09 16:22 ` [PATCH v2 3/3] perf lock contention: Fix SIGCHLD race in __cmd_contention() Swapnil Sapkal
2026-04-09 17:37 ` sashiko-bot [this message]
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=20260409173734.BC1E5C4CEF7@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko@lists.linux.dev \
--cc=swapnil.sapkal@amd.com \
/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