> Subject: [PATCH v7 1/4] net/iavf: fix MAC addresses leak on reset
> 
> When resetting, calling iavf_dev_uninit + iavf_dev_init results in
> leaking the previous dev->data->mac_addrs array.
> As a consequence, secondary MAC addresses are lost during a VF reset.
> 
> Move the MAC addresses array in the private iavf_info structure, along
> the multicast MAC addresses.
> Set/clear dev->data->mac_addrs in iavf_dev_init/iavf_dev_uninit.
> 
> Consistently use RTE_DIM() to avoid mixing with the multicast addresses
> array.
> 
> Fixes: e74e1bb6280d ("net/iavf: enable port reset")
> Cc: [email protected]
> 
> Signed-off-by: David Marchand <[email protected]>
> ---
>  drivers/net/intel/iavf/iavf.h        |  3 +++
>  drivers/net/intel/iavf/iavf_ethdev.c | 20 +++++++-------------
>  drivers/net/intel/iavf/iavf_vchnl.c  | 10 +++++-----
>  3 files changed, 15 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/net/intel/iavf/iavf.h b/drivers/net/intel/iavf/iavf.h
> index 044de3cfd4..1d52b3d113 100644
> --- a/drivers/net/intel/iavf/iavf.h
> +++ b/drivers/net/intel/iavf/iavf.h
> @@ -255,6 +255,9 @@ struct iavf_info {
>       bool link_up;
>       uint32_t link_speed;
> 
> +     /* Unicast addrs */
> +     struct rte_ether_addr mac_addrs[IAVF_NUM_MACADDR_MAX];
> +
>       /* Multicast addrs */
>       struct rte_ether_addr mc_addrs[IAVF_NUM_MACADDR_MAX];
>       uint16_t mc_addrs_num;   /* Multicast mac addresses number */
> diff --git a/drivers/net/intel/iavf/iavf_ethdev.c
> b/drivers/net/intel/iavf/iavf_ethdev.c
> index 2ac4dbdac4..b498258d58 100644
> --- a/drivers/net/intel/iavf/iavf_ethdev.c
> +++ b/drivers/net/intel/iavf/iavf_ethdev.c
> @@ -1186,7 +1186,7 @@ iavf_dev_info_get(struct rte_eth_dev *dev, struct
> rte_eth_dev_info *dev_info)
>       dev_info->hash_key_size = vf->vf_res->rss_key_size;
>       dev_info->reta_size = vf->vf_res->rss_lut_size;
>       dev_info->flow_type_rss_offloads = IAVF_RSS_OFFLOAD_ALL;
> -     dev_info->max_mac_addrs = IAVF_NUM_MACADDR_MAX;
> +     dev_info->max_mac_addrs = RTE_DIM(vf->mac_addrs);
>       /*
>        * Runtime queue setup can race with the hardware Tx rate limiter on
>        * E810 VFs and corrupt queue state. Once a per-queue bandwidth
> rte_tm
> @@ -3104,16 +3104,9 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
>       /* set default ptype table */
>       iavf_set_default_ptype_table(eth_dev);
> 
> -     /* copy mac addr */
> -     eth_dev->data->mac_addrs = rte_zmalloc(
> -             "iavf_mac", RTE_ETHER_ADDR_LEN *
> IAVF_NUM_MACADDR_MAX, 0);
> -     if (!eth_dev->data->mac_addrs) {
> -             PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to"
> -                          " store MAC addresses",
> -                          RTE_ETHER_ADDR_LEN *
> IAVF_NUM_MACADDR_MAX);
> -             ret = -ENOMEM;
> -             goto init_vf_err;
> -     }
> +     /* Point at the MAC addresses array from priv */
> +     eth_dev->data->mac_addrs = vf->mac_addrs;
> +
>       /* If the MAC address is not configured by host,
>        * generate a random one.
>        */
> @@ -3123,7 +3116,6 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
>       rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
>                       &eth_dev->data->mac_addrs[0]);
> 
> -

Nit: stray line removal. The rest LGTM.

Acked-by: Ciara Loftus <[email protected]>

>       if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR
> &&
>                       /* register callback func to eal lib */
>                       rte_intr_callback_register(pci_dev->intr_handle,
> @@ -3199,7 +3191,6 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
>       iavf_phc_sync_alarm_stop(eth_dev);
>       rte_eal_alarm_cancel(iavf_dev_alarm_handler, eth_dev);
> 
> -     rte_free(eth_dev->data->mac_addrs);
>       eth_dev->data->mac_addrs = NULL;
> 
>  init_vf_err:
> @@ -3256,6 +3247,9 @@ iavf_dev_close(struct rte_eth_dev *dev)
> 
>       adapter->closed = true;
> 
> +     /* Clear reference to the MAC addresses in priv */
> +     dev->data->mac_addrs = NULL;
> +
>       /* free iAVF security device context all related resources */
>       iavf_security_ctx_destroy(adapter);
> 
> diff --git a/drivers/net/intel/iavf/iavf_vchnl.c
> b/drivers/net/intel/iavf/iavf_vchnl.c
> index e3120c655d..df97ff2052 100644
> --- a/drivers/net/intel/iavf/iavf_vchnl.c
> +++ b/drivers/net/intel/iavf/iavf_vchnl.c
> @@ -1674,19 +1674,19 @@ iavf_config_irq_map_lv(struct iavf_adapter
> *adapter, uint16_t num)
>  void
>  iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
>  {
> +     struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
>       struct {
>               struct virtchnl_ether_addr_list list;
> -             struct virtchnl_ether_addr
> addr[IAVF_NUM_MACADDR_MAX];
> +             struct virtchnl_ether_addr addr[RTE_DIM(vf->mac_addrs)];
>       } list_req = {0};
>       struct virtchnl_ether_addr_list *list = &list_req.list;
> -     struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
>       uint8_t msg_buf[IAVF_AQ_BUF_SZ] = {0};
>       struct iavf_cmd_info args = {0};
> -     int err, i;
> +     int err;
>       size_t buf_len;
> 
> -     for (i = 0; i < IAVF_NUM_MACADDR_MAX; i++) {
> -             struct rte_ether_addr *addr = &adapter->dev_data-
> >mac_addrs[i];
> +     for (unsigned int i = 0; i < RTE_DIM(vf->mac_addrs); i++) {
> +             struct rte_ether_addr *addr = &vf->mac_addrs[i];
>               struct virtchnl_ether_addr *vc_addr = &list->list[list-
> >num_elements];
> 
>               /* ignore empty addresses */
> --
> 2.54.0

Reply via email to