This will send CVQ commands in the destination machine, seting up everything o there is no guest-visible change.
Signed-off-by: Eugenio Pérez <epere...@redhat.com> --- net/vhost-vdpa.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 38e6912255..15c3e4f703 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -203,10 +203,73 @@ static ssize_t vhost_vdpa_receive(NetClientState *nc, const uint8_t *buf, return 0; } +static bool vhost_vdpa_start_control_svq(VhostShadowVirtqueue *svq, + VirtIODevice *vdev) +{ + VirtIONet *n = VIRTIO_NET(vdev); + uint64_t features = vdev->host_features; + + if (features & BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR)) { + const struct virtio_net_ctrl_hdr ctrl = { + .class = VIRTIO_NET_CTRL_MAC, + .cmd = VIRTIO_NET_CTRL_MAC_ADDR_SET, + }; + uint8_t mac[6]; + const struct iovec data[] = { + { + .iov_base = (void *)&ctrl, + .iov_len = sizeof(ctrl), + },{ + .iov_base = mac, + .iov_len = sizeof(mac), + },{ + .iov_base = NULL, + .iov_len = sizeof(virtio_net_ctrl_ack), + } + }; + bool ret; + + /* TODO: Only best effort? */ + memcpy(mac, n->mac, sizeof(mac)); + ret = vhost_svq_inject(svq, data, 2, 1); + if (!ret) { + return false; + } + } + + return true; +} + +static void vhost_vdpa_start(NetClientState *nc) +{ + assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); + VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); + struct vhost_vdpa *v = &s->vhost_vdpa; + struct vhost_dev *dev = &s->vhost_net->dev; + VhostShadowVirtqueue *svq; + + if (nc->is_datapath) { + /* This is not the cvq dev */ + return; + } + + if (dev->vq_index + dev->nvqs != dev->vq_index_end) { + return; + } + + if (!v->shadow_vqs_enabled) { + return; + } + + svq = g_ptr_array_index(v->shadow_vqs, 0); + vhost_vdpa_start_control_svq(svq, dev->vdev); +} + static NetClientInfo net_vhost_vdpa_info = { .type = NET_CLIENT_DRIVER_VHOST_VDPA, .size = sizeof(VhostVDPAState), .receive = vhost_vdpa_receive, + .start = vhost_vdpa_start, .cleanup = vhost_vdpa_cleanup, .has_vnet_hdr = vhost_vdpa_has_vnet_hdr, .has_ufo = vhost_vdpa_has_ufo, -- 2.27.0