From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id D86AB29CA for ; Thu, 7 Dec 2017 11:30:09 +0100 (CET) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Dec 2017 02:30:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,372,1508828400"; d="scan'208";a="184899204" Received: from deepin-15.sh.intel.com (HELO debian-xvivbkq) ([10.67.104.165]) by fmsmga006.fm.intel.com with ESMTP; 07 Dec 2017 02:30:07 -0800 Date: Thu, 7 Dec 2017 18:29:37 +0800 From: Tiwei Bie To: Maxime Coquelin Cc: dev@dpdk.org, yliu@fridaylinux.org, jianfeng.tan@intel.com, lprosek@redhat.com, lersek@redhat.com Message-ID: <20171207102937.im52kcwlxvinthzu@debian-xvivbkq> References: <20171206092048.3568-1-maxime.coquelin@redhat.com> <20171206092048.3568-2-maxime.coquelin@redhat.com> <20171207080820.jkzcam47deipsqcv@debian-xvivbkq> <041f54c0-4222-eedc-615d-4aa6c2503438@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <041f54c0-4222-eedc-615d-4aa6c2503438@redhat.com> User-Agent: NeoMutt/20170609 (1.8.3) Subject: Re: [dpdk-dev] [PATCH v3 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: Thu, 07 Dec 2017 10:30:10 -0000 On Thu, Dec 07, 2017 at 09:39:06AM +0100, Maxime Coquelin wrote: > On 12/07/2017 09:08 AM, Tiwei Bie wrote: > > On Wed, Dec 06, 2017 at 10:20:45AM +0100, Maxime Coquelin wrote: > > > 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..2d86c0ca8 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->features == features) > > > + return 0; > > > + > > > > We couldn't return directly when dev->features == features. > > Otherwise, if the features provided by virtio driver is 0, > > dev->vhost_hlen won't get a chance to be initialized. > > Good catch. > > Either we do : > if ((dev->features == features) && dev->vhost_len) > return 0; > > Or we could initialize dev->vhost_len to sizeof(struct virtio_net_hdr) > at alloc time. > > I prefer the former, what do you think? > I prefer to give other code (e.g. LOG code) a chance to run. So maybe we could remove the "fast return" and check whether the features are changed when calling dev->notify_ops->features_changed()? Or return only when device is running and features are not changed? Best regards, Tiwei Bie