qemu-devel
[Top][All Lists]
Advanced

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

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


From: Eugenio Pérez
Subject: [RFC PATCH 2/3] vdpa: load guest offloads at device start
Date: Fri, 25 Nov 2022 15:38:58 +0100

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

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 net/vhost-vdpa.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index 2b4b85d8f8..7ce094bd67 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -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 = {
-- 
2.31.1




reply via email to

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