DPDK patches and discussions
 help / color / mirror / Atom feed
From: gavin hu <gavin.hu@arm.com>
To: 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, gavin.hu@arm.com,
	olivier.matz@6wind.com
Subject: [dpdk-dev] [PATCH v1] ring: enforce reading the tails before ring operations
Date: Wed,  6 Mar 2019 11:07:41 +0800	[thread overview]
Message-ID: <1551841661-42892-1-git-send-email-gavin.hu@arm.com> (raw)

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.  There must be a read fence before writing
or reading the ring slots, rte_atomic32_cmpset() provides the same ordering
for MP (and MC) case. This patch is to enforce this ordering for SP (and
SC) case.

Signed-off-by: gavin hu <gavin.hu@arm.com>
Reviewed-by: Ola Liljedahl <Ola.Liljedahl@arm.com>
Tested-by: Nipun Gupta <nipun.gupta@nxp.com>
---
 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));
-- 
2.7.4

             reply	other threads:[~2019-03-06  3:08 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-06  3:07 gavin hu [this message]
     [not found] ` <CGME20190306114906eucas1p19c2572b1fe777e1eb0ca96d2e47295bd@eucas1p1.samsung.com>
2019-03-06 11:49   ` [dpdk-dev] [v1] " Ilya Maximets
2019-03-07  6:50     ` Gavin Hu (Arm Technology China)
2019-03-07  6:45 ` [dpdk-dev] [PATCH v2] " gavin hu
2019-03-07  8:52   ` Ilya Maximets
2019-03-07  9:27     ` Gavin Hu (Arm Technology China)
2019-03-07  9:48       ` Ilya Maximets
2019-03-07 10:44         ` Gavin Hu (Arm Technology China)
2019-03-07 11:17           ` Ananyev, Konstantin
2019-03-08  3:21             ` Honnappa Nagarahalli
2019-03-08  5:27               ` Gavin Hu (Arm Technology China)
2019-03-08 16:33                 ` Ananyev, Konstantin
2019-03-10 20:47                   ` Honnappa Nagarahalli
2019-03-11 13:58                     ` Ananyev, Konstantin
2019-03-08  4:23           ` Gavin Hu (Arm Technology China)
2019-03-08  5:06             ` Honnappa Nagarahalli
2019-03-08 12:13             ` Ananyev, Konstantin
2019-03-08 15:05               ` Gavin Hu (Arm Technology China)
2019-03-08 15:50                 ` Ananyev, Konstantin
2019-03-08 23:18                   ` Thomas Monjalon
2019-03-08 23:48                     ` Honnappa Nagarahalli
2019-03-09 10:28                       ` Gavin Hu (Arm Technology China)
2019-03-12 16:58 ` [dpdk-dev] [PATCH v3 0/1] ring: enforce reading the tail before reading ring slots Gavin Hu
2019-03-12 16:58 ` [dpdk-dev] [PATCH v3 1/1] " Gavin Hu
2019-03-13  8:12   ` Nipun Gupta
2019-03-15 13:26   ` Ananyev, Konstantin
2019-03-15 13:26     ` Ananyev, Konstantin
2019-03-28  0:21     ` Thomas Monjalon
2019-03-28  0:21       ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1551841661-42892-1-git-send-email-gavin.hu@arm.com \
    --to=gavin.hu@arm.com \
    --cc=Honnappa.Nagarahalli@arm.com \
    --cc=dev@dpdk.org \
    --cc=hemant.agrawal@nxp.com \
    --cc=jerinj@marvell.com \
    --cc=nd@arm.com \
    --cc=nipun.gupta@nxp.com \
    --cc=olivier.matz@6wind.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).