From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yuanhan Liu Subject: Re: [PATCH] virito: fix reuse index in nested loop Date: Mon, 13 Jun 2016 16:57:49 +0800 Message-ID: <20160613085749.GM10038@yliu-dev.sh.intel.com> References: <1465725945-95964-1-git-send-email-jianfeng.tan@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: dev@dpdk.org, huawei.xie@intel.com To: Jianfeng Tan Return-path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id B24324CE6 for ; Mon, 13 Jun 2016 10:55:52 +0200 (CEST) Content-Disposition: inline In-Reply-To: <1465725945-95964-1-git-send-email-jianfeng.tan@intel.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Sun, Jun 12, 2016 at 10:05:45AM +0000, Jianfeng Tan wrote: > This patches fixes problem of reusing index of outmost loop in nested > loops. This bug will lead to failure when starting a multi queue > virtio device: rx queues (except from the first one) cannot be started, > expecially their vq_ring cannot be initialized, so that when invoking > rx func on these queues, segment fault happens. > > Fixes: a900472aedef ("virtio: split virtio Rx/Tx queue") Good catch! > Signed-off-by: Jianfeng Tan > --- > drivers/net/virtio/virtio_rxtx.c | 36 ++++++++++++++++++++---------------- > 1 file changed, 20 insertions(+), 16 deletions(-) > > diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c > index 2e7205b..b96d0cb 100644 > --- a/drivers/net/virtio/virtio_rxtx.c > +++ b/drivers/net/virtio/virtio_rxtx.c > @@ -331,7 +331,7 @@ virtio_dev_rxtx_start(struct rte_eth_dev *dev) > * - Allocate blank mbufs for the each rx descriptor > * > */ > - int i; > + int i, j; However, I don't quite like using "i, j, k" stuff. So, how about renaming "j" to "ring_idx"? > PMD_INIT_FUNC_TRACE(); > > @@ -352,15 +352,18 @@ virtio_dev_rxtx_start(struct rte_eth_dev *dev) > error = ENOSPC; > > #ifdef RTE_MACHINE_CPUFLAG_SSSE3 > - if (use_simple_rxtx) > - for (i = 0; i < vq->vq_nentries; i++) { > - vq->vq_ring.avail->ring[i] = i; > - vq->vq_ring.desc[i].flags = VRING_DESC_F_WRITE; > + if (use_simple_rxtx) { > + uint16_t k; We could reuse "ring_idx" here; no need to define yet another iterate var for that. --yliu