> -----Original Message-----
> From: Mike Pattrick <m...@redhat.com>
> Sent: Tuesday, December 20, 2022 11:54 PM
> To: dev@dpdk.org
> Cc: Zhang, Qi Z <qi.z.zh...@intel.com>; tho...@monjalon.net;
> david.march...@redhat.com; Zhou, YidingX <yidingx.z...@intel.com>;
> ktray...@redhat.com; Mike Pattrick <m...@redhat.com>; sta...@dpdk.org
> Subject: [PATCH v2] net/iavf: add lock for vf commands
>
> iavf admin queue commands aren't thread-safe. Bugs surrounding this issue
> can manifest in a variety of ways but frequently pend_cmd is over written.
> Simultaneously executing commands can result in a misconfigured device or
> DPDK sleeping in a thread for 2 second.
>
> Despite this limitation, vf commands may be executed from both
> iavf_dev_alarm_handler() in a control thread and the applications main
> thread. This is trivial to simulate in the testpmd application by creating a
> bond of vf's in active backup mode, and then turning the bond off and then
> on again repeatedly.
>
> Previously [1] was proposed as a potential solution, but this commit did not
> resolve all potential issues concerning the admin queue and has been
> reverted from the stable branch. I propose adding locks until a more
> complete solution is available.
>
> [1] commit cb5c1b91f76f ("net/iavf: add thread for event callbacks")
>
> Fixes: 48de41ca11f0 ("net/avf: enable link status update")
> Fixes: 84108425054a ("net/iavf: support asynchronous virtual channel
> message")
> Cc: sta...@dpdk.org
>
> Signed-off-by: Mike Pattrick <m...@redhat.com>
>
> ---
>
> v2:
> - Added locks around some iavf_execute_vf_cmd calls which were missed in
> v1
> - Changed description to indicate that [1] was only reverted out of the
> stable
> branch.
> ---
> drivers/net/iavf/iavf.h | 1 +
> drivers/net/iavf/iavf_vchnl.c | 90 +++++++++++++++++++++++++++++++++++
> 2 files changed, 91 insertions(+)
>
> diff --git a/drivers/net/iavf/iavf.h b/drivers/net/iavf/iavf.h index
> 1edebab8dc..aa18650ffa 100644
> --- a/drivers/net/iavf/iavf.h
> +++ b/drivers/net/iavf/iavf.h
> @@ -262,6 +262,7 @@ struct iavf_info {
> struct iavf_qv_map *qv_map; /* queue vector mapping */
> struct iavf_flow_list flow_list;
> rte_spinlock_t flow_ops_lock;
> + rte_spinlock_t aq_lock;
> struct iavf_parser_list rss_parser_list;
> struct iavf_parser_list dist_parser_list;
> struct iavf_parser_list ipsec_crypto_parser_list; diff --git
> a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c index
> f92daf97f2..edb74edcac 100644
> --- a/drivers/net/iavf/iavf_vchnl.c
> +++ b/drivers/net/iavf/iavf_vchnl.c
> @@ -554,7 +554,9 @@ iavf_enable_vlan_strip(struct iavf_adapter *adapter)
> args.in_args_size = 0;
> args.out_buffer = vf->aq_resp;
> args.out_size = IAVF_AQ_BUF_SZ;
> + rte_spinlock_lock(&vf->aq_lock);
> ret = iavf_execute_vf_cmd(adapter, &args, 0);
> + rte_spinlock_unlock(&vf->aq_lock);
> if (ret)
> PMD_DRV_LOG(ERR, "Failed to execute command of"
> " OP_ENABLE_VLAN_STRIPPING");
> @@ -575,7 +577,9 @@ iavf_disable_vlan_strip(struct iavf_adapter *adapter)
> args.in_args_size = 0;
> args.out_buffer = vf->aq_resp;
> args.out_size = IAVF_AQ_BUF_SZ;
> + rte_spinlock_lock(&vf->aq_lock);
> ret = iavf_execute_vf_cmd(adapter, &args, 0);
> + rte_spinlock_unlock(&vf->aq_lock);
> if (ret)
> PMD_DRV_LOG(ERR, "Failed to execute command of"
> " OP_DISABLE_VLAN_STRIPPING");
> @@ -604,7 +608,9 @@ iavf_check_api_version(struct iavf_adapter *adapter)
> args.out_buffer = vf->aq_resp;
> args.out_size = IAVF_AQ_BUF_SZ;
>
> + rte_spinlock_lock(&vf->aq_lock);
> err = iavf_execute_vf_cmd(adapter, &args, 0);
> + rte_spinlock_unlock(&vf->aq_lock);
Instead of wrapping lock and unlock every place, can we add a new wrap function
e.g.: iavf_execute_vf_cmd_safe?