qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH v9 00/23] Net Control VQ support in SVQ


From: Eugenio Pérez
Subject: [RFC PATCH v9 00/23] Net Control VQ support in SVQ
Date: Wed, 6 Jul 2022 20:39:45 +0200

Control virtqueue is used by networking device for accepting various
commands from the driver. It's a must to support multiqueue and other
configurations.

Shadow VirtQueue (SVQ) already makes possible migration of virtqueue
states, effectively intercepting them so qemu can track what regions of memory
are dirty because device action and needs migration. However, this does not
solve networking device state seen by the driver because CVQ messages, like
changes on MAC addresses from the driver.

This series uses SVQ infraestructure to intercept networking control messages
used by the device. This way, qemu is able to update VirtIONet device model and
to migrate it.

To intercept all queues slows device data forwarding, so this is not the final
solution. To solve that, only the CVQ must be intercepted all the time. This
will be achieved in future revisions using the ASID infraestructure, that
allows different translations for different virtqueues.

Another pending item is to move data virtqueues from passthrough mode to SVQ
one. To achieve that, a reliable way to obtain the vq state is needed. STOP
ioctl will be added for that.

To intercept all the virtqueues and update the qemu nic device model as the
guest changes the device state add the cmdline opt x-svq=on:

-netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-0,id=vhost-vdpa0,x-svq=on

Lastly, device state is sent each time qemu starts the device, using SVQ to
inject commands through CVQ. This allows the guest to transparently see the
same guest-visible state at resume.

First two patches reorder code so it's easier to apply later patches on top of
the code base.

Third patch reorders the device ok and the set_vring_enable ioctl sending. This
is done so CVQ commands reach the device before the device have the chance to
use rx queues, with incorrect data.

Fourth patch replaces the way of getting vq state. Since qemu will be able to
inject buffers, device's used_idx is not valid anymore and we must use
guest-visible one.

Fifth patch creates the API in SVQ to call when device start. This will allow
vhost-vdpa net to inject control commands before the rest of queues start.

Sixth path enables SVQ to return buffers externally. While it's not possible at
this point in the series, CVQ will need to return the available buffers

Patches 8-12 enables SVQ to communicate the caller of SVQ context data of the
used buffer.

Patch 13 enables vhost-vdpa net to inject buffers to the device. This will be
used both to inject the state at the beginning and to decouple guest's CVQ
buffers from the ones sent to the device. This brings protections against
TOCTOU, avoiding the device and qemu to see different messages. In the future,
this may also be used to emulate _F_ANNOUNCE.

The previous patch and patches from 14 to 17 makes SVQ capable of being
inspected.

Patches 18 to 20 enable the update of the virtio-net device model for each
CVQ message acknoledged by the device.

Patches 21-22 enables the update of the device configuration right at start.

Finally, last commit enables x-svq parameter.

Comments are welcomed.

TODO:
* Review failure paths, some are with TODO notes, other don't.

Changes from rfc v8:
* Remove ASID part. Delete x-svq-cvq mode too.
* Move all DMA memory management to net/vhost-vdpa, instead of svq.
* Use of qemu_real_host_page_size.
* Improved doc, general fixes.

Changes from rfc v7:
* Don't map all guest space in ASID 1 but copy all the buffers. No need for
  more memory listeners.
* Move net backend start callback to SVQ.
* Wait for device CVQ commands used by the device at SVQ start, avoiding races.
* Changed ioctls, but they're provisional anyway.
* Reorder commits so refactor and code adding ones are closer to usage.
* Usual cleaning: better tracing, doc, patches messages, ...

Changes from rfc v6:
* Fix bad iotlb updates order when batching was enabled
* Add reference counting to iova_tree so cleaning is simpler.

Changes from rfc v5:
* Fixes bad calculus of cvq end group when MQ is not acked by the guest.

Changes from rfc v4:
* Add missing tracing
* Add multiqueue support
* Use already sent version for replacing g_memdup
* Care with memory management

Changes from rfc v3:
* Fix bad returning of descriptors to SVQ list.

Changes from rfc v2:
* Fix use-after-free.

Changes from rfc v1:
* Rebase to latest master.
* Configure ASID instead of assuming cvq asid != data vqs asid.
* Update device model so (MAC) state can be migrated too.

Eugenio Pérez (23):
  vhost: Return earlier if used buffers overrun
  vhost: move descriptor translation to vhost_svq_vring_write_descs
  vdpa: delay set_vring_ready after DRIVER_OK
  vhost: Get vring base from vq, not svq
  vhost: Add ShadowVirtQueueStart operation
  virtio-net: Expose ctrl virtqueue logic
  vhost: add vhost_svq_push_elem
  vhost: Decouple vhost_svq_add_split from VirtQueueElement
  vhost: Add SVQElement
  vhost: Reorder vhost_svq_last_desc_of_chain
  vhost: Move last chain id to SVQ element
  vhost: Add opaque member to SVQElement
  vhost: Add vhost_svq_inject
  vhost: add vhost_svq_poll
  vhost: Add custom used buffer callback
  vhost: Add svq avail_handler callback
  vhost: add detach SVQ operation
  vdpa: Export vhost_vdpa_dma_map and unmap calls
  vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs
  vdpa: Buffer CVQ support on shadow virtqueue
  vdpa: Add vhost_vdpa_start_control_svq
  vdpa: Inject virtio-net mac address via CVQ at start
  vdpa: Add x-svq to NetdevVhostVDPAOptions

 qapi/net.json                      |   9 +-
 hw/virtio/vhost-shadow-virtqueue.h |  67 +++-
 include/hw/virtio/vhost-vdpa.h     |   7 +
 include/hw/virtio/virtio-net.h     |   4 +
 include/hw/virtio/virtio.h         |   1 +
 hw/net/virtio-net.c                |  84 +++--
 hw/virtio/vhost-shadow-virtqueue.c | 284 ++++++++++++---
 hw/virtio/vhost-vdpa.c             |  54 ++-
 hw/virtio/virtio.c                 |   5 +
 net/vhost-vdpa.c                   | 541 ++++++++++++++++++++++++++++-
 10 files changed, 935 insertions(+), 121 deletions(-)

-- 
2.31.1





reply via email to

[Prev in Thread] Current Thread [Next in Thread]