From: Hillf Danton <hdanton@sina.com>
To: Nikolay Kuratov <kniv@yandex-team.ru>
Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev,
"Michael S. Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@redhat.com>, Lei Yang <leiyang@redhat.com>,
Andrey Ryabinin <arbn@yandex-team.com>,
Andrey Smetanin <asmetanin@yandex-team.ru>
Subject: Re: [PATCH v2] vhost/net: Replace wait_queue with completion in ubufs reference
Date: Fri, 18 Jul 2025 20:46:56 +0800 [thread overview]
Message-ID: <20250718124657.2394-1-hdanton@sina.com> (raw)
In-Reply-To: <20250718110355.1550454-1-kniv@yandex-team.ru>
On Fri, 18 Jul 2025 14:03:55 +0300 Nikolay Kuratov wrote:
>
> drivers/vhost/net.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
> index 7cbfc7d718b3..69e1bfb9627e 100644
> --- a/drivers/vhost/net.c
> +++ b/drivers/vhost/net.c
> @@ -94,7 +94,7 @@ struct vhost_net_ubuf_ref {
> * >1: outstanding ubufs
> */
> atomic_t refcount;
> - wait_queue_head_t wait;
> + struct completion wait;
> struct vhost_virtqueue *vq;
> };
>
> @@ -240,7 +240,7 @@ vhost_net_ubuf_alloc(struct vhost_virtqueue *vq, bool zcopy)
> if (!ubufs)
> return ERR_PTR(-ENOMEM);
> atomic_set(&ubufs->refcount, 1);
> - init_waitqueue_head(&ubufs->wait);
> + init_completion(&ubufs->wait);
> ubufs->vq = vq;
> return ubufs;
> }
> @@ -249,14 +249,14 @@ static int vhost_net_ubuf_put(struct vhost_net_ubuf_ref *ubufs)
> {
> int r = atomic_sub_return(1, &ubufs->refcount);
> if (unlikely(!r))
> - wake_up(&ubufs->wait);
> + complete_all(&ubufs->wait);
> return r;
> }
>
> static void vhost_net_ubuf_put_and_wait(struct vhost_net_ubuf_ref *ubufs)
> {
> vhost_net_ubuf_put(ubufs);
> - wait_event(ubufs->wait, !atomic_read(&ubufs->refcount));
> + wait_for_completion(&ubufs->wait);
> }
>
> static void vhost_net_ubuf_put_wait_and_free(struct vhost_net_ubuf_ref *ubufs)
> @@ -1381,6 +1381,7 @@ static void vhost_net_flush(struct vhost_net *n)
> mutex_lock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex);
> n->tx_flush = false;
> atomic_set(&n->vqs[VHOST_NET_VQ_TX].ubufs->refcount, 1);
> + reinit_completion(&n->vqs[VHOST_NET_VQ_TX].ubufs->wait);
> mutex_unlock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex);
> }
> }
> --
> 2.34.1
>
In the sequence below,
vhost_net_flush()
vhost_net_ubuf_put_and_wait(n->vqs[VHOST_NET_VQ_TX].ubufs);
wait_for_completion(&ubufs->wait);
reinit_completion(&n->vqs[VHOST_NET_VQ_TX].ubufs->wait);
reinit after wait, so the chance for missing wakeup still exists.
next prev parent reply other threads:[~2025-07-18 12:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-18 11:03 [PATCH v2] vhost/net: Replace wait_queue with completion in ubufs reference Nikolay Kuratov
2025-07-18 12:46 ` Hillf Danton [this message]
2025-07-18 13:24 ` [PATCH] " Nikolay Kuratov
2025-07-18 22:11 ` Hillf Danton
2025-07-18 23:03 ` [PATCH v2] " Hillf Danton
2025-07-20 16:13 ` Michael S. Tsirkin
2025-07-21 14:52 ` Lei Yang
2025-08-05 10:02 ` 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=20250718124657.2394-1-hdanton@sina.com \
--to=hdanton@sina.com \
--cc=arbn@yandex-team.com \
--cc=asmetanin@yandex-team.ru \
--cc=jasowang@redhat.com \
--cc=kniv@yandex-team.ru \
--cc=leiyang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox