Skip to content

Commit 77d64d2

Browse files
iveceraanguy11
authored andcommitted
ice: Protect vf_state check by cfg_lock in ice_vc_process_vf_msg()
Previous patch labelled "ice: Fix incorrect locking in ice_vc_process_vf_msg()" fixed an issue with ignored messages sent by VF driver but a small race window still left. Recently caught trace during 'ip link set ... vf 0 vlan ...' operation: [ 7332.995625] ice 0000:3b:00.0: Clearing port VLAN on VF 0 [ 7333.001023] iavf 0000:3b:01.0: Reset indication received from the PF [ 7333.007391] iavf 0000:3b:01.0: Scheduling reset task [ 7333.059575] iavf 0000:3b:01.0: PF returned error -5 (IAVF_ERR_PARAM) to our request 3 [ 7333.059626] ice 0000:3b:00.0: Invalid message from VF 0, opcode 3, len 4, error -1 Setting of VLAN for VF causes a reset of the affected VF using ice_reset_vf() function that runs with cfg_lock taken: 1. ice_notify_vf_reset() informs IAVF driver that reset is needed and IAVF schedules its own reset procedure 2. Bit ICE_VF_STATE_DIS is set in vf->vf_state 3. Misc initialization steps 4. ice_sriov_post_vsi_rebuild() -> ice_vf_set_initialized() and that clears ICE_VF_STATE_DIS in vf->vf_state Step 3 is mentioned race window because IAVF reset procedure runs in parallel and one of its step is sending of VIRTCHNL_OP_GET_VF_RESOURCES message (opcode==3). This message is handled in ice_vc_process_vf_msg() and if it is received during the mentioned race window then it's marked as invalid and error is returned to VF driver. Protect vf_state check in ice_vc_process_vf_msg() by cfg_lock to avoid this race condition. Fixes: e6ba527 ("ice: Fix race conditions between virtchnl handling and VF ndo ops") Tested-by: Fei Liu <feliu@redhat.com> Signed-off-by: Ivan Vecera <ivecera@redhat.com> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
1 parent aaf461a commit 77d64d2

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

drivers/net/ethernet/intel/ice/ice_virtchnl.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3625,6 +3625,8 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event)
36253625
return;
36263626
}
36273627

3628+
mutex_lock(&vf->cfg_lock);
3629+
36283630
/* Check if VF is disabled. */
36293631
if (test_bit(ICE_VF_STATE_DIS, vf->vf_states)) {
36303632
err = -EPERM;
@@ -3648,19 +3650,14 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event)
36483650
NULL, 0);
36493651
dev_err(dev, "Invalid message from VF %d, opcode %d, len %d, error %d\n",
36503652
vf_id, v_opcode, msglen, err);
3651-
ice_put_vf(vf);
3652-
return;
3653+
goto finish;
36533654
}
36543655

3655-
mutex_lock(&vf->cfg_lock);
3656-
36573656
if (!ice_vc_is_opcode_allowed(vf, v_opcode)) {
36583657
ice_vc_send_msg_to_vf(vf, v_opcode,
36593658
VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL,
36603659
0);
3661-
mutex_unlock(&vf->cfg_lock);
3662-
ice_put_vf(vf);
3663-
return;
3660+
goto finish;
36643661
}
36653662

36663663
switch (v_opcode) {
@@ -3773,6 +3770,7 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event)
37733770
vf_id, v_opcode, err);
37743771
}
37753772

3773+
finish:
37763774
mutex_unlock(&vf->cfg_lock);
37773775
ice_put_vf(vf);
37783776
}

0 commit comments

Comments
 (0)