From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 756921AEF5 for ; Mon, 11 Dec 2017 16:15:41 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8E8E22D1EF0; Mon, 11 Dec 2017 15:15:40 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-42.ams2.redhat.com [10.36.112.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id 269C45E9D5; Mon, 11 Dec 2017 15:15:36 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, yliu@fridaylinux.org, tiwei.bie@intel.com, jianfeng.tan@intel.com, lprosek@redhat.com, lersek@redhat.com Cc: Maxime Coquelin Date: Mon, 11 Dec 2017 16:15:00 +0100 Message-Id: <20171211151503.19195-2-maxime.coquelin@redhat.com> In-Reply-To: <20171211151503.19195-1-maxime.coquelin@redhat.com> References: <20171211151503.19195-1-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 11 Dec 2017 15:15:40 +0000 (UTC) Subject: [dpdk-dev] [PATCH v4 1/4] vhost: prevent features to be changed while device is running X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Dec 2017 15:15:41 -0000 As section 2.2 of the Virtio spec states about features negotiation: "During device initialization, the driver reads this and tells the device the subset that it accepts. The only way to renegotiate is to reset the device." This patch implements a check to prevent illegal features change while the device is running. One exception is the VHOST_F_LOG_ALL feature bit, which is enabled when live-migration is initiated. But this feature is not negotiated with the Virtio driver, but directly with the Vhost master. Signed-off-by: Maxime Coquelin --- lib/librte_vhost/vhost_user.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index f4c7ce462..545dbcb2b 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -183,7 +183,22 @@ vhost_user_set_features(struct virtio_net *dev, uint64_t features) return -1; } - if ((dev->flags & VIRTIO_DEV_RUNNING) && dev->features != features) { + if (dev->flags & VIRTIO_DEV_RUNNING) { + if (dev->features == features) + return 0; + + /* + * Error out if master tries to change features while device is + * in running state. The exception being VHOST_F_LOG_ALL, which + * is enabled when the live-migration starts. + */ + if ((dev->features ^ features) & ~(1ULL << VHOST_F_LOG_ALL)) { + RTE_LOG(ERR, VHOST_CONFIG, + "(%d) features changed while device is running.\n", + dev->vid); + return -1; + } + if (dev->notify_ops->features_changed) dev->notify_ops->features_changed(dev->vid, features); } -- 2.14.3