ice: Fix incorrect locking in ice_vc_process_vf_msg()
Subsystems (3)
PATCH v2 1/1 ice: Fix incorrect locking in ice_vc_process_vf_msg()
Usage of mutex_trylock() in ice_vc_process_vf_msg() is incorrect because message sent from VF is ignored and never processed.
Use mutex_lock() instead to fix the issue. It is safe because this mutex is used to prevent races between VF related NDOs and handlers processing request messages from VF and these handlers are running in ice_service_task() context. Additionally move this mutex lock prior ice_vc_is_opcode_allowed() call to avoid potential races during allowlist acccess.
--- drivers/net/ethernet/intel/ice/ice_virtchnl.c | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-)
drivers/net/ethernet/intel/ice/ice_virtchnl.c +7 -14
@@ -3642,14 +3642,6 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event) err = -EINVAL ; } -if (!ice_vc_is_opcode_allowed (vf, v_opcode)) { -ice_vc_send_msg_to_vf (vf, v_opcode, -VIRTCHNL_STATUS_ERR_NOT_SUPPORTED ,NULL , -0 ); -ice_put_vf (vf); -return ; - } - error_handler:if (err) { ice_vc_send_msg_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_PARAM,
@@ -3660,12 +3652,13 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event)return ; } -/* VF is being configured in another context that triggers a VFR, so no -* need to process this message -*/ -if (!mutex_trylock (&vf->cfg_lock)) { -dev_info (dev,"VF %u is being configured in another context that will trigger a VFR, so there is no need to handle this message\n" , - vf->vf_id); +mutex_lock (&vf->cfg_lock); + +if (!ice_vc_is_opcode_allowed (vf, v_opcode)) { +ice_vc_send_msg_to_vf (vf, v_opcode, +VIRTCHNL_STATUS_ERR_NOT_SUPPORTED ,NULL , +0 ); +mutex_unlock (&vf->cfg_lock);ice_put_vf (vf);return ; }
Signature · 1 line
2.35.1
From: Ivan Vecera <[email protected]>
Date: Fri, 1 Apr 2022 12:40:52 +0200
Quoted 10 lines
Usage of
mutex_trylock()inice_vc_process_vf_msg()is incorrect because message sent from VF is ignored and never processed.Use
mutex_lock()instead to fix the issue. It is safe because this mutex is used to prevent races between VF related NDOs and handlers processing request messages from VF and these handlers are running inice_service_task()context. Additionally move this mutex lock priorice_vc_is_opcode_allowed()call to avoid potential races during allowlist acccess.
Quoted 2 lines
Fixes e6ba5273d4ed ("ice: Fix race conditions between virtchnl handling and VF ndo ops")Signed-off-by Ivan Vecera <[email protected]>
Hey Tony,
I guess you missed this one due to being on a vacation previously. It's been previously reviewed IIRC, could you take it into net-queue?
Quoted 45 lines
--- drivers/net/ethernet/intel/ice/ice_virtchnl.c | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-)drivers/net/ethernet/intel/ice/ice_virtchnl.c +7
-14@@ -3642,14 +3642,6 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event) err = -EINVAL ; } -if (!ice_vc_is_opcode_allowed (vf, v_opcode)) { -ice_vc_send_msg_to_vf (vf, v_opcode, -VIRTCHNL_STATUS_ERR_NOT_SUPPORTED ,NULL , -0 ); -ice_put_vf (vf); -return ; - } - error_handler:if (err) { ice_vc_send_msg_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_PARAM,@@ -3660,12 +3652,13 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event)return ; } -/* VF is being configured in another context that triggers a VFR, so no -* need to process this message -*/ -if (!mutex_trylock (&vf->cfg_lock)) { -dev_info (dev,"VF %u is being configured in another context that will trigger a VFR, so there is no need to handle this message\n" , - vf->vf_id); +mutex_lock (&vf->cfg_lock); + +if (!ice_vc_is_opcode_allowed (vf, v_opcode)) { +ice_vc_send_msg_to_vf (vf, v_opcode, +VIRTCHNL_STATUS_ERR_NOT_SUPPORTED ,NULL , +0 ); +mutex_unlock (&vf->cfg_lock);ice_put_vf (vf);return ; }Signature · 1 line
2.35.1
Thanks,
Al
Tony Nguyen
maintainerQuoted 13 lines · Alexander Lobakin
From: Ivan Vecera <[email protected]>
Date: Fri, 1 Apr 2022 12:40:52 +0200Quoted 10 lines
Usage of
mutex_trylock()inice_vc_process_vf_msg()is incorrect because message sent from VF is ignored and never processed.Use
mutex_lock()instead to fix the issue. It is safe because this mutex is used to prevent races between VF related NDOs and handlers processing request messages from VF and these handlers are running inice_service_task()context. Additionally move this mutex lock priorice_vc_is_opcode_allowed()call to avoid potential races during allowlist acccess.
Quoted 7 lines
Quoted 2 lines
Fixes e6ba5273d4ed ("ice: Fix race conditions between virtchnl handling and VF ndo ops")Signed-off-by Ivan Vecera <[email protected]>Hey Tony,
I guess you missed this one due to being on a vacation previously. It's been previously reviewed IIRC, could you take it into net-queue?
I remember applying this but I don't see it on the tree so I must be mistaken. :( I'll get it applied, thanks for catching.
-Tony
Quoted 47 lines
Quoted 45 lines
--- drivers/net/ethernet/intel/ice/ice_virtchnl.c | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-)drivers/net/ethernet/intel/ice/ice_virtchnl.c +7
-14@@ -3642,14 +3642,6 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event) err = -EINVAL ; } -if (!ice_vc_is_opcode_allowed (vf, v_opcode)) { -ice_vc_send_msg_to_vf (vf, v_opcode, -VIRTCHNL_STATUS_ERR_NOT_SUPPORTED ,NULL , -0 ); -ice_put_vf (vf); -return ; - } - error_handler:if (err) { ice_vc_send_msg_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_PARAM,@@ -3660,12 +3652,13 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event)return ; } -/* VF is being configured in another context that triggers a VFR, so no -* need to process this message -*/ -if (!mutex_trylock (&vf->cfg_lock)) { -dev_info (dev,"VF %u is being configured in another context that will trigger a VFR, so there is no need to handle this message\n" , - vf->vf_id); +mutex_lock (&vf->cfg_lock); + +if (!ice_vc_is_opcode_allowed (vf, v_opcode)) { +ice_vc_send_msg_to_vf (vf, v_opcode, +VIRTCHNL_STATUS_ERR_NOT_SUPPORTED ,NULL , +0 ); +mutex_unlock (&vf->cfg_lock);ice_put_vf (vf);return ; }Signature · 1 line
2.35.1Thanks,
Al
Jankowski, Konrad0
Tested-byQuoted 48 lines
-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Tony Nguyen
Sent: Friday, April 8, 2022 6:01 PM
To: Lobakin, Alexandr <[email protected]>
Cc: ivecera <[email protected]>; netdev at vger.kernel.org; mschmidt <[email protected]>; Brett Creeley <[email protected]>; open list <[email protected]>; poros <[email protected]>; moderated list:INTEL ETHERNET DRIVERS <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; David S. Miller <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net v2] ice: Fix incorrect locking inice_vc_process_vf_msg()Quoted 13 lines · Alexander Lobakin
From: Ivan Vecera <[email protected]>
Date: Fri, 1 Apr 2022 12:40:52 +0200Quoted 10 lines
Usage of
mutex_trylock()inice_vc_process_vf_msg()is incorrect because message sent from VF is ignored and never processed.Use
mutex_lock()instead to fix the issue. It is safe because this mutex is used to prevent races between VF related NDOs and handlers processing request messages from VF and these handlers are running inice_service_task()context. Additionally move this mutex lock priorice_vc_is_opcode_allowed()call to avoid potential races during allowlist acccess.Quoted 7 lines
Quoted 3 lines
Fixes e6ba5273d4ed ("ice: Fix race conditions between virtchnlhandling and VF ndo ops")
Signed-off-by Ivan Vecera <[email protected]>Hey Tony,
I guess you missed this one due to being on a vacation previously. It's been previously reviewed IIRC, could you take it into net-queue?
I remember applying this but I don't see it on the tree so I must be mistaken. :( I'll get it applied, thanks for catching.
-Tony
Quoted 4 lines
Quoted 4 lines
--- drivers/net/ethernet/intel/ice/ice_virtchnl.c | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-)
Quoted 6 lines
Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_virtchnl.c void ice_vc_process_vf_msg(struct ice_pf *pf,
Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_virtchnl.c +0
-0@@ -3642,14 +3642,6 @@ void ice_vc_process_vf_msg(struct ice_pf *pf,