vcl: add reattach spinlock 76/43276/2
authorFlorin Coras <[email protected]>
Sat, 21 Jun 2025 22:42:58 +0000 (15:42 -0700)
committerDave Barach <[email protected]>
Sun, 22 Jun 2025 23:54:22 +0000 (23:54 +0000)
Avoid potential deadlock if app is sigtermed and wants workers lock to
cleanup worker while reattaching.

Type: improvement

Change-Id: I97f5935d309de83717e5a0a82055c91e07c4cb17
Signed-off-by: Florin Coras <[email protected]>
src/vcl/vcl_private.h
src/vcl/vppcom.c

index 61894d7..cc51946 100644 (file)
@@ -362,10 +362,6 @@ typedef struct vppcom_main_t_
   /** Lock to protect worker registrations */
   clib_spinlock_t workers_lock;
 
-  /** Counter to determine order of execution of `vcl_api_retry_attach`
-   * function by multiple workers */
-  int reattach_count;
-
   /** Lock to protect segment hash table */
   clib_rwlock_t segment_table_lock;
 
@@ -387,6 +383,11 @@ typedef struct vppcom_main_t_
   int (*vcl_epoll_wait) (int epfd, struct epoll_event *events, int maxevents,
                         int timeout);
 
+  clib_spinlock_t reattach_lock;
+  /** Counter to determine order of execution of `vcl_api_retry_attach`
+   * function by multiple workers */
+  int reattach_count;
+
   /*
    * Binary api context
    */
index 40209ba..ffa29ba 100644 (file)
@@ -1413,23 +1413,23 @@ vcl_api_retry_attach (vcl_worker_t *wrk)
 
   vcl_worker_detached_signal_mq (wrk);
 
-  clib_spinlock_lock (&vcm->workers_lock);
+  clib_spinlock_lock (&vcm->reattach_lock);
   if (vcl_is_first_reattach_to_execute ())
     {
       if (vcl_api_attach ())
        {
-         clib_spinlock_unlock (&vcm->workers_lock);
+         clib_spinlock_unlock (&vcm->reattach_lock);
          return;
        }
       vcl_worker_detached_stop_signal_mq (wrk);
       vcl_set_reattach_counter ();
-      clib_spinlock_unlock (&vcm->workers_lock);
+      clib_spinlock_unlock (&vcm->reattach_lock);
     }
   else
     {
       vcl_set_reattach_counter ();
       vcl_worker_detached_stop_signal_mq (wrk);
-      clib_spinlock_unlock (&vcm->workers_lock);
+      clib_spinlock_unlock (&vcm->reattach_lock);
       vcl_worker_register_with_vpp ();
     }
 
@@ -1494,6 +1494,7 @@ vppcom_app_create (const char *app_name)
                          20 /* timeout in secs */);
   pool_alloc (vcm->workers, vcl_cfg->max_workers);
   clib_spinlock_init (&vcm->workers_lock);
+  clib_spinlock_init (&vcm->reattach_lock);
   clib_rwlock_init (&vcm->segment_table_lock);
   atexit (vppcom_app_exit);
   vcl_elog_init (vcm);