From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7156BA057B; Wed, 15 Apr 2020 03:06:49 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C0B401D381; Wed, 15 Apr 2020 03:06:48 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id A4C9B1D178 for ; Wed, 15 Apr 2020 03:06:47 +0200 (CEST) IronPort-SDR: VZVdLkXTolj6uxZPRTi4TVeW/MbYxE7cQo9y9ni8PKH0aoelTAMPiW5SgFGHsh060ZjsNmKlvP Se0sYQz1zALA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2020 18:06:46 -0700 IronPort-SDR: zlxXft18BxiCMqtLCBgKs+nck3IfpK/ERWq/Rp01pPWlvhn6M9+1IFA2oRj7VtjwWDM3Io7+9J xVxRGfTP2wPA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,385,1580803200"; d="scan'208";a="363534879" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga001.fm.intel.com with ESMTP; 14 Apr 2020 18:06:46 -0700 Received: from shsmsx603.ccr.corp.intel.com (10.109.6.143) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 14 Apr 2020 18:06:45 -0700 Received: from shsmsx603.ccr.corp.intel.com (10.109.6.143) by SHSMSX603.ccr.corp.intel.com (10.109.6.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 15 Apr 2020 09:06:43 +0800 Received: from shsmsx603.ccr.corp.intel.com ([10.109.6.143]) by SHSMSX603.ccr.corp.intel.com ([10.109.6.143]) with mapi id 15.01.1713.004; Wed, 15 Apr 2020 09:06:43 +0800 From: "Wang, Yinan" To: "Liu, Yong" , "maxime.coquelin@redhat.com" , "Wang, Zhihong" , "Ye, Xiaolong" CC: "dev@dpdk.org" , "Ding, Xuan" , "Liu, Yong" Thread-Topic: [dpdk-dev] [PATCH] net/virtio: fix crash when device reconnecting Thread-Index: AQHWEhykh0eq3yvjpUajjUYDiAafQ6h5X+Ew Date: Wed, 15 Apr 2020 01:06:43 +0000 Message-ID: References: <20200414125555.86601-1-yong.liu@intel.com> In-Reply-To: <20200414125555.86601-1-yong.liu@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-reaction: no-action dlp-version: 11.2.0.6 dlp-product: dlpe-windows x-originating-ip: [10.239.127.36] Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] net/virtio: fix crash when device reconnecting 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Tested-by: Wang, Yinan > -----Original Message----- > From: dev On Behalf Of Marvin Liu > Sent: 2020=1B$BG/=1B(B4=1B$B7n=1B(B14=1B$BF|=1B(B 20:56 > To: maxime.coquelin@redhat.com; Wang, Zhihong ; > Ye, Xiaolong > Cc: dev@dpdk.org; Ding, Xuan ; Liu, Yong > > Subject: [dpdk-dev] [PATCH] net/virtio: fix crash when device reconnectin= g >=20 > When doing virtio device initialization, virtqueues will be reset in serv= er mode if > ring type is packed. This will cause issue because queues have been freed= in the > beginning of device initialization. >=20 > Fix this issue by splitting device initial process and device reinit proc= ess. Virt > queues won't be freed or realloc in reinit process. Also moved virtio dev= ice > initialization from configuration to start stage, which can reduce number= of > reinitialization times. >=20 > Fixes: 6ebbf4109f35 ("net/virtio-user: fix packed ring server mode") >=20 > Signed-off-by: Marvin Liu >=20 > diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virt= io_ethdev.c > index 21570e5cf..8c84bfe91 100644 > --- a/drivers/net/virtio/virtio_ethdev.c > +++ b/drivers/net/virtio/virtio_ethdev.c > @@ -1670,7 +1670,9 @@ virtio_configure_intr(struct rte_eth_dev *dev) >=20 > /* reset device and renegotiate features if needed */ static int - > virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features) > +virtio_init_device(struct rte_eth_dev *eth_dev, > + uint64_t req_features, > + bool reinit) > { > struct virtio_hw *hw =3D eth_dev->data->dev_private; > struct virtio_net_config *config; > @@ -1681,7 +1683,7 @@ virtio_init_device(struct rte_eth_dev *eth_dev, > uint64_t req_features) > /* Reset the device although not necessary at startup */ > vtpci_reset(hw); >=20 > - if (hw->vqs) { > + if (hw->vqs && !reinit) { > virtio_dev_free_mbufs(eth_dev); > virtio_free_queues(hw); > } > @@ -1794,9 +1796,11 @@ virtio_init_device(struct rte_eth_dev *eth_dev, > uint64_t req_features) > VLAN_TAG_LEN - hw->vtnet_hdr_size; > } >=20 > - ret =3D virtio_alloc_queues(eth_dev); > - if (ret < 0) > - return ret; > + if (!reinit) { > + ret =3D virtio_alloc_queues(eth_dev); > + if (ret < 0) > + return ret; > + } >=20 > if (eth_dev->data->dev_conf.intr_conf.rxq) { > if (virtio_configure_intr(eth_dev) < 0) { @@ -1925,7 +1929,8 > @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) > rte_spinlock_init(&hw->state_lock); >=20 > /* reset device and negotiate default features */ > - ret =3D virtio_init_device(eth_dev, > VIRTIO_PMD_DEFAULT_GUEST_FEATURES); > + ret =3D virtio_init_device(eth_dev, > VIRTIO_PMD_DEFAULT_GUEST_FEATURES, > + false); > if (ret < 0) > goto err_virtio_init; >=20 > @@ -2091,12 +2096,6 @@ virtio_dev_configure(struct rte_eth_dev *dev) > return -EINVAL; > } >=20 > - if (dev->data->dev_conf.intr_conf.rxq) { > - ret =3D virtio_init_device(dev, hw->req_guest_features); > - if (ret < 0) > - return ret; > - } > - > if (rxmode->max_rx_pkt_len > hw->max_mtu + ether_hdr_len) > req_features &=3D ~(1ULL << VIRTIO_NET_F_MTU); >=20 > @@ -2120,7 +2119,7 @@ virtio_dev_configure(struct rte_eth_dev *dev) >=20 > /* if request features changed, reinit the device */ > if (req_features !=3D hw->req_guest_features) { > - ret =3D virtio_init_device(dev, req_features); > + ret =3D virtio_negotiate_features(hw, req_features); > if (ret < 0) > return ret; > } > @@ -2235,6 +2234,11 @@ virtio_dev_start(struct rte_eth_dev *dev) > struct virtio_hw *hw =3D dev->data->dev_private; > int ret; >=20 > + /* reinit the device */ > + ret =3D virtio_init_device(dev, hw->req_guest_features, true); > + if (ret < 0) > + return ret; > + > /* Finish the initialization of the queues */ > for (i =3D 0; i < dev->data->nb_rx_queues; i++) { > ret =3D virtio_dev_rx_queue_setup_finish(dev, i); > -- > 2.17.1