From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id E04E9F72 for ; Mon, 21 Dec 2015 10:03:17 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 21 Dec 2015 01:03:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,458,1444719600"; d="scan'208";a="875830668" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga002.jf.intel.com with ESMTP; 21 Dec 2015 01:03:17 -0800 Received: from fmsmsx112.amr.corp.intel.com (10.18.116.6) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.248.2; Mon, 21 Dec 2015 01:03:16 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.110.15) by FMSMSX112.amr.corp.intel.com (10.18.116.6) with Microsoft SMTP Server (TLS) id 14.3.248.2; Mon, 21 Dec 2015 01:03:16 -0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.190]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.151]) with mapi id 14.03.0248.002; Mon, 21 Dec 2015 17:03:14 +0800 From: "Qiu, Michael" To: "Iremonger, Bernard" , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH] librte_ether: fix crashes in rte_ethdev functions. Thread-Index: AQHROO/UmpUTQo5ZyUOEPvtR/E1pSw== Date: Mon, 21 Dec 2015 09:03:13 +0000 Message-ID: <533710CFB86FA344BFBF2D6802E6028622EFB065@SHSMSX101.ccr.corp.intel.com> References: <1450373016-16356-1-git-send-email-bernard.iremonger@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] librte_ether: fix crashes in rte_ethdev functions. X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Dec 2015 09:03:18 -0000 On 2015/12/18 1:24, Bernard Iremonger wrote:=0A= > The nb_rx_queues and nb_tx_queues are initialised before=0A= > the tx_queue and rx_queue arrays are allocated. The arrays=0A= > are allocated when the ethdev port is started.=0A= >=0A= > If any of the following functions are called before the ethdev=0A= > port is started there is a segmentation fault:=0A= >=0A= > rte_eth_stats_get=0A= > rte_eth_stats_reset=0A= > rte_eth_xstats_get=0A= > rte_eth_xstats_reset=0A= >=0A= > Fixes: af75078fece3 ("first public release")=0A= > Fixes: ce757f5c9a4d ("ethdev: new method to retrieve extended statistics"= )=0A= > Fixes: d4fef8b0d5e5 ("ethdev: expose generic and driver specific stats in= xstats")=0A= > Signed-off-by: Bernard Iremonger =0A= > ---=0A= > lib/librte_ether/rte_ethdev.c | 16 ++++++++++++----=0A= > 1 file changed, 12 insertions(+), 4 deletions(-)=0A= >=0A= > diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.= c=0A= > index ed971b4..a0ee84d 100644=0A= > --- a/lib/librte_ether/rte_ethdev.c=0A= > +++ b/lib/librte_ether/rte_ethdev.c=0A= > @@ -1441,7 +1441,10 @@ rte_eth_stats_get(uint8_t port_id, struct rte_eth_= stats *stats)=0A= > memset(stats, 0, sizeof(*stats));=0A= > =0A= > RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);=0A= > - (*dev->dev_ops->stats_get)(dev, stats);=0A= > +=0A= > + if (dev->data->dev_started)=0A= > + (*dev->dev_ops->stats_get)(dev, stats);=0A= > +=0A= =0A= My question is should we mark an error or a warning here and return an=0A= error so that the caller knows what happens?=0A= =0A= Thanks,=0A= Michael=0A= =0A= > stats->rx_nombuf =3D dev->data->rx_mbuf_alloc_failed;=0A= > return 0;=0A= > }=0A= > @@ -1455,7 +1458,10 @@ rte_eth_stats_reset(uint8_t port_id)=0A= > dev =3D &rte_eth_devices[port_id];=0A= > =0A= > RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);=0A= > - (*dev->dev_ops->stats_reset)(dev);=0A= > +=0A= > + if (dev->data->dev_started)=0A= > + (*dev->dev_ops->stats_reset)(dev);=0A= > +=0A= > dev->data->rx_mbuf_alloc_failed =3D 0;=0A= > }=0A= > =0A= > @@ -1479,7 +1485,8 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_= xstats *xstats,=0A= > (dev->data->nb_tx_queues * RTE_NB_TXQ_STATS);=0A= > =0A= > /* implemented by the driver */=0A= > - if (dev->dev_ops->xstats_get !=3D NULL) {=0A= > + if ((dev->dev_ops->xstats_get !=3D NULL) &&=0A= > + (dev->data->dev_started)) {=0A= > /* Retrieve the xstats from the driver at the end of the=0A= > * xstats struct.=0A= > */=0A= > @@ -1548,7 +1555,8 @@ rte_eth_xstats_reset(uint8_t port_id)=0A= > dev =3D &rte_eth_devices[port_id];=0A= > =0A= > /* implemented by the driver */=0A= > - if (dev->dev_ops->xstats_reset !=3D NULL) {=0A= > + if ((dev->dev_ops->xstats_reset !=3D NULL) &&=0A= > + (dev->data->dev_started)) {=0A= > (*dev->dev_ops->xstats_reset)(dev);=0A= > return;=0A= > }=0A= =0A=