DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] virito: fix reuse index in nested loop
@ 2016-06-12 10:05 Jianfeng Tan
  2016-06-13  8:57 ` Yuanhan Liu
  0 siblings, 1 reply; 4+ messages in thread
From: Jianfeng Tan @ 2016-06-12 10:05 UTC (permalink / raw)
  To: dev; +Cc: yuanhan.liu, huawei.xie, Jianfeng Tan

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")

Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
 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;
 
 	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;
+
+			for (k = 0; k < vq->vq_nentries; k++) {
+				vq->vq_ring.avail->ring[k] = k;
+				vq->vq_ring.desc[k].flags = VRING_DESC_F_WRITE;
 			}
+		}
 #endif
 		memset(&rxvq->fake_mbuf, 0, sizeof(rxvq->fake_mbuf));
-		for (i = 0; i < RTE_PMD_VIRTIO_RX_MAX_BURST; i++)
-			vq->sw_ring[vq->vq_nentries + i] = &rxvq->fake_mbuf;
+		for (j = 0; j < RTE_PMD_VIRTIO_RX_MAX_BURST; j++)
+			vq->sw_ring[vq->vq_nentries + j] = &rxvq->fake_mbuf;
 
 		while (!virtqueue_full(vq)) {
 			m = rte_mbuf_raw_alloc(rxvq->mpool);
@@ -399,20 +402,21 @@ virtio_dev_rxtx_start(struct rte_eth_dev *dev)
 #ifdef RTE_MACHINE_CPUFLAG_SSSE3
 		if (use_simple_rxtx) {
 			int mid_idx  = vq->vq_nentries >> 1;
-			for (i = 0; i < mid_idx; i++) {
-				vq->vq_ring.avail->ring[i] = i + mid_idx;
-				vq->vq_ring.desc[i + mid_idx].next = i;
-				vq->vq_ring.desc[i + mid_idx].addr =
+
+			for (j = 0; j < mid_idx; j++) {
+				vq->vq_ring.avail->ring[j] = j + mid_idx;
+				vq->vq_ring.desc[j + mid_idx].next = j;
+				vq->vq_ring.desc[j + mid_idx].addr =
 					txvq->virtio_net_hdr_mem +
 					offsetof(struct virtio_tx_region, tx_hdr);
-				vq->vq_ring.desc[i + mid_idx].len =
+				vq->vq_ring.desc[j + mid_idx].len =
 					vq->hw->vtnet_hdr_size;
-				vq->vq_ring.desc[i + mid_idx].flags =
+				vq->vq_ring.desc[j + mid_idx].flags =
 					VRING_DESC_F_NEXT;
-				vq->vq_ring.desc[i].flags = 0;
+				vq->vq_ring.desc[j].flags = 0;
 			}
-			for (i = mid_idx; i < vq->vq_nentries; i++)
-				vq->vq_ring.avail->ring[i] = i;
+			for (j = mid_idx; j < vq->vq_nentries; j++)
+				vq->vq_ring.avail->ring[j] = j;
 		}
 #endif
 		VIRTQUEUE_DUMP(vq);
-- 
2.1.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-dev] [PATCH] virito: fix reuse index in nested loop
  2016-06-12 10:05 [dpdk-dev] [PATCH] virito: fix reuse index in nested loop Jianfeng Tan
@ 2016-06-13  8:57 ` Yuanhan Liu
  2016-06-13  9:11   ` Tan, Jianfeng
  0 siblings, 1 reply; 4+ messages in thread
From: Yuanhan Liu @ 2016-06-13  8:57 UTC (permalink / raw)
  To: Jianfeng Tan; +Cc: dev, huawei.xie

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 <jianfeng.tan@intel.com>
> ---
>  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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-dev] [PATCH] virito: fix reuse index in nested loop
  2016-06-13  8:57 ` Yuanhan Liu
@ 2016-06-13  9:11   ` Tan, Jianfeng
  2016-06-13  9:31     ` Yuanhan Liu
  0 siblings, 1 reply; 4+ messages in thread
From: Tan, Jianfeng @ 2016-06-13  9:11 UTC (permalink / raw)
  To: Yuanhan Liu; +Cc: dev, Xie, Huawei



> -----Original Message-----
> From: Yuanhan Liu [mailto:yuanhan.liu@linux.intel.com]
> Sent: Monday, June 13, 2016 4:58 PM
> To: Tan, Jianfeng
> Cc: dev@dpdk.org; Xie, Huawei
> Subject: Re: [PATCH] virito: fix reuse index in nested loop
> 
> 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 <jianfeng.tan@intel.com>
> > ---
> >  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.

Make sense. Besides, since comparison between unsigned and signed is a violation to static code analyzer, I'll redefine these variables as unsigned.
Such as,
int i -> uint16_t q_idx
int j -> uint16_t r_idx
k -> r_idx

Thanks,
Jianfeng

> 
> 	--yliu

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-dev] [PATCH] virito: fix reuse index in nested loop
  2016-06-13  9:11   ` Tan, Jianfeng
@ 2016-06-13  9:31     ` Yuanhan Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Yuanhan Liu @ 2016-06-13  9:31 UTC (permalink / raw)
  To: Tan, Jianfeng; +Cc: dev, Xie, Huawei

On Mon, Jun 13, 2016 at 09:11:57AM +0000, Tan, Jianfeng wrote:
> 
> 
> > -----Original Message-----
> > From: Yuanhan Liu [mailto:yuanhan.liu@linux.intel.com]
> > Sent: Monday, June 13, 2016 4:58 PM
> > To: Tan, Jianfeng
> > Cc: dev@dpdk.org; Xie, Huawei
> > Subject: Re: [PATCH] virito: fix reuse index in nested loop
> > 
> > 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 <jianfeng.tan@intel.com>
> > > ---
> > >  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.
> 
> Make sense. Besides, since comparison between unsigned and signed is a violation to static code analyzer, I'll redefine these variables as unsigned.
> Such as,
> int i -> uint16_t q_idx
> int j -> uint16_t r_idx
> k -> r_idx

It's nothing big deal, but if I were you, I would keep the var name "i"
unchanged (yes, we need define it to uint16_t), and introduce "ring_idx"
but not "r_idx": I will not sacrifice the readability by saving few
typings.

	--yliu

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-06-13  9:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-12 10:05 [dpdk-dev] [PATCH] virito: fix reuse index in nested loop Jianfeng Tan
2016-06-13  8:57 ` Yuanhan Liu
2016-06-13  9:11   ` Tan, Jianfeng
2016-06-13  9:31     ` Yuanhan Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).