ip: add barrier sync, ip4_ply_pool expand case 23/35723/4
authorVladislav Grishenko <themiron@yandex-team.ru>
Wed, 12 Jan 2022 10:22:23 +0000 (15:22 +0500)
committerNeale Ranns <neale@graphiant.com>
Mon, 28 Mar 2022 07:33:49 +0000 (07:33 +0000)
ply_create() is not thread safe when the ip4_ply_pool expands.

Type: fix
Signed-off-by: Vladislav Grishenko <themiron@yandex-team.ru>
Change-Id: Ie11cc8b1ba587d5e9239a60f4e288492da61368e

src/vnet/ip/ip4_mtrie.c

index e61b4aa..00855f7 100644 (file)
@@ -115,12 +115,24 @@ static ip4_mtrie_leaf_t
 ply_create (ip4_mtrie_leaf_t init_leaf, u32 leaf_prefix_len, u32 ply_base_len)
 {
   ip4_mtrie_8_ply_t *p;
-  /* Get cache aligned ply. */
+  ip4_mtrie_leaf_t l;
+  u8 need_barrier_sync = pool_get_will_expand (ip4_ply_pool);
+  vlib_main_t *vm = vlib_get_main ();
+  ASSERT (vm->thread_index == 0);
 
+  if (need_barrier_sync)
+    vlib_worker_thread_barrier_sync (vm);
+
+  /* Get cache aligned ply. */
   pool_get_aligned (ip4_ply_pool, p, CLIB_CACHE_LINE_BYTES);
 
   ply_8_init (p, init_leaf, leaf_prefix_len, ply_base_len);
-  return ip4_mtrie_leaf_set_next_ply_index (p - ip4_ply_pool);
+  l = ip4_mtrie_leaf_set_next_ply_index (p - ip4_ply_pool);
+
+  if (need_barrier_sync)
+    vlib_worker_thread_barrier_release (vm);
+
+  return l;
 }
 
 always_inline ip4_mtrie_8_ply_t *