@samitouri / QOSamiQemu / commits / 60abdf60d5

vhost: move vrings mapping to the top of vhost_virtqueue_start()

This simplifies further refactoring and final introduction of vhost backend live migration. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Reviewed-by: Raphael Norwitz <raphael.s.norwitz@gmail.com> Reviewed-by: Daniil Tatianin <d-tatianin@yandex-team.ru> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20260420200339.708640-14-vsementsov@yandex-team.ru>

Vladimir Sementsov-Ogievskiy committed Apr 20, 2026 at 23:03 UTC 60abdf60d505748a729b05de2864813f20f4b8f4
1 file changed +22 -23
hw/virtio/vhost.c
+22 -23
@@ -1303,29 +1303,6 @@ int vhost_virtqueue_start(struct vhost_dev *dev,
1303 return 0;
1304 }
1305
1306 - vq->num = state.num = virtio_queue_get_num(vdev, idx);
1307 - r = dev->vhost_ops->vhost_set_vring_num(dev, &state);
1308 - if (r) {
1309 - VHOST_OPS_DEBUG(r, "vhost_set_vring_num failed");
1310 - return r;
1311 - }
1312 -
1313 - state.num = virtio_queue_get_last_avail_idx(vdev, idx);
1314 - r = dev->vhost_ops->vhost_set_vring_base(dev, &state);
1315 - if (r) {
1316 - VHOST_OPS_DEBUG(r, "vhost_set_vring_base failed");
1317 - return r;
1318 - }
1319 -
1320 - if (vhost_needs_vring_endian(vdev)) {
1321 - r = vhost_virtqueue_set_vring_endian_legacy(dev,
1322 - virtio_vdev_is_big_endian(vdev),
1323 - vhost_vq_index);
1324 - if (r) {
1325 - return r;
1326 - }
1327 - }
1328 -
1306 l = vq->desc_size;
1307 vq->desc = vhost_memory_map(dev, vq->desc_phys, l, false);
1308 if (!vq->desc) {
@@ -1347,6 +1324,28 @@ int vhost_virtqueue_start(struct vhost_dev *dev,
1324 goto fail;
1325 }
1326
1327 + vq->num = state.num = virtio_queue_get_num(vdev, idx);
1328 + r = dev->vhost_ops->vhost_set_vring_num(dev, &state);
1329 + if (r) {
1330 + VHOST_OPS_DEBUG(r, "vhost_set_vring_num failed");
1331 + goto fail;
1332 + }
1333 +
1334 + state.num = virtio_queue_get_last_avail_idx(vdev, idx);
1335 + r = dev->vhost_ops->vhost_set_vring_base(dev, &state);
1336 + if (r) {
1337 + VHOST_OPS_DEBUG(r, "vhost_set_vring_base failed");
1338 + goto fail;
1339 + }
1340 +
1341 + if (vhost_needs_vring_endian(vdev)) {
1342 + r = vhost_virtqueue_set_vring_endian_legacy(
1343 + dev, virtio_vdev_is_big_endian(vdev), vhost_vq_index);
1344 + if (r) {
1345 + goto fail;
1346 + }
1347 + }
1348 +
1349 r = vhost_virtqueue_set_addr(dev, vq, vhost_vq_index, dev->log_enabled);
1350 if (r < 0) {
1351 goto fail;