From: Gavin Hu Date: Tue, 12 Mar 2019 16:58:53 +0000 (+0800) Subject: ring: enforce reading tail before slots X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=85cffb2eccd9edf89a9e28539206a79258a6e9d9;p=dpdk.git ring: enforce reading tail before slots 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: c9fb3c62896f ("ring: move code in a new header file") 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 --- diff --git a/lib/librte_ring/rte_ring_generic.h b/lib/librte_ring/rte_ring_generic.h index ea7dbe5b9c..953cdbbd5e 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, 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)); return n; }