Skip to contentSkip to conversation

VIRTIO_NET_F_CTRL_GUEST_OFFLOADS vDPA Shadow VirtQueue implementation

RFC PATCH New Eugenio Pérez 1 participant 4 messages Nov 25, 2022 Networking

lore
Share & tools
lore
#0 lore raw

cover VIRTIO_NET_F_CTRL_GUEST_OFFLOADS vDPA Shadow VirtQueue implementation

This feature allows the driver to send control commands for dynamic offloads state configuration.

When a guest is migrated the destination device needs to be restored with the same offloads. As other features configurable via CVQ, intercept the control messages, update the device model and load that configuration at device restore.

Only tested with modified vdpa_sim_net. Comments are welcome.

Eugenio Pérez (3):
virtio_net: export virtio_net_guest_offloads_by_features
vdpa: load guest offloads at device start
vdpa: add VIRTIO_NET_F_CTRL_GUEST_OFFLOADS to SVQ features

 include/hw/virtio/virtio-net.h |  1 +
 hw/net/virtio-net.c            |  2 +-
 net/vhost-vdpa.c               | 32 ++++++++++++++++++++++++++++++--
 3 files changed, 32 insertions(+), 3 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

RFC PATCH 1/3 virtio_net: export virtio_net_guest_offloads_by_features

vdpa NIC can use it to know if it needs to restore guest offloads at startup / migration.

---
 include/hw/virtio/virtio-net.h | 1 +
 hw/net/virtio-net.c            | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
include/hw/virtio/virtio-net.h +1 -0
index ef234ffe7e..491eafef16 100644
@@ -221,6 +221,7 @@ struct VirtIONet {
     struct EBPFRSSContext ebpf_rss;
 };
 
+uint64_t virtio_net_guest_offloads_by_features(uint32_t features);
 size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev,
                                   const struct iovec *in_sg, unsigned in_num,
                                   const struct iovec *out_sg,
hw/net/virtio-net.c +1 -1
index aba12759d5..87eb086dee 100644
@@ -845,7 +845,7 @@ static void virtio_net_apply_guest_offloads(VirtIONet *n)
             !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_UFO)));
 }
 
-static uint64_t virtio_net_guest_offloads_by_features(uint32_t features)
+uint64_t virtio_net_guest_offloads_by_features(uint32_t features)
 {
     static const uint64_t guest_offloads_mask =
         (1ULL << VIRTIO_NET_F_GUEST_CSUM) |
Signature · 1 line
2.31.1
#2 lore raw

RFC PATCH 2/3 vdpa: load guest offloads at device start

In reply to Eugenio Pérez

This allows to migrate them. Save some device's startup time if they are the default.

---
 net/vhost-vdpa.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)
net/vhost-vdpa.c +29 -2
index 2b4b85d8f8..7ce094bd67 100644
@@ -423,6 +423,34 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,
     return *s->status != VIRTIO_NET_OK;
 }
 
+static int vhost_vdpa_net_load_offloads(VhostVDPAState *s,
+                                        const VirtIONet *n)
+{
+    uint64_t features = n->parent_obj.guest_features;
+    uint64_t guest_offloads_mask;
+    ssize_t dev_written;
+
+    if (!n->has_vnet_hdr || !(features & VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
+        return 0;
+    }
+
+    if (n->curr_guest_offloads ==
+        virtio_net_guest_offloads_by_features(features)) {
+        return 0;
+    }
+
+    guest_offloads_mask = cpu_to_le64(n->curr_guest_offloads);
+    dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_GUEST_OFFLOADS,
+                                          VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET,
+                                          &guest_offloads_mask,
+                                          sizeof(uint64_t));
+    if (unlikely(dev_written < 0)) {
+        return dev_written;
+    }
+
+    return *s->status != VIRTIO_NET_OK;
+}
+
 static int vhost_vdpa_net_load(NetClientState *nc)
 {
     VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);
@@ -445,8 +473,7 @@ static int vhost_vdpa_net_load(NetClientState *nc)
     if (unlikely(r)) {
         return r;
     }
-
-    return 0;
+    return vhost_vdpa_net_load_offloads(s, n);
 }
 
 static NetClientInfo net_vhost_vdpa_cvq_info = {
Signature · 1 line
2.31.1
#3 lore raw

RFC PATCH 3/3 vdpa: add VIRTIO_NET_F_CTRL_GUEST_OFFLOADS to SVQ features

In reply to Eugenio Pérez

This way it is possible to migrate them.

---
 net/vhost-vdpa.c | 1 +
 1 file changed, 1 insertion(+)
net/vhost-vdpa.c +1 -0
index 7ce094bd67..eca0184d3a 100644
@@ -81,6 +81,7 @@ const int vdpa_feature_bits[] = {
 static const uint64_t vdpa_svq_device_features =
     BIT_ULL(VIRTIO_NET_F_CSUM) |
     BIT_ULL(VIRTIO_NET_F_GUEST_CSUM) |
+    BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) |
     BIT_ULL(VIRTIO_NET_F_MTU) |
     BIT_ULL(VIRTIO_NET_F_MAC) |
     BIT_ULL(VIRTIO_NET_F_GUEST_TSO4) |

--
2.31.1