[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] vhost-net: Fix the virito features negotiation flaw
From: |
huangy81 |
Subject: |
[PATCH 2/2] vhost-net: Fix the virito features negotiation flaw |
Date: |
Mon, 26 Sep 2022 14:36:41 +0800 |
From: Hyman Huang(黄勇) <huangy81@chinatelecom.cn>
Save the acked_features once it be configured by guest
virtio driver so it can't miss any features.
Signed-off-by: Hyman Huang(黄勇) <huangy81@chinatelecom.cn>
Signed-off-by: Guoyi Tu <tugy@chinatelecom.cn>
---
hw/net/vhost_net.c | 9 +++++++++
hw/net/virtio-net.c | 5 +++++
include/net/vhost_net.h | 2 ++
3 files changed, 16 insertions(+)
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index d28f8b974b..2bffc276b9 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -141,6 +141,15 @@ uint64_t vhost_net_get_acked_features(VHostNetState *net)
return net->dev.acked_features;
}
+void vhost_net_save_acked_features(NetClientState *nc)
+{
+ if (nc->info->type != NET_CLIENT_DRIVER_VHOST_USER) {
+ return;
+ }
+
+ vhost_user_save_acked_features(nc, false);
+}
+
static int vhost_net_get_fd(NetClientState *backend)
{
switch (backend->info->type) {
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index dd0d056fde..69c00b4e74 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -918,6 +918,11 @@ static void virtio_net_set_features(VirtIODevice *vdev,
uint64_t features)
continue;
}
vhost_net_ack_features(get_vhost_net(nc->peer), features);
+ /*
+ * keep acked_features in NetVhostUserState up-to-date so it
+ * can't miss any features configured by guest virtio driver.
+ */
+ vhost_net_save_acked_features(nc->peer);
}
if (virtio_has_feature(features, VIRTIO_NET_F_CTRL_VLAN)) {
diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h
index 387e913e4e..3a5579b075 100644
--- a/include/net/vhost_net.h
+++ b/include/net/vhost_net.h
@@ -46,6 +46,8 @@ int vhost_set_vring_enable(NetClientState * nc, int enable);
uint64_t vhost_net_get_acked_features(VHostNetState *net);
+void vhost_net_save_acked_features(NetClientState *nc);
+
int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu);
#endif
--
2.27.0