All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Michal Pluta" <michalpl2003@gmail.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 1/8] perf bench futex: Retry futex_wait() when interrupted by a signal
Date: Sat, 26 Sep 2026 19:13:47 +0000	[thread overview]
Message-ID: <20260926191347.E59281F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260926190407.1106421-2-michalpl2003@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf: deadlock in futex wake-parallel due to missed one-shot futex_wake()
--

commit 4425d175409b64dbe77117f655f0ffa4eca2b864
Author: Michal Pluta <michalpl2003@gmail.com>

perf bench futex: Retry futex_wait() when interrupted by a signal

The worker threads in 'futex wake' and 'futex wake-parallel' are meant
to go back to sleep when a signal interrupts futex_wait(), but the check
never works. futex_wait() returns -1 and sets errno, so comparing its
return value with EINTR is always true and the loop ends at the first
interruption.

> diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c
> index 6aede7c46b337..a089d8ee4b023 100644
> --- a/tools/perf/bench/futex-wake-parallel.c
> +++ b/tools/perf/bench/futex-wake-parallel.c
> @@ -139,10 +139,9 @@ static void *blocked_workerfn(void *arg __maybe_unused)
>  	cond_wait(&thread_worker, &thread_lock);
>  	mutex_unlock(&thread_lock);
>  
> -	while (1) { /* handle spurious wakeups */
> -		if (futex_wait(&futex, 0, NULL, futex_flag) != EINTR)
> -			break;
> -	}
> +	/* Retry if the wait was interrupted by a signal. */
> +	while (futex_wait(&futex, 0, NULL, futex_flag) == -1 && errno == EINTR)
> +		;

[Severity: Medium]
Can this retry loop cause a deadlock if a signal interrupts the wait?

If blocked_workerfn() receives a signal, futex_wait() returns -1 and
errno == EINTR. The thread then temporarily leaves the futex wait queue before
looping back to call futex_wait() again.

If waking_workerfn() in tools/perf/bench/futex-wake-parallel.c happens to
execute its single futex_wake() call during this unqueued window:

tools/perf/bench/futex-wake-parallel.c:waking_workerfn() {
    ...
    waker->nwoken = futex_wake(&futex, nwakes, futex_flag);
    if (waker->nwoken != nwakes)
        warnx("couldn't wakeup all tasks (%d/%d)",
    ...
}

Will the waker thread miss the unqueued worker and exit, leaving the worker to
block forever on its next futex_wait() and causing the main thread to hang in
pthread_join()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260926190407.1106421-1-michalpl2003@gmail.com?part=1

  reply	other threads:[~2026-09-26 19:13 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-26 19:03 [PATCH 0/8] perf bench futex: Fix several bugs and bad inputs Michal Pluta
2026-09-26 19:04 ` [PATCH 1/8] perf bench futex: Retry futex_wait() when interrupted by a signal Michal Pluta
2026-09-26 19:13   ` sashiko-bot [this message]
2026-10-05 23:49     ` Namhyung Kim
2026-09-26 19:04 ` [PATCH 2/8] perf bench futex: Set the number of hash buckets in futex wake Michal Pluta
2026-09-26 19:09   ` sashiko-bot
2026-09-26 19:04 ` [PATCH 3/8] perf bench futex: Use the whole timeval for elapsed times Michal Pluta
2026-09-26 19:11   ` sashiko-bot
2026-10-05 23:54   ` Namhyung Kim
2026-09-26 19:04 ` [PATCH 4/8] perf bench futex: Reject invalid -q, -f and -b values Michal Pluta
2026-09-26 19:10   ` sashiko-bot
2026-09-26 19:04 ` [PATCH 5/8] perf bench futex: Stop when futex_wake() fails in futex wake Michal Pluta
2026-09-26 19:10   ` sashiko-bot
2026-09-26 19:04 ` [PATCH 6/8] perf bench futex: Use a 64-bit operation counter in hash and lock-pi Michal Pluta
2026-09-26 19:10   ` sashiko-bot
2026-09-26 19:04 ` [PATCH 7/8] perf bench futex: Clean up two nits in futex hash Michal Pluta
2026-09-26 19:10   ` sashiko-bot
2026-09-26 19:04 ` [PATCH 8/8] perf bench futex: Fix wording in futex bench messages Michal Pluta
2026-09-26 19:13   ` sashiko-bot
2026-10-05 23:57   ` 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=20260926191347.E59281F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=michalpl2003@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.