bucket update in the cmap lib is protected by a counter. But hash setting
is possible to be moved before counter update. This patch fix this issue.

Reviewed-by: Ola Liljedahl <[email protected]>
Reviewed-by: Gavin Hu <[email protected]>
Signed-off-by: Yanqin Wei <[email protected]>
---
 lib/cmap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/cmap.c b/lib/cmap.c
index c9eef3f4a..e41c40794 100644
--- a/lib/cmap.c
+++ b/lib/cmap.c
@@ -598,7 +598,9 @@ cmap_set_bucket(struct cmap_bucket *b, int i,
     uint32_t c;
 
     atomic_read_explicit(&b->counter, &c, memory_order_acquire);
-    atomic_store_explicit(&b->counter, c + 1, memory_order_release);
+    atomic_store_explicit(&b->counter, c + 1, memory_order_relaxed);
+    /*need to make sure setting hash is not moved up before counter update*/
+    atomic_thread_fence(memory_order_release);
     ovsrcu_set(&b->nodes[i].next, node); /* Also atomic. */
     b->hashes[i] = hash;
     atomic_store_explicit(&b->counter, c + 2, memory_order_release);
-- 
2.17.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to