From: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
To: Konstantin Khorenko <khorenko@virtuozzo.com>
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH vz10] drivers/vhost/blk: take vq->mutex in the kick handlers
Date: Tue, 29 Sep 2026 18:58:46 +0200 [thread overview]
Message-ID: <6f244655-ecaf-404f-95ce-f903d2bd6f21@virtuozzo.com> (raw)
In-Reply-To: <20260928-prep-kh-vstor-138640-vhost-blk-vq-mutex-v1-1-48ae0775bc8a@virtuozzo.com>
LGTM
Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
On 9/28/26 17:25, Konstantin Khorenko wrote:
> vhost.h documents vhost_vq_set_backend()/vhost_vq_get_backend() as
> "need to call with vq->mutex acquired": vq->private_data is a plain
> field with no barriers.
> * vhost-net, vsock and scsi all take vq->mutex in their kick handlers
> * vhost-blk reads the backend and works with the ring without it
>
> On a weakly ordered CPU (arm64) the two stores can become visible in the
> opposite order:
>
> CPU0: VHOST_BLK_SET_BACKEND CPU1: vhost worker
> ----------------------------------- -------------------------------
> blk_vq->req = kvmalloc_array(...);
> mutex_lock(&vq->mutex);
> vhost_vq_set_backend(vq, backend);
> mutex_unlock(&vq->mutex);
>
> backend store becomes visible
> f = vhost_vq_get_backend(vq);
> /* sees the new backend */
> head = vhost_get_vq_desc(...);
> req = &blk_vq->req[head];
> /* sees the old req: NULL on
> the first SET_BACKEND, a
> freed pointer after a -1/fd
> cycle - a NULL-offset oops
> or a use-after-free */
> req store becomes visible - too late
>
> x86-64 TSO forbids both the store-store reordering on CPU0 and the
> load-load reordering on CPU1, which is the only reason the current code
> works there.
>
> Fixes: d8722ff88c5d ("drivers/vhost: vhost-blk accelerator for virtio-blk guests")
> https://virtuozzo.atlassian.net/browse/VSTOR-138640
> Feature: vhost-blk: in-kernel accelerator for virtio-blk guests
>
> Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
> ---
> drivers/vhost/blk.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
> index fbdd04f5a7e28..b170439a1806d 100644
> --- a/drivers/vhost/blk.c
> +++ b/drivers/vhost/blk.c
> @@ -530,9 +530,11 @@ static void vhost_blk_handle_guest_kick(struct vhost_work *work)
> blk = container_of(vq->dev, struct vhost_blk, dev);
> blk_vq = container_of(vq, struct vhost_blk_vq, vq);
>
> + mutex_lock(&vq->mutex);
> +
> f = vhost_vq_get_backend(vq);
> if (!f)
> - return;
> + goto out;
>
> vhost_disable_notify(&blk->dev, vq);
> for (;;) {
> @@ -580,6 +582,8 @@ static void vhost_blk_handle_guest_kick(struct vhost_work *work)
> break;
> }
> }
> +out:
> + mutex_unlock(&vq->mutex);
> }
>
> static void vhost_blk_handle_host_kick(struct vhost_work *work)
> @@ -594,6 +598,8 @@ static void vhost_blk_handle_host_kick(struct vhost_work *work)
>
> blk_vq = container_of(work, struct vhost_blk_vq, work);
> vq = &blk_vq->vq;
> +
> + mutex_lock(&vq->mutex);
> llnode = llist_del_all(&blk_vq->llhead);
> added = false;
> while (llnode) {
> @@ -627,6 +633,7 @@ static void vhost_blk_handle_host_kick(struct vhost_work *work)
>
> if (likely(added))
> vhost_signal(&blk->dev, vq);
> + mutex_unlock(&vq->mutex);
> }
>
> /* It is forbidden to call more than one vhost_blk_flush() simultaneously */
>
> ---
> base-commit: 0679f0d70523972eec3a0643565521d93e26eb9c
> change-id: 20260928-prep-kh-vstor-138640-vhost-blk-vq-mutex-84a1a46032ae
>
> Best regards,
> --
> Konstantin Khorenko <khorenko@virtuozzo.com>
>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-09-29 17:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 15:25 Konstantin Khorenko
2026-09-29 16:58 ` Andrey Zhadchenko [this message]
2026-09-29 17:45 ` Konstantin Khorenko
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=6f244655-ecaf-404f-95ce-f903d2bd6f21@virtuozzo.com \
--to=andrey.zhadchenko@virtuozzo.com \
--cc=devel@openvz.org \
--cc=khorenko@virtuozzo.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 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.