From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5B1EBA2F6B for ; Tue, 8 Oct 2019 08:39:00 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 16E2C1C00D; Tue, 8 Oct 2019 08:39:00 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 632131C00D for ; Tue, 8 Oct 2019 08:38:58 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9C7301570; Mon, 7 Oct 2019 23:38:57 -0700 (PDT) Received: from net-arm-thunderx2-01.test.ast.arm.com (net-arm-thunderx2-01.shanghai.arm.com [10.169.40.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1A5723F6C4; Mon, 7 Oct 2019 23:41:36 -0700 (PDT) From: Gavin Hu To: stable@dpdk.org Cc: nd@arm.com, thomas@monjalon.net, nipun.gupta@nxp.com, konstantin.ananyev@intel.com, gavin.hu@arm.com Date: Tue, 8 Oct 2019 14:38:43 +0800 Message-Id: <1570516723-10217-1-git-send-email-gavin.hu@arm.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-stable] [PATCH] ring: enforce reading tail before 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" 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. 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. For MP (and MC) case, rte_atomic32_cmpset() already provides the required ordering. For SP case, the control depependency between if-statement (which depends on the read of r->cons.tail) and the later stores to the ring slots make RMB unnecessary. About the control dependency, read more at: https://www.cl.cam.ac.uk/~pes20/ppc-supplemental/test7.pdf This patch is adding the required read barrier to prevent reading the ring slots get reordered before reading prod.tail for SC case. Fixes: 0dfc98c507b1 ("ring: separate out head index manipulation") Cc: stable@dpdk.org Signed-off-by: Gavin Hu Reviewed-by: Ola Liljedahl Tested-by: Nipun Gupta Acked-by: Nipun Gupta Acked-by: Konstantin Ananyev --- lib/librte_ring/rte_ring.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h index e924438..9e6ccfe 100644 --- a/lib/librte_ring/rte_ring.h +++ b/lib/librte_ring/rte_ring.h @@ -544,11 +544,14 @@ __rte_ring_move_cons_head(struct rte_ring *r, 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)); return n; } -- 2.7.4