• B
    ice: Fix race conditions between virtchnl handling and VF ndo ops · 96c8b486
    Brett Creeley 提交于
    stable inclusion
    from stable-v5.10.104
    commit 41edeeaae51a1064a7e7cdea70623377cb2655cc
    bugzilla: https://gitee.com/openeuler/kernel/issues/I56XAC
    
    Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=41edeeaae51a1064a7e7cdea70623377cb2655cc
    
    --------------------------------
    
    commit e6ba5273 upstream.
    
    The VF can be configured via the PF's ndo ops at the same time the PF is
    receiving/handling virtchnl messages. This has many issues, with
    one of them being the ndo op could be actively resetting a VF (i.e.
    resetting it to the default state and deleting/re-adding the VF's VSI)
    while a virtchnl message is being handled. The following error was seen
    because a VF ndo op was used to change a VF's trust setting while the
    VIRTCHNL_OP_CONFIG_VSI_QUEUES was ongoing:
    
    [35274.192484] ice 0000:88:00.0: Failed to set LAN Tx queue context, error: ICE_ERR_PARAM
    [35274.193074] ice 0000:88:00.0: VF 0 failed opcode 6, retval: -5
    [35274.193640] iavf 0000:88:01.0: PF returned error -5 (IAVF_ERR_PARAM) to our request 6
    
    Fix this by making sure the virtchnl handling and VF ndo ops that
    trigger VF resets cannot run concurrently. This is done by adding a
    struct mutex cfg_lock to each VF structure. For VF ndo ops, the mutex
    will be locked around the critical operations and VFR. Since the ndo ops
    will trigger a VFR, the virtchnl thread will use mutex_trylock(). This
    is done because if any other thread (i.e. VF ndo op) has the mutex, then
    that means the current VF message being handled is no longer valid, so
    just ignore it.
    
    This issue can be seen using the following commands:
    
    for i in {0..50}; do
            rmmod ice
            modprobe ice
    
            sleep 1
    
            echo 1 > /sys/class/net/ens785f0/device/sriov_numvfs
            echo 1 > /sys/class/net/ens785f1/device/sriov_numvfs
    
            ip link set ens785f1 vf 0 trust on
            ip link set ens785f0 vf 0 trust on
    
            sleep 2
    
            echo 0 > /sys/class/net/ens785f0/device/sriov_numvfs
            echo 0 > /sys/class/net/ens785f1/device/sriov_numvfs
            sleep 1
            echo 1 > /sys/class/net/ens785f0/device/sriov_numvfs
            echo 1 > /sys/class/net/ens785f1/device/sriov_numvfs
    
            ip link set ens785f1 vf 0 trust on
            ip link set ens785f0 vf 0 trust on
    done
    
    Fixes: 7c710869 ("ice: Add handlers for VF netdevice operations")
    Signed-off-by: NBrett Creeley <brett.creeley@intel.com>
    Tested-by: NKonrad Jankowski <konrad0.jankowski@intel.com>
    Signed-off-by: NTony Nguyen <anthony.l.nguyen@intel.com>
    Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
    Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: NYu Liao <liaoyu15@huawei.com>
    Reviewed-by: NWei Li <liwei391@huawei.com>
    Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
    96c8b486
ice_virtchnl_pf.c 110.2 KB