From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yuanhan Liu Subject: Re: [PATCH] net/virtio-user: fix cannot get initialized Date: Thu, 13 Apr 2017 09:58:12 +0800 Message-ID: <20170413015812.GE7333@yliu-dev.sh.intel.com> References: <1491551860-15005-1-git-send-email-jianfeng.tan@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: dev@dpdk.org, Maxime Coquelin To: Jianfeng Tan Return-path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 98D382C27 for ; Thu, 13 Apr 2017 04:01:08 +0200 (CEST) Content-Disposition: inline In-Reply-To: <1491551860-15005-1-git-send-email-jianfeng.tan@intel.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Fri, Apr 07, 2017 at 07:57:40AM +0000, Jianfeng Tan wrote: > After the introduction of vhost MTU, VIRTIO_NET_F_MTU is enabled > by default. However, virtio-user vtpci does not support to get > MTU from device yet, i.e., vtpci_read_dev_config(MTU) fails. > Plus, struct virtio_net_config is defined as a uninitialized > variable, and could be different values in > virtio_negotiate_features() and virtio_init_device(). > > In some cases, it passes the check in virtio_negotiate_features() > but fails the check in virtio_init_device(). As a result, > virtio-user canno be initialized. > > To fix it, (1) accessing uninitialized variable is not a good > practice, so initialize it as zero; (2) explicitly disable MTU > feature in virtio-user. > > Fixes: 49d26d9e3f47 ("net/virtio: support MTU feature") > Cc: Maxime Coquelin > Cc: Yuanhan Liu > > Signed-off-by: Jianfeng Tan > --- > drivers/net/virtio/virtio_ethdev.c | 4 ++-- > drivers/net/virtio/virtio_user/virtio_user_dev.c | 6 ++++++ > 2 files changed, 8 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c > index 78cb3e8..4c43784 100644 > --- a/drivers/net/virtio/virtio_ethdev.c > +++ b/drivers/net/virtio/virtio_ethdev.c > @@ -1163,7 +1163,7 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features) > > /* If supported, ensure MTU value is valid before acknowledging it. */ > if (host_features & req_features & (1ULL << VIRTIO_NET_F_MTU)) { > - struct virtio_net_config config; > + struct virtio_net_config config = {0}; virtio-user does not support the MTU feature, this patch should not be reached. The virtio-user feature negotiation should be broken. --yliu > > vtpci_read_dev_config(hw, > offsetof(struct virtio_net_config, mtu), > @@ -1332,7 +1332,7 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features) > { > struct virtio_hw *hw = eth_dev->data->dev_private; > struct virtio_net_config *config; > - struct virtio_net_config local_config; > + struct virtio_net_config local_config = {0}; > struct rte_pci_device *pci_dev = NULL; > int ret; > > diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c > index 6871cd4..529b3d7 100644 > --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c > +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c > @@ -362,6 +362,12 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues, > /* The backend will not report this feature, we add it explicitly */ > dev->device_features |= (1ull << VIRTIO_NET_F_STATUS); > > + /* TODO: VIRTIO_NET_F_MTU is for QEMU to advertise MTU to both frontend > + * and backend driver. For virtio-user, disable it for now, until we > + * have a parameter to specify the MTU. > + */ > + dev->device_features &= ~(1ull << VIRTIO_NET_F_MTU); > + > return 0; > } > > -- > 2.7.4