From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hiroshi Shimamoto Subject: [memnic PATCH v2] pmd: fix race condition Date: Thu, 3 Apr 2014 06:35:06 +0000 Message-ID: <7F861DC0615E0C47A872E6F3C5FCDDBD0109D398@BPXM14GP.gisp.nec.co.jp> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: quoted-printable Cc: "dev-VfR2kkLFssw@public.gmane.org" , Hayato Momma To: Thomas Monjalon Return-path: Content-Language: ja-JP List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "dev" 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