|WARNING| [v2] examples/vhost: fix hang on exit

dpdklab at iol.unh.edu dpdklab at iol.unh.edu
Thu Oct 29 19:15:07 CET 2026


Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/172244

_AI Code Review_

=== Patch Review: series.patch (via Claude) ===
Review date: 2026-10-29

# DPDK Patch Review

## ERRORS

**Error: Stop flag checked with relaxed ordering but no full barrier on write**

Line: `while (!rte_atomic_load_explicit(&stop_workers, rte_memory_order_relaxed))`

The worker loop polls `stop_workers` with `rte_memory_order_relaxed`, which is correct for a simple flag.
However, the main thread writes to this flag with:

```c
rte_atomic_store_explicit(&stop_workers, true, rte_memory_order_relaxed);
```

**After** calling `unregister_drivers()`, which performs cleanup operations the workers must not race with.
The store should use `rte_memory_order_release` to ensure all prior cleanup (driver unregistration) is visible to workers before they observe the flag and exit:

```c
rte_atomic_store_explicit(&stop_workers, true, rte_memory_order_release);
```

And the load should use `rte_memory_order_acquire`:

```c
while (!rte_atomic_load_explicit(&stop_workers, rte_memory_order_acquire))
```

This ensures workers see a consistent view of the cleanup state when they observe the stop flag.

---

**Error: Signal mask restored before workers exit creates race**

Lines:
```c
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();
```

The signal mask is unblocked immediately after `sigwait()` returns, before workers are stopped.
If a second SIGINT/SIGTERM arrives during `unregister_drivers()` or `rte_eal_mp_wait_lcore()`,
the default handler will run (terminating the process) or the process may be killed,
preventing clean shutdown.

Move the `pthread_sigmask(SIG_UNBLOCK, ...)` to after `rte_eal_mp_wait_lcore()`:

```c
sigwait(&set, &sig);

unregister_drivers(nb_sockets);

rte_atomic_store_explicit(&stop_workers, true, rte_memory_order_release);
rte_eal_mp_wait_lcore();

pthread_sigmask(SIG_UNBLOCK, &set, NULL);
```

---

## WARNINGS

**Warning: Missing `rte_atomic_init()` for stop_workers**

Line: `static RTE_ATOMIC(bool) stop_workers;`

While zero-initialization of global atomics is guaranteed by C, DPDK style for atomics prefers explicit initialization.
Add in `main()` before launching workers:

```c
rte_atomic_store_explicit(&stop_workers, false, rte_memory_order_relaxed);
```

This makes the initial state explicit and is consistent with DPDK atomic usage patterns.

---

## INFO

None.

---

Review-Result: ERROR


More information about the test-report mailing list