From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <huawei.xie@intel.com>
Received: from mga09.intel.com (mga09.intel.com [134.134.136.24])
 by dpdk.org (Postfix) with ESMTP id 235372BE4
 for <dev@dpdk.org>; Mon, 25 Apr 2016 09:33:58 +0200 (CEST)
Received: from orsmga001.jf.intel.com ([10.7.209.18])
 by orsmga102.jf.intel.com with ESMTP; 25 Apr 2016 00:33:57 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.24,531,1455004800"; d="scan'208";a="939490394"
Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205])
 by orsmga001.jf.intel.com with ESMTP; 25 Apr 2016 00:33:43 -0700
Received: from fmsmsx153.amr.corp.intel.com (10.18.125.6) by
 fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS)
 id 14.3.248.2; Mon, 25 Apr 2016 00:33:42 -0700
Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by
 FMSMSX153.amr.corp.intel.com (10.18.125.6) with Microsoft SMTP Server (TLS)
 id 14.3.248.2; Mon, 25 Apr 2016 00:33:42 -0700
Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.136]) by
 SHSMSX104.ccr.corp.intel.com ([169.254.5.184]) with mapi id 14.03.0248.002;
 Mon, 25 Apr 2016 15:33:40 +0800
From: "Xie, Huawei" <huawei.xie@intel.com>
To: "Tan, Jianfeng" <jianfeng.tan@intel.com>, "dev@dpdk.org" <dev@dpdk.org>
CC: "yuanhan.liu@linux.intel.com" <yuanhan.liu@linux.intel.com>, "Stephen
 Hemminger" <stephen@networkplumber.org>
Thread-Topic: [PATCH v2] virtio: fix segfault when transmit pkts
Thread-Index: AdGexMlnk4tr0GkvWUC33ZQUXpHbnw==
Date: Mon, 25 Apr 2016 07:33:40 +0000
Message-ID: <C37D651A908B024F974696C65296B57B4C71F13E@SHSMSX101.ccr.corp.intel.com>
References: <1461242170-146337-1-git-send-email-jianfeng.tan@intel.com>
 <1461551865-15930-1-git-send-email-jianfeng.tan@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 v2] virtio: fix segfault when transmit pkts
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Mon, 25 Apr 2016 07:33:59 -0000

On 4/25/2016 10:37 AM, Tan, Jianfeng wrote:=0A=
> Issue: when using virtio nic to transmit pkts, it causes segment fault.=
=0A=
>=0A=
> How to reproduce:=0A=
> Basically, we need to construct a case with vm send packets to vhost-user=
,=0A=
> and this issue does not happen when transmitting packets using indirect=
=0A=
> desc. Besides, make sure all descriptors are exhausted before vhost=0A=
> dequeues any packets.=0A=
>=0A=
> a. start testpmd with vhost.=0A=
>   $ testpmd -c 0x3 -n 4 --socket-mem 1024,0 --no-pci \=0A=
>     --vdev 'eth_vhost0,iface=3D/tmp/sock0,queues=3D1' -- -i --nb-cores=3D=
1=0A=
>=0A=
> b. start a qemu with a virtio nic connected with the vhost-user port, jus=
t=0A=
> make sure mrg_rxbuf is enabled.=0A=
>=0A=
> c. enable testpmd on the host.=0A=
>   testpmd> set fwd io=0A=
>   testpmd> start (better without start vhost-user)=0A=
>=0A=
> d. start testpmd in VM.=0A=
>   $testpmd -c 0x3 -n 4 -m 1024 -- -i --disable-hw-vlan-filter --txqflags=
=3D0xf01=0A=
>   testpmd> set fwd txonly=0A=
>   testpmd> start=0A=
>=0A=
> How to fix: this bug is because inside virtqueue_enqueue_xmit(), the flag=
 of=0A=
> desc has been updated inside the do {} while (), not necessary to update =
after=0A=
> the loop. (And if we do that after the loop, if all descs could have run =
out,=0A=
> idx is VQ_RING_DESC_CHAIN_END (32768), use this idx to reference the star=
t_dp=0A=
> array will lead to segment fault.)=0A=
>=0A=
> Fixes: dd856dfcb9e ("virtio: use any layout on Tx")=0A=
>=0A=
> Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>=0A=
> ---=0A=
>  v2: refine the commit message.=0A=
>=0A=
>  drivers/net/virtio/virtio_rxtx.c | 2 --=0A=
>  1 file changed, 2 deletions(-)=0A=
>=0A=
> diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio=
_rxtx.c=0A=
> index ef21d8e..432aeab 100644=0A=
> --- a/drivers/net/virtio/virtio_rxtx.c=0A=
> +++ b/drivers/net/virtio/virtio_rxtx.c=0A=
> @@ -271,8 +271,6 @@ virtqueue_enqueue_xmit(struct virtqueue *txvq, struct=
 rte_mbuf *cookie,=0A=
>  		idx =3D start_dp[idx].next;=0A=
>  	} while ((cookie =3D cookie->next) !=3D NULL);=0A=
>  =0A=
> -	start_dp[idx].flags &=3D ~VRING_DESC_F_NEXT;=0A=
> -=0A=
>  	if (use_indirect)=0A=
>  		idx =3D txvq->vq_ring.desc[head_idx].next;=0A=
>  =0A=
=0A=
Ack the code.=0A=
=0A=
Acked-by: Huawei Xie <huawei.xie@intel.com>=0A=