On 3 Nov 2026, at 13:01, David Marchand wrote:

> Move list insertion (resp. removal) out of common_construct()
> (resp. common_destruct()) into their callers.
>
> In constructors, the device is not visible to other threads until
> inserted in the list, so field initialization does not need the
> mutex.
> netdev_request_reconfigure() is moved next to the list insertion
> in each constructor.
> In the vhost server constructor, rte_vhost_driver_start() is kept
> under the mutex so that vhost event callbacks cannot race with
> list insertion.
>
> In the eth destructor, the mutex still covers the sibling check and
> DPDK device close/remove to prevent races on shared rte_device
> objects.
> In the vhost destructor, only the orphan check and list removal
> need the mutex.
>
> While at it, move the per-device mutex init out of common_construct()
> and destroy out of common_destruct() into their per-type callers.
> Introduce vhost_common_destruct() to mirror vhost_common_construct(),
> carrying the OVS_EXCLUDED(dev->mutex) annotation required by the
> dpdk_vhost_driver_unregister() callback path.
>
> This prepares for replacing dpdk_mutex with per-type list mutexes.
>
> Signed-off-by: David Marchand <[email protected]>

Hi David,

One potential resource leak due to reordering, but the rest looks good.

//Eelco

[...]

>  static int
>  vhost_common_construct(struct netdev *netdev)
> -    OVS_REQUIRES(dpdk_mutex)
>  {
>      int socket_id = rte_lcore_to_socket_id(rte_get_main_lcore());
>      struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
> @@ -1610,11 +1602,13 @@ vhost_common_construct(struct netdev *netdev)
>          return ENOMEM;
>      }
>
> +    common_construct(netdev, DPDK_ETH_PORT_ID_INVALID, socket_id);
> +
> +    ovs_mutex_init(&dev->mutex);
>      atomic_init(&dev->vhost_tx_retries_max, VHOST_ENQ_RETRY_DEF);
>
>      dev->vhost_max_queue_pairs = VHOST_MAX_QUEUE_PAIRS_DEF;
>
> -    common_construct(netdev, DPDK_ETH_PORT_ID_INVALID, socket_id);
>      return 0;
>  }
>
> @@ -1635,7 +1629,6 @@ netdev_dpdk_vhost_construct(struct netdev *netdev)
>          return EINVAL;
>      }
>
> -    ovs_mutex_lock(&dpdk_mutex);
>      /* Take the name of the vhost-user port and append it to the location 
> where
>       * the socket is to be created, then register the socket.
>       */
> @@ -1676,18 +1669,23 @@ netdev_dpdk_vhost_construct(struct netdev *netdev)
>          }
>      }
>
> -    err = rte_vhost_driver_start(dev->vhost_id);
> +    err = vhost_common_construct(netdev);
>      if (err) {
> -        VLOG_ERR("rte_vhost_driver_start failed for vhost user "
> +        VLOG_ERR("vhost_common_construct failed for vhost user "
>                   "port: %s\n", name);
>          goto out;
>      }
>
> -    err = vhost_common_construct(netdev);
> -    if (err) {
> -        VLOG_ERR("vhost_common_construct failed for vhost user "
> +    ovs_mutex_lock(&dpdk_mutex);
> +    err = rte_vhost_driver_start(dev->vhost_id);
> +    if (!err) {
> +        ovs_list_push_back(&dpdk_list, &dev->list_node);
> +        netdev_request_reconfigure(netdev);
> +    } else {
> +        VLOG_ERR("rte_vhost_driver_start failed for vhost user "
>                   "port: %s\n", name);
>      }
> +    ovs_mutex_unlock(&dpdk_mutex);
>
>  out:
>      if (err) {

If rte_vhost_driver_start() fails after vhost_common_construct() has
succeeded, does this path need to call vhost_common_destruct() to free
vhost_rxq_enabled, tx_q, and sw_stats?

[...]
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to