<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 24, 2022 at 6:05 PM Ferruh Yigit <<a href="mailto:ferruh.yigit@intel.com">ferruh.yigit@intel.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 1/24/2022 12:12 PM, Kumara Parameshwaran wrote:<br>
> From: Kumara Parameshwaran <<a href="mailto:kparameshwar@vmware.com" target="_blank">kparameshwar@vmware.com</a>><br>
> <br>
> When a tap device is hotplugged to primary process which in turn<br>
> adds the device to all secondary process, the secondary process<br>
> does a tap_mp_attach_queues, but the fds are not populated in<br>
> the primary during the probe they are populated during the queue_setup,<br>
> added a fix to sync the queues during rte_eth_dev_start<br>
> <br>
> Fixes: 4852aa8f6e21 ("drivers/net: enable hotplug on secondary process")<br>
> Cc: <a href="mailto:stable@dpdk.org" target="_blank">stable@dpdk.org</a><br>
> <br>
> Signed-off-by: Kumara Parameshwaran <<a href="mailto:kparameshwar@vmware.com" target="_blank">kparameshwar@vmware.com</a>><br>
> ---<br>
> <br>
> v2:<br>
> * Addressed review comments to move the function declaration and version<br>
>    map<br>
> <br>
<br>
Thanks for adding patch version.<br>
<br>
>   drivers/net/tap/rte_eth_tap.c | 196 +++++++++++++---------------------<br>
>   lib/ethdev/ethdev_driver.h    |  17 +++<br>
>   lib/ethdev/rte_ethdev.c       |  11 ++<br>
>   lib/ethdev/version.map        |   2 +<br>
>   4 files changed, 102 insertions(+), 124 deletions(-)<br>
> <br>
<br>
Can you please separate etdev (API) changes to another patch, so this will be a patchset<br>
with two patches,<br>
first patch adds ethdev API<br>
second patch is tap patch, that uses the API in the first patch </blockquote><div>    Sure, I will do it.  <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c<br>
> index f1b48cae82..f6c25d7e21 100644<br>
> --- a/drivers/net/tap/rte_eth_tap.c<br>
> +++ b/drivers/net/tap/rte_eth_tap.c<br>
> @@ -66,7 +66,7 @@<br>
>       (TAP_GSO_MBUFS_PER_CORE * TAP_GSO_MBUF_CACHE_SIZE)<br>
>   <br>
>   /* IPC key for queue fds sync */<br>
> -#define TAP_MP_KEY "tap_mp_sync_queues"<br>
> +#define TAP_MP_REQ_START_RXTX "tap_mp_req_start_rxtx"<br>
> <br>
<br>
We said we can drop "tap_mp_sync_queues", but thinking twice,<br>
will current implementation cover following usecase:<br>
<br>
- Primary applicaiton started with tap interface, all config, setup,<br>
   start done<br>
- Secondary app started without any parameter<br>
<br>
Since primary already started, I think secondary fds will be wrong,<br>
what do you think?<br>
That is true, the fds would be unitialised, we should retain for the secondary attach case. <br>
>   #define TAP_IOV_DEFAULT_MAX 1024<br>
>   <br>
> @@ -880,11 +880,48 @@ tap_link_set_up(struct rte_eth_dev *dev)<br>
>       return tap_ioctl(pmd, SIOCSIFFLAGS, &ifr, 1, LOCAL_AND_REMOTE);<br>
>   }<br>
>   <br>
> +static int tap_mp_req_on_rxtx(struct rte_eth_dev *dev)<br>
<br>
Can you please follow the coding convention:<br>
sure, will do it. <br>
static int<br>
tap_mp_req_on_rxtx(struct rte_eth_dev *dev)<br>
{<br>
<br>
> +{<br>
> +     struct rte_mp_msg msg;<br>
> +     struct ipc_queues *request_param = (struct ipc_queues *)msg.param;<br>
> +     int err;<br>
> +     int fd_iterator = 0;<br>
> +     struct pmd_process_private *process_private = dev->process_private;<br>
> +     int i;<br>
> +<br>
> +     memset(&msg, 0, sizeof(msg));<br>
> +     strlcpy(<a href="http://msg.name" rel="noreferrer" target="_blank">msg.name</a>, TAP_MP_REQ_START_RXTX, sizeof(<a href="http://msg.name" rel="noreferrer" target="_blank">msg.name</a>));<br>
> +     strlcpy(request_param->port_name, dev->data->name, sizeof(request_param->port_name));<br>
> +     msg.len_param = sizeof(*request_param);<br>
> +     for (i = 0; i < dev->data->nb_tx_queues; i++) {<br>
> +             msg.fds[fd_iterator++] = process_private->txq_fds[i];<br>
> +             msg.num_fds++;<br>
> +             request_param->txq_count++;<br>
> +     }<br>
> +     for (i = 0; i < dev->data->nb_rx_queues; i++) {<br>
> +             msg.fds[fd_iterator++] = process_private->rxq_fds[i];<br>
> +             msg.num_fds++;<br>
> +             request_param->rxq_count++;<br>
> +     }<br>
> +<br>
> +     err = rte_mp_sendmsg(&msg);<br>
> +     if (err < 0) {<br>
> +             TAP_LOG(ERR, "Failed to send start req to secondary %d",<br>
> +                     rte_errno);<br>
> +             return -1;<br>
> +     }<br>
> +<br>
> +     return 0;<br>
> +}<br>
> +<br>
>   static int<br>
>   tap_dev_start(struct rte_eth_dev *dev)<br>
>   {<br>
>       int err, i;<br>
>   <br>
> +     if (rte_eal_process_type() == RTE_PROC_PRIMARY)<br>
> +             tap_mp_req_on_rxtx(dev);<br>
> +<br>
>       err = tap_intr_handle_set(dev, 1);<br>
>       if (err)<br>
>               return err;<br>
> @@ -901,6 +938,34 @@ tap_dev_start(struct rte_eth_dev *dev)<br>
>       return err;<br>
>   }<br>
>   <br>
> +static int<br>
> +tap_mp_req_start_rxtx(const struct rte_mp_msg *request, __rte_unused const void *peer)<br>
> +{<br>
<br>
I asked last time but I don't remember the response,<br>
what should be in the 'peer' variable?<br>
<br>
> +     struct rte_eth_dev *dev;<br>
> +     const struct ipc_queues *request_param =<br>
> +             (const struct ipc_queues *)request->param;<br>
> +     int fd_iterator;<br>
> +     int queue;<br>
> +     struct pmd_process_private *process_private;<br>
> +<br>
> +     dev = rte_get_eth_dev_by_name(request_param->port_name);<br>
> +     if (!dev) {<br>
> +             TAP_LOG(ERR, "Failed to get dev for %s",<br>
> +                     request_param->port_name);<br>
> +             return -1;<br>
> +     }<br>
> +     process_private = dev->process_private;<br>
> +     fd_iterator = 0;<br>
> +     TAP_LOG(DEBUG, "tap_attach rx_q:%d tx_q:%d\n", request_param->rxq_count,<br>
> +             request_param->txq_count);<br>
> +     for (queue = 0; queue < request_param->txq_count; queue++)<br>
> +             process_private->txq_fds[queue] = request->fds[fd_iterator++];<br>
> +     for (queue = 0; queue < request_param->rxq_count; queue++)<br>
> +             process_private->rxq_fds[queue] = request->fds[fd_iterator++];<br>
> +<br>
> +     return 0;<br>
> +}<br>
> +<br>
>   /* This function gets called when the current port gets stopped.<br>
>    */<br>
>   static int<br>
> @@ -1084,6 +1149,7 @@ tap_dev_close(struct rte_eth_dev *dev)<br>
>   <br>
>       if (rte_eal_process_type() != RTE_PROC_PRIMARY) {<br>
>               rte_free(dev->process_private);<br>
> +             rte_mp_action_unregister(TAP_MP_REQ_START_RXTX);<br>
>               return 0;<br>
>       }<br>
>   <br>
> @@ -1140,8 +1206,6 @@ tap_dev_close(struct rte_eth_dev *dev)<br>
>               internals->ioctl_sock = -1;<br>
>       }<br>
>       rte_free(dev->process_private);<br>
> -     if (tap_devices_count == 1)<br>
> -             rte_mp_action_unregister(TAP_MP_KEY);<br>
>       tap_devices_count--;<br>
>       /*<br>
>        * Since TUN device has no more opened file descriptors<br>
> @@ -2292,113 +2356,6 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)<br>
>       return ret;<br>
>   }<br>
>   <br>
> -/* Request queue file descriptors from secondary to primary. */<br>
> -static int<br>
> -tap_mp_attach_queues(const char *port_name, struct rte_eth_dev *dev)<br>
> -{<br>
> -     int ret;<br>
> -     struct timespec timeout = {.tv_sec = 1, .tv_nsec = 0};<br>
> -     struct rte_mp_msg request, *reply;<br>
> -     struct rte_mp_reply replies;<br>
> -     struct ipc_queues *request_param = (struct ipc_queues *)request.param;<br>
> -     struct ipc_queues *reply_param;<br>
> -     struct pmd_process_private *process_private = dev->process_private;<br>
> -     int queue, fd_iterator;<br>
> -<br>
> -     /* Prepare the request */<br>
> -     memset(&request, 0, sizeof(request));<br>
> -     strlcpy(<a href="http://request.name" rel="noreferrer" target="_blank">request.name</a>, TAP_MP_KEY, sizeof(<a href="http://request.name" rel="noreferrer" target="_blank">request.name</a>));<br>
> -     strlcpy(request_param->port_name, port_name,<br>
> -             sizeof(request_param->port_name));<br>
> -     request.len_param = sizeof(*request_param);<br>
> -     /* Send request and receive reply */<br>
> -     ret = rte_mp_request_sync(&request, &replies, &timeout);<br>
> -     if (ret < 0 || replies.nb_received != 1) {<br>
> -             TAP_LOG(ERR, "Failed to request queues from primary: %d",<br>
> -                     rte_errno);<br>
> -             return -1;<br>
> -     }<br>
> -     reply = &replies.msgs[0];<br>
> -     reply_param = (struct ipc_queues *)reply->param;<br>
> -     TAP_LOG(DEBUG, "Received IPC reply for %s", reply_param->port_name);<br>
> -<br>
> -     /* Attach the queues from received file descriptors */<br>
> -     if (reply_param->rxq_count + reply_param->txq_count != reply->num_fds) {<br>
> -             TAP_LOG(ERR, "Unexpected number of fds received");<br>
> -             return -1;<br>
> -     }<br>
> -<br>
> -     dev->data->nb_rx_queues = reply_param->rxq_count;<br>
> -     dev->data->nb_tx_queues = reply_param->txq_count;<br>
> -     fd_iterator = 0;<br>
> -     for (queue = 0; queue < reply_param->rxq_count; queue++)<br>
> -             process_private->rxq_fds[queue] = reply->fds[fd_iterator++];<br>
> -     for (queue = 0; queue < reply_param->txq_count; queue++)<br>
> -             process_private->txq_fds[queue] = reply->fds[fd_iterator++];<br>
> -     free(reply);<br>
> -     return 0;<br>
> -}<br>
> -<br>
> -/* Send the queue file descriptors from the primary process to secondary. */<br>
> -static int<br>
> -tap_mp_sync_queues(const struct rte_mp_msg *request, const void *peer)<br>
> -{<br>
> -     struct rte_eth_dev *dev;<br>
> -     struct pmd_process_private *process_private;<br>
> -     struct rte_mp_msg reply;<br>
> -     const struct ipc_queues *request_param =<br>
> -             (const struct ipc_queues *)request->param;<br>
> -     struct ipc_queues *reply_param =<br>
> -             (struct ipc_queues *)reply.param;<br>
> -     uint16_t port_id;<br>
> -     int queue;<br>
> -     int ret;<br>
> -<br>
> -     /* Get requested port */<br>
> -     TAP_LOG(DEBUG, "Received IPC request for %s", request_param->port_name);<br>
> -     ret = rte_eth_dev_get_port_by_name(request_param->port_name, &port_id);<br>
> -     if (ret) {<br>
> -             TAP_LOG(ERR, "Failed to get port id for %s",<br>
> -                     request_param->port_name);<br>
> -             return -1;<br>
> -     }<br>
> -     dev = &rte_eth_devices[port_id];<br>
> -     process_private = dev->process_private;<br>
> -<br>
> -     /* Fill file descriptors for all queues */<br>
> -     reply.num_fds = 0;<br>
> -     reply_param->rxq_count = 0;<br>
> -     if (dev->data->nb_rx_queues + dev->data->nb_tx_queues ><br>
> -                     RTE_MP_MAX_FD_NUM){<br>
> -             TAP_LOG(ERR, "Number of rx/tx queues exceeds max number of fds");<br>
> -             return -1;<br>
> -     }<br>
> -<br>
> -     for (queue = 0; queue < dev->data->nb_rx_queues; queue++) {<br>
> -             reply.fds[reply.num_fds++] = process_private->rxq_fds[queue];<br>
> -             reply_param->rxq_count++;<br>
> -     }<br>
> -     RTE_ASSERT(reply_param->rxq_count == dev->data->nb_rx_queues);<br>
> -<br>
> -     reply_param->txq_count = 0;<br>
> -     for (queue = 0; queue < dev->data->nb_tx_queues; queue++) {<br>
> -             reply.fds[reply.num_fds++] = process_private->txq_fds[queue];<br>
> -             reply_param->txq_count++;<br>
> -     }<br>
> -     RTE_ASSERT(reply_param->txq_count == dev->data->nb_tx_queues);<br>
> -<br>
> -     /* Send reply */<br>
> -     strlcpy(<a href="http://reply.name" rel="noreferrer" target="_blank">reply.name</a>, request->name, sizeof(<a href="http://reply.name" rel="noreferrer" target="_blank">reply.name</a>));<br>
> -     strlcpy(reply_param->port_name, request_param->port_name,<br>
> -             sizeof(reply_param->port_name));<br>
> -     reply.len_param = sizeof(*reply_param);<br>
> -     if (rte_mp_reply(&reply, peer) < 0) {<br>
> -             TAP_LOG(ERR, "Failed to reply an IPC request to sync queues");<br>
> -             return -1;<br>
> -     }<br>
> -     return 0;<br>
> -}<br>
> -<br>
>   /* Open a TAP interface device.<br>
>    */<br>
>   static int<br>
> @@ -2442,9 +2399,11 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)<br>
>                       return -1;<br>
>               }<br>
>   <br>
> -             ret = tap_mp_attach_queues(name, eth_dev);<br>
> -             if (ret != 0)<br>
> -                     return -1;<br>
> +             ret = rte_mp_action_register(TAP_MP_REQ_START_RXTX, tap_mp_req_start_rxtx);<br>
> +             if (ret < 0 && rte_errno != ENOTSUP)<br>
> +                     TAP_LOG(ERR, "tap: Failed to register IPC callback: %s",<br>
> +                             strerror(rte_errno));<br>
> +<br>
>               rte_eth_dev_probing_finish(eth_dev);<br>
>               return 0;<br>
>       }<br>
> @@ -2492,15 +2451,6 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)<br>
>   <br>
>       TAP_LOG(DEBUG, "Initializing pmd_tap for %s", name);<br>
>   <br>
> -     /* Register IPC feed callback */<br>
> -     if (!tap_devices_count) {<br>
> -             ret = rte_mp_action_register(TAP_MP_KEY, tap_mp_sync_queues);<br>
> -             if (ret < 0 && rte_errno != ENOTSUP) {<br>
> -                     TAP_LOG(ERR, "tap: Failed to register IPC callback: %s",<br>
> -                             strerror(rte_errno));<br>
> -                     goto leave;<br>
> -             }<br>
> -     }<br>
>       tap_devices_count++;<br>
>       tap_devices_count_increased = 1;<br>
>       ret = eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac,<br>
> @@ -2511,8 +2461,6 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)<br>
>               TAP_LOG(ERR, "Failed to create pmd for %s as %s",<br>
>                       name, tap_name);<br>
>               if (tap_devices_count_increased == 1) {<br>
> -                     if (tap_devices_count == 1)<br>
> -                             rte_mp_action_unregister(TAP_MP_KEY);<br>
>                       tap_devices_count--;<br>
>               }<br>
>       }<br>
> diff --git a/lib/ethdev/ethdev_driver.h b/lib/ethdev/ethdev_driver.h<br>
> index d95605a355..a08991bcdf 100644<br>
> --- a/lib/ethdev/ethdev_driver.h<br>
> +++ b/lib/ethdev/ethdev_driver.h<br>
> @@ -1629,6 +1629,23 @@ rte_eth_hairpin_queue_peer_bind(uint16_t cur_port, uint16_t cur_queue,<br>
>                               struct rte_hairpin_peer_info *peer_info,<br>
>                               uint32_t direction);<br>
>   <br>
> +/**<br>
<br>
Please add '@internal' tag into doxygen comment.<br>
<br>
> +* Get rte_eth_dev from device name. The device name should be specified<br>
> +* as below:<br>
> +* - PCIe address (Domain:Bus:Device.Function), for example- 0000:2:00.0<br>
> +* - SoC device name, for example- fsl-gmac0<br>
> +* - vdev dpdk name, for example- net_[pcap0|null0|tap0]<br>
> +*<br>
> +* @param name<br>
> +*  pci address or name of the device<br>
> +* @return<br>
> +*   - rte_eth_dev if successful<br>
> +*   - NULL on failure<br>
> +*/<br>
> +__rte_internal<br>
> +struct rte_eth_dev*<br>
> +rte_get_eth_dev_by_name(const char *name);<br>
<br>
As the API name, better to start with 'rte_eth_' prefix to be consistent with<br>
rest of the APIs.<br>
I suggest 'rte_eth_dev_get_by_name' but feel free to chose better one.<br>
<br>
> +<br>
>   /**<br>
>    * @internal<br>
>    * Reset the current queue state and configuration to disconnect (unbind) it<br>
> diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c<br>
> index a1d475a292..9192b0d664 100644<br>
> --- a/lib/ethdev/rte_ethdev.c<br>
> +++ b/lib/ethdev/rte_ethdev.c<br>
> @@ -894,6 +894,17 @@ rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)<br>
>       return -ENODEV;<br>
>   }<br>
>   <br>
> +struct rte_eth_dev *<br>
> +rte_get_eth_dev_by_name(const char *name)<br>
> +{<br>
> +     uint16_t pid;<br>
> +<br>
> +     if (rte_eth_dev_get_port_by_name(name, &pid))<br>
> +             return NULL;<br>
> +<br>
> +     return &rte_eth_devices[pid];<br>
> +}<br>
> +<br>
>   static int<br>
>   eth_err(uint16_t port_id, int ret)<br>
>   {<br>
> diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map<br>
> index c2fb0669a4..7e3797189b 100644<br>
> --- a/lib/ethdev/version.map<br>
> +++ b/lib/ethdev/version.map<br>
> @@ -256,6 +256,7 @@ EXPERIMENTAL {<br>
>       rte_flow_flex_item_create;<br>
>       rte_flow_flex_item_release;<br>
>       rte_flow_pick_transfer_proxy;<br>
> +<br>
<br>
This is unintendent change.<br>
<br>
>   };<br>
>   <br>
>   INTERNAL {<br>
> @@ -282,4 +283,5 @@ INTERNAL {<br>
>       rte_eth_representor_id_get;<br>
>       rte_eth_switch_domain_alloc;<br>
>       rte_eth_switch_domain_free;<br>
> +     rte_get_eth_dev_by_name;<br>
<br>
Please add in a sorted way.<br>
<br>
>   };<br>
<br>
</blockquote></div></div>