examples/vhost: fix hang on exit
PATCH 1/1 examples/vhost: fix hang on exit
destroy_device() waits for the worker lcore to ack device removal. Since the signal handler rework, the workers exit before the vhost drivers are unregistered, so the destroy callback spins forever.
Unregister the drivers while the workers are still polling, then stop and join them.
Bugzilla ID: 2071
--- examples/vhost/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
examples/vhost/main.c +3 -1
@@ -69,6 +69,8 @@ static uint32_t enabled_port_mask = 0;/* Set by the SIGINT handler to stop the worker loops. */ static volatile sig_atomic_t quit; +static RTE_ATOMIC (bool ) stop_workers; +/* Promiscuous mode */ static uint32_t promiscuous;
@@ -1242,7 +1244,7 @@ switch_worker(void *arg) } } -while (!quit) { +while (!rte_atomic_load_explicit (&stop_workers, rte_memory_order_relaxed)) {drain_mbuf_table (tx_q);drain_vhost_table ();/*
Signature · 1 line
2.53.0
Quoted 31 lines · Stephen Hemminger
destroy_device()waits for the worker lcore to ack device removal. Since the signal handler rework, the workers exit before the vhost drivers are unregistered, so the destroy callback spins forever.Unregister the drivers while the workers are still polling, then stop and join them.
Bugzilla ID: 2071
Fixes 5ffa8fafcbd3 ("examples/vhost: make signal handler safe")Reported-by Yu Jiang <[email protected]>Signed-off-by Stephen Hemminger <[email protected]>--- examples/vhost/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)examples/vhost/main.c +2
-0@@ -69,6 +69,8 @@ static uint32_t enabled_port_mask = 0;/* Set by the SIGINT handler to stop the worker loops. */ static volatile sig_atomic_t quit; +static RTE_ATOMIC (bool ) stop_workers; +/* Promiscuous mode */ static uint32_t promiscuous;
examples/vhost/main.c switch_worker(void *arg) · line 1250
Quoted 8 lines
examples/vhost/main.c +1
-1@@ -1242,7 +1244,7 @@ switch_worker(void *arg) } } -while (!quit) { +while (!rte_atomic_load_explicit (&stop_workers, rte_memory_order_relaxed)) {drain_mbuf_table (tx_q);drain_vhost_table ();/*
Are you sure you committed all the changes? I don't see a store of true to stop_workers.
PATCH v2 1/1 examples/vhost: fix hang on exit
In reply to Stephen Hemmingerdestroy_device() waits for the worker lcore to ack device removal. Since the signal handler rework, the workers exit before the vhost drivers are unregistered, so the destroy callback spins forever.
Maing thread now blocks SIGINT and SIGTERM and uses sigwait to wait for one of these signals. Then unregisters and tells worker threads to stop.
Bugzilla ID: 2071
--- examples/vhost/main.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
examples/vhost/main.c +15 -12
@@ -66,8 +66,7 @@ static int total_num_mbufs = NUM_MBUFS_DEFAULT;/* mask of enabled ports */ static uint32_t enabled_port_mask =0 ; -/* Set by the SIGINT handler to stop the worker loops. */ -static volatile sig_atomic_t quit; +static RTE_ATOMIC (bool ) stop_workers;/* Promiscuous mode */ static uint32_t promiscuous;
@@ -1242,7 +1241,7 @@ switch_worker(void *arg) } } -while (!quit) { +while (!rte_atomic_load_explicit (&stop_workers, rte_memory_order_relaxed)) {drain_mbuf_table (tx_q);drain_vhost_table ();/*
@@ -1494,12 +1493,6 @@ unregister_drivers(int socket_num) } } -static void -sigint_handler(__rte_unused int signum) -{ - quit =1 ; -} -/* * Main function, does initialisation and calls the per-lcore functions. */
@@ -1513,8 +1506,13 @@ main(int argc, char *argv[])uint16_t portid;rte_thread_t tid;uint64_t flags =RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS ; +sigset_t set; +int sig; -signal (SIGINT , sigint_handler); +sigemptyset (&set); +sigaddset (&set,SIGINT ); +sigaddset (&set,SIGTERM ); +pthread_sigmask (SIG_BLOCK , &set,NULL );/* init EAL */ ret =rte_eal_init (argc, argv);
@@ -1654,12 +1652,17 @@ main(int argc, char *argv[]) } } -RTE_LCORE_FOREACH_WORKER (lcore_id) -rte_eal_wait_lcore (lcore_id); +/* Wait until SIGINT or SIGTERM */ +sigwait (&set, &sig); +pthread_sigmask (SIG_UNBLOCK , &set,NULL );/* Unregister vhost driver. */ unregister_drivers (nb_sockets); +/* Tell worker threads to exit */ +rte_atomic_store_explicit (&stop_workers, true, rte_memory_order_relaxed); +rte_eal_mp_wait_lcore (); +/* clean up the EAL */ rte_eal_cleanup ();
Signature · 1 line
2.53.0
Quoted 8 lines · On Thu, 29 Oct 2026 09:57:29 -0700 Stephen Hemminger…
destroy_device()waits for the worker lcore to ack device removal. Since the signal handler rework, the workers exit before the vhost drivers are unregistered, so the destroy callback spins forever.Maing thread now blocks SIGINT and SIGTERM and uses sigwait to wait for one of these signals. Then unregisters and tells worker threads to stop.
Quoted 6 lines
Bugzilla ID: 2071
Fixes 5ffa8fafcbd3 ("examples/vhost: make signal handler safe")Reported-by Yu Jiang <[email protected]>Signed-off-by Stephen Hemminger <[email protected]>
This is compile test only, and needs ack from Maxime or submitter.
Jiang, YuX
Tested-byQuoted 20 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Friday, October 30, 2026 2:04 AM
To: [email protected]
Cc: [email protected]; Jiang, YuX <[email protected]>; Maxime Coquelin <[email protected]>; Chenbo Xia <[email protected]>; Richardson, Bruce <[email protected]>
Subject: Re: [PATCH v2] examples/vhost: fix hang on exitQuoted 8 lines · On Thu, 29 Oct 2026 09:57:29 -0700 Stephen Hemminger…
destroy_device()waits for the worker lcore to ack device removal. Since the signal handler rework, the workers exit before the vhost drivers are unregistered, so the destroy callback spins forever.Maing thread now blocks SIGINT and SIGTERM and uses sigwait to wait for one of these signals. Then unregisters and tells worker threads to stop.
Quoted 8 lines
Quoted 6 lines
Bugzilla ID: 2071
Fixes 5ffa8fafcbd3 ("examples/vhost: make signal handler safe")Reported-by Yu Jiang <[email protected]>Signed-off-by Stephen Hemminger <[email protected]>This is compile test only, and needs ack from Maxime or submitter.
Best Regards
Yu Jiang
David Marchand
AppliedQuoted 9 lines · Stephen Hemminger
destroy_device()waits for the worker lcore to ack device removal. Since the signal handler rework, the workers exit before the vhost drivers are unregistered, so the destroy callback spins forever.Maing thread now blocks SIGINT and SIGTERM and uses sigwait to wait for one of these signals. Then unregisters and tells worker threads to stop.
Quoted 7 lines
Bugzilla ID: 2071
Fixes 5ffa8fafcbd3 ("examples/vhost: make signal handler safe")Reported-by Yu Jiang <[email protected]>Signed-off-by Stephen Hemminger <[email protected]>Tested-by Yu Jiang <[email protected]>
Applied, thanks.
Signature · 1 line
David Marchand