All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yuri Benditovich <yuri.benditovich@daynix.com>
To: mst@redhat.com, jasowang@redhat.com, berrange@redhat.com
Cc: yan@daynix.com, qemu-devel@nongnu.org
Subject: [RFC PATCH v2 3/3] virtio-net: implement missing_features_migrated callback
Date: Mon, 22 Mar 2021 14:24:52 +0200	[thread overview]
Message-ID: <20210322122452.369750-4-yuri.benditovich@daynix.com> (raw)
In-Reply-To: <20210322122452.369750-1-yuri.benditovich@daynix.com>

Graceful drop to userspace virtio in case selected features
are missing on the destination system. Currently used for
3 features that might be supported by the vhost kernel on
the source machine and not supported on the destination machine:
rss, hash reporting, packed ring.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
---
 hw/net/virtio-net.c | 51 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 96a3cc8357..97afca34e7 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -527,6 +527,15 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
     return info;
 }
 
+static void virtio_net_allow_vhost(VirtIONet *n, bool allow)
+{
+    int i;
+    for (i = 0; i < n->max_queues; i++) {
+        NetClientState *nc = qemu_get_subqueue(n->nic, i)->peer;
+        nc->vhost_net_disabled = !allow;
+    }
+}
+
 static void virtio_net_reset(VirtIODevice *vdev)
 {
     VirtIONet *n = VIRTIO_NET(vdev);
@@ -564,6 +573,7 @@ static void virtio_net_reset(VirtIODevice *vdev)
             assert(!virtio_net_get_subqueue(nc)->async_tx.elem);
         }
     }
+    virtio_net_allow_vhost(n, true);
 }
 
 static void peer_test_vnet_hdr(VirtIONet *n)
@@ -701,6 +711,27 @@ static void virtio_net_set_queues(VirtIONet *n)
     }
 }
 
+static bool can_disable_vhost(VirtIONet *n)
+{
+    NetClientState *peer = qemu_get_queue(n->nic)->peer;
+    NetdevInfo *ndi;
+    if (!get_vhost_net(peer)) {
+        return false;
+    }
+    if (!peer) {
+        return true;
+    }
+    if (peer->info->type != NET_CLIENT_DRIVER_TAP) {
+        return false;
+    }
+    ndi = peer->stored_config;
+    if (ndi && ndi->u.tap.has_vhostforce && ndi->u.tap.vhostforce) {
+        printf("vhost forced, can't drop it\n");
+        return false;
+    }
+    return true;
+}
+
 static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue);
 
 static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
@@ -3433,6 +3464,25 @@ static bool dev_unplug_pending(void *opaque)
     return vdc->primary_unplug_pending(dev);
 }
 
+static bool virtio_net_missing_features_migrated(VirtIODevice *vdev,
+                                                 uint64_t missing)
+{
+    VirtIONet *n = VIRTIO_NET(vdev);
+    bool disable_vhost = false;
+    if (virtio_has_feature(missing, VIRTIO_NET_F_HASH_REPORT) ||
+        virtio_has_feature(missing, VIRTIO_NET_F_RSS) ||
+        virtio_has_feature(missing, VIRTIO_F_RING_PACKED)) {
+        disable_vhost = true;
+    }
+    disable_vhost = disable_vhost && can_disable_vhost(n);
+    if (disable_vhost) {
+        warn_report("falling back to userspace virtio due to missing"
+                    " features %lx", missing);
+        virtio_net_allow_vhost(n, false);
+    }
+    return disable_vhost;
+}
+
 static const VMStateDescription vmstate_virtio_net = {
     .name = "virtio-net",
     .minimum_version_id = VIRTIO_NET_VM_VERSION,
@@ -3527,6 +3577,7 @@ static void virtio_net_class_init(ObjectClass *klass, void *data)
     vdc->get_features = virtio_net_get_features;
     vdc->set_features = virtio_net_set_features;
     vdc->bad_features = virtio_net_bad_features;
+    vdc->missing_features_migrated = virtio_net_missing_features_migrated;
     vdc->reset = virtio_net_reset;
     vdc->set_status = virtio_net_set_status;
     vdc->guest_notifier_mask = virtio_net_guest_notifier_mask;
-- 
2.26.2



  parent reply	other threads:[~2021-03-22 12:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22 12:24 [RFC PATCH v2 0/3] virtio-net: graceful drop of vhost for TAP Yuri Benditovich
2021-03-22 12:24 ` [RFC PATCH v2 1/3] net: add ability to hide (disable) vhost_net Yuri Benditovich
2021-03-22 12:24 ` [RFC PATCH v2 2/3] virtio: introduce 'missing_features_migrated' device callback Yuri Benditovich
2021-03-22 12:24 ` Yuri Benditovich [this message]
2021-03-25  6:59 ` [RFC PATCH v2 0/3] virtio-net: graceful drop of vhost for TAP Jason Wang
2021-03-25  9:00   ` Yuri Benditovich
2021-03-26  7:51     ` Jason Wang
2021-03-26  9:09       ` Yuri Benditovich
2021-03-26  9:18         ` Jason Wang
2021-04-02  5:05           ` Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210322122452.369750-4-yuri.benditovich@daynix.com \
    --to=yuri.benditovich@daynix.com \
    --cc=berrange@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yan@daynix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.