From: sashiko-bot@kernel.org
To: "Prabhakar Reddy K" <k.prabhakarr84@gmail.com>
Cc: kvm@vger.kernel.org, virtualization@lists.linux.dev,
"Michael S. Tsirkin" <mst@redhat.com>,
"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH] vhost_task: avoid hanging in vhost_task_stop() when worker is frozen
Date: Thu, 03 Dec 2026 06:26:10 +0000 [thread overview]
Message-ID: <sashiko-outbox-247226@kernel.org> (raw)
In-Reply-To: <20261202062516.677164-1-K.Prabhakarr84@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] vhost_task: per-iteration exit_mutex lock in vhost_task_fn()
hot path
--
commit 87833b26c841d86ec6124bf02ba1edeecfcdf435
Author: Prabhakar Reddy K <k.prabhakarr84@gmail.com>
vhost_task: avoid hanging in vhost_task_stop() when worker is frozen
This commit replaces vhost_task's exit completion with a refcount_t and
serializes vtsk->fn() with exit_mutex so vhost_task_stop() can return
without waiting for a frozen or stopped worker thread to exit.
> diff --git a/kernel/vhost_task.c b/kernel/vhost_task.c
> index 3717885a5992a..56b9080469ed7 100644
> --- a/kernel/vhost_task.c
> +++ b/kernel/vhost_task.c
[ ... ]
> @@ -38,15 +46,19 @@ static int vhost_task_fn(void *data)
> break;
> }
>
> + mutex_lock(&vtsk->exit_mutex);
> /* mb paired w/ vhost_task_stop */
> set_current_state(TASK_INTERRUPTIBLE);
>
> if (test_bit(VHOST_TASK_FLAGS_STOP, &vtsk->flags)) {
> __set_current_state(TASK_RUNNING);
> + mutex_unlock(&vtsk->exit_mutex);
> break;
> }
>
> did_work = vtsk->fn(vtsk->data);
> + mutex_unlock(&vtsk->exit_mutex);
> +
> if (!did_work)
> schedule();
> }
[Severity: Medium]
Does locking vtsk->exit_mutex on every iteration of vhost_task_fn() add
mutex overhead to the lockless vhost I/O worker hot path and hold the
mutex across multi-second sleeps?
For vhost I/O workers, vhost_run_work_list() drains worker->work_list
locklessly via llist_del_all(), and each wakeup runs at least two loop
iterations (one to process the work and a second to re-check the list
before calling schedule()), incurring at least two mutex_lock() and
mutex_unlock() pairs per wakeup.
In addition, kvm_nx_huge_page_recovery_worker() sleeps in
schedule_timeout() inside vtsk->fn():
arch/x86/kvm/mmu/mmu.c:kvm_nx_huge_page_recovery_worker() {
...
if (remaining_time > 0) {
schedule_timeout(remaining_time);
/* check for signals and come back */
return true;
}
...
}
Holding vtsk->exit_mutex across that sleep forces vhost_task_stop() to
block in TASK_UNINTERRUPTIBLE on exit_mutex until the worker is scheduled
back onto a CPU to return from schedule_timeout(), which can stall if the
worker's cgroup CPU quota is throttled.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202062516.677164-1-K.Prabhakarr84@gmail.com?part=1
next prev parent reply other threads:[~2026-12-03 6:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 6:25 [PATCH] vhost_task: avoid hanging in vhost_task_stop() when worker is frozen Prabhakar Reddy K
2026-12-03 6:26 ` sashiko-bot [this message]
2026-12-03 7:09 ` Michael S. Tsirkin
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=sashiko-outbox-247226@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=eperezma@redhat.com \
--cc=k.prabhakarr84@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=virtualization@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.