From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 814CC2B87 for ; Thu, 7 Mar 2019 09:52:18 +0100 (CET) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20190307085217euoutp02074dd04f1fcaf36f44bbed117aeb64df~JoSdnqT4F0074500745euoutp02V for ; Thu, 7 Mar 2019 08:52:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20190307085217euoutp02074dd04f1fcaf36f44bbed117aeb64df~JoSdnqT4F0074500745euoutp02V DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1551948737; bh=aC8oncooSp+06oFQ3Ygr3DpLtEgseMD6JpgFcAv6+IA=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=qX3N9gy/eN7Ro2ZSeejN6xN6SA4jTo7xGaEQibfEVjHoJQ3qSGF4xPqnc+LzCPV/q HAg9hjD9ewPOB5z6KXviZFSpSq17a2fMLL5yCidU1Ir4XBKQNH3qwvURxSzkHWWel9 a2938kVk1puMPJ4JFK/tFEM+ox3fQil8B/ktx7fA= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20190307085216eucas1p2aac17f443722c7b8864c130d82135f76~JoSdC7JYB1329213292eucas1p2P; Thu, 7 Mar 2019 08:52:16 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 3C.75.04806.0CBD08C5; Thu, 7 Mar 2019 08:52:16 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20190307085215eucas1p146bbd073d4c2f5403f38d0389cab0c25~JoScRtWwK1727917279eucas1p1q; Thu, 7 Mar 2019 08:52:15 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20190307085215eusmtrp1df5ddf0ccbb81e6b601825275765d4ab~JoScC48RJ1783917839eusmtrp1J; Thu, 7 Mar 2019 08:52:15 +0000 (GMT) X-AuditID: cbfec7f5-34dff700000012c6-11-5c80dbc0c6da Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 6C.CC.04128.FBBD08C5; Thu, 7 Mar 2019 08:52:15 +0000 (GMT) Received: from [106.109.129.180] (unknown [106.109.129.180]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20190307085214eusmtip1597cd781be2bc05e23ddb4017adefc73~JoSbcvoGV2419924199eusmtip1S; Thu, 7 Mar 2019 08:52:14 +0000 (GMT) To: gavin hu , dev@dpdk.org Cc: nd@arm.com, thomas@monjalon.net, jerinj@marvell.com, hemant.agrawal@nxp.com, nipun.gupta@nxp.com, Honnappa.Nagarahalli@arm.com, olivier.matz@6wind.com From: Ilya Maximets Message-ID: <3cdf6747-21f3-d77e-0935-d73b5cc617f6@samsung.com> Date: Thu, 7 Mar 2019 11:52:09 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <1551941137-33250-1-git-send-email-gavin.hu@arm.com> Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA02Sa0hTYRjHe3fOPMfR7HUaPmlZLAksb5EfTmR2IfIQCH6JxIRceZiWTtnU Mj84bTgzu6DZ0EJmVuqyizJvCV6WOG8ZluYlM8Mks1x4CXSK1TyT/PZ7nuf/PO//Dy9NSNqE 7nSsIolTKmRxUgcRWdu+1Ovb8lEdGZBXgBnLXJ2A6ZyaRkzFRJUDUzipoZh+7RLF3Hx7HzE9 ZbkE02vuRkxN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rO XsYuRi4OIYGljBK3Oi+zQiSkJH78ugBlC0v8udbFBlH0nlHiydfvzCAJYQE/iWXPHrGB2CIC uhIf27YygxQxC8xjlLi5aRITRMdpRonvrZtYQKrYBHQkTq0+wghi8wrYSUx9cJAdxGYRUJHY ffA42DpRgQiJuxdfsEDUCEqcnPkEzOYUcJR4cfwq2GZmAXWJP/MuQdniEk1fVrJC2PIS29/O YZ7AKDQLSfssJC2zkLTMQtKygJFlFaNIamlxbnpusZFecWJucWleul5yfu4mRmC0bjv2c8sO xq53wYcYBTgYlXh4GU7WxwixJpYVV+YeYpTgYFYS4T1xoyFGiDclsbIqtSg/vqg0J7X4EKMp 0HMTmaVEk/OBiSSvJN7Q1NDcwtLQ3Njc2MxCSZz3vEFllJBAemJJanZqakFqEUwfEwenVANj z0vXTzd7XoWaxRwVqMloDC41ZPlh8nH78ihGwVlsS1d+8NjylYHBeXn//eqphjtvn2bhOvKD xSfVfWv59AnJS9qElvzcN+PhS2bvDc+P3F7t67ajNE37p8KCN5NfMtvWpWn/q3tg9n7Flbjn ocfOLN/KcJTx6R/Jp68O/zW78n7foX+Ze/3nXFViKc5INNRiLipOBAD6D3aV7AIAAA== X-CMS-MailID: 20190307085215eucas1p146bbd073d4c2f5403f38d0389cab0c25 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20190307064616epcas4p141948c129d532da259eab6fd3e6e4dc7 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20190307064616epcas4p141948c129d532da259eab6fd3e6e4dc7 References: <1551841661-42892-1-git-send-email-gavin.hu@arm.com> <1551941137-33250-1-git-send-email-gavin.hu@arm.com> Subject: Re: [dpdk-dev] [PATCH v2] ring: enforce reading the tails before ring operations X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Mar 2019 08:52:18 -0000 On 07.03.2019 9:45, gavin hu wrote: > In weak memory models, like arm64, reading the {prod,cons}.tail may get > reordered after reading or writing the ring slots, which corrupts the ring > and stale data is observed. > > This issue was reported by NXP on 8-A72 DPAA2 board. The problem is most > likely caused by missing the acquire semantics when reading cons.tail (in > SP enqueue) or prod.tail (in SC dequeue) which makes it possible to read a > stale value from the ring slots. > > For MP (and MC) case, rte_atomic32_cmpset() already provides the required > ordering. This patch is to prevent reading and writing the ring slots get > reordered before reading {prod,cons}.tail for SP (and SC) case. Read barrier rte_smp_rmb() is OK to prevent reading the ring get reordered before reading the tail. However, to prevent *writing* the ring get reordered *before reading* the tail you need a full memory barrier, i.e. rte_smp_mb(). > > Signed-off-by: gavin hu > Reviewed-by: Ola Liljedahl > Tested-by: Nipun Gupta > --- > lib/librte_ring/rte_ring_generic.h | 16 ++++++++++------ > 1 file changed, 10 insertions(+), 6 deletions(-) > > diff --git a/lib/librte_ring/rte_ring_generic.h b/lib/librte_ring/rte_ring_generic.h > index ea7dbe5..1bd3dfd 100644 > --- a/lib/librte_ring/rte_ring_generic.h > +++ b/lib/librte_ring/rte_ring_generic.h > @@ -90,9 +90,11 @@ __rte_ring_move_prod_head(struct rte_ring *r, unsigned int is_sp, > return 0; > > *new_head = *old_head + n; > - if (is_sp) > - r->prod.head = *new_head, success = 1; > - else > + if (is_sp) { > + r->prod.head = *new_head; > + rte_smp_rmb(); > + success = 1; > + } else > success = rte_atomic32_cmpset(&r->prod.head, > *old_head, *new_head); > } while (unlikely(success == 0)); > @@ -158,9 +160,11 @@ __rte_ring_move_cons_head(struct rte_ring *r, unsigned int is_sc, > return 0; > > *new_head = *old_head + n; > - if (is_sc) > - r->cons.head = *new_head, success = 1; > - else > + if (is_sc) { > + r->cons.head = *new_head; > + rte_smp_rmb(); > + success = 1; > + } else > success = rte_atomic32_cmpset(&r->cons.head, *old_head, > *new_head); > } while (unlikely(success == 0)); >