From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 469C1A0096 for ; Fri, 15 Mar 2019 14:26:51 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DE7584C9C; Fri, 15 Mar 2019 14:26:50 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 1C9A42BD3; Fri, 15 Mar 2019 14:26:46 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Mar 2019 06:26:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,482,1544515200"; d="scan'208";a="152006911" Received: from irsmsx104.ger.corp.intel.com ([163.33.3.159]) by fmsmga002.fm.intel.com with ESMTP; 15 Mar 2019 06:26:43 -0700 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.210]) by IRSMSX104.ger.corp.intel.com ([169.254.5.56]) with mapi id 14.03.0415.000; Fri, 15 Mar 2019 13:26:43 +0000 From: "Ananyev, Konstantin" 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" , "i.maximets@samsung.com" , "chaozhu@linux.vnet.ibm.com" , "stable@dpdk.org" Thread-Topic: [PATCH v3 1/1] ring: enforce reading the tail before reading ring slots Thread-Index: AQHU2PTtcVPi254LAECyVwEF8CXWyqYMszqA Date: Fri, 15 Mar 2019 13:26:41 +0000 Message-ID: <2601191342CEEE43887BDE71AB977258013655C014@irsmsx105.ger.corp.intel.com> References: <1551841661-42892-1-git-send-email-gavin.hu@arm.com> <1552409933-45684-2-git-send-email-gavin.hu@arm.com> In-Reply-To: <1552409933-45684-2-git-send-email-gavin.hu@arm.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiM2JkMTRiNDctZTUyMi00OTc5LTg0YTctMjJlZmE4ODgxOTY1IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiVHRuMEhmNGU2UVIwK1BtM2VpM0NLSlN5anZhdW5ZSVRKXC9NYm1xU0hYRDd1azA0RGl5clQ2WVpzTUQyUGJSVFUifQ== x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-stable] [PATCH v3 1/1] ring: enforce reading the tail before reading ring slots X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" > -----Original Message----- > From: Gavin Hu [mailto:gavin.hu@arm.com] > Sent: Tuesday, March 12, 2019 4:59 PM > To: dev@dpdk.org > Cc: nd@arm.com; gavin hu ; thomas@monjalon.net; Ananyev= , Konstantin ; > jerinj@marvell.com; hemant.agrawal@nxp.com; nipun.gupta@nxp.com; Honnappa= .Nagarahalli@arm.com; i.maximets@samsung.com; > chaozhu@linux.vnet.ibm.com; stable@dpdk.org > Subject: [PATCH v3 1/1] ring: enforce reading the tail before reading rin= g slots >=20 > From: gavin hu >=20 > In weak memory models, like arm64, reading the prod.tail may get > reordered after reading the ring slots, which corrupts the ring and > stale data is observed. >=20 > This issue was reported by NXP on 8-A72 DPAA2 board. The problem is most > likely caused by missing the acquire semantics when reading > prod.tail (in SC dequeue) which makes it possible to read a > stale value from the ring slots. >=20 > For MP (and MC) case, rte_atomic32_cmpset() already provides the required > ordering. For SP case, the control depependency between if-statement(whic= h > depends on the read of r->cons.tail) and the later stores to the ring slo= ts > make RMB unnecessary. About the control dependency, read more at: > https://www.cl.cam.ac.uk/~pes20/ppc-supplemental/test7.pdf >=20 > This patch is adding the required read barrier to prevent reading the rin= g > slots get reordered before reading prod.tail for SC case. >=20 > Fixes: c9fb3c62896f ("ring: move code in a new header file") > Cc: stable@dpdk.org >=20 > Signed-off-by: gavin hu > Reviewed-by: Ola Liljedahl > Tested-by: Nipun Gupta > --- > lib/librte_ring/rte_ring_generic.h | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) >=20 > diff --git a/lib/librte_ring/rte_ring_generic.h b/lib/librte_ring/rte_rin= g_generic.h > index ea7dbe5..953cdbb 100644 > --- a/lib/librte_ring/rte_ring_generic.h > +++ b/lib/librte_ring/rte_ring_generic.h > @@ -158,11 +158,14 @@ __rte_ring_move_cons_head(struct rte_ring *r, unsig= ned int is_sc, > return 0; >=20 > *new_head =3D *old_head + n; > - if (is_sc) > - r->cons.head =3D *new_head, success =3D 1; > - else > + if (is_sc) { > + r->cons.head =3D *new_head; > + rte_smp_rmb(); > + success =3D 1; > + } else { > success =3D rte_atomic32_cmpset(&r->cons.head, *old_head, > *new_head); > + } > } while (unlikely(success =3D=3D 0)); > return n; > } > -- Acked-by: Konstantin Ananyev > 2.7.4