[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v7 21/25] vdpa: Add vhost_vdpa_start_control_svq
From: |
Eugenio Pérez |
Subject: |
[RFC PATCH v7 21/25] vdpa: Add vhost_vdpa_start_control_svq |
Date: |
Wed, 13 Apr 2022 18:32:02 +0200 |
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 <eperezma@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
- Re: [RFC PATCH v7 16/25] vdpa: control virtqueue support on shadow virtqueue, (continued)
- [RFC PATCH v7 17/25] vhost: Add vhost_iova_tree_find, Eugenio Pérez, 2022/04/13
- [RFC PATCH v7 18/25] vdpa: Add map/unmap operation callback to SVQ, Eugenio Pérez, 2022/04/13
- [RFC PATCH v7 20/25] vdpa: add NetClientState->start() callback, Eugenio Pérez, 2022/04/13
- [RFC PATCH v7 19/25] vhost: Add vhost_svq_inject, Eugenio Pérez, 2022/04/13
- [RFC PATCH v7 22/25] vhost: Update kernel headers, Eugenio Pérez, 2022/04/13
- [RFC PATCH v7 21/25] vdpa: Add vhost_vdpa_start_control_svq,
Eugenio Pérez <=
- [RFC PATCH v7 23/25] vhost: Make possible to check for device exclusive vq group, Eugenio Pérez, 2022/04/13
- [RFC PATCH v7 24/25] vdpa: Add asid attribute to vdpa device, Eugenio Pérez, 2022/04/13
- [RFC PATCH v7 25/25] vdpa: Add x-cvq-svq, Eugenio Pérez, 2022/04/13