Blame SOURCES/0001-vhost-prevent-features-to-be-changed-while-device-is.patch

a6040a
From fec618a3fdcc88fa50089edb5748a6554ac49070 Mon Sep 17 00:00:00 2001
a6040a
From: Maxime Coquelin <maxime.coquelin@redhat.com>
a6040a
Date: Wed, 13 Dec 2017 09:51:06 +0100
a6040a
Subject: [PATCH 1/6] vhost: prevent features to be changed while device is
a6040a
 running
a6040a
a6040a
As section 2.2 of the Virtio spec states about features
a6040a
negotiation:
a6040a
"During device initialization, the driver reads this and tells
a6040a
the device the subset that it accepts. The only way to
a6040a
renegotiate is to reset the device."
a6040a
a6040a
This patch implements a check to prevent illegal features change
a6040a
while the device is running.
a6040a
a6040a
One exception is the VHOST_F_LOG_ALL feature bit, which is enabled
a6040a
when live-migration is initiated. But this feature is not negotiated
a6040a
with the Virtio driver, but directly with the Vhost master.
a6040a
a6040a
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
a6040a
Acked-by: Laszlo Ersek <lersek@redhat.com>
a6040a
Acked-by: Yuanhan Liu <yliu@fridaylinux.org>
a6040a
(cherry picked from commit 07f8db29b8833378dd506f3e197319f8b669aed9)
a6040a
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
a6040a
---
a6040a
 dpdk-17.11/lib/librte_vhost/vhost_user.c | 17 ++++++++++++++++-
a6040a
 1 file changed, 16 insertions(+), 1 deletion(-)
a6040a
a6040a
diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
a6040a
index f4c7ce462..545dbcb2b 100644
a6040a
--- a/lib/librte_vhost/vhost_user.c
a6040a
+++ b/lib/librte_vhost/vhost_user.c
a6040a
@@ -183,7 +183,22 @@ vhost_user_set_features(struct virtio_net *dev, uint64_t features)
a6040a
 		return -1;
a6040a
 	}
a6040a
 
a6040a
-	if ((dev->flags & VIRTIO_DEV_RUNNING) && dev->features != features) {
a6040a
+	if (dev->flags & VIRTIO_DEV_RUNNING) {
a6040a
+		if (dev->features == features)
a6040a
+			return 0;
a6040a
+
a6040a
+		/*
a6040a
+		 * Error out if master tries to change features while device is
a6040a
+		 * in running state. The exception being VHOST_F_LOG_ALL, which
a6040a
+		 * is enabled when the live-migration starts.
a6040a
+		 */
a6040a
+		if ((dev->features ^ features) & ~(1ULL << VHOST_F_LOG_ALL)) {
a6040a
+			RTE_LOG(ERR, VHOST_CONFIG,
a6040a
+				"(%d) features changed while device is running.\n",
a6040a
+				dev->vid);
a6040a
+			return -1;
a6040a
+		}
a6040a
+
a6040a
 		if (dev->notify_ops->features_changed)
a6040a
 			dev->notify_ops->features_changed(dev->vid, features);
a6040a
 	}
a6040a
-- 
a6040a
2.14.3
a6040a