Subject: Re: [PATCH net 2/3] ice: Fix ice VF reset during iavf initialization

From: Leon Romanovsky <[email-masked]>
Date: Wed, 26 Apr 2023 09:49:41 +0300

On Tue, Apr 25, 2023 at 10:01:26AM -0700, Tony Nguyen wrote:
> From: Dawid Wesierski <[email-masked]>
> 
> Fix the current implementation that causes ice_trigger_vf_reset()
> to start resetting the VF even when the VF is still resetting itself
> and initializing adminq. This leads to a series of -53 errors
> (failed to init adminq) from the IAVF.
> 
> Change the state of the vf_state field to be not active when the IAVF
> asks for a reset. To avoid issues caused by the VF being reset too
> early, make sure to wait until receiving the message on the message
> box to know the exact state of the IAVF driver.
> 
> Fixes: c54d209c78b8 ("ice: Wait for VF to be reset/ready before configuration")
> Signed-off-by: Dawid Wesierski <[email-masked]>
> Signed-off-by: Kamil Maziarz <[email-masked]>
> Acked-by: Jacob Keller <[email-masked]>
> Tested-by: Rafal Romanowski <[email-masked]>
> Signed-off-by: Tony Nguyen <[email-masked]>
> ---
>  drivers/net/ethernet/intel/ice/ice_sriov.c    |  8 ++++----
>  drivers/net/ethernet/intel/ice/ice_vf_lib.c   | 19 +++++++++++++++++++
>  drivers/net/ethernet/intel/ice/ice_vf_lib.h   |  1 +
>  drivers/net/ethernet/intel/ice/ice_virtchnl.c |  1 +
>  4 files changed, 25 insertions(+), 4 deletions(-)

<...>

> -	ret = ice_check_vf_ready_for_cfg(vf);
> +	ret = ice_check_vf_ready_for_reset(vf);
>  	if (ret)
>  		goto out_put_vf;

<...>

> +/**
> + * ice_check_vf_ready_for_reset - check if VF is ready to be reset
> + * @vf: VF to check if it's ready to be reset
> + *
> + * The purpose of this function is to ensure that the VF is not in reset,
> + * disabled, and is both initialized and active, thus enabling us to safely
> + * initialize another reset.
> + */
> +int ice_check_vf_ready_for_reset(struct ice_vf *vf)
> +{
> +	int ret;
> +
> +	ret = ice_check_vf_ready_for_cfg(vf);
> +	if (!ret && !test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
> +		ret = -EAGAIN;

I don't know your driver enough to say how it is it possible to find VF
"resetting itself" and PF trying to reset VF at the same time.

But what I see is that ICE_VF_STATE_ACTIVE bit check is racy and you
don't really fix the root cause of calling to reset without proper locking.

Thanks

> +
> +	return ret;
> +}

<...>

>  	case VIRTCHNL_OP_RESET_VF:
> +		clear_bit(ICE_VF_STATE_ACTIVE, vf->vf_states);
>  		ops->reset_vf(vf);
>  		break;
>  	case VIRTCHNL_OP_ADD_ETH_ADDR:
> -- 
> 2.38.1
>