From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from tyo202.gate.nec.co.jp (TYO202.gate.nec.co.jp [210.143.35.52]) by dpdk.org (Postfix) with ESMTP id 9517A68F8 for ; Thu, 3 Apr 2014 08:35:19 +0200 (CEST) Received: from mailgate3.nec.co.jp ([10.7.69.193]) by tyo202.gate.nec.co.jp (8.13.8/8.13.4) with ESMTP id s336apLS023013; Thu, 3 Apr 2014 15:36:51 +0900 (JST) Received: from mailsv.nec.co.jp (imss62.nec.co.jp [10.7.69.157]) by mailgate3.nec.co.jp (8.11.7/3.7W-MAILGATE-NEC) with ESMTP id s336aol29106; Thu, 3 Apr 2014 15:36:50 +0900 (JST) Received: from mail01b.kamome.nec.co.jp (mail01b.kamome.nec.co.jp [10.25.43.2]) by mailsv.nec.co.jp (8.13.8/8.13.4) with ESMTP id s336aowk018419; Thu, 3 Apr 2014 15:36:50 +0900 (JST) Received: from bpxc99gp.gisp.nec.co.jp ([10.38.151.145] [10.38.151.145]) by mail03.kamome.nec.co.jp with ESMTP id BT-MMP-649288; Thu, 3 Apr 2014 15:35:08 +0900 Received: from BPXM14GP.gisp.nec.co.jp ([169.254.1.238]) by BPXC17GP.gisp.nec.co.jp ([10.38.151.145]) with mapi id 14.02.0328.011; Thu, 3 Apr 2014 15:35:07 +0900 From: Hiroshi Shimamoto To: Thomas Monjalon Thread-Topic: [memnic PATCH v2] pmd: fix race condition Thread-Index: Ac9PBry2FmI9WSQrTQWTk+STBAxyfg== Date: Thu, 3 Apr 2014 06:35:06 +0000 Message-ID: <7F861DC0615E0C47A872E6F3C5FCDDBD0109D398@BPXM14GP.gisp.nec.co.jp> Accept-Language: ja-JP, en-US Content-Language: ja-JP X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.205.5.123] Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: "dev@dpdk.org" , Hayato Momma Subject: [dpdk-dev] [memnic PATCH v2] pmd: fix race condition 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: Thu, 03 Apr 2014 06:35:20 -0000 From: Hiroshi Shimamoto There is a race condition, on transmit to host. Guest PMD Host Thread-A Thread-B vSwitch |idx=3D0 |idx=3D0 |p[0] st!=3D2 |cmpxchg | | |p[0] st->1 | | |idx=3D1 | | |fill data | | |p[0] st->2 | |p[0] st=3D=3D2 | | |receive data | | |p[0] st->0 | |cmpxchg | | |success |p[1] st!=3D2 | |p[0] st->1 | This is BAD That causes traffic stop. We have to take care about that race condition with checking whether current index is correct. Signed-off-by: Hiroshi Shimamoto Reviewed-by: Hayato Momma --- pmd/pmd_memnic.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pmd/pmd_memnic.c b/pmd/pmd_memnic.c index d833130..4a1c1e4 100644 --- a/pmd/pmd_memnic.c +++ b/pmd/pmd_memnic.c @@ -345,6 +345,15 @@ retry: goto retry; } =20 + if (idx !=3D ACCESS_ONCE(adapter->down_idx)) { + /* + * host freed this and got false positive, + * need to recover the status and retry. + */ + p->status =3D MEMNIC_PKT_ST_FREE; + goto retry; + } + if (++idx >=3D MEMNIC_NR_PACKET) idx =3D 0; adapter->down_idx =3D idx; --=20 1.8.4