[PATCH v2 01/25] vhost: store busyloop_timeout into struct vhost_dev

Vladimir Sementsov-Ogievskiy posted 25 patches 4 weeks, 1 day ago
[PATCH v2 01/25] vhost: store busyloop_timeout into struct vhost_dev
Posted by Vladimir Sementsov-Ogievskiy 4 weeks, 1 day ago
We'll split vhost_dev_init() into _init() and _connect(), to be able
to postpone communication with backend, to support backend-transfer
migration of vhost-user-blk in future commit.

So, instead of passing it through parameters, store it in vhost_dev
structure.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 hw/virtio/vhost.c         | 11 +++++------
 include/hw/virtio/vhost.h |  1 +
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 7ba90c24db..9fc6e7ba65 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -1501,8 +1501,7 @@ static void vhost_virtqueue_error_notifier(EventNotifier *n)
 }
 
 static int vhost_virtqueue_init(struct vhost_dev *dev,
-                                struct vhost_virtqueue *vq, int n,
-                                bool busyloop_timeout)
+                                struct vhost_virtqueue *vq, int n)
 {
     int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index(dev, n);
     struct vhost_vring_file file = {
@@ -1539,8 +1538,8 @@ static int vhost_virtqueue_init(struct vhost_dev *dev,
                                    vhost_virtqueue_error_notifier);
     }
 
-    if (busyloop_timeout) {
-        r = vhost_virtqueue_set_busyloop_timeout(dev, n, busyloop_timeout);
+    if (dev->busyloop_timeout) {
+        r = vhost_virtqueue_set_busyloop_timeout(dev, n, dev->busyloop_timeout);
         if (r < 0) {
             VHOST_OPS_DEBUG(r, "Failed to set busyloop timeout");
             goto fail_err;
@@ -1628,6 +1627,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
 
     hdev->vdev = NULL;
     hdev->migration_blocker = NULL;
+    hdev->busyloop_timeout = busyloop_timeout;
 
     r = vhost_set_backend_type(hdev, backend_type);
     assert(r >= 0);
@@ -1650,8 +1650,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
     }
 
     for (i = 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) {
-        r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i,
-                                 busyloop_timeout);
+        r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i);
         if (r < 0) {
             error_setg_errno(errp, -r, "Failed to initialize virtqueue %d", i);
             goto fail;
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index 1ba1af1d86..f1a7e7b971 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -105,6 +105,7 @@ struct vhost_dev {
     VIRTIO_DECLARE_FEATURES(_features);
     VIRTIO_DECLARE_FEATURES(acked_features);
 
+    uint32_t busyloop_timeout;
     uint64_t max_queues;
     uint64_t backend_cap;
     /* @started: is the vhost device started? */
-- 
2.48.1
Re: [PATCH v2 01/25] vhost: store busyloop_timeout into struct vhost_dev
Posted by Raphael Norwitz 3 weeks, 3 days ago
Reviewed-by: Raphael Norwitz <raphael.s.norwitz@gmail.com>


On Thu, Oct 16, 2025 at 7:50 AM Vladimir Sementsov-Ogievskiy
<vsementsov@yandex-team.ru> wrote:
>
> We'll split vhost_dev_init() into _init() and _connect(), to be able
> to postpone communication with backend, to support backend-transfer
> migration of vhost-user-blk in future commit.
>
> So, instead of passing it through parameters, store it in vhost_dev
> structure.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
>  hw/virtio/vhost.c         | 11 +++++------
>  include/hw/virtio/vhost.h |  1 +
>  2 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index 7ba90c24db..9fc6e7ba65 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -1501,8 +1501,7 @@ static void vhost_virtqueue_error_notifier(EventNotifier *n)
>  }
>
>  static int vhost_virtqueue_init(struct vhost_dev *dev,
> -                                struct vhost_virtqueue *vq, int n,
> -                                bool busyloop_timeout)
> +                                struct vhost_virtqueue *vq, int n)
>  {
>      int vhost_vq_index = dev->vhost_ops->vhost_get_vq_index(dev, n);
>      struct vhost_vring_file file = {
> @@ -1539,8 +1538,8 @@ static int vhost_virtqueue_init(struct vhost_dev *dev,
>                                     vhost_virtqueue_error_notifier);
>      }
>
> -    if (busyloop_timeout) {
> -        r = vhost_virtqueue_set_busyloop_timeout(dev, n, busyloop_timeout);
> +    if (dev->busyloop_timeout) {
> +        r = vhost_virtqueue_set_busyloop_timeout(dev, n, dev->busyloop_timeout);
>          if (r < 0) {
>              VHOST_OPS_DEBUG(r, "Failed to set busyloop timeout");
>              goto fail_err;
> @@ -1628,6 +1627,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
>
>      hdev->vdev = NULL;
>      hdev->migration_blocker = NULL;
> +    hdev->busyloop_timeout = busyloop_timeout;
>
>      r = vhost_set_backend_type(hdev, backend_type);
>      assert(r >= 0);
> @@ -1650,8 +1650,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
>      }
>
>      for (i = 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) {
> -        r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i,
> -                                 busyloop_timeout);
> +        r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i);
>          if (r < 0) {
>              error_setg_errno(errp, -r, "Failed to initialize virtqueue %d", i);
>              goto fail;
> diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
> index 1ba1af1d86..f1a7e7b971 100644
> --- a/include/hw/virtio/vhost.h
> +++ b/include/hw/virtio/vhost.h
> @@ -105,6 +105,7 @@ struct vhost_dev {
>      VIRTIO_DECLARE_FEATURES(_features);
>      VIRTIO_DECLARE_FEATURES(acked_features);
>
> +    uint32_t busyloop_timeout;
>      uint64_t max_queues;
>      uint64_t backend_cap;
>      /* @started: is the vhost device started? */
> --
> 2.48.1
>
>