[PATCH v3] net/virtio-user: fix eventfd sharing in secondary process
Maxime Coquelin
maxime.coquelin at redhat.com
Tue Aug 18 11:03:19 CEST 2026
Hello Samar,
On Fri, Jul 3, 2026 at 12:25 PM Samar Yadav <samaryadav5 at gmail.com> wrote:
>
> virtio_user secondary processes cannot communicate with the vhost
> backend: the kick/call eventfds are opened by the primary and never
> shared, so a secondary's queue notification writes to an invalid fd
> and traffic stalls.
>
> Share the fds over a dedicated virtio-user multiprocess channel. The
> primary registers a process-wide MP action that returns a port's
> kick/call fds (looked up by port name); a secondary requests them at
> probe time, before the port is announced.
>
> The received fds are stored in eth_dev->process_private, which is
> per-process, instead of the primary-owned shared dev->kickfds and
> dev->callfds arrays; the secondary data path notifies the backend using
> its own kickfd. In the primary, the MP handler reads the fd arrays under
> dev->mutex, and the teardown path takes the same lock while closing and
> freeing them, so the two cannot race.
>
> Also fix the pre-existing pthread_mutex_init(&dev->mutex, NULL) call in
> virtio_user_dev_init(): POSIX requires PTHREAD_PROCESS_SHARED for a mutex
> stored in shared memory regardless of which processes actually lock it;
> use rte_thread_mutex_init_shared() as other multiprocess-aware drivers do.
>
> Fixes: 1c8489da561b ("net/virtio-user: fix multi-process support")
> Cc: tiwei.bie at intel.com
> Cc: stable at dpdk.org
>
> Signed-off-by: Samar Yadav <samaryadav5 at gmail.com>
> ---
> v3:
> - Reorder new #includes: system headers first, then DPDK lib headers
> (alphabetized), then local virtio_* headers, per project convention.
> - Name the "2" in eventfd count/index arithmetic (kick + call per queue)
> as VIRTIO_USER_EVENTFDS_PER_QUEUE instead of a bare literal. Leaves
> the pre-existing max_queue_pairs * 2 vring math untouched, since that
> is a different multiplier (vrings per queue pair) and already matches
> this file's existing style.
> - Name the 5-second MP reply timeout in virtio_user_sync_eventfds() as
> VIRTIO_USER_MP_TIMEOUT_SEC with a comment on the rationale.
>
> v2:
> - Use rte_calloc() instead of rte_malloc() for the kick/call fd arrays
> in virtio_user_sync_eventfds() so allocation failures are cleaner and
> unset entries are zero-initialised before the explicit -1 sentinel loop.
> (Stephen Hemminger)
> - Fix the pre-existing pthread_mutex_init(&dev->mutex, NULL) call in
> virtio_user_dev_init() to use rte_thread_mutex_init_shared(), which
> sets PTHREAD_PROCESS_SHARED as POSIX requires for a mutex in shared
> memory. Add #include <rte_thread.h> to pull in the declaration.
> (Stephen Hemminger)
>
> .mailmap | 1 +
> .../net/virtio/virtio_user/virtio_user_dev.c | 59 +++-
> .../net/virtio/virtio_user/virtio_user_dev.h | 23 ++
> drivers/net/virtio/virtio_user_ethdev.c | 276 +++++++++++++++++-
> 4 files changed, 350 insertions(+), 9 deletions(-)
>
The patch looks good to me.
Reviewed-by: Maxime Coquelin <maxime.coquelin at redhat.com>
Thanks,
Maxime
More information about the stable
mailing list